[jboss-cvs] JBossAS SVN: r111312 - in projects/jboss-jca/trunk: adapters/src/test/resources and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 9 11:27:11 EDT 2011
Author: maeste
Date: 2011-05-09 11:27:11 -0400 (Mon, 09 May 2011)
New Revision: 111312
Added:
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverTestCase.java
projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-ds.xml
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/DriverImpl.java
projects/jboss-jca/trunk/common/src/test/resources/ds/example/h2-driver-ds.xml
Modified:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSources.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.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/DatasourcesImpl.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/ds/XADataSourceImpl.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
Log:
JBJCA-569 support driver as part of datasources_1.0.xsd
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/unit/H2DriverTestCase.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -0,0 +1,94 @@
+/*
+ * 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.embedded.arquillian.ArquillianJCATestUtils;
+
+import java.sql.Connection;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
+
+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 H2DriverTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ //---------------------- GIVEN --------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+ /**
+ * Define the deployment
+ * @return The deployment archive
+ * @throws Exception in case of errors
+ */
+ @Deployment
+ public static ResourceAdapterArchive createDeployment() throws Exception
+ {
+ String archiveName = "jdbc-local.rar";
+ ResourceAdapterArchive raa = ArquillianJCATestUtils.buildShrinkwrapJdbcLocal(archiveName);
+ ResourceAdapterArchive external = ShrinkWrap.create(ResourceAdapterArchive.class, "complex_" + archiveName);
+ external.add(raa, "/");
+ external.addResource("h2-driver-ds.xml", "datasources-ds.xml");
+ return external;
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ //---------------------- 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-driver-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-driver-ds.xml 2011-05-09 15:27:11 UTC (rev 111312)
@@ -0,0 +1,17 @@
+<?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">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver>h2</driver>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ </datasource>
+ <driver name="h2">
+ <driver-class>org.h2.Driver</driver-class>
+ </driver>
+
+</datasources>
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSources.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSources.java 2011-05-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSources.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -56,6 +56,14 @@
public List<XaDataSource> getXaDataSource();
/**
+ * Get the driver with given name
+ * @param name driver's name
+ *
+ * @return the list of drivers.
+ */
+ public Driver getDriver(String name);
+
+ /**
*
* A Tag.
*
@@ -77,8 +85,13 @@
/**
* xa-datasource tag
*/
- XA_DATASOURCE("xa-datasource");
+ XA_DATASOURCE("xa-datasource"),
+ /**
+ * driver tag
+ */
+ DRIVER("driver");
+
private final String name;
/**
Copied: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java (from rev 111311, projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSources.java)
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Driver.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -0,0 +1,213 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.api.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.JCAMetadata;
+import org.jboss.jca.common.api.metadata.ValidatableMetadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * A DataSource.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public interface Driver extends JCAMetadata, ValidatableMetadata
+{
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ public String getName();
+
+ /**
+ * Get the MajorVersion
+ * @return the MajorVersion.
+ */
+ public Integer getMajorVersion();
+
+ /**
+ *Get the MinorVersion
+ *
+ * @return the MinorVersion.
+ */
+ public Integer getMinorVersion();
+
+
+ /**
+ * Get the module providing the driver. Used in AS7 configuration
+ *
+ * @return the module.
+ */
+ public String getModule();
+
+
+ /**
+ * Get the DriverClass.
+ *
+ * @return the module.
+ */
+ public String getDriverClass();
+
+
+ /**
+ * Get the XaDataSourceClass.
+ *
+ * @return the XaDataSourceClass.
+ */
+ public String getXaDataSourceClass();
+
+
+
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /**
+ * driverClass tag
+ */
+ DRIVERCLASS("driver-class"),
+ /**
+ * xaDatasourceClass tag
+ */
+ XADATASOURCECLASS("xa-datasource-class");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName XsdString
+ *
+ * @param localName a XsdString used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
+ /**
+ *
+ * A Attribute.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Attribute
+ {
+
+ /**
+ * name attribute
+ */
+ NAME("name"),
+ /**
+ * major-version attribute
+ */
+ MAJOR_VERSION("major-version"),
+ /**
+ * minor-version attribute
+ */
+ MINOR_VERSION("minor-version"),
+ /**
+ * module attribute
+ */
+ MODULE("module");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Attribute(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ }
+
+}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java 2011-05-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -45,11 +45,11 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.jboss.logging.Logger;
+
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-import org.jboss.logging.Logger;
-
/**
*
* A AbstractParser.
@@ -162,6 +162,20 @@
}
/**
+ * convert an xml element in String value
+ *
+ * @param reader the StAX reader
+ * @param attributeName the name of the attribute
+ * @return the string representing element
+ * @throws XMLStreamException StAX exception
+ */
+ protected Integer attributeAsInt(XMLStreamReader reader, String attributeName) throws XMLStreamException
+ {
+ String attributeString = getSubstitutionValue(rawAttributeText(reader, attributeName));
+ return attributeString != null ? Integer.valueOf(getSubstitutionValue(attributeString)) : null;
+ }
+
+ /**
* FIXME Comment this
*
* @param reader
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-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -48,7 +48,7 @@
private final String connectionUrl;
- private final String driverClass;
+ private String driverClass;
private final String driver;
@@ -289,9 +289,21 @@
if (this.connectionUrl == null || this.connectionUrl.trim().length() == 0)
throw new ValidateException("connectionUrl (xml tag " + Tag.CONNECTIONURL + ") is required in " +
this.getClass().getCanonicalName());
- if (this.driverClass == null || this.driverClass.trim().length() == 0)
+ if ((this.driverClass == null || this.driverClass.trim().length() == 0) &&
+ (this.driver == null || this.driver.trim().length() == 0))
throw new ValidateException("driverClass (xml tag " + Tag.DRIVERCLASS + ") is required in " +
- this.getClass().getCanonicalName());
+ this.getClass().getCanonicalName() + "if no driver (xml tag " + Tag.DRIVER +
+ ") is not specified");
}
+
+ /**
+ * Set the driverClass.
+ *
+ * @param driverClass The driverClass to set.
+ */
+ public final void forceDriverClass(String driverClass)
+ {
+ this.driverClass = driverClass;
+ }
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DatasourcesImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DatasourcesImpl.java 2011-05-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DatasourcesImpl.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -23,11 +23,13 @@
import org.jboss.jca.common.api.metadata.ds.DataSource;
import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ds.Driver;
import org.jboss.jca.common.api.metadata.ds.XaDataSource;
import org.jboss.jca.common.api.validator.ValidateException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
@@ -47,14 +49,19 @@
private final ArrayList<XaDataSource> xaDataSource;
+ private final HashMap<String, Driver> drivers;
+
/**
* Create a new DatasourcesImpl.
*
* @param datasource datasource
* @param xaDataSource xaDataSource
+ * @param drivers drivers
* @throws ValidateException ValidateException
*/
- public DatasourcesImpl(List<DataSource> datasource, List<XaDataSource> xaDataSource) throws ValidateException
+ public DatasourcesImpl(List<DataSource> datasource, List<XaDataSource> xaDataSource,
+ HashMap<String, Driver> drivers)
+ throws ValidateException
{
super();
if (datasource != null)
@@ -75,6 +82,15 @@
{
this.xaDataSource = new ArrayList<XaDataSource>(0);
}
+ if (drivers != null)
+ {
+ this.drivers = new HashMap<String, Driver>(drivers.size());
+ this.drivers.putAll(drivers);
+ }
+ else
+ {
+ this.drivers = new HashMap<String, Driver>(0);
+ }
this.validate();
}
@@ -157,4 +173,10 @@
}
}
+ @Override
+ public Driver getDriver(String name)
+ {
+ return drivers.get(name);
+ }
+
}
Added: 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 (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DriverImpl.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -0,0 +1,226 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.ds.Driver;
+import org.jboss.jca.common.api.validator.ValidateException;
+
+/**
+ *
+ * A DriverImpl.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class DriverImpl implements Driver
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 6228505574424288182L;
+
+ private final String name;
+
+ private final Integer minorVersion;
+
+ private final Integer majorVersion;
+
+
+ private final String module;
+
+ private final String driverClass;
+
+ private final String xaDataSourceClass;
+
+ /**
+ * Create a new DriverImpl.
+ *
+ * @param name name
+ * @param majorVersion majorVersion
+ * @param minorVersion minorVersion
+ * @param module module
+ * @param driverClass driverClass
+ * @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)
+ throws ValidateException
+ {
+ super();
+ this.name = name;
+ this.majorVersion = majorVersion;
+ this.minorVersion = minorVersion;
+ this.module = module;
+ this.driverClass = driverClass;
+ this.xaDataSourceClass = xaDataSourceClass;
+ this.validate();
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ @Override
+ public final String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the version.
+ *
+ * @return the version.
+ */
+
+ /**
+ * Get the module.
+ *
+ * @return the module.
+ */
+ @Override
+ public final String getModule()
+ {
+ return module;
+ }
+
+ /**
+ * Get the driverClass.
+ *
+ * @return the driverClass.
+ */
+ @Override
+ public final String getDriverClass()
+ {
+ return driverClass;
+ }
+
+ /**
+ * Get the xsDataSourceClass.
+ *
+ * @return the xsDataSourceClass.
+ */
+ @Override
+ public final String getXaDataSourceClass()
+ {
+ return xaDataSourceClass;
+ }
+
+ @Override
+ public void validate() throws ValidateException
+ {
+ if (this.name == null || this.name.trim().length() == 0)
+ throw new ValidateException("name (xml attribute " + Attribute.NAME + ") is required in " +
+ this.getClass().getCanonicalName());
+
+ }
+
+ @Override
+ public Integer getMajorVersion()
+ {
+ return majorVersion;
+ }
+
+ @Override
+ public Integer getMinorVersion()
+ {
+ return minorVersion;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DriverImpl [name=" + name + ", minorVersion=" + minorVersion + ", majorVersion=" + majorVersion +
+ ", module=" + module + ", driverClass=" + driverClass + ", xaDataSourceClass=" + xaDataSourceClass + "]";
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((driverClass == null) ? 0 : driverClass.hashCode());
+ result = prime * result + ((majorVersion == null) ? 0 : majorVersion.hashCode());
+ 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 + ((xaDataSourceClass == null) ? 0 : xaDataSourceClass.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof DriverImpl))
+ return false;
+ DriverImpl other = (DriverImpl) obj;
+ if (driverClass == null)
+ {
+ if (other.driverClass != null)
+ return false;
+ }
+ else if (!driverClass.equals(other.driverClass))
+ return false;
+ if (majorVersion == null)
+ {
+ if (other.majorVersion != null)
+ return false;
+ }
+ else if (!majorVersion.equals(other.majorVersion))
+ return false;
+ if (minorVersion == null)
+ {
+ if (other.minorVersion != null)
+ return false;
+ }
+ else if (!minorVersion.equals(other.minorVersion))
+ return false;
+ if (module == null)
+ {
+ if (other.module != null)
+ return false;
+ }
+ else if (!module.equals(other.module))
+ return false;
+ if (name == null)
+ {
+ if (other.name != null)
+ return false;
+ }
+ else if (!name.equals(other.name))
+ return false;
+ if (xaDataSourceClass == null)
+ {
+ if (other.xaDataSourceClass != null)
+ return false;
+ }
+ else if (!xaDataSourceClass.equals(other.xaDataSourceClass))
+ return false;
+ return true;
+ }
+
+}
+
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-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -27,6 +27,7 @@
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.ds.DataSource;
import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ds.Driver;
import org.jboss.jca.common.api.metadata.ds.DsSecurity;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.Statement.TrackStatementsEnum;
@@ -132,6 +133,7 @@
{
ArrayList<XaDataSource> xaDataSource = new ArrayList<XaDataSource>();
ArrayList<DataSource> datasource = new ArrayList<DataSource>();
+ HashMap<String, Driver> drivers = new HashMap<String, Driver>();
while (reader.hasNext())
{
switch (reader.nextTag())
@@ -140,7 +142,7 @@
if (Tag.forName(reader.getLocalName()) == Tag.DATASOURCES)
{
- return new DatasourcesImpl(datasource, xaDataSource);
+ return new DatasourcesImpl(datasource, xaDataSource, drivers);
}
else
{
@@ -162,6 +164,11 @@
xaDataSource.add(parseXADataSource(reader));
break;
}
+ case DRIVER : {
+ Driver driver = parseDriver(reader);
+ drivers.put(driver.getName(), driver);
+ break;
+ }
default :
throw new ParserException("Unexpected element:" + reader.getLocalName());
}
@@ -172,6 +179,87 @@
throw new ParserException("Reached end of xml document unexpectedly");
}
+ private Driver parseDriver(XMLStreamReader reader) throws XMLStreamException, ParserException,
+ ValidateException
+ {
+
+ String xaDataSourceClass = null;
+ String driverClass = null;
+
+ //attributes reading
+
+ String name = null;
+ Integer majorVersion = null;
+ Integer minorVersion = null;
+ String module = null;
+
+ for (org.jboss.jca.common.api.metadata.ds.Driver.Attribute attribute : Driver.Attribute.values())
+ {
+ switch (attribute)
+ {
+
+ case NAME : {
+ name = attributeAsString(reader, attribute.getLocalName());
+ break;
+ }
+ case MAJOR_VERSION : {
+ majorVersion = attributeAsInt(reader, attribute.getLocalName());
+ break;
+ }
+ case MINOR_VERSION : {
+ minorVersion = attributeAsInt(reader, attribute.getLocalName());
+ break;
+ }
+ case MODULE : {
+ module = attributeAsString(reader, attribute.getLocalName());
+ break;
+ }
+ default :
+ break;
+ }
+ }
+
+ //elements reading
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DRIVER)
+ {
+
+ return new DriverImpl(name, majorVersion, minorVersion, module, driverClass, xaDataSourceClass);
+ }
+ else
+ {
+ if (Driver.Tag.forName(reader.getLocalName()) == Driver.Tag.UNKNOWN)
+ {
+ throw new ParserException("unexpected end tag" + reader.getLocalName());
+ }
+ }
+ break;
+ }
+ case START_ELEMENT : {
+ switch (Driver.Tag.forName(reader.getLocalName()))
+ {
+ case XADATASOURCECLASS : {
+ xaDataSourceClass = elementAsString(reader);
+ break;
+ }
+ case DRIVERCLASS : {
+ driverClass = elementAsString(reader);
+ break;
+ }
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+ break;
+ }
+ }
+ }
+ throw new ParserException("Reached end of xml document unexpectedly");
+ }
+
private XaDataSource parseXADataSource(XMLStreamReader reader) throws XMLStreamException, ParserException,
ValidateException
{
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java 2011-05-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -49,7 +49,7 @@
private final HashMap<String, String> xaDataSourceProperty;
- private final String xaDataSourceClass;
+ private String xaDataSourceClass;
private final String driver;
@@ -284,4 +284,14 @@
{
return recovery;
}
+
+ /**
+ * Set the xaDataSourceClass.
+ *
+ * @param xaDataSourceClass The xaDataSourceClass to set.
+ */
+ public final void forceXaDataSourceClass(String xaDataSourceClass)
+ {
+ this.xaDataSourceClass = xaDataSourceClass;
+ }
}
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-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd 2011-05-09 15:27:11 UTC (rev 111312)
@@ -14,26 +14,29 @@
</xs:annotation>
</xs:element>
<xs:complexType name="datasourcesType">
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="datasource" type="datasourceType">
- <xs:annotation>
- <xs:documentation>
- <![CDATA[[
- Specifies a non-XA datasource, using local transactions
- ]]>
- </xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element name="xa-datasource" type="xa-datasourceType">
- <xs:annotation>
- <xs:documentation>
- <![CDATA[[
- Specifies a XA datasource
- ]]>
- </xs:documentation>
- </xs:annotation>
- </xs:element>
- </xs:choice>
+ <xs:sequence>
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="datasource" type="datasourceType">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies a non-XA datasource, using local transactions
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="xa-datasource" type="xa-datasourceType">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies a XA datasource
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ </xs:choice>
+ <xs:element name="driver" type="driverType" maxOccurs="unbounded" minOccurs="0"></xs:element>
+ </xs:sequence>
</xs:complexType>
<xs:complexType name="datasourceType" mixed="false">
<xs:sequence>
@@ -46,7 +49,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="driver-class" type="xs:token">
+ <xs:element name="driver-class" type="xs:token" maxOccurs="1" minOccurs="0">
<xs:annotation>
<xs:documentation>
<![CDATA[[
@@ -188,7 +191,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="xa-datasource-class" type="xs:token">
+ <xs:element name="xa-datasource-class" type="xs:token" maxOccurs="1" minOccurs="0">
<xs:annotation>
<xs:documentation>
<![CDATA[[
@@ -837,4 +840,67 @@
</xs:attribute>
</xs:complexType>
+
+
+ <xs:complexType name="driverType">
+ <xs:sequence>
+ <xs:element name="driver-class" type="xs:token" maxOccurs="1" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ The fully qualifed name of the JDBC driver class Ex: <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="xa-datasource-class" type="xs:token" maxOccurs="1" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ The fully qualifed name of the javax.sql.XADataSource implementation
+ class. Ex: <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
+ ]]>
+ </xs:documentation>
+ </xs:annotation></xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:token" use="required">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies the symbolic name of this driver used to reference this driver
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="module" type="xs:token" use="optional">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies the name of AS7 module providing this driver.
+ Thios tag is not used in IronJacamar standalone container.
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="major-version" type="xs:int" use="optional">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies the major version of this driver. If the major and minor version is obmitted the fist availabe
+ Driver in module will be used.
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="minor-verion" type="xs:int" use="optional">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies the minor version of this driver. If the major and minor version is obmitted the fist availabe
+ Driver in module will be used.
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:complexType>
</xs:schema>
Added: projects/jboss-jca/trunk/common/src/test/resources/ds/example/h2-driver-ds.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/ds/example/h2-driver-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/ds/example/h2-driver-ds.xml 2011-05-09 15:27:11 UTC (rev 111312)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
+
+ <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver>h2</driver>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ </datasource>
+ <driver name="h2">
+ <driver-class>org.h2.Driver</driver-class>
+ </driver>
+
+</datasources>
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-09 09:01:30 UTC (rev 111311)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java 2011-05-09 15:27:11 UTC (rev 111312)
@@ -33,6 +33,8 @@
import org.jboss.jca.common.api.metadata.ds.XaDataSource;
import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
import org.jboss.jca.common.api.metadata.ra.XsdString;
+import org.jboss.jca.common.metadata.ds.DataSourceImpl;
+import org.jboss.jca.common.metadata.ds.XADataSourceImpl;
import org.jboss.jca.common.metadata.ra.common.ConfigPropertyImpl;
import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
@@ -229,6 +231,14 @@
{
org.jboss.jca.core.api.management.DataSource mgtDataSource =
new org.jboss.jca.core.api.management.DataSource(false);
+
+ if (dataSource.getDriverClass() == null && dataSource.getDriver() != null &&
+ dataSource instanceof DataSourceImpl)
+ {
+ ((DataSourceImpl) dataSource).forceDriverClass(dataSources.getDriver(dataSource
+ .getDriver()).getDriverClass());
+ }
+
Object cf = deployDataSource(dataSource, jndiName,
uniqueJdbcLocalId, mgtDataSource, jdbcLocalDeploymentCl);
@@ -270,6 +280,15 @@
org.jboss.jca.core.api.management.DataSource mgtDataSource =
new org.jboss.jca.core.api.management.DataSource(true);
XAResourceRecovery recovery = null;
+
+ if (xaDataSource.getXaDataSourceClass() == null && xaDataSource.getDriver() != null &&
+ xaDataSource instanceof XADataSourceImpl)
+ {
+ ((XADataSourceImpl) xaDataSource).forceXaDataSourceClass(dataSources.getDriver(
+ xaDataSource
+ .getDriver()).getXaDataSourceClass());
+ }
+
Object cf = deployXADataSource(xaDataSource,
jndiName, uniqueJdbcXAId,
recovery,
@@ -912,7 +931,7 @@
if (securityDomain == null)
throw new IllegalArgumentException("SecurityDomain is null");
- return AccessController.doPrivileged(new PrivilegedAction<Subject>()
+ return AccessController.doPrivileged(new PrivilegedAction<Subject>()
{
public Subject run()
{
@@ -921,14 +940,14 @@
// Create a security context on the association
SecurityContext securityContext = SecurityContextFactory.createSecurityContext(securityDomain);
SecurityContextAssociation.setSecurityContext(securityContext);
-
+
// Unauthenticated
Subject unauthenticated = new Subject();
-
+
// Leave the subject empty as we don't have any information to do the
// authentication with - and we only need it to be able to get the
// real subject from the SubjectFactory
-
+
// Set the authenticated subject
securityContext.getSubjectInfo().setAuthenticatedSubject(unauthenticated);
@@ -946,7 +965,7 @@
if (log.isDebugEnabled())
log.debug("Subject=" + subject);
-
+
return subject;
}
catch (Throwable t)
More information about the jboss-cvs-commits
mailing list