[jboss-cvs] JBossAS SVN: r107685 - in projects/jboss-jca/trunk: common/src/main/java/org/jboss/jca/common/api/metadata/ds and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 19 11:32:49 EDT 2010
Author: maeste
Date: 2010-08-19 11:32:48 -0400 (Thu, 19 Aug 2010)
New Revision: 107685
Added:
projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/MetadataFactoryTestCase.java
projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/package.html
projects/jboss-jca/trunk/common/src/test/resources/adapters/
projects/jboss-jca/trunk/common/src/test/resources/adapters/ra.xml
Modified:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/MergeUtil.java
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/TimeOut.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/XaDataSource.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ra/ra10/ResourceAdapter10.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/MetadataFactory.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/TimeOutImpl.java
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/ra/common/ConfigPropertyImpl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/OutboundResourceAdapterImpl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/Connector10Impl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/ResourceAdapter10Impl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra15/Connector15Impl.java
projects/jboss-jca/trunk/tools/findbugs/filter.xml
Log:
JBJCA-385 JBJCA-400 adding merge capabilities for connector and ds metadatas
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/MergeUtil.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/MergeUtil.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/MergeUtil.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -108,4 +108,6 @@
newList.trimToSize();
return newList;
}
+
+
}
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 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DataSource.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -22,6 +22,7 @@
package org.jboss.jca.common.api.metadata.ds;
import org.jboss.jca.common.api.metadata.JCAMetadata;
+import org.jboss.jca.common.api.metadata.ra.MergeableMetadata;
import java.util.HashMap;
import java.util.Map;
@@ -33,7 +34,7 @@
* @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
*
*/
-public interface DataSource extends JCAMetadata
+public interface DataSource extends JCAMetadata, MergeableMetadata<DataSource>
{
/**
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/TimeOut.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/TimeOut.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/TimeOut.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -55,7 +55,7 @@
*
* @return the setTxQuertTimeout.
*/
- public boolean isSetTxQuertTimeout();
+ public boolean isSetTxQueryTimeout();
/**
* Get the queryTimeout.
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/XaDataSource.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/XaDataSource.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/XaDataSource.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -71,12 +71,6 @@
*/
public String getPassword();
- /**
- * Get the xaDataSoourceProperty.
- *
- * @return the xaDataSoourceProperty.
- */
- public Map<String, String> getXaDataSoourceProperty();
/**
* Get the xaDataSourceClass.
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ra/ra10/ResourceAdapter10.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ra/ra10/ResourceAdapter10.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ra/ra10/ResourceAdapter10.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -24,6 +24,7 @@
import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
import org.jboss.jca.common.api.metadata.ra.AuthenticationMechanism;
import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
+import org.jboss.jca.common.api.metadata.ra.MergeableMetadata;
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter;
import org.jboss.jca.common.api.metadata.ra.SecurityPermission;
import org.jboss.jca.common.api.metadata.ra.XsdString;
@@ -40,7 +41,7 @@
* @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
*
*/
-public interface ResourceAdapter10 extends ResourceAdapter
+public interface ResourceAdapter10 extends ResourceAdapter, MergeableMetadata<ResourceAdapter10>
{
/**
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/MetadataFactory.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/MetadataFactory.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/MetadataFactory.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -22,14 +22,44 @@
package org.jboss.jca.common.metadata;
+import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
+import org.jboss.jca.common.api.metadata.ds.DataSource;
+import org.jboss.jca.common.api.metadata.ds.XaDataSource;
import org.jboss.jca.common.api.metadata.jbossra.JbossRa;
+import org.jboss.jca.common.api.metadata.ra.AdminObject;
+import org.jboss.jca.common.api.metadata.ra.AuthenticationMechanism;
+import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
+import org.jboss.jca.common.api.metadata.ra.ConnectionDefinition;
import org.jboss.jca.common.api.metadata.ra.Connector;
+import org.jboss.jca.common.api.metadata.ra.Connector.Version;
+import org.jboss.jca.common.api.metadata.ra.Icon;
+import org.jboss.jca.common.api.metadata.ra.InboundResourceAdapter;
+import org.jboss.jca.common.api.metadata.ra.LicenseType;
+import org.jboss.jca.common.api.metadata.ra.LocalizedXsdString;
+import org.jboss.jca.common.api.metadata.ra.OutboundResourceAdapter;
+import org.jboss.jca.common.api.metadata.ra.ResourceAdapter;
+import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
+import org.jboss.jca.common.api.metadata.ra.SecurityPermission;
+import org.jboss.jca.common.api.metadata.ra.XsdString;
import org.jboss.jca.common.metadata.jbossra.JbossRaParser;
import org.jboss.jca.common.metadata.ra.RaParser;
+import org.jboss.jca.common.metadata.ra.common.ConfigPropertyImpl;
+import org.jboss.jca.common.metadata.ra.common.ConnectionDefinitionImpl;
+import org.jboss.jca.common.metadata.ra.common.OutboundResourceAdapterImpl;
+import org.jboss.jca.common.metadata.ra.common.ResourceAdapter1516Impl;
+import org.jboss.jca.common.metadata.ra.ra10.Connector10Impl;
+import org.jboss.jca.common.metadata.ra.ra10.ResourceAdapter10Impl;
+import org.jboss.jca.common.metadata.ra.ra15.Connector15Impl;
+import org.jboss.jca.common.metadata.ra.ra16.Connector16Impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.jboss.logging.Logger;
@@ -140,4 +170,615 @@
return result;
}
+ /**
+ *
+ * Create a connector from a DataSource metadata
+ *
+ * @param ds the datasource
+ * @param connector the connector to merge
+ * @return the connector with mapped properties taken forn ds
+ * @throws IllegalArgumentException if version is't 1.0, 1.5 or 1.6
+ * @throws Exception in case of error
+ */
+ public static Connector mergeConnectorAndDs(DataSource ds, Connector connector)
+ throws IllegalArgumentException, Exception
+ {
+ if (ds == null)
+ {
+ return null;
+ }
+ else
+ {
+
+ XsdString managedconnectionfactoryClass = null;
+
+ String id = null;
+
+ XsdString connectionfactoryImplClass = null;
+ XsdString connectionfactoryInterface = null;
+ XsdString connectionImplClass = null;
+ XsdString connectionInterface = null;
+ List<AuthenticationMechanism> authenticationMechanism = null;
+ boolean reauthenticationSupport = false;
+ List<SecurityPermission> securityPermissions = null;
+
+ XsdString vendorName = null;
+ List<LocalizedXsdString> description = null;
+ XsdString resourceadapterVersion = null;
+ String moduleName = null;
+ XsdString eisType = null;
+ LicenseType license = null;
+ List<LocalizedXsdString> displayNames = null;
+ List<Icon> icons = null;
+ List<AdminObject> adminobjects = null;
+ TransactionSupportEnum transactionSupport = null;
+
+ if (connector.getVersion() == Version.V_10)
+ {
+
+ List<ConfigProperty> configProperties = createConfigProperties(ds,
+ connector.getResourceadapter().getConfigProperties());
+
+ ResourceAdapter resourceadapter = new ResourceAdapter10Impl(managedconnectionfactoryClass,
+ connectionfactoryInterface, connectionfactoryImplClass, connectionInterface, connectionImplClass,
+ transactionSupport, authenticationMechanism, configProperties, reauthenticationSupport,
+ securityPermissions, id);
+
+ Connector newConnector = new Connector10Impl(moduleName, vendorName, eisType, resourceadapterVersion,
+ license, resourceadapter, description, displayNames, icons, id);
+
+ return newConnector.merge(connector);
+ }
+ else
+ {
+ List<? extends ConfigProperty> originalProperties = null;
+ if (connector.getResourceadapter() != null
+ && connector.getResourceadapter() instanceof ResourceAdapter1516
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter() != null
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions() != null)
+ {
+ originalProperties = ((ResourceAdapter1516) connector
+ .getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions().get(0).getConfigProperties();
+ }
+
+ List<ConfigProperty> configProperties = createConfigProperties(ds, originalProperties);
+
+ List<ConnectionDefinition> connectionDefinitions = new ArrayList<ConnectionDefinition>(1);
+ ConnectionDefinition connectionDefinition = new ConnectionDefinitionImpl(managedconnectionfactoryClass,
+ configProperties, connectionfactoryInterface, connectionfactoryImplClass, connectionInterface,
+ connectionImplClass, id);
+ connectionDefinitions.add(connectionDefinition);
+ OutboundResourceAdapter outboundResourceadapter = new OutboundResourceAdapterImpl(connectionDefinitions,
+ transactionSupport, authenticationMechanism, reauthenticationSupport, id);
+ String resourceadapterClass = null;
+ List<? extends ConfigProperty> raConfigProperties = null;
+ InboundResourceAdapter inboundResourceadapter = null;
+ ResourceAdapter1516 resourceadapter = new ResourceAdapter1516Impl(resourceadapterClass, raConfigProperties,
+ outboundResourceadapter, inboundResourceadapter, adminobjects, securityPermissions, id);
+
+ if (connector.getVersion() == Version.V_16)
+ {
+ List<String> requiredWorkContexts = null;
+ boolean metadataComplete = false;
+
+ Connector newConnector = new Connector16Impl(moduleName, vendorName, eisType, resourceadapterVersion,
+ license,
+ resourceadapter, requiredWorkContexts, metadataComplete, description, displayNames, icons, id);
+
+ return newConnector.merge(connector);
+ }
+ else if (connector.getVersion() == Version.V_15)
+ {
+ Connector newConnector = new Connector15Impl(vendorName, eisType, resourceadapterVersion, license,
+ resourceadapter, description, displayNames, icons, id);
+
+ return newConnector.merge(connector);
+ }
+ else
+ throw new IllegalArgumentException("version= " + connector.getVersion().name());
+ }
+
+ }
+
+ }
+
+ private static List<ConfigProperty> createConfigProperties(DataSource ds,
+ List<? extends ConfigProperty> originalProperties)
+ {
+ if (originalProperties != null)
+ {
+ List<ConfigProperty> configProperties = new ArrayList<ConfigProperty>(originalProperties.size());
+ for (ConfigProperty property : originalProperties)
+ {
+
+ ConfigPropertyFactory.Prototype prototype = ConfigPropertyFactory.Prototype.forName(property
+ .getConfigPropertyName().getValue());
+ switch (prototype)
+ {
+ case USERNAME : {
+ if (ds.getUserName() != null && !ds.getUserName().trim().equals(""))
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getUserName()));
+ }
+
+ break;
+ }
+
+ case PASSWORD : {
+ if (ds.getPassword() != null && !ds.getPassword().trim().equals(""))
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getPassword()));
+ }
+
+ break;
+ }
+
+ case XADATASOURCEPROPERTIES : {
+ if (ds instanceof XaDataSource && ((XaDataSource) ds).getXaDataSourceProperty() != null)
+ {
+ StringBuffer valueBuf = new StringBuffer();
+ for (Entry<String, String> xaConfigProperty : ((XaDataSource) ds).getXaDataSourceProperty()
+ .entrySet())
+ {
+ valueBuf.append(xaConfigProperty.getKey());
+ valueBuf.append("=");
+ valueBuf.append(xaConfigProperty.getValue());
+ valueBuf.append(";");
+ }
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
+
+ }
+
+ break;
+ }
+
+ case URLDELIMITER : {
+ if (ds.getUrlDelimiter() != null && !ds.getUrlDelimiter().trim().equals(""))
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getUrlDelimiter()));
+ }
+
+ break;
+ }
+
+ case URLSELECTORSTRATEGYCLASSNAME : {
+ if (ds.getUrlSelectorStrategyClassName() != null
+ && !ds.getUrlSelectorStrategyClassName().trim().equals(""))
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
+ ds.getUrlSelectorStrategyClassName()));
+ }
+
+ break;
+ }
+
+ case XADATASOURCECLASS : {
+ if (ds instanceof XaDataSource && ((XaDataSource) ds).getXaDataSourceClass() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
+ ((XaDataSource) ds).getXaDataSourceClass()));
+ }
+
+ break;
+ }
+
+ case TRANSACTIONISOLATION : {
+ if (ds.getTransactionIsolation() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds
+ .getTransactionIsolation().name()));
+ }
+
+ break;
+ }
+
+ case PREPAREDSTATEMENTCACHESIZE : {
+ if (ds.getStatement() != null && ds.getStatement().getPreparedStatementsCacheSize() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getStatement()
+ .getPreparedStatementsCacheSize()));
+ }
+
+ break;
+ }
+
+ case SHAREPREPAREDSTATEMENTS : {
+ if (ds.getStatement() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
+ ds.getStatement() != null
+ && ds.getStatement().isSharePreparedStatements()));
+ }
+
+ break;
+ }
+
+ case NEWCONNECTIONSQL : {
+ if (ds.getNewConnectionSql() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
+ ds.getNewConnectionSql()));
+ }
+
+ break;
+ }
+
+ case CHECKVALIDCONNECTIONSQL : {
+ if (ds.getValidation() != null && ds.getValidation().getCheckValidConnectionSql() != null
+ && !ds.getValidation().getCheckValidConnectionSql().trim().equals(""))
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
+ .getCheckValidConnectionSql()));
+ }
+
+ break;
+ }
+
+ case VALIDCONNECTIONCHECKERCLASSNAME : {
+ if (ds.getValidation() != null && ds.getValidation().getCheckValidConnectionSql() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
+ .getCheckValidConnectionSql()));
+ }
+
+ break;
+ }
+
+ case EXCEPTIONSORTERCLASSNAME : {
+ if (ds.getValidation() != null && ds.getValidation().getExceptionSorterClassName() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
+ .getExceptionSorterClassName()));
+ }
+
+ break;
+ }
+
+ case STALECONNECTIONCHECKERCLASSNAME : {
+ if (ds.getValidation() != null && ds.getValidation().getStaleConnectionCheckerClassName() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
+ .getStaleConnectionCheckerClassName()));
+ }
+
+ break;
+ }
+
+ case TRACKSTATEMENTS : {
+ if (ds.getStatement() != null && ds.getStatement().getTrackStatements() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getStatement()
+ .getTrackStatements().name()));
+ }
+
+ break;
+ }
+
+ case VALIDATEONMATCH : {
+ if (ds.getValidation() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
+ .isValidateOnMatch()));
+ }
+
+ break;
+ }
+
+ case TRANSACTIONQUERYTIMEOUT : {
+ if (ds.getTimeOut() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getTimeOut()
+ .isSetTxQueryTimeout()));
+ }
+
+ break;
+ }
+
+ case QUERYTIMEOUT : {
+ if (ds.getTimeOut() != null && ds.getTimeOut().getQueryTimeout() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getTimeOut()
+ .getQueryTimeout()));
+ }
+
+ break;
+ }
+
+ case USETRYLOCK : {
+ if (ds.getTimeOut() != null && ds.getTimeOut().getUseTryLock() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getTimeOut()
+ .getUseTryLock()));
+ }
+
+ break;
+ }
+ case DRIVERCLASS : {
+ if (ds.getDriverClass() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getDriverClass()));
+ }
+ break;
+ }
+ case URLPROPERTY :
+ case CONNECTIONPROPERTIES : {
+ if (ds.getConnectionProperties() != null)
+ {
+ StringBuffer valueBuf = new StringBuffer();
+ for (Entry<String, String> connProperty : ds.getConnectionProperties().entrySet())
+ {
+ valueBuf.append(connProperty.getKey());
+ valueBuf.append("=");
+ valueBuf.append(connProperty.getValue());
+ valueBuf.append(";");
+ }
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
+
+ }
+ break;
+ }
+ case CONNECTIONURL : {
+ if (ds.getConnectionUrl() != null)
+ {
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getConnectionUrl()));
+ }
+ break;
+ }
+ default :
+ break;
+ }
+ }
+ for (Entry<String, String> connectionProperty : ds.getConnectionProperties().entrySet())
+ {
+ ConfigPropertyFactory.Prototype prototype = ConfigPropertyFactory.Prototype.forName(connectionProperty
+ .getKey());
+ if (prototype != ConfigPropertyFactory.Prototype.UNKNOWN)
+ {
+ configProperties
+ .add(ConfigPropertyFactory.createConfigProperty(prototype, connectionProperty.getValue()));
+ }
+ }
+ return configProperties;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ *
+ * A ConfigPropertyFactory.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ protected static class ConfigPropertyFactory
+ {
+ /**
+ *
+ * create a config property from a prototype
+ *
+ * @param prototype prototype
+ * @param value value
+ * @return the property created
+ */
+ public static ConfigProperty createConfigProperty(Prototype prototype, String value)
+ {
+
+ return new ConfigPropertyImpl(prototype.getDescription(), prototype.getLocalName(), prototype.getLocalType(),
+ new XsdString(
+ value, null), null);
+ }
+
+ /**
+ *
+ * create a config property from a prototype
+ *
+ * @param prototype prototype
+ * @param value value
+ * @return the property created
+ */
+ public static ConfigProperty createConfigProperty(Prototype prototype, boolean value)
+ {
+
+ return new ConfigPropertyImpl(prototype.getDescription(), prototype.getLocalName(), prototype.getLocalType(),
+ new XsdString(
+ String.valueOf(value), null), null);
+ }
+
+ /**
+ *
+ * create a config property from a prototype
+ *
+ * @param prototype prototype
+ * @param value value
+ * @return the property created
+ */
+ public static ConfigProperty createConfigProperty(Prototype prototype, Number value)
+ {
+
+ return new ConfigPropertyImpl(prototype.getDescription(), prototype.getLocalName(), prototype.getLocalType(),
+ new XsdString(
+ String.valueOf(value), null), null);
+ }
+
+ /**
+ *
+ * A Prototype.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ enum Prototype
+ {
+ /** UNKNOWN **/
+ UNKNOWN(null, null, null),
+ /** DRIVERCLASS **/
+ DRIVERCLASS("DriverClass", "java.lang.String", "The jdbc driver class."),
+ /** CONNECTIONURL **/
+ CONNECTIONURL("ConnectionURL", "java.lang.String", "The jdbc connection url class."),
+ /** CONNECTIONPROPERTIES **/
+ CONNECTIONPROPERTIES("ConnectionProperties", "java.lang.String", "Connection properties for the database."),
+
+ /** USERNAME **/
+ USERNAME("UserName", "java.lang.String", "The default user name used to create JDBC connections."),
+ /** PASSWORD **/
+ PASSWORD("Password", "java.lang.String", "The default password used to create JDBC connections."),
+ /** XADATASOURCEPROPERTIES **/
+ XADATASOURCEPROPERTIES(
+ "XADataSourceProperties",
+ "java.lang.String",
+ "The properties to set up the XA driver. These properties must be in the form " +
+ "name1=value1;name2=value2;...namen=valuen"),
+ /** URLDELIMITER **/
+ URLDELIMITER("URLDelimiter", "java.lang.String", "The jdbc connection url delimeter."),
+ /** URLPROPERTY **/
+ URLPROPERTY("URLProperty", "java.lang.String", "The property that contains the list of URLs."),
+ /** URLSELECTORSTRATEGYCLASSNAME **/
+ URLSELECTORSTRATEGYCLASSNAME("UrlSelectorStrategyClassName", "java.lang.String",
+ "The configurable URLSelectorStrategy class name."),
+ /** XADATASOURCECLASS **/
+ XADATASOURCECLASS("XADataSourceClass", "java.lang.String",
+ "The class name of the JDBC XA driver that handlesthis JDBC URL."),
+ /** TRANSACTIONISOLATION **/
+ TRANSACTIONISOLATION(
+ "TransactionIsolation",
+ "java.lang.String",
+ "The transaction isolation for new connections. Not necessary: the driver default will be used " +
+ "if ommitted."),
+ /** PREPAREDSTATEMENTCACHESIZE **/
+ PREPAREDSTATEMENTCACHESIZE("PreparedStatementCacheSize", "java.lang.Integer",
+ "The number of cached prepared statements per connection."),
+ /** SHAREPREPAREDSTATEMENTS **/
+ SHAREPREPAREDSTATEMENTS("SharePreparedStatements", "java.lang.Boolean",
+ "Whether to share prepared statements."),
+ /** NEWCONNECTIONSQL **/
+ NEWCONNECTIONSQL("NewConnectionSQL", "java.lang.String",
+ "An SQL statement to be executed when a new connection is created as auxillary setup."),
+ /** CHECKVALIDCONNECTIONSQL **/
+ CHECKVALIDCONNECTIONSQL(
+ "CheckValidConnectionSQL",
+ "java.lang.String",
+ "An SQL statement that may be executed when a managed connection is taken out of the pool and is " +
+ "about to be given to a client: the purpose is to verify that the connection still works."),
+ /** VALIDCONNECTIONCHECKERCLASSNAME **/
+ VALIDCONNECTIONCHECKERCLASSNAME(
+ "ValidConnectionCheckerClassName",
+ "java.lang.String",
+ "The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.ValidConnectionChecker" +
+ " that can determine for a particular vender db when a connection is valid."),
+ /** EXCEPTIONSORTERCLASSNAME **/
+ EXCEPTIONSORTERCLASSNAME(
+ "ExceptionSorterClassName",
+ "java.lang.String",
+ "The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.ExceptionSorter that"
+ +
+ " can determine for a particular vender db which exceptions are fatal and mean a connection should"
+ +
+ " be discarded."),
+ /** STALECONNECTIONCHECKERCLASSNAME **/
+ STALECONNECTIONCHECKERCLASSNAME(
+ "StaleConnectionCheckerClassName",
+ "java.lang.String",
+ "The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.StaleConnectionChecker" +
+ " that can determine for a particular vender db when a connection is stale."),
+ /** TRACKSTATEMENTS **/
+ TRACKSTATEMENTS("TrackStatements", "java.lang.String",
+ "Whether to track unclosed statements - false/true/nowarn"),
+ /** VALIDATEONMATCH **/
+ VALIDATEONMATCH("ValidateOnMatch", "java.lang.Boolean",
+ "Whether to validate the connection on the ManagedConnectionFactory.matchManagedConnection method"),
+ /** TRANSACTIONQUERYTIMEOUT **/
+ TRANSACTIONQUERYTIMEOUT("TransactionQueryTimeout", "java.lang.Boolean",
+ "Whether to set the query timeout based on the transaction timeout"),
+ /** QUERYTIMEOUT **/
+ QUERYTIMEOUT("QueryTimeout", "java.lang.Integer", "A configured query timeout"),
+ /** USETRYLOCK **/
+ USETRYLOCK("UseTryLock", "java.lang.Integer", "Maximum wait for a lock");
+
+ private final XsdString localName;
+
+ private final XsdString localType;
+
+ private final ArrayList<LocalizedXsdString> description = new ArrayList<LocalizedXsdString>(1);
+
+ /**
+ * Create a new Prototype.
+ *
+ * @param name name
+ * @param type type
+ * @param description description
+ */
+ private Prototype(String name, String type, String description)
+ {
+ this.localName = new XsdString(name, null);
+ this.localType = new XsdString(type, null);;
+ this.description.add(new LocalizedXsdString(description, null));
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ public final XsdString getLocalName()
+ {
+ return localName;
+ }
+
+ /**
+ * Get the type.
+ *
+ * @return the type.
+ */
+ public final XsdString getLocalType()
+ {
+ return localType;
+ }
+
+ /**
+ * Get the description.
+ *
+ * @return the description.
+ */
+ public final List<LocalizedXsdString> getDescription()
+ {
+ return description;
+ }
+
+ private static final Map<String, Prototype> MAP;
+
+ static
+ {
+ final Map<String, Prototype> map = new HashMap<String, Prototype>();
+ for (Prototype element : values())
+ {
+ final String name = element.getLocalName().getValue();
+ 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 Prototype forName(String localName)
+ {
+ final Prototype element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+ }
+
+ }
+
}
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 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -27,6 +27,7 @@
import org.jboss.jca.common.api.metadata.ds.TimeOut;
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.ra.MergeableMetadata;
import java.util.Collections;
import java.util.HashMap;
@@ -380,4 +381,10 @@
+ newConnectionSql + ", useJavaContext=" + useJavaContext + ", poolName=" + poolName + ", enabled="
+ enabled + ", jndiName=" + jndiName + "]";
}
+
+ @Override
+ public DataSource merge(MergeableMetadata<?> jmd) throws Exception
+ {
+ return this;
+ }
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/TimeOutImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/TimeOutImpl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/TimeOutImpl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -106,7 +106,7 @@
* @return the setTxQuertTimeout.
*/
@Override
- public final boolean isSetTxQuertTimeout()
+ public final boolean isSetTxQueryTimeout()
{
return setTxQuertTimeout;
}
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 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -155,17 +155,8 @@
return password;
}
- /**
- * Get the xaDataSoourceProperty.
- *
- * @return the xaDataSoourceProperty.
- */
- @Override
- public final Map<String, String> getXaDataSoourceProperty()
- {
- return Collections.unmodifiableMap(xaDataSourceProperty);
- }
+
/**
* Get the xaDataSourceClass.
*
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/ConfigPropertyImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/ConfigPropertyImpl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/ConfigPropertyImpl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -215,4 +215,12 @@
return false;
return true;
}
+
+ @Override
+ public String toString()
+ {
+ return "ConfigPropertyImpl [description=" + description + ", configPropertyName=" + configPropertyName
+ + ", configPropertyType=" + configPropertyType + ", configPropertyValue=" + configPropertyValue + ", id="
+ + id + "]";
+ }
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/OutboundResourceAdapterImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/OutboundResourceAdapterImpl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/common/OutboundResourceAdapterImpl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -264,7 +264,8 @@
boolean isNew = true;
for (ConnectionDefinition lcd : this.connectionDefinition)
{
- if (rcd.getManagedConnectionFactoryClass().equals(lcd.getManagedConnectionFactoryClass()))
+ if (lcd.getManagedConnectionFactoryClass() == null
+ || rcd.getManagedConnectionFactoryClass().equals(lcd.getManagedConnectionFactoryClass()))
{
newConnectionDefinition.remove(lcd);
newConnectionDefinition.add(lcd.merge(rcd));
@@ -274,7 +275,9 @@
if (isNew) newConnectionDefinition.add(rcd);
}
- TransactionSupportEnum newTransactionSupport = this.transactionSupport;
+ TransactionSupportEnum newTransactionSupport = this.transactionSupport == null
+ ? input.transactionSupport
+ : this.transactionSupport;
boolean newReauthenticationSupport = this.reauthenticationSupport || input.reauthenticationSupport;
List<AuthenticationMechanism> newAuthenticationMechanism = MergeUtil.mergeList(
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/Connector10Impl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/Connector10Impl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/Connector10Impl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -23,12 +23,17 @@
import org.jboss.jca.common.api.metadata.CopyUtil;
import org.jboss.jca.common.api.metadata.CopyableMetaData;
+import org.jboss.jca.common.api.metadata.MergeUtil;
+import org.jboss.jca.common.api.metadata.jbossra.JbossRa;
+import org.jboss.jca.common.api.metadata.ra.Connector;
import org.jboss.jca.common.api.metadata.ra.Icon;
import org.jboss.jca.common.api.metadata.ra.LicenseType;
import org.jboss.jca.common.api.metadata.ra.LocalizedXsdString;
+import org.jboss.jca.common.api.metadata.ra.MergeableMetadata;
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter;
import org.jboss.jca.common.api.metadata.ra.XsdString;
import org.jboss.jca.common.api.metadata.ra.ra10.Connector10;
+import org.jboss.jca.common.api.metadata.ra.ra10.ResourceAdapter10;
import org.jboss.jca.common.metadata.ra.common.ConnectorAbstractmpl;
import java.util.List;
@@ -149,5 +154,40 @@
CopyUtil.cloneString(id));
}
+ @Override
+ public Connector merge(MergeableMetadata<?> inputMd) throws Exception
+ {
+ if (inputMd instanceof JbossRa)
+ {
+ mergeJbossMetaData((JbossRa) inputMd);
+ return this;
+ }
+ if (inputMd instanceof Connector10Impl)
+ {
+ Connector10Impl input10 = (Connector10Impl) inputMd;
+ XsdString newResourceadapterVersion = XsdString.isNull(this.resourceadapterVersion)
+ ? input10.resourceadapterVersion : this.resourceadapterVersion;
+ XsdString newEisType = XsdString.isNull(this.eisType) ? input10.eisType : this.eisType;
+ String newModuleName = this.moduleName == null ? input10.moduleName : this.moduleName;
+ List<Icon> newIcons = MergeUtil.mergeList(this.icon, input10.icon);
+ LicenseType newLicense = this.license == null ? input10.license : this.license.merge(input10.license);
+ List<LocalizedXsdString> newDescriptions = MergeUtil.mergeList(this.description,
+ input10.description);
+ List<LocalizedXsdString> newDisplayNames = MergeUtil.mergeList(this.displayName,
+ input10.displayName);
+ XsdString newVendorName = XsdString.isNull(this.vendorName)
+ ? input10.vendorName : this.vendorName;;
+ ResourceAdapter10 newResourceadapter = this.resourceadapter == null
+ ? (ResourceAdapter10) input10.resourceadapter
+ : ((ResourceAdapter10) this.resourceadapter)
+ .merge((ResourceAdapter10) input10.resourceadapter);
+ return new Connector10Impl(newModuleName, newVendorName, newEisType, newResourceadapterVersion, newLicense,
+ newResourceadapter, newDescriptions, newDisplayNames, newIcons, null);
+ }
+ return this;
+
+ }
+
+
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/ResourceAdapter10Impl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/ResourceAdapter10Impl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra10/ResourceAdapter10Impl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -23,9 +23,11 @@
import org.jboss.jca.common.api.metadata.CopyUtil;
import org.jboss.jca.common.api.metadata.CopyableMetaData;
+import org.jboss.jca.common.api.metadata.MergeUtil;
import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
import org.jboss.jca.common.api.metadata.ra.AuthenticationMechanism;
import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
+import org.jboss.jca.common.api.metadata.ra.MergeableMetadata;
import org.jboss.jca.common.api.metadata.ra.SecurityPermission;
import org.jboss.jca.common.api.metadata.ra.XsdString;
import org.jboss.jca.common.api.metadata.ra.ra10.ResourceAdapter10;
@@ -387,4 +389,47 @@
reauthenticationSupport, CopyUtil.cloneList(securityPermissions), CopyUtil.cloneString(id));
}
+ @Override
+ public ResourceAdapter10 merge(MergeableMetadata<?> jmd) throws Exception
+ {
+ if (jmd instanceof ResourceAdapter10Impl)
+ {
+ ResourceAdapter10Impl inputMD = (ResourceAdapter10Impl) jmd;
+ List<ConfigProperty> newconfigProperties = MergeUtil
+ .mergeList(this.configProperties, inputMD.configProperties);
+ XsdString newManagedConnectionFactoryClass = XsdString.isNull(this.managedConnectionFactoryClass)
+ ? inputMD.managedConnectionFactoryClass
+ : this.managedConnectionFactoryClass;
+ XsdString newconnectionInterface = XsdString.isNull(this.connectionInterface)
+ ? inputMD.connectionInterface
+ : this.connectionInterface;
+ List<AuthenticationMechanism> newauthenticationMechanism = MergeUtil.mergeList(this.authenticationMechanism,
+ inputMD.authenticationMechanism);
+ Boolean newreauthenticationSupport = this.reauthenticationSupport == null
+ ? inputMD.reauthenticationSupport
+ : this.reauthenticationSupport;
+ TransactionSupportEnum newtransactionSupport = this.transactionSupport == null
+ ? inputMD.transactionSupport
+ : this.transactionSupport;
+ XsdString newconnectionImplClass = XsdString.isNull(this.connectionImplClass)
+ ? inputMD.connectionImplClass
+ : this.connectionImplClass;
+ XsdString newConnectionFactoryInterface = XsdString.isNull(this.connectionFactoryInterface)
+ ? inputMD.connectionFactoryInterface
+ : this.connectionFactoryInterface;
+ List<SecurityPermission> newsecurityPermissions = MergeUtil.mergeList(this.securityPermissions,
+ inputMD.securityPermissions);
+ XsdString newconnectionFactoryImplClass = XsdString.isNull(this.connectionFactoryImplClass)
+ ? inputMD.connectionFactoryImplClass
+ : this.connectionFactoryImplClass;
+ return new ResourceAdapter10Impl(newManagedConnectionFactoryClass, newConnectionFactoryInterface,
+ newconnectionFactoryImplClass, newconnectionInterface, newconnectionImplClass, newtransactionSupport,
+ newauthenticationMechanism, newconfigProperties, newreauthenticationSupport, newsecurityPermissions,
+ null);
+ }
+ else
+ {
+ return this;
+ }
+ }
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra15/Connector15Impl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra15/Connector15Impl.java 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ra/ra15/Connector15Impl.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -23,9 +23,13 @@
import org.jboss.jca.common.api.metadata.CopyUtil;
import org.jboss.jca.common.api.metadata.CopyableMetaData;
+import org.jboss.jca.common.api.metadata.MergeUtil;
+import org.jboss.jca.common.api.metadata.jbossra.JbossRa;
+import org.jboss.jca.common.api.metadata.ra.Connector;
import org.jboss.jca.common.api.metadata.ra.Icon;
import org.jboss.jca.common.api.metadata.ra.LicenseType;
import org.jboss.jca.common.api.metadata.ra.LocalizedXsdString;
+import org.jboss.jca.common.api.metadata.ra.MergeableMetadata;
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
import org.jboss.jca.common.api.metadata.ra.XsdString;
import org.jboss.jca.common.api.metadata.ra.ra15.Connector15;
@@ -137,5 +141,39 @@
CopyUtil.cloneList(icon), CopyUtil.cloneString(id));
}
+ @Override
+ public Connector merge(MergeableMetadata<?> inputMd) throws Exception
+ {
+ if (inputMd instanceof JbossRa)
+ {
+ mergeJbossMetaData((JbossRa) inputMd);
+ return this;
+ }
+ if (inputMd instanceof Connector15Impl)
+ {
+ Connector15Impl input15 = (Connector15Impl) inputMd;
+ XsdString newResourceadapterVersion = XsdString.isNull(this.resourceadapterVersion)
+ ? input15.resourceadapterVersion : this.resourceadapterVersion;
+ XsdString newEisType = XsdString.isNull(this.eisType) ? input15.eisType : this.eisType;
+ List<Icon> newIcons = MergeUtil.mergeList(this.icon, input15.icon);
+ LicenseType newLicense = this.license == null ? input15.license : this.license.merge(input15.license);
+ List<LocalizedXsdString> newDescriptions = MergeUtil.mergeList(this.description,
+ input15.description);
+ List<LocalizedXsdString> newDisplayNames = MergeUtil.mergeList(this.displayName,
+ input15.displayName);
+ XsdString newVendorName = XsdString.isNull(this.vendorName)
+ ? input15.vendorName : this.vendorName;;
+ ResourceAdapter1516 newResourceadapter = this.resourceadapter == null
+ ? (ResourceAdapter1516) input15.resourceadapter
+ : ((ResourceAdapter1516) this.resourceadapter)
+ .merge((ResourceAdapter1516) input15.resourceadapter);
+ return new Connector15Impl(newVendorName, newEisType, newResourceadapterVersion, newLicense,
+ newResourceadapter, newDescriptions, newDisplayNames,
+ newIcons, null);
+ }
+ return this;
+
+ }
+
}
Added: projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/MetadataFactoryTestCase.java
===================================================================
--- projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/MetadataFactoryTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/MetadataFactoryTestCase.java 2010-08-19 15:32:48 UTC (rev 107685)
@@ -0,0 +1,165 @@
+/*
+ * 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;
+
+import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
+import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
+import org.jboss.jca.common.api.metadata.ra.Connector;
+import org.jboss.jca.common.api.metadata.ra.Connector.Version;
+import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
+import org.jboss.jca.common.api.metadata.ra.XsdString;
+import org.jboss.jca.common.api.metadata.ra.ra15.Connector15;
+import org.jboss.jca.common.metadata.ds.DsParser;
+import org.jboss.jca.common.metadata.ra.RaParser;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+
+/**
+ *
+ * A RaParserTestCase.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class MetadataFactoryTestCase
+{
+ /**
+ * shouldParseConnector16
+ * @throws Exception in case of error
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void shouldMergeDsAndCOnnector() throws Exception
+ {
+
+ FileInputStream is = null;
+ try
+ {
+ //given
+ File xmlFile = new File(Thread.currentThread().getContextClassLoader()
+ .getResource("adapters/ra.xml").toURI());
+ is = new FileInputStream(xmlFile);
+ RaParser parser = new RaParser();
+ Connector connector = parser.parse(is);
+ is.close();
+ xmlFile = new File(Thread.currentThread().getContextClassLoader()
+ .getResource("ds/postgres-ds.xml").toURI());
+ is = new FileInputStream(xmlFile);
+ DsParser dsparser = new DsParser();
+ //when
+ DataSources ds = dsparser.parse(is);
+
+ List<? extends ConfigProperty> properties = null;
+ if (connector.getResourceadapter() != null
+ && connector.getResourceadapter() instanceof ResourceAdapter1516
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter() != null
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions() != null)
+ {
+ properties = ((ResourceAdapter1516) connector
+ .getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions().get(0).getConfigProperties();
+ }
+
+ //verify pre-condition
+ assertThat(((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter()
+ .getTransactionSupport(), is(TransactionSupportEnum.LocalTransaction));
+ assertThat(((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions().get(0).getManagedConnectionFactoryClass(), equalTo(new XsdString(
+ "org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory", null)));
+
+ //when
+ Connector merged = MetadataFactory.mergeConnectorAndDs(ds.getDatasource().get(0), connector);
+ //then
+ assertThat(merged, instanceOf(Connector15.class));
+ assertThat(merged.getVersion(), is(Version.V_15));
+
+ List<? extends ConfigProperty> mergedProperties = null;
+
+ if (connector.getResourceadapter() != null
+ && connector.getResourceadapter() instanceof ResourceAdapter1516
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter() != null
+ &&
+ ((ResourceAdapter1516) connector.getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions() != null)
+ {
+ mergedProperties = ((ResourceAdapter1516) merged
+ .getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions().get(0).getConfigProperties();
+ }
+ //then merged properties are presents
+ assertThat((List<ConfigProperty>) mergedProperties,
+ hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.USERNAME, "x")));
+ assertThat((List<ConfigProperty>) mergedProperties,
+ hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.PASSWORD, "y")));
+ assertThat((List<ConfigProperty>) mergedProperties,
+ hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.CONNECTIONURL,
+ "jdbc:postgresql://[servername]:[port]/[database name]")));
+ assertThat((List<ConfigProperty>) mergedProperties,
+ hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.DRIVERCLASS, "org.postgresql.Driver")));
+
+ //then metadata read from ra.xml still present (not deleted by merge)
+ assertThat(((ResourceAdapter1516) merged.getResourceadapter()).getOutboundResourceadapter()
+ .getTransactionSupport(), is(TransactionSupportEnum.LocalTransaction));
+ assertThat(((ResourceAdapter1516) merged.getResourceadapter()).getOutboundResourceadapter()
+ .getConnectionDefinitions().get(0).getManagedConnectionFactoryClass(), equalTo(new XsdString(
+ "org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory", null)));
+
+ //then it have empty property for not set ones
+ assertThat((List<ConfigProperty>) mergedProperties,
+ not(hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.PREPAREDSTATEMENTCACHESIZE, ""))));
+
+ //then it does not contain property not in ra.xml
+ assertThat((List<ConfigProperty>) mergedProperties,
+ not(hasItem(MetadataFactory.ConfigPropertyFactory.createConfigProperty(
+ MetadataFactory.ConfigPropertyFactory.Prototype.XADATASOURCEPROPERTIES, ""))));
+
+ }
+ finally
+ {
+ if (is != null)
+ is.close();
+ }
+
+ }
+
+}
Added: projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/package.html
===================================================================
--- projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/package.html (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/package.html 2010-08-19 15:32:48 UTC (rev 107685)
@@ -0,0 +1,3 @@
+<body>
+This package contains Metadata general tet cases
+</body>
Added: projects/jboss-jca/trunk/common/src/test/resources/adapters/ra.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/adapters/ra.xml (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/adapters/ra.xml 2010-08-19 15:32:48 UTC (rev 107685)
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connector xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+
+ <description>JBoss LocalTransaction JDBC Wrapper Resource Adapter</description>
+ <display-name>JBoss LocalTransaction JDBC Wrapper</display-name>
+
+ <vendor-name>Red Hat Middleware LLC</vendor-name>
+ <eis-type>JDBC 4.0 Relational Database</eis-type>
+ <resourceadapter-version>7.0</resourceadapter-version>
+
+ <license>
+ <description>
+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.
+ </description>
+ <license-required>true</license-required>
+ </license>
+
+ <resourceadapter>
+ <outbound-resourceadapter>
+ <connection-definition>
+ <managedconnectionfactory-class>org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory</managedconnectionfactory-class>
+ <config-property>
+ <description>The jdbc driver class.</description>
+ <config-property-name>DriverClass</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>
+ </config-property>
+ <config-property>
+ <description>The jdbc connection url delimeter.</description>
+ <config-property-name>URLDelimiter</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The configurable URLSelectorStrategy class name.</description>
+ <config-property-name>UrlSelectorStrategyClassName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The default transaction isolation of the connections.</description>
+ <config-property-name>TransactionIsolation</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The number of cached prepared statements per connection.</description>
+ <config-property-name>PreparedStatementCacheSize</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Whether to share prepared statements.</description>
+ <config-property-name>SharePreparedStatements</config-property-name>
+ <config-property-type>java.lang.Boolean</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The user name to connect to the database.</description>
+ <config-property-name>UserName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The password to connect to the database.</description>
+ <config-property-name>Password</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Connection properties for the database.</description>
+ <config-property-name>ConnectionProperties</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>An SQL statement to be executed when a new connection is created as auxillary setup.</description>
+ <config-property-name>NewConnectionSQL</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>An SQL statement that may be executed when a managed connection is taken out of the pool and is about to be given to a client: the purpose is to verify that the connection still works.</description>
+ <config-property-name>CheckValidConnectionSQL</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.ValidConnectionChecker that can determine for a particular vender db when a connection is valid.</description>
+ <config-property-name>ValidConnectionCheckerClassName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.ExceptionSorter that can determine for a particular vender db which exceptions are fatal and mean a connection should be discarded.</description>
+ <config-property-name>ExceptionSorterClassName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>The fully qualified name of a class implementing org.jboss.jca.adapters.jdbc.StaleConnectionChecker that can determine for a particular vender db when a connection is stale.</description>
+ <config-property-name>StaleConnectionCheckerClassName</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Whether to track unclosed statements - false/true/nowarn</description>
+ <config-property-name>TrackStatements</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Whether to validate the connection on the ManagedConnectionFactory.matchManagedConnection method</description>
+ <config-property-name>ValidateOnMatch</config-property-name>
+ <config-property-type>java.lang.Boolean</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Whether to set the query timeout based on the transaction timeout</description>
+ <config-property-name>TransactionQueryTimeout</config-property-name>
+ <config-property-type>java.lang.Boolean</config-property-type>
+ </config-property>
+ <config-property>
+ <description>A configured query timeout</description>
+ <config-property-name>QueryTimeout</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ </config-property>
+ <config-property>
+ <description>Maximum wait for a lock</description>
+ <config-property-name>UseTryLock</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ </config-property>
+ <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
+ <connectionfactory-impl-class>org.jboss.jca.adapters.jdbc.WrapperDataSource</connectionfactory-impl-class>
+ <connection-interface>java.sql.Connection</connection-interface>
+ <connection-impl-class>org.jboss.jca.adapters.jdbc.WrappedConnection</connection-impl-class>
+ </connection-definition>
+ <transaction-support>LocalTransaction</transaction-support>
+ <authentication-mechanism>
+ <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
+ <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
+ </authentication-mechanism>
+ <reauthentication-support>false</reauthentication-support>
+ </outbound-resourceadapter>
+ </resourceadapter>
+</connector>
Modified: projects/jboss-jca/trunk/tools/findbugs/filter.xml
===================================================================
--- projects/jboss-jca/trunk/tools/findbugs/filter.xml 2010-08-19 15:08:45 UTC (rev 107684)
+++ projects/jboss-jca/trunk/tools/findbugs/filter.xml 2010-08-19 15:32:48 UTC (rev 107685)
@@ -27,6 +27,11 @@
<Class name="org.jboss.jca.common.api.ThreadPool"/>
<Bug code="Nm"/>
</Match>
+ <Match>
+ <Class name="org.jboss.jca.common.metadata.MetadataFactory"/>
+ <Method name="mergeConnectorAndDs" />
+ <Bug code="NP"/>
+ </Match>
<!-- org.jboss.jca.core filter -->
<Match>
@@ -111,5 +116,6 @@
<Class name="org.jboss.jca.web.console.Server"/>
<Bug code="RCN"/>
</Match>
+
</FindBugsFilter>
More information about the jboss-cvs-commits
mailing list