[jboss-cvs] JBossAS SVN: r111883 - in projects/jboss-jca/trunk: adapters/src/main/resources/jdbc/local/META-INF and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 29 11:06:45 EDT 2011


Author: jesper.pedersen
Date: 2011-07-29 11:06:45 -0400 (Fri, 29 Jul 2011)
New Revision: 111883

Added:
   projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DataSourceTestCase.java
   projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverDataSourceTestCase.java
   projects/jboss-jca/trunk/adapters/src/test/resources/h2-datasource-ds.xml
   projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-datasource-ds.xml
Modified:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
   projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml
   projects/jboss-jca/trunk/adapters/src/test/resources/h2-xa-ds.xml
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DriverImpl.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java
   projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java
   projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml
Log:
[JBJCA-637] DataSource support

Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -24,6 +24,7 @@
 
 import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory;
 import org.jboss.jca.adapters.jdbc.spi.URLSelectorStrategy;
+import org.jboss.jca.adapters.jdbc.util.Injection;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -45,23 +46,27 @@
 import javax.resource.spi.ConnectionRequestInfo;
 import javax.resource.spi.ManagedConnection;
 import javax.security.auth.Subject;
+import javax.sql.DataSource;
 
-
 /**
  * LocalManagedConnectionFactory
  *
  * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
  * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 73443 $
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
  */
 public class LocalManagedConnectionFactory extends BaseWrapperManagedConnectionFactory
 {
-   private static final long serialVersionUID = 4698955390505160469L;
+   private static final long serialVersionUID = -2751268690794983375L;
 
    private String driverClass;
 
+   private String dataSourceClass;
+
    private transient Driver driver;
 
+   private transient DataSource dataSource;
+
    private String connectionURL;
 
    private URLSelectorStrategy urlSelector;
@@ -85,10 +90,10 @@
    public Object createConnectionFactory(ConnectionManager cm) throws ResourceException
    {
       // check some invariants before they come back to haunt us
-      if (driverClass == null)
+      if (driverClass == null && dataSourceClass == null)
          throw new ResourceException("driverClass is null");
 
-      if (connectionURL == null)
+      if (connectionURL == null && driverClass != null)
          throw new ResourceException("connectionURL is null");
 
       return super.createConnectionFactory(cm);
@@ -139,6 +144,27 @@
    }
 
    /**
+    * Get the DataSourceClass value.
+    *
+    * @return the DataSourceClass value.
+    */
+   public String getDataSourceClass()
+   {
+      return dataSourceClass;
+   }
+
+   /**
+    * Set the DataSourceClass value.
+    *
+    * @param dataSourceClass The new DataSourceClass value.
+    */
+   public synchronized void setDataSourceClass(final String dataSourceClass)
+   {
+      this.dataSourceClass = dataSourceClass;
+      driver = null;
+   }
+
+   /**
     * Get the value of connectionProperties.
     *
     * @return value of connectionProperties.
@@ -216,12 +242,22 @@
       Connection con = null;
       try
       {
-         String url = getConnectionURL();
-         Driver d = getDriver(url);
-         con = d.connect(url, copy);
-         if (con == null)
-            throw new ResourceException("Wrong driver class [" + d.getClass() + "] for this connection URL [" + url +
-                                        "]");
+         if (driverClass != null)
+         {
+            String url = getConnectionURL();
+            Driver d = getDriver(url);
+            con = d.connect(url, copy);
+            if (con == null)
+               throw new ResourceException("Wrong driver class [" + d.getClass() + "] for this connection URL [" +
+                                           url + "]");
+         }
+         else
+         {
+            DataSource d = getDataSource();
+            con = d.getConnection(copy.getProperty("user"), copy.getProperty("password"));
+            if (con == null)
+               throw new ResourceException("Unable to create connection from datasource");
+         }
 
          return new LocalManagedConnection(this, con, props, transactionIsolation, preparedStatementCacheSize);
       }
@@ -246,6 +282,9 @@
       throws ResourceException
    {
       boolean trace = log.isTraceEnabled();
+      
+      if (driverClass == null || driverClass.trim().equals(""))
+         throw new ResourceException("HALocalManagedConnection only supported with <driver-class>");
 
       // try to get a connection as many times as many urls we have in the list
       for (int i = 0; i < urlSelector.getCustomSortedUrls().size(); ++i)
@@ -485,6 +524,7 @@
       int result = 17;
       result = result * 37 + ((connectionURL == null) ? 0 : connectionURL.hashCode());
       result = result * 37 + ((driverClass == null) ? 0 : driverClass.hashCode());
+      result = result * 37 + ((dataSourceClass == null) ? 0 : dataSourceClass.hashCode());
       result = result * 37 + ((userName == null) ? 0 : userName.hashCode());
       result = result * 37 + ((password == null) ? 0 : password.hashCode());
       result = result * 37 + transactionIsolation;
@@ -505,7 +545,10 @@
 
       LocalManagedConnectionFactory otherMcf = (LocalManagedConnectionFactory) other;
 
-      return this.connectionURL.equals(otherMcf.connectionURL) && this.driverClass.equals(otherMcf.driverClass)
+      return this.connectionURL.equals(otherMcf.connectionURL)
+         && ((this.driverClass == null) ? otherMcf.driverClass == null : this.driverClass.equals(otherMcf.driverClass))
+         && ((this.dataSourceClass == null) ? otherMcf.dataSourceClass == null : 
+             this.dataSourceClass.equals(otherMcf.dataSourceClass))
          && ((this.userName == null) ? otherMcf.userName == null : this.userName.equals(otherMcf.userName))
          && ((this.password == null) ? otherMcf.password == null : this.password.equals(otherMcf.password))
          && this.transactionIsolation == otherMcf.transactionIsolation;
@@ -528,6 +571,7 @@
       {
          return driver;
       }
+
       if (trace)
          log.trace("Checking driver for URL: " + url);
 
@@ -536,26 +580,27 @@
          throw new ResourceException("No Driver class specified (url = " + url + ")!");
       }
 
+      String driverKey = url.substring(0, url.indexOf(":", 6));
+
       // Check if the driver is already loaded, if not then try to load it
+      driver = driverCache.get(driverKey);
+      if (driver != null)
+         return driver;
 
-      driver = driverCache.get(url.substring(0, url.indexOf(":", 6)));
-
       try
       {
-         //try to load the class... this should register with DriverManager.
+         // Load class to trigger static initialization of the driver
          Class<?> clazz = Class.forName(driverClass, true, getClassLoaderPlugin().getClassLoader());
+
          if (isDriverLoadedForURL(url))
-            //return immediately, some drivers (Cloudscape) do not let you create an instance.
             return driver;
 
-         //We loaded the class, but either it didn't register
-         //and is not spec compliant, or is the wrong class.
-         driver = (Driver) clazz.newInstance();
+         driver = (Driver)clazz.newInstance();
+
          DriverManager.registerDriver(driver);
-         log.debug("class loaded and instance created:" + driver);
+         log.debug("Driver loaded and instance created:" + driver);
 
-         driverCache.put(url.substring(0, url.indexOf(":", 6)), driver);
-         //We can even instantiate one, it must be the wrong class for the URL.
+         driverCache.put(driverKey, driver);
       }
       catch (Exception e)
       {
@@ -574,14 +619,17 @@
       {
          Thread.currentThread().setContextClassLoader(getClassLoaderPlugin().getClassLoader());
          driver = DriverManager.getDriver(url);
+
          if (trace)
             log.trace("Driver already registered for url: " + url);
+
          return true;
       }
       catch (Exception e)
       {
          if (trace)
             log.trace("Driver not yet registered for url: " + url);
+
          return false;
       }
       finally
@@ -598,4 +646,50 @@
    {
       return connectionURL;
    }
+
+   /**
+    * Get the datasource instance
+    * @return The handle
+    * @exception ResourceException Thrown if an error occurs
+    */
+   private synchronized DataSource getDataSource() throws ResourceException
+   {
+      if (dataSource == null)
+      {
+         if (dataSourceClass == null || dataSourceClass.trim().equals(""))
+            throw new ResourceException("DataSourceClass not defined");
+
+         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+         try
+         {
+            Thread.currentThread().setContextClassLoader(getClassLoaderPlugin().getClassLoader());
+
+            Class<?> clz = Class.forName(dataSourceClass, true, getClassLoaderPlugin().getClassLoader());
+            dataSource = (DataSource)clz.newInstance();
+
+            if (connectionProps != null)
+            {
+               Injection injector = new Injection();
+               Iterator<Map.Entry<Object, Object>> it = connectionProps.entrySet().iterator();
+               while (it.hasNext())
+               {
+                  Map.Entry<Object, Object> entry = it.next();
+                  String key = (String)entry.getKey();
+                  String value = (String)entry.getValue();
+                  injector.inject(dataSource, key, value);
+               }
+            }
+         }
+         catch (Throwable t)
+         {
+            throw new ResourceException("Failed to load datasource: " + dataSourceClass, t);
+         }
+         finally
+         {
+            Thread.currentThread().setContextClassLoader(tccl);
+         }
+      }
+
+      return dataSource;
+   }
 }

Modified: projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml	2011-07-29 15:06:45 UTC (rev 111883)
@@ -48,6 +48,11 @@
           <config-property-type>java.lang.String</config-property-type>
         </config-property>
         <config-property>
+          <description>The jdbc datasource class.</description>
+          <config-property-name>DataSourceClass</config-property-name>
+          <config-property-type>java.lang.String</config-property-type>
+        </config-property>
+        <config-property>
           <description>The jdbc connection url class.</description>
           <config-property-name>ConnectionURL</config-property-name>
           <config-property-type>java.lang.String</config-property-type>

Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DataSourceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DataSourceTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DataSourceTestCase.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.unit;
+
+import org.jboss.jca.adapters.ArquillianJCATestUtils;
+import org.jboss.jca.embedded.dsl.InputStreamDescriptor;
+
+import java.sql.Connection;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptor;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test cases for getting a connection from the H2 database
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class H2DataSourceTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- GIVEN --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Define the deployment
+    * @return The deployment archive
+    * @throws Exception in case of errors
+    */
+   @Deployment(order = 1)
+   public static ResourceAdapterArchive createArchive() throws Exception
+   {
+      return ArquillianJCATestUtils.buildShrinkwrapJdbcLocal();
+   }
+
+   /**
+    * Define the -ds.xml
+    * @return The deployment archive
+    * @throws Exception in case of errors
+    */
+   @Deployment(order = 2)
+   public static Descriptor createDescriptor() throws Exception
+   {
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      InputStreamDescriptor isd = new InputStreamDescriptor("h2-datasource-ds.xml",
+                                                            cl.getResourceAsStream("h2-datasource-ds.xml"));
+      return isd;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- WHEN  --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   //
+   @Resource(mappedName = "java:/H2DS")
+   private DataSource ds;
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- THEN  --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Basic
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testBasic() throws Throwable
+   {
+      assertNotNull(ds);
+      Connection c = ds.getConnection();
+      assertNotNull(c);
+   }
+}

Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverDataSourceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverDataSourceTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverDataSourceTestCase.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.unit;
+
+import org.jboss.jca.adapters.ArquillianJCATestUtils;
+import org.jboss.jca.embedded.dsl.InputStreamDescriptor;
+
+import java.sql.Connection;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptor;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test cases for getting a connection from the H2 database
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class H2DriverDataSourceTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- GIVEN --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Define the deployment
+    * @return The deployment archive
+    * @throws Exception in case of errors
+    */
+   @Deployment(order = 1)
+   public static ResourceAdapterArchive createArchive() throws Exception
+   {
+      return ArquillianJCATestUtils.buildShrinkwrapJdbcLocal();
+   }
+
+   /**
+    * Define the -ds.xml
+    * @return The deployment archive
+    * @throws Exception in case of errors
+    */
+   @Deployment(order = 2)
+   public static Descriptor createDescriptor() throws Exception
+   {
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      InputStreamDescriptor isd = new InputStreamDescriptor("h2-driver-datasource-ds.xml",
+                                                            cl.getResourceAsStream("h2-driver-datasource-ds.xml"));
+      return isd;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- WHEN  --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   //
+   @Resource(mappedName = "java:/H2DS")
+   private DataSource ds;
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- THEN  --------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Basic
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testBasic() throws Throwable
+   {
+      assertNotNull(ds);
+      Connection c = ds.getConnection();
+      assertNotNull(c);
+   }
+}

Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-datasource-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-datasource-ds.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-datasource-ds.xml	2011-07-29 15:06:45 UTC (rev 111883)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
+  <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+    <datasource-class>org.h2.jdbcx.JdbcDataSource</datasource-class>
+    <connection-property name="URL">jdbc:h2:mem:test</connection-property>
+    <security>
+      <user-name>sa</user-name>
+      <password>sa</password>
+    </security>
+  </datasource>
+
+</datasources>

Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-datasource-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-datasource-ds.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-datasource-ds.xml	2011-07-29 15:06:45 UTC (rev 111883)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
+  <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+    <driver>h2</driver>
+    <connection-property name="URL">jdbc:h2:mem:test</connection-property>
+    <security>
+      <user-name>sa</user-name>
+      <password>sa</password>
+    </security>
+  </datasource>
+  <drivers>
+      <driver name="h2">
+         <datasource-class>org.h2.jdbcx.JdbcDataSource</datasource-class>
+      </driver>
+  </drivers>
+
+</datasources>

Modified: projects/jboss-jca/trunk/adapters/src/test/resources/h2-xa-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-xa-ds.xml	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-xa-ds.xml	2011-07-29 15:06:45 UTC (rev 111883)
@@ -3,7 +3,7 @@
 <datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
   <xa-datasource jndi-name="java:/H2XADS" pool-name="H2XADS">
-   <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
+    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
     <xa-datasource-property name="URL">jdbc:h2:mem:test</xa-datasource-property>
     <security>
        <!-- Have to defined as a primary property - otherwise it won't work -->

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -56,6 +56,13 @@
    public String getDriverClass();
 
    /**
+    * Get the dataSourceClass.
+    *
+    * @return the value.
+    */
+   public String getDataSourceClass();
+
+   /**
     * Get the connectionProperties.
     *
     * @return the connectionProperties.
@@ -127,6 +134,10 @@
       */
       DRIVERCLASS("driver-class"),
       /**
+      * dataSourceClass tag
+      */
+      DATASOURCECLASS("datasource-class"),
+      /**
       * module tag
       */
       DRIVER("driver"),

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -73,6 +73,12 @@
     */
    public String getDriverClass();
 
+   /**
+    * Get the DataSourceClass.
+    *
+    * @return the DataSourceClass.
+    */
+   public String getDataSourceClass();
 
    /**
     * Get the XaDataSourceClass.
@@ -81,15 +87,13 @@
     */
    public String getXaDataSourceClass();
 
-
-
    /**
-   *
-   * A Tag.
-   *
-   * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
-   *
-   */
+    *
+    * A Tag.
+    *
+    * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+    *
+    */
    public enum Tag
    {
       /** always first
@@ -101,7 +105,13 @@
        * driverClass tag
        */
       DRIVERCLASS("driver-class"),
+
       /**
+       * DatasourceClass tag
+       */
+      DATASOURCECLASS("datasource-class"),
+
+      /**
        * xaDatasourceClass tag
        */
       XADATASOURCECLASS("xa-datasource-class");

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -58,6 +58,8 @@
 
    private String driverClass;
 
+   private String dataSourceClass;
+
    private final String driver;
 
    private final HashMap<String, String> connectionProperties;
@@ -71,6 +73,7 @@
     *
     * @param connectionUrl connectionUrl
     * @param driverClass driverClass
+    * @param dataSourceClass dataSourceClass
     * @param driver driver
     * @param transactionIsolation transactionIsolation
     * @param connectionProperties connectionProperties
@@ -91,7 +94,7 @@
     * @param pool pool
     * @throws ValidateException ValidateException
     */
-   public DataSourceImpl(String connectionUrl, String driverClass, String driver,
+   public DataSourceImpl(String connectionUrl, String driverClass, String dataSourceClass, String driver,
                          TransactionIsolation transactionIsolation, Map<String, String> connectionProperties, 
                          TimeOut timeOut, DsSecurity security, Statement statement, Validation validation, 
                          String urlDelimiter, String urlSelectorStrategyClassName, String newConnectionSql, 
@@ -104,6 +107,7 @@
       this.jta = jta;
       this.connectionUrl = connectionUrl;
       this.driverClass = driverClass;
+      this.dataSourceClass = dataSourceClass;
       this.driver = driver;
       if (connectionProperties != null)
       {
@@ -150,6 +154,17 @@
    }
 
    /**
+    * Get the dataSourceClass.
+    *
+    * @return the dataSourceClass.
+    */
+   @Override
+   public final String getDataSourceClass()
+   {
+      return dataSourceClass;
+   }
+
+   /**
     * Get the driver.
     *
     * @return the driver.
@@ -235,6 +250,7 @@
       result = prime * result + ((connectionUrl == null) ? 0 : connectionUrl.hashCode());
       result = prime * result + ((driver == null) ? 0 : driver.hashCode());
       result = prime * result + ((driverClass == null) ? 0 : driverClass.hashCode());
+      result = prime * result + ((dataSourceClass == null) ? 0 : dataSourceClass.hashCode());
       result = prime * result + ((newConnectionSql == null) ? 0 : newConnectionSql.hashCode());
       result = prime * result + ((pool == null) ? 0 : pool.hashCode());
       return result;
@@ -278,6 +294,13 @@
       }
       else if (!driverClass.equals(other.driverClass))
          return false;
+      if (dataSourceClass == null)
+      {
+         if (other.dataSourceClass != null)
+            return false;
+      }
+      else if (!dataSourceClass.equals(other.dataSourceClass))
+         return false;
       if (newConnectionSql == null)
       {
          if (other.newConnectionSql != null)
@@ -298,19 +321,21 @@
    @Override
    public String toString()
    {
-      return "DataSourceImpl [connectionUrl=" + connectionUrl + ", driverClass=" + driverClass + ", driver=" +
-             driver + ", connectionProperties=" + connectionProperties + ", newConnectionSql=" + newConnectionSql +
-             ", pool=" + pool + "]";
+      return "DataSourceImpl [connectionUrl=" + connectionUrl + ", driverClass=" + driverClass +
+         ", dataSourceClass=" + dataSourceClass + ", driver=" + driver +
+         ", connectionProperties=" + connectionProperties + ", newConnectionSql=" + newConnectionSql +
+         ", pool=" + pool + "]";
    }
 
    @Override
    public void validate() throws ValidateException
    {
-      if (this.connectionUrl == null || this.connectionUrl.trim().length() == 0)
+      if (this.driverClass != null && (this.connectionUrl == null || this.connectionUrl.trim().length() == 0))
          throw new ValidateException(bundle.requiredElementMissing(Tag.CONNECTIONURL.getLocalName(), 
                                                                    this.getClass().getCanonicalName()));
-
+      
       if ((this.driverClass == null || this.driverClass.trim().length() == 0) &&
+          (this.dataSourceClass == null || this.dataSourceClass.trim().length() == 0) &&
           (this.driver == null || this.driver.trim().length() == 0))
          throw new ValidateException(bundle.requiredElementMissing(Tag.DRIVERCLASS.getLocalName(), 
                                                                    this.getClass().getCanonicalName()));
@@ -325,4 +350,14 @@
    {
       this.driverClass = driverClass;
    }
+
+   /**
+    * Set the dataSourceClass.
+    *
+    * @param dataSourceClass The dataSourceClass to set.
+    */
+   public final void forceDataSourceClass(String dataSourceClass)
+   {
+      this.dataSourceClass = dataSourceClass;
+   }
 }

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DriverImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DriverImpl.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DriverImpl.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -53,6 +53,8 @@
 
    private final String driverClass;
 
+   private final String dataSourceClass;
+
    private final String xaDataSourceClass;
 
    /**
@@ -63,11 +65,12 @@
     * @param minorVersion minorVersion
     * @param module module
     * @param driverClass driverClass
+    * @param dataSourceClass xaDataSourceClass
     * @param xaDataSourceClass xaDataSourceClass
     * @throws ValidateException in case name is not specified
     */
    public DriverImpl(String name, Integer majorVersion, Integer minorVersion, String module, String driverClass,
-      String xaDataSourceClass)
+                     String dataSourceClass, String xaDataSourceClass)
       throws ValidateException
    {
       super();
@@ -76,6 +79,7 @@
       this.minorVersion = minorVersion;
       this.module = module;
       this.driverClass = driverClass;
+      this.dataSourceClass = dataSourceClass;
       this.xaDataSourceClass = xaDataSourceClass;
       this.validate();
    }
@@ -120,6 +124,17 @@
    }
 
    /**
+    * Get the dataSourceClass.
+    *
+    * @return the value
+    */
+   @Override
+   public final String getDataSourceClass()
+   {
+      return dataSourceClass;
+   }
+
+   /**
     * Get the xsDataSourceClass.
     *
     * @return the xsDataSourceClass.
@@ -155,7 +170,8 @@
    public String toString()
    {
       return "DriverImpl [name=" + name + ", minorVersion=" + minorVersion + ", majorVersion=" + majorVersion +
-             ", module=" + module + ", driverClass=" + driverClass + ", xaDataSourceClass=" + xaDataSourceClass + "]";
+         ", module=" + module + ", driverClass=" + driverClass + ", dataSourceClass=" + dataSourceClass + 
+         ", xaDataSourceClass=" + xaDataSourceClass + "]";
    }
 
    @Override
@@ -168,6 +184,7 @@
       result = prime * result + ((minorVersion == null) ? 0 : minorVersion.hashCode());
       result = prime * result + ((module == null) ? 0 : module.hashCode());
       result = prime * result + ((name == null) ? 0 : name.hashCode());
+      result = prime * result + ((dataSourceClass == null) ? 0 : dataSourceClass.hashCode());
       result = prime * result + ((xaDataSourceClass == null) ? 0 : xaDataSourceClass.hashCode());
       return result;
    }
@@ -217,6 +234,13 @@
       }
       else if (!name.equals(other.name))
          return false;
+      if (dataSourceClass == null)
+      {
+         if (other.dataSourceClass != null)
+            return false;
+      }
+      else if (!dataSourceClass.equals(other.dataSourceClass))
+         return false;
       if (xaDataSourceClass == null)
       {
          if (other.xaDataSourceClass != null)

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -191,9 +191,9 @@
    private Driver parseDriver(XMLStreamReader reader) throws XMLStreamException, ParserException,
       ValidateException
    {
-
+      String driverClass = null;
+      String dataSourceClass = null;
       String xaDataSourceClass = null;
-      String driverClass = null;
 
       //attributes reading
 
@@ -237,7 +237,8 @@
                if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DRIVER)
                {
 
-                  return new DriverImpl(name, majorVersion, minorVersion, module, driverClass, xaDataSourceClass);
+                  return new DriverImpl(name, majorVersion, minorVersion, module, 
+                                        driverClass, dataSourceClass, xaDataSourceClass);
                }
                else
                {
@@ -251,6 +252,10 @@
             case START_ELEMENT : {
                switch (Driver.Tag.forName(reader.getLocalName()))
                {
+                  case DATASOURCECLASS : {
+                     dataSourceClass = elementAsString(reader);
+                     break;
+                  }
                   case XADATASOURCECLASS : {
                      xaDataSourceClass = elementAsString(reader);
                      break;
@@ -481,6 +486,7 @@
    {
       String connectionUrl = null;
       String driverClass = null;
+      String dataSourceClass = null;
       String driver = null;
       TransactionIsolation transactionIsolation = null;
       Map<String, String> connectionProperties = new HashMap<String, String>();
@@ -548,7 +554,7 @@
                if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE)
                {
 
-                  return new DataSourceImpl(connectionUrl, driverClass, driver, transactionIsolation,
+                  return new DataSourceImpl(connectionUrl, driverClass, dataSourceClass, driver, transactionIsolation,
                                             connectionProperties, timeOutSettings, securitySettings,
                                             statementSettings, validationSettings, urlDelimiter,
                                             urlSelectorStrategyClassName, newConnectionSql, useJavaContext, poolName,
@@ -578,6 +584,10 @@
                      driverClass = elementAsString(reader);
                      break;
                   }
+                  case DATASOURCECLASS : {
+                     dataSourceClass = elementAsString(reader);
+                     break;
+                  }
                   case DRIVER : {
                      driver = elementAsString(reader);
                      break;

Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -729,6 +729,13 @@
                   }
                   break;
                }
+               case DATASOURCECLASS : {
+                  if (ds != null && ds.getDataSourceClass() != null)
+                  {
+                     configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getDataSourceClass()));
+                  }
+                  break;
+               }
                case URLPROPERTY :
                case CONNECTIONPROPERTIES : {
                   if (ds != null && ds.getConnectionProperties() != null)
@@ -847,6 +854,8 @@
          UNKNOWN(null, null, null),
          /** DRIVERCLASS **/
          DRIVERCLASS("DriverClass", "java.lang.String", "The jdbc driver class."),
+         /** DATASOURCECLASS **/
+         DATASOURCECLASS("DataSourceClass", "java.lang.String", "The jdbc datasource class."),
          /** CONNECTIONURL **/
          CONNECTIONURL("ConnectionURL", "java.lang.String", "The jdbc connection url class."),
          /** CONNECTIONPROPERTIES **/

Modified: projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
===================================================================
--- projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd	2011-07-29 15:06:45 UTC (rev 111883)
@@ -58,6 +58,15 @@
           </xs:documentation>
         </xs:annotation>
       </xs:element>
+      <xs:element name="datasource-class" type="xs:token" maxOccurs="1" minOccurs="0">
+        <xs:annotation>
+          <xs:documentation>
+            <![CDATA[[
+              The fully qualifed name of the JDBC datasource class Ex: <datasource-class>org.h2.jdbcx.JdbcDataSource</datasource-class>
+             ]]>
+          </xs:documentation>
+        </xs:annotation>
+      </xs:element>
       <xs:element name="driver" type="xs:token" minOccurs="0">
         <xs:annotation>
           <xs:documentation>
@@ -848,9 +857,7 @@
       </xs:annotation>
     </xs:attribute>
   </xs:complexType>
-  
 
-
   <xs:complexType name="driverType">
     <xs:sequence>
       <xs:element name="driver-class" type="xs:token" maxOccurs="1" minOccurs="0">
@@ -862,6 +869,15 @@
           </xs:documentation>
         </xs:annotation>
       </xs:element>
+      <xs:element name="datasource-class" type="xs:token" maxOccurs="1" minOccurs="0">
+      <xs:annotation>
+          <xs:documentation>
+           <![CDATA[[
+              The fully qualifed name of the javax.sql.DataSource implementation 
+              class.
+             ]]>
+          </xs:documentation>
+        </xs:annotation></xs:element>
       <xs:element name="xa-datasource-class" type="xs:token" maxOccurs="1" minOccurs="0">
       <xs:annotation>
           <xs:documentation>

Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java	2011-07-29 15:06:45 UTC (rev 111883)
@@ -263,6 +263,20 @@
                               ((DataSourceImpl) dataSource).forceDriverClass(driverClass);
                         }
 
+                        if (dataSource.getDriverClass() == null && dataSource.getDataSourceClass() == null &&
+                            dataSource.getDriver() != null && dataSource instanceof DataSourceImpl)
+                        {
+                           String driverName = dataSource.getDriver();
+
+                           if (dataSources.getDriver(driverName) != null)
+                           {
+                              String dataSourceClass = dataSources.getDriver(driverName).getDataSourceClass();
+
+                              if (dataSources != null)
+                                 ((DataSourceImpl) dataSource).forceDataSourceClass(dataSourceClass);
+                           }
+                        }
+
                         Object cf = deployDataSource(dataSource, jndiName,
                                                      uniqueJdbcLocalId, mgtDataSource, jdbcLocalDeploymentCl);
 

Modified: projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml
===================================================================
--- projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml	2011-07-29 13:32:24 UTC (rev 111882)
+++ projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml	2011-07-29 15:06:45 UTC (rev 111883)
@@ -749,6 +749,12 @@
                 </entry>
               </row>
               <row>
+                <entry><code>datasource-class</code></entry>
+                <entry>
+                  The fully qualifed name of the JDBC datasource class
+                </entry>
+              </row>
+              <row>
                 <entry><code>driver</code></entry>
                 <entry>
                   An unique name for the JDBC driver specified in the drivers section.
@@ -1406,6 +1412,12 @@
                 </entry>
               </row>
               <row>
+                <entry><code>datasource-class</code></entry>
+                <entry>
+                  The fully qualified class name of the datasource class
+                </entry>
+              </row>
+              <row>
                 <entry><code>xa-datasource-class</code></entry>
                 <entry>
                   The fully qualified class name of the XA datasource class



More information about the jboss-cvs-commits mailing list