[jboss-cvs] JBossAS SVN: r111456 - in projects/jboss-jca/trunk: adapters/src/test/resources and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 26 09:33:13 EDT 2011


Author: jesper.pedersen
Date: 2011-05-26 09:33:12 -0400 (Thu, 26 May 2011)
New Revision: 111456

Added:
   projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2NonJTATestCase.java
   projects/jboss-jca/trunk/adapters/src/test/resources/h2-nonjta-ds.xml
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/metadata/ds/DataSourceImpl.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.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-588] Support non JTA datasources

Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2NonJTATestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2NonJTATestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2NonJTATestCase.java	2011-05-26 13:33:12 UTC (rev 111456)
@@ -0,0 +1,105 @@
+/*
+ * 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 non JTA H2 database
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class H2NonJTATestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   //---------------------- 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-nonjta-ds.xml", cl.getResourceAsStream("h2-nonjta-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);
+      c.close();
+   }
+}

Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-nonjta-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-nonjta-ds.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-nonjta-ds.xml	2011-05-26 13:33:12 UTC (rev 111456)
@@ -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" jta="false">
+    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+    <driver-class>org.h2.Driver</driver-class>
+    <security>
+      <user-name>sa</user-name>
+      <password>sa</password>
+    </security>
+  </datasource>
+
+</datasources>

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-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java	2011-05-26 13:33:12 UTC (rev 111456)
@@ -35,8 +35,12 @@
  */
 public interface DataSource extends CommonDataSource
 {
+   /**
+    * Get the JTA setting.
+    * @return The value
+    */
+   public boolean isJTA();
 
-
    /**
     * Get the connectionUrl.
     *
@@ -252,8 +256,13 @@
       /** use-ccm attribute
       *
       */
-      USE_CCM("use-ccm");
+      USE_CCM("use-ccm"),
 
+      /**
+       * jta attribute
+       */
+      JTA("jta");
+
       private final String name;
 
       /**

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-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java	2011-05-26 13:33:12 UTC (rev 111456)
@@ -46,6 +46,8 @@
    /** The serialVersionUID */
    private static final long serialVersionUID = -5214100851560229431L;
 
+   private final boolean jta;
+
    private final String connectionUrl;
 
    private String driverClass;
@@ -79,17 +81,21 @@
     * @param jndiName jndiName
     * @param spy spy
     * @param useccm useccm
+    * @param jta jta
     * @param pool pool
     * @throws ValidateException ValidateException
     */
    public DataSourceImpl(String connectionUrl, String driverClass, String driver,
-      TransactionIsolation transactionIsolation, Map<String, String> connectionProperties, TimeOut timeOut,
-      DsSecurity security, Statement statement, Validation validation, String urlDelimiter,
-      String urlSelectorStrategyClassName, String newConnectionSql, boolean useJavaContext, String poolName,
-      boolean enabled, String jndiName, boolean spy, boolean useccm, CommonPool pool) throws ValidateException
+                         TransactionIsolation transactionIsolation, Map<String, String> connectionProperties, 
+                         TimeOut timeOut, DsSecurity security, Statement statement, Validation validation, 
+                         String urlDelimiter, String urlSelectorStrategyClassName, String newConnectionSql, 
+                         boolean useJavaContext, String poolName, boolean enabled, String jndiName, 
+                         boolean spy, boolean useccm, boolean jta, CommonPool pool)
+      throws ValidateException
    {
       super(transactionIsolation, timeOut, security, statement, validation, urlDelimiter,
             urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useccm);
+      this.jta = jta;
       this.connectionUrl = connectionUrl;
       this.driverClass = driverClass;
       this.driver = driver;
@@ -108,6 +114,14 @@
    }
 
    /**
+    * {@inheritDoc}
+    */
+   public boolean isJTA()
+   {
+      return jta;
+   }
+
+   /**
     * Get the connectionUrl.
     *
     * @return the connectionUrl.

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-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java	2011-05-26 13:33:12 UTC (rev 111456)
@@ -35,7 +35,6 @@
 import org.jboss.jca.common.api.metadata.ds.TransactionIsolation;
 import org.jboss.jca.common.api.metadata.ds.Validation;
 import org.jboss.jca.common.api.metadata.ds.XaDataSource;
-import org.jboss.jca.common.api.metadata.ds.XaDataSource.Attribute;
 import org.jboss.jca.common.api.validator.ValidateException;
 import org.jboss.jca.common.metadata.AbstractParser;
 import org.jboss.jca.common.metadata.MetadataParser;
@@ -294,7 +293,7 @@
       boolean spy = false;
       boolean useCcm = true;
 
-      for (Attribute attribute : XaDataSource.Attribute.values())
+      for (XaDataSource.Attribute attribute : XaDataSource.Attribute.values())
       {
          switch (attribute)
          {
@@ -498,8 +497,9 @@
       String jndiName = null;
       boolean spy = false;
       boolean useCcm = true;
+      boolean jta = true;
 
-      for (Attribute attribute : XaDataSource.Attribute.values())
+      for (DataSource.Attribute attribute : DataSource.Attribute.values())
       {
          switch (attribute)
          {
@@ -527,6 +527,10 @@
                useCcm = attributeAsBoolean(reader, attribute.getLocalName(), true);
                break;
             }
+            case JTA : {
+               jta = attributeAsBoolean(reader, attribute.getLocalName(), true);
+               break;
+            }
             default :
                break;
          }
@@ -545,7 +549,7 @@
                                             connectionProperties, timeOutSettings, securitySettings,
                                             statementSettings, validationSettings, urlDelimiter,
                                             urlSelectorStrategyClassName, newConnectionSql, useJavaContext, poolName,
-                                            enabled, jndiName, spy, useCcm, pool);
+                                            enabled, jndiName, spy, useCcm, jta, pool);
                }
                else
                {

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-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd	2011-05-26 13:33:12 UTC (rev 111456)
@@ -167,6 +167,15 @@
         </xs:annotation>
       </xs:element>
     </xs:sequence>
+    <xs:attribute name="jta" type="xs:boolean" default="true" use="optional">
+      <xs:annotation>
+        <xs:documentation>
+          <![CDATA[[
+            Enable JTA integration
+           ]]>
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
     <xs:attributeGroup ref="common-datasourceAttributes" />
   </xs:complexType>
   <xs:complexType name="xa-datasourceType">

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-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java	2011-05-26 13:33:12 UTC (rev 111456)
@@ -423,16 +423,27 @@
          flushStrategy = ds.getPool().getFlushStrategy();
 
       // Select the correct connection manager
-      TransactionSupportLevel tsl = TransactionSupportLevel.LocalTransaction;
       ConnectionManagerFactory cmf = new ConnectionManagerFactory();
-      ConnectionManager cm =
-         cmf.createTransactional(tsl, pool, getSubjectFactory(securityDomain), securityDomain,
-                                 ds.isUseCcm(), getCachedConnectionManager(),
-                                 flushStrategy,
-                                 allocationRetry, allocationRetryWaitMillis,
-                                 getTransactionIntegration(),
-                                 null, null, null, null, null);
+      ConnectionManager cm = null;
 
+      if (ds.isJTA())
+      {
+         cm = cmf.createTransactional(TransactionSupportLevel.LocalTransaction, pool, 
+                                      getSubjectFactory(securityDomain), securityDomain,
+                                      ds.isUseCcm(), getCachedConnectionManager(),
+                                      flushStrategy,
+                                      allocationRetry, allocationRetryWaitMillis,
+                                      getTransactionIntegration(),
+                                      null, null, null, null, null);
+      }
+      else
+      {
+         cm = cmf.createNonTransactional(TransactionSupportLevel.NoTransaction, pool, 
+                                         getSubjectFactory(securityDomain), securityDomain,
+                                         ds.isUseCcm(), getCachedConnectionManager(),
+                                         flushStrategy, allocationRetry, allocationRetryWaitMillis);
+      }
+
       cm.setJndiName(jndiName);
 
       String poolName = null;
@@ -855,6 +866,7 @@
          for (int i = 0; !found && i < methods.length; i++)
          {
             Method m = methods[i];
+            m.setAccessible(true);
 
             if (m.getName().equals(methodName) && m.getParameterTypes().length == 1)
             {

Modified: projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml
===================================================================
--- projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml	2011-05-26 03:03:22 UTC (rev 111455)
+++ projects/jboss-jca/trunk/doc/userguide/en-US/modules/deployment.xml	2011-05-26 13:33:12 UTC (rev 111456)
@@ -714,6 +714,12 @@
                   Enable the cached connection manager
                 </entry>
               </row>
+              <row>
+                <entry><code>jta</code></entry>
+                <entry>
+                  Enable JTA integration (only <code>&lt;datasource&gt;</code>)
+                </entry>
+              </row>
             </tbody>
           </tgroup>
         </table>



More information about the jboss-cvs-commits mailing list