[mule-scm] [mule][25307] branches/mule-3.x/transports/jdbc/src: MULE-6649: Addition of DB2 and MS SQL Server to the list of databases on Studio JDBC connector configuration window

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[mule-scm] [mule][25307] branches/mule-3.x/transports/jdbc/src: MULE-6649: Addition of DB2 and MS SQL Server to the list of databases on Studio JDBC connector configuration window

pablo.kraan
[mule][25307] branches/mule-3.x/transports/jdbc/src: MULE-6649: Addition of DB2 and MS SQL Server to the list of databases on Studio JDBC connector configuration window

Diff

Added: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/Db2DatasourceFactoryBean.java (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/Db2DatasourceFactoryBean.java	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/Db2DatasourceFactoryBean.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.transport.jdbc.config;
+
+public class Db2DatasourceFactoryBean extends AbstractHostPortDatabaseDataSourceFactoryBean
+{
+    private static final String DRIVER_CLASS_NAME = "com.ibm.db2.jcc.DB2Driver";
+    private static final String JDBC_URL_PREFIX = "jdbc:db2://";
+
+    public Db2DatasourceFactoryBean()
+    {
+        super();
+        driverClassName = DRIVER_CLASS_NAME;
+        updateUrl();
+    }
+
+    @Override
+    protected String getJdbcUrlPrefix()
+    {
+        return JDBC_URL_PREFIX;
+    }
+}
Property changes on: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/Db2DatasourceFactoryBean.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Modified: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/JdbcNamespaceHandler.java (25306 => 25307)


--- branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/JdbcNamespaceHandler.java	2013-02-26 01:26:25 UTC (rev 25306)
+++ branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/JdbcNamespaceHandler.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -30,8 +30,9 @@
  */
 public class JdbcNamespaceHandler extends AbstractMuleNamespaceHandler
 {
+
     public static final String QUERY_KEY = "queryKey";
-    public static final String[] ADDRESS_ATTRIBUTES = new String[]{QUERY_KEY};
+    public static final String[] ADDRESS_ATTRIBUTES = new String[] {QUERY_KEY};
     public static final String SQL_STATEMENT_FACTORY_PROPERTY = "sqlStatementStrategyFactory";
 
     @Override
@@ -55,8 +56,10 @@
     {
         registerDerbyDataSourceDefinitionParser();
         registerMysqlDataSourceDefinitionParser();
-        registerOracleDataSourceDefinitionParser();
+        registerInstanceDatasource("oracle-data-source", OracleDataSourceFactoryBean.class);
         registerPostgresqlDataSourceDefinitionParser();
+        registerDb2DataSourceDefinitionParser();
+        registerInstanceDatasource("mssql-data-source", MssqlDatasourceFactoryBean.class);
     }
 
     protected void registerDerbyDataSourceDefinitionParser()
@@ -72,38 +75,56 @@
     protected void registerMysqlDataSourceDefinitionParser()
     {
         registerHostAndPortTypeDefinitionParser(MysqlDataSourceFactoryBean.class,
-            "mysql-data-source");
+                                                "mysql-data-source");
     }
 
-    protected void registerOracleDataSourceDefinitionParser()
+    protected void registerDb2DataSourceDefinitionParser()
     {
-        DataSourceDefinitionParser parser = new DataSourceDefinitionParser(OracleDataSourceFactoryBean.class);
+        DataSourceDefinitionParser parser = new DataSourceDefinitionParser(Db2DatasourceFactoryBean.class);
 
+        // make sure that either url or host/port are configured
         String[][] attributeGroups = new String[][] {
-            new String[] { "url" },
-            new String[] { "host", "port", "instance" }
+                new String[] {"url"},
+                new String[] {"host", "port", "database"}
         };
         CheckExclusiveAttributes attributeCheck = new CheckExclusiveAttributes(attributeGroups);
         parser.registerPreProcessor(attributeCheck);
 
-        registerBeanDefinitionParser("oracle-data-source", parser);
+        // make sure that either url or database is configured
+        parser.registerPreProcessor(new CheckDatabaseOrUrl());
+
+        registerBeanDefinitionParser("db2-data-source", parser);
     }
 
+    private void registerInstanceDatasource(String elementName, Class<? extends AbstractDataSourceFactoryBean> poolFactoryClass)
+    {
+        DataSourceDefinitionParser parser = new DataSourceDefinitionParser(poolFactoryClass);
+
+        String[][] attributeGroups = new String[][] {
+                new String[] {"url"},
+                new String[] {"host", "port", "instance"}
+        };
+        CheckExclusiveAttributes attributeCheck = new CheckExclusiveAttributes(attributeGroups);
+        parser.registerPreProcessor(attributeCheck);
+
+        registerBeanDefinitionParser(elementName, parser);
+    }
+
     protected void registerPostgresqlDataSourceDefinitionParser()
     {
         registerHostAndPortTypeDefinitionParser(PostgresqlDataSourceFactoryBean.class,
-            "postgresql-data-source");
+                                                "postgresql-data-source");
     }
 
     protected void registerHostAndPortTypeDefinitionParser(Class<? extends AbstractDataSourceFactoryBean> poolFactoryClass,
-        String elementName)
+                                                           String elementName)
     {
         DataSourceDefinitionParser parser = new DataSourceDefinitionParser(poolFactoryClass);
 
         // make sure that either url or host/port are configured
         String[][] attributeGroups = new String[][] {
-            new String[] { "url" },
-            new String[] { "host", "port" }
+                new String[] {"url"},
+                new String[] {"host", "port"}
         };
         CheckExclusiveAttributes attributeCheck = new CheckExclusiveAttributes(attributeGroups);
         parser.registerPreProcessor(attributeCheck);

Added: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/MssqlDatasourceFactoryBean.java (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/MssqlDatasourceFactoryBean.java	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/MssqlDatasourceFactoryBean.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.transport.jdbc.config;
+
+public class MssqlDatasourceFactoryBean extends AbstractHostPortDatabaseDataSourceFactoryBean
+{
+    private static final String DRIVER_CLASS_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+    private static final String JDBC_URL_PREFIX = "jdbc:sqlserver://";
+
+    public MssqlDatasourceFactoryBean()
+    {
+        super();
+        driverClassName = DRIVER_CLASS_NAME;
+        updateUrl();
+    }
+
+    @Override
+    protected String getJdbcUrlPrefix()
+    {
+        return JDBC_URL_PREFIX;
+    }
+}
Property changes on: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/config/MssqlDatasourceFactoryBean.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Modified: branches/mule-3.x/transports/jdbc/src/main/resources/META-INF/mule-jdbc.xsd (25306 => 25307)


--- branches/mule-3.x/transports/jdbc/src/main/resources/META-INF/mule-jdbc.xsd	2013-02-26 01:26:25 UTC (rev 25306)
+++ branches/mule-3.x/transports/jdbc/src/main/resources/META-INF/mule-jdbc.xsd	2013-02-26 13:44:47 UTC (rev 25307)
@@ -497,4 +497,64 @@
             </xsd:extension>
         </xsd:complexContent>
     </xsd:complexType>
+
+    <xsd:element name="db2-data-source" type="db2DataSourceType" substitutionGroup="mule:abstract-extension"/>
+
+    <xsd:complexType name="db2DataSourceType">
+        <xsd:complexContent>
+            <xsd:extension base="abstractDataSourceMandatoryUserAndPasswordType">
+                <xsd:attribute name="host" type="xsd:string" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the host part of the JDBC URL (and leave the rest of the default JDBC URL untouched).
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+                <xsd:attribute name="port" type="xsd:int" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the port part of the JDBC URL (and leave the rest of the default JDBC URL untouched).
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+                <xsd:attribute name="database" type="xsd:string" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the database part of the JDBC URL (and leave the rest of the default JDBC URL untouched). When no server/port are defined, database points to a native component and requires native libraries.
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
+    <xsd:element name="mssql-data-source" type="mssqlDataSourceType" substitutionGroup="mule:abstract-extension"/>
+
+    <xsd:complexType name="mssqlDataSourceType">
+        <xsd:complexContent>
+            <xsd:extension base="abstractDataSourceMandatoryUserAndPasswordType">
+                <xsd:attribute name="host" type="xsd:string" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the host part of the JDBC URL (and leave the rest of the default JDBC URL untouched).
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+                <xsd:attribute name="port" type="xsd:int" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the port part of the JDBC URL (and leave the rest of the default JDBC URL untouched).
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+                <xsd:attribute name="instance" type="xsd:string" use="optional">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Allows to configure just the instance part of the JDBC URL (and leave the rest of the default JDBC URL untouched). If not specified, the default instance is used
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
 </xsd:schema>

Modified: branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/AbstractDataSourceConfigurationTestCase.java (25306 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/AbstractDataSourceConfigurationTestCase.java	2013-02-26 01:26:25 UTC (rev 25306)
+++ branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/AbstractDataSourceConfigurationTestCase.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -10,6 +10,7 @@
 
 package org.mule.transport.jdbc.config;
 
+import static org.junit.Assert.fail;
 import org.mule.api.MuleException;
 import org.mule.api.config.ConfigurationBuilder;
 import org.mule.api.context.MuleContextFactory;
@@ -17,8 +18,6 @@
 import org.mule.context.DefaultMuleContextFactory;
 import org.mule.tck.junit4.AbstractMuleTestCase;
 
-import static org.junit.Assert.fail;
-
 public class AbstractDataSourceConfigurationTestCase extends AbstractMuleTestCase
 {
     protected void tryBuildingMuleContextFromInvalidConfig(String config) throws MuleException

Added: branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/Db2DataSourceConfigurationTestCase.java (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/Db2DataSourceConfigurationTestCase.java	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/Db2DataSourceConfigurationTestCase.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,31 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.transport.jdbc.config;
+
+import org.mule.api.MuleException;
+import org.mule.api.config.ConfigurationException;
+
+import org.junit.Test;
+
+public class Db2DataSourceConfigurationTestCase extends AbstractDataSourceConfigurationTestCase
+{
+    @Test(expected=ConfigurationException.class)
+    public void failWhenUrlAndDatabaseConfigured() throws MuleException
+    {
+        tryBuildingMuleContextFromInvalidConfig("jdbc-data-source-db2-url-and-database.xml");
+    }
+
+    @Test(expected=ConfigurationException.class)
+    public void failWhenUrlAndHostConfigured() throws MuleException
+    {
+        tryBuildingMuleContextFromInvalidConfig("jdbc-data-source-db2-url-and-host.xml");
+    }
+}
Property changes on: branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/Db2DataSourceConfigurationTestCase.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/MssqlDataSourceConfigurationTestCase.java (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/MssqlDataSourceConfigurationTestCase.java	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/MssqlDataSourceConfigurationTestCase.java	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,26 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.transport.jdbc.config;
+
+import org.mule.api.MuleException;
+import org.mule.api.config.ConfigurationException;
+
+import org.junit.Test;
+
+public class MssqlDataSourceConfigurationTestCase extends AbstractDataSourceConfigurationTestCase
+{
+
+    @Test(expected=ConfigurationException.class)
+    public void failWhenUrlAndHostConfigured() throws MuleException
+    {
+        tryBuildingMuleContextFromInvalidConfig("jdbc-data-source-mssql-url-and-host.xml");
+    }
+}
Property changes on: branches/mule-3.x/transports/jdbc/src/test/java/org/mule/transport/jdbc/config/MssqlDataSourceConfigurationTestCase.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-database.xml (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-database.xml	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-database.xml	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
+      xsi:schemaLocation="
+        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+        http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd">
+
+    <!-- this data source has both url and database configured, can only be one of both -->
+    <jdbc:db2-data-source name="db2ds" url="jdbc:db2:muleDatabase" database="mule" user="admin" password="secret"/>
+</mule>
Property changes on: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-database.xml
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-host.xml (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-host.xml	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-host.xml	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
+      xsi:schemaLocation="
+        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+        http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd">
+
+    <!-- this data source has both url and host/port configured, can only be one of both -->
+    <jdbc:db2-data-source name="db2ds" url="jdbc:db2://localhost/mule" database="mule"
+                            host="localhost" port="3306" user="admin" password="secret"/>
+</mule>
Property changes on: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-db2-url-and-host.xml
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-mssql-url-and-host.xml (0 => 25307)


--- branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-mssql-url-and-host.xml	                        (rev 0)
+++ branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-mssql-url-and-host.xml	2013-02-26 13:44:47 UTC (rev 25307)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
+      xsi:schemaLocation="
+        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+        http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd">
+
+    <!-- this data source has both url and host configured, can only be one of both -->
+    <jdbc:mssql-data-source name="mysqlDs" url="jdbc:sqlserver://localhost/mule"
+                             host="localhost" user="scott" password="tiger"/>
+</mule>
Property changes on: branches/mule-3.x/transports/jdbc/src/test/resources/jdbc-data-source-mssql-url-and-host.xml
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email