();
+ Reference ref = (Reference)obj;
+ Enumeration> en = ref.getAll();
+ while (en.hasMoreElements()) {
+ RefAddr subref = (RefAddr)en.nextElement();
+ if (subref instanceof StringRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value != null) values.put(key, value.toString());
+ }
+ }
+ String sourceName = values.get(SOURCE_NAME);
+ String rootNodeUuid = values.get(ROOT_NODE_UUID);
+ String dataSourceJndiName = values.get(DATA_SOURCE_JNDI_NAME);
+ String username = values.get(USERNAME);
+ String password = values.get(PASSWORD);
+ String url = values.get(URL);
+ String driverClassName = values.get(DRIVER_CLASS_NAME);
+ String driverClassloaderName = values.get(DRIVER_CLASSLOADER_NAME);
+ String maxConnectionsInPool = values.get(MAXIMUM_CONNECTIONS_IN_POOL);
+ String minConnectionsInPool = values.get(MINIMUM_CONNECTIONS_IN_POOL);
+ String maxConnectionIdleTimeInSec = values.get(MAXIMUM_CONNECTION_IDLE_TIME_IN_SECONDS);
+ String maxSizeOfStatementCache = values.get(MAXIMUM_SIZE_OF_STATEMENT_CACHE);
+ String acquisitionIncrement = values.get(NUMBER_OF_CONNECTIONS_TO_BE_ACQUIRED_AS_NEEDED);
+ String idleTimeInSeconds = values.get(IDLE_TIME_IN_SECONDS_BEFORE_TESTING_CONNECTIONS);
+ String cacheTtlInMillis = values.get(CACHE_TIME_TO_LIVE_IN_MILLISECONDS);
+ String retryLimit = values.get(RETRY_LIMIT);
+ String defaultWorkspace = values.get(DEFAULT_WORKSPACE);
+ String defaultCatalogName = values.get(DEFAULT_CATALOG_NAME);
+ String defaultSchemaName = values.get(DEFAULT_SCHEMA_NAME);
+ String metadataCollectorClassName = values.get(METADATA_COLLECTOR_CLASS_NAME);
+
+ // Create the source instance ...
+ JdbcMetadataSource source = new JdbcMetadataSource();
+ if (sourceName != null) source.setName(sourceName);
+ if (rootNodeUuid != null) source.setRootNodeUuid(rootNodeUuid);
+ if (dataSourceJndiName != null) source.setDataSourceJndiName(dataSourceJndiName);
+ if (username != null) source.setUsername(username);
+ if (password != null) source.setPassword(password);
+ if (url != null) source.setUrl(url);
+ if (driverClassName != null) source.setDriverClassName(driverClassName);
+ if (driverClassloaderName != null) source.setDriverClassloaderName(driverClassloaderName);
+ if (maxConnectionsInPool != null) source.setMaximumConnectionsInPool(Integer.parseInt(maxConnectionsInPool));
+ if (minConnectionsInPool != null) source.setMinimumConnectionsInPool(Integer.parseInt(minConnectionsInPool));
+ if (maxConnectionIdleTimeInSec != null) source.setMaximumConnectionIdleTimeInSeconds(Integer.parseInt(maxConnectionIdleTimeInSec));
+ if (maxSizeOfStatementCache != null) source.setMaximumSizeOfStatementCache(Integer.parseInt(maxSizeOfStatementCache));
+ if (acquisitionIncrement != null) source.setNumberOfConnectionsToAcquireAsNeeded(Integer.parseInt(acquisitionIncrement));
+ if (idleTimeInSeconds != null) source.setIdleTimeInSecondsBeforeTestingConnections(Integer.parseInt(idleTimeInSeconds));
+ if (cacheTtlInMillis != null) source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(cacheTtlInMillis));
+ if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ if (defaultWorkspace != null) source.setDefaultWorkspaceName(defaultWorkspace);
+ if (defaultCatalogName != null) source.setDefaultCatalogName(defaultCatalogName);
+ if (defaultSchemaName != null) source.setDefaultCatalogName(defaultSchemaName);
+ if (metadataCollectorClassName != null) source.setMetadataCollectorClassName(metadataCollectorClassName);
+
+ return source;
+
+ }
+
+ /**
+ * @return dataSourceJndiName
+ */
+ public String getDataSourceJndiName() {
+ return dataSourceJndiName;
+ }
+
+ /**
+ * @param dataSourceJndiName Sets dataSourceJndiName to the specified value.
+ */
+ public void setDataSourceJndiName( String dataSourceJndiName ) {
+ if (dataSourceJndiName != null && dataSourceJndiName.trim().length() == 0) dataSourceJndiName = null;
+ this.dataSourceJndiName = dataSourceJndiName;
+ }
+
+ /**
+ * @return driverClassName
+ */
+ public String getDriverClassName() {
+ return driverClassName;
+ }
+
+ /**
+ * @param driverClassName Sets driverClassName to the specified value.
+ */
+ public synchronized void setDriverClassName( String driverClassName ) {
+ if (driverClassName != null && driverClassName.trim().length() == 0) driverClassName = null;
+ this.driverClassName = driverClassName;
+ }
+
+ /**
+ * @return driverClassloaderName
+ */
+ public String getDriverClassloaderName() {
+ return driverClassloaderName;
+ }
+
+ /**
+ * @param driverClassloaderName Sets driverClassloaderName to the specified value.
+ */
+ public synchronized void setDriverClassloaderName( String driverClassloaderName ) {
+ if (driverClassloaderName != null && driverClassloaderName.trim().length() == 0) driverClassloaderName = null;
+ this.driverClassloaderName = driverClassloaderName;
+ }
+
+ /**
+ * @return username
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * @param username Sets username to the specified value.
+ */
+ public synchronized void setUsername( String username ) {
+ this.username = username;
+ }
+
+ /**
+ * @return password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * @param password Sets password to the specified value.
+ */
+ public synchronized void setPassword( String password ) {
+ this.password = password;
+ }
+
+ /**
+ * @return url
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * @param url Sets url to the specified value.
+ */
+ public synchronized void setUrl( String url ) {
+ if (url != null && url.trim().length() == 0) url = null;
+ this.url = url;
+ }
+
+ /**
+ * @return maximumConnectionsInPool
+ */
+ public int getMaximumConnectionsInPool() {
+ return maximumConnectionsInPool;
+ }
+
+ /**
+ * @param maximumConnectionsInPool Sets maximumConnectionsInPool to the specified value.
+ */
+ public synchronized void setMaximumConnectionsInPool( int maximumConnectionsInPool ) {
+ if (maximumConnectionsInPool < 0) maximumConnectionsInPool = DEFAULT_MAXIMUM_CONNECTIONS_IN_POOL;
+ this.maximumConnectionsInPool = maximumConnectionsInPool;
+ }
+
+ /**
+ * @return minimumConnectionsInPool
+ */
+ public int getMinimumConnectionsInPool() {
+ return minimumConnectionsInPool;
+ }
+
+ /**
+ * @param minimumConnectionsInPool Sets minimumConnectionsInPool to the specified value.
+ */
+ public synchronized void setMinimumConnectionsInPool( int minimumConnectionsInPool ) {
+ if (minimumConnectionsInPool < 0) minimumConnectionsInPool = DEFAULT_MINIMUM_CONNECTIONS_IN_POOL;
+ this.minimumConnectionsInPool = minimumConnectionsInPool;
+ }
+
+ /**
+ * @return maximumConnectionIdleTimeInSeconds
+ */
+ public int getMaximumConnectionIdleTimeInSeconds() {
+ return maximumConnectionIdleTimeInSeconds;
+ }
+
+ /**
+ * @param maximumConnectionIdleTimeInSeconds Sets maximumConnectionIdleTimeInSeconds to the specified value.
+ */
+ public synchronized void setMaximumConnectionIdleTimeInSeconds( int maximumConnectionIdleTimeInSeconds ) {
+ if (maximumConnectionIdleTimeInSeconds < 0) maximumConnectionIdleTimeInSeconds = DEFAULT_MAXIMUM_CONNECTION_IDLE_TIME_IN_SECONDS;
+ this.maximumConnectionIdleTimeInSeconds = maximumConnectionIdleTimeInSeconds;
+ }
+
+ /**
+ * @return maximumSizeOfStatementCache
+ */
+ public int getMaximumSizeOfStatementCache() {
+ return maximumSizeOfStatementCache;
+ }
+
+ /**
+ * @param maximumSizeOfStatementCache Sets maximumSizeOfStatementCache to the specified value.
+ */
+ public synchronized void setMaximumSizeOfStatementCache( int maximumSizeOfStatementCache ) {
+ if (maximumSizeOfStatementCache < 0) maximumSizeOfStatementCache = DEFAULT_MAXIMUM_NUMBER_OF_STATEMENTS_TO_CACHE;
+ this.maximumSizeOfStatementCache = maximumSizeOfStatementCache;
+ }
+
+ /**
+ * @return numberOfConnectionsToAcquireAsNeeded
+ */
+ public int getNumberOfConnectionsToAcquireAsNeeded() {
+ return numberOfConnectionsToAcquireAsNeeded;
+ }
+
+ /**
+ * @param numberOfConnectionsToAcquireAsNeeded Sets numberOfConnectionsToAcquireAsNeeded to the specified value.
+ */
+ public synchronized void setNumberOfConnectionsToAcquireAsNeeded( int numberOfConnectionsToAcquireAsNeeded ) {
+ if (numberOfConnectionsToAcquireAsNeeded < 0) numberOfConnectionsToAcquireAsNeeded = DEFAULT_NUMBER_OF_CONNECTIONS_TO_ACQUIRE_AS_NEEDED;
+ this.numberOfConnectionsToAcquireAsNeeded = numberOfConnectionsToAcquireAsNeeded;
+ }
+
+ /**
+ * @return idleTimeInSecondsBeforeTestingConnections
+ */
+ public int getIdleTimeInSecondsBeforeTestingConnections() {
+ return idleTimeInSecondsBeforeTestingConnections;
+ }
+
+ /**
+ * @param idleTimeInSecondsBeforeTestingConnections Sets idleTimeInSecondsBeforeTestingConnections to the specified value.
+ */
+ public synchronized void setIdleTimeInSecondsBeforeTestingConnections( int idleTimeInSecondsBeforeTestingConnections ) {
+ if (idleTimeInSecondsBeforeTestingConnections < 0) idleTimeInSecondsBeforeTestingConnections = DEFAULT_IDLE_TIME_IN_SECONDS_BEFORE_TESTING_CONNECTIONS;
+ this.idleTimeInSecondsBeforeTestingConnections = idleTimeInSecondsBeforeTestingConnections;
+ }
+
+ /**
+ * Set the {@link DataSource} instance that this source should use.
+ *
+ * @param dataSource the data source; may be null
+ * @see #getDataSource()
+ * @see #setDataSourceJndiName(String)
+ */
+ /*package*/synchronized void setDataSource( DataSource dataSource ) {
+ this.dataSource = dataSource;
+ }
+
+ /**
+ * @return rootNodeUuid
+ */
+ public String getRootNodeUuid() {
+ return rootNodeUuid;
+ }
+
+ /**
+ * @return rootUuid
+ */
+ public UUID getRootUuid() {
+ return rootUuid;
+ }
+
+ /**
+ * @param rootNodeUuid Sets rootNodeUuid to the specified value.
+ * @throws IllegalArgumentException if the string value cannot be converted to UUID
+ */
+ public void setRootNodeUuid( String rootNodeUuid ) {
+ if (rootNodeUuid != null && rootNodeUuid.trim().length() == 0) rootNodeUuid = DEFAULT_ROOT_NODE_UUID;
+ this.rootUuid = UUID.fromString(rootNodeUuid);
+ this.rootNodeUuid = rootNodeUuid;
+ }
+
+ /**
+ * Get the name of the default workspace.
+ *
+ * @return the name of the workspace that should be used by default, or null if there is no default workspace
+ */
+ public String getDefaultWorkspaceName() {
+ return defaultWorkspace;
+ }
+
+ /**
+ * Set the name of the workspace that should be used when clients don't specify a workspace.
+ *
+ * @param nameOfDefaultWorkspace the name of the workspace that should be used by default, or null if the
+ * {@link #DEFAULT_NAME_OF_DEFAULT_WORKSPACE default name} should be used
+ */
+ public synchronized void setDefaultWorkspaceName( String nameOfDefaultWorkspace ) {
+ this.defaultWorkspace = nameOfDefaultWorkspace != null ? nameOfDefaultWorkspace : DEFAULT_NAME_OF_DEFAULT_WORKSPACE;
+ }
+
+ /**
+ * Get the name of the default catalog.
+ *
+ * @return the name that should be used as the catalog name when the database does not support catalogs
+ */
+ public String getDefaultCatalogName() {
+ return defaultCatalogName;
+ }
+
+ /**
+ * Set the name of the catalog that should be used when the database does not support catalogs.
+ *
+ * @param defaultCatalogName the name that should be used as the catalog name by default, or null if the
+ * {@link #DEFAULT_NAME_OF_DEFAULT_CATALOG default name} should be used
+ */
+ public void setDefaultCatalogName( String defaultCatalogName ) {
+ this.defaultCatalogName = defaultCatalogName == null ? DEFAULT_NAME_OF_DEFAULT_CATALOG : defaultCatalogName;
+ }
+
+ /**
+ * Get the name of the default schema.
+ *
+ * @return the name that should be used as the schema name when the database does not support schemas
+ */
+ public String getDefaultSchemaName() {
+ return defaultSchemaName;
+ }
+
+ /**
+ * Set the name of the schema that should be used when the database does not support schemas.
+ *
+ * @param defaultSchemaName the name that should be used as the schema name by default, or null if the
+ * {@link #DEFAULT_NAME_OF_DEFAULT_SCHEMA default name} should be used
+ */
+ public void setDefaultSchemaName( String defaultSchemaName ) {
+ this.defaultSchemaName = defaultSchemaName == null ? DEFAULT_NAME_OF_DEFAULT_SCHEMA : defaultSchemaName;
+ }
+
+ /**
+ * Get the class name of the metadata collector.
+ *
+ * @return the name the class name of the metadata collector
+ */
+ public String getMetadataCollectorClassName() {
+ return metadataCollectorClassName;
+ }
+
+ /**
+ * Set the class name of the metadata collector and instantiates a new metadata collector object for that class
+ *
+ * @param metadataCollectorClassName the class name for the metadata collector, or null if the
+ * {@link #DEFAULT_METADATA_COLLECTOR default metadata collector} should be used
+ * @throws ClassNotFoundException if the the named metadata collector class cannot be located
+ * @throws IllegalAccessException if the metadata collector class or its nullary constructor is not accessible.
+ * @throws InstantiationException if the metadata collector class represents an abstract class, an interface, an array class,
+ * a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other
+ * reason.
+ * @throws ClassCastException if the given class cannot be cast to {@link MetadataCollector}.
+ * @see Class#forName(String)
+ * @see Class#newInstance()
+ */
+ @SuppressWarnings( "unchecked" )
+ public synchronized void setMetadataCollectorClassName( String metadataCollectorClassName )
+ throws ClassNotFoundException, IllegalAccessException, InstantiationException {
+ if (metadataCollectorClassName == null) {
+ this.metadataCollectorClassName = DEFAULT_METADATA_COLLECTOR.getClass().getName();
+ this.metadataCollector = DEFAULT_METADATA_COLLECTOR;
+ } else {
+ Class newCollectorClass = Class.forName(metadataCollectorClassName);
+ this.metadataCollector = (MetadataCollector)newCollectorClass.newInstance();
+ this.metadataCollectorClassName = metadataCollectorClassName;
+ }
+ }
+
+ /**
+ * Returns the metadata collector instance
+ *
+ * @return the metadata collector
+ */
+ public synchronized MetadataCollector getMetadataCollector() {
+ return metadataCollector;
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\main\java\org\jboss\dna\connector\meta\jdbc\JdbcMetadataSource.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/MetadataCollector.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/MetadataCollector.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/MetadataCollector.java (revision 0)
@@ -0,0 +1,147 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.util.List;
+
+/**
+ * The {@code MetadataCollector} provides hooks for DBMS-specific implementations of metadata retrieval methods. These methods
+ * largely duplicate what is provided in {@link DatabaseMetaData the JDBC metadata interface}, but allow a pluggable way to work
+ * around JDBC driver-specific shortcomings.
+ *
+ * For convenience, a {@link JdbcMetadataCollector} default implementation} of this interface is provided that is based on
+ * {@link DatabaseMetaData}.
+ *
+ *
+ * @see JdbcMetadataCollector
+ */
+public interface MetadataCollector {
+
+ /**
+ * Return the list of catalog names that currently exist in the database to which {@code connection} is connected. The names
+ * must be sorted in a manner that is stable between successive calls to this method.
+ *
+ * @param conn the connection to the database; must not be non-null and must be open. This connection should not be closed by
+ * this method.
+ * @return An ordered list of the catalogs in the database, or an empty list if no catalogs exist; may not be null
+ * @throws JdbcMetadataException if the catalog names cannot be retrieved
+ * @see DatabaseMetaData#getCatalogs()
+ */
+ List getCatalogNames( Connection conn ) throws JdbcMetadataException;
+
+ /**
+ * Return the list of schema names that currently exist in the database to which {@code connection} is connected within the
+ * named catalog. If {@code catalogName} is null, then all schema names should be returned regardless of the catalog with
+ * which they are associated. The schema names must be sorted in a manner that is stable between successive calls to this
+ * method.
+ *
+ * @param conn the connection to the database; must not be non-null and must be open. This connection should not be closed by
+ * this method.
+ * @param catalogName the name of the catalog to which returned schemas must belong, or null if all schemas are to be returned
+ * @return An ordered list of the schemas in the database, or an empty list if no schemas exist; may not be null
+ * @throws JdbcMetadataException if the schema names cannot be retrieved
+ * @see DatabaseMetaData#getSchemas()
+ */
+ List getSchemaNames( Connection conn,
+ String catalogName ) throws JdbcMetadataException;
+
+ /**
+ * Return the list of tables that currently exist in the database to which {@code connection} is connected within the named
+ * catalog (if {@code catalogName} is non-null) and named schema (if {@code schemaName} is non-null). If {@code tableName} is
+ * null, then all tables which conform to the catalog and schema restriction noted previously should be returned. If {@code
+ * tableName} is non-null, then only the table(s) that exactly match that name should be returned. The table metadata must be
+ * sorted in a manner that is stable between successive calls to this method.
+ *
+ * @param conn the connection to the database; must not be non-null and must be open. This connection should not be closed by
+ * this method.
+ * @param catalogName the name of the catalog to which returned tables must belong, or null if tables are to be returned
+ * without regard to their catalog
+ * @param schemaName the name of the schema to which returned tables must belong, or null if tables are to be returned without
+ * regard to their schema
+ * @param tableName the name of the table to be returned, or null if all tables within the given catalog and schema are to be
+ * returned
+ * @return An ordered list of the tables in the database that match the given constraints, or an empty list if no tables exist
+ * that match the given constraints; may not be null
+ * @throws JdbcMetadataException if the table metadata cannot be retrieved
+ * @see DatabaseMetaData#getTables(String, String, String, String[])
+ */
+ List getTables( Connection conn,
+ String catalogName,
+ String schemaName,
+ String tableName ) throws JdbcMetadataException;
+
+ /**
+ * Return the list of columns that currently exist in the database to which {@code connection} is connected within the named
+ * catalog (if {@code catalogName} is non-null), named schema (if {@code schemaName} is non-null), and named table. If {@code
+ * columnName} is null, then all columns which conform to the catalog, schema, and table restrictions noted previously should
+ * be returned. If {@code columnName} is non-null, then only the column that exactly matches that name should be returned. The
+ * column metadata must be sorted in a manner that is stable between successive calls to this method.
+ *
+ * @param conn the connection to the database; must not be non-null and must be open. This connection should not be closed by
+ * this method.
+ * @param catalogName the name of the catalog to which returned columns must belong, or null if columns are to be returned
+ * without regard to their catalog
+ * @param schemaName the name of the schema to which returned columns must belong, or null if columns are to be returned
+ * without regard to their schema
+ * @param tableName the name of the table to which returned columns must belong; may not be null
+ * @param columnName the name of the column to be returned, or null if all columns within the given catalog, schema, and table
+ * are to be returned
+ * @return An ordered list of the columns in the database that match the given constraints, or an empty list if no columns
+ * exist that match the given constraints; may not be null
+ * @throws JdbcMetadataException if the column metadata cannot be retrieved
+ * @see DatabaseMetaData#getColumns(String, String, String, String)
+ */
+ List getColumns( Connection conn,
+ String catalogName,
+ String schemaName,
+ String tableName,
+ String columnName ) throws JdbcMetadataException;
+
+ /**
+ * Return the list of procedures that currently exist in the database to which {@code connection} is connected within the
+ * named catalog (if {@code catalogName} is non-null) and named schema (if {@code schemaName} is non-null). If {@code
+ * procedureName} is null, then all procedures which conform to the catalog and schema restriction noted previously should be
+ * returned. If {@code procedureName} is non-null, then only the procedure(s) that exactly match that name should be returned.
+ * The procedure metadata must be sorted in a manner that is stable between successive calls to this method.
+ *
+ * @param conn the connection to the database; must not be non-null and must be open. This connection should not be closed by
+ * this method.
+ * @param catalogName the name of the catalog to which returned procedures must belong, or null if procedures are to be
+ * returned without regard to their catalog
+ * @param schemaName the name of the schema to which returned procedures must belong, or null if procedures are to be returned
+ * without regard to their schema
+ * @param procedureName the name of the procedure(s) to be returned, or null if all procedures within the given catalog and
+ * schema are to be returned
+ * @return An ordered list of the procedures in the database that match the given constraints, or an empty list if no
+ * procedures exist that match the given constraints; may not be null
+ * @throws JdbcMetadataException if the procedure metadata cannot be retrieved
+ */
+ List getProcedures( Connection conn,
+ String catalogName,
+ String schemaName,
+ String procedureName ) throws JdbcMetadataException;
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\main\java\org\jboss\dna\connector\meta\jdbc\MetadataCollector.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/ProcedureMetadata.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/ProcedureMetadata.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/ProcedureMetadata.java (revision 0)
@@ -0,0 +1,71 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import java.sql.DatabaseMetaData;
+
+/**
+ * Container for column-level metadata. The fields in this class roughly parallel the information returned from the
+ * {@link DatabaseMetaData#getProcedures(String, String, String)} method.
+ */
+public class ProcedureMetadata {
+
+ private final String name;
+ private final String description;
+ private final int type;
+
+ public ProcedureMetadata( String name,
+ String description,
+ int type ) {
+ super();
+ this.name = name;
+ this.description = description;
+ this.type = type;
+ }
+
+ /**
+ * @return the procedure name (PROCEDURE_NAME in the {@link DatabaseMetaData#getProcedures(String, String, String)} result
+ * set).
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the procedure description (REMARKS in the {@link DatabaseMetaData#getProcedures(String, String, String)} result
+ * set).
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the kind of procedure (PROCEDURE_TYPE in the {@link DatabaseMetaData#getProcedures(String, String, String)} result
+ * set).
+ */
+ public int getType() {
+ return type;
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\main\java\org\jboss\dna\connector\meta\jdbc\ProcedureMetadata.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/TableMetadata.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/TableMetadata.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/meta/jdbc/TableMetadata.java (revision 0)
@@ -0,0 +1,126 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import java.sql.DatabaseMetaData;
+import net.jcip.annotations.Immutable;
+
+/**
+ * Container for table-level metadata. The fields in this class roughly parallel the information returned from the
+ * {@link DatabaseMetaData#getTables(String, String, String, String[])} method.
+ */
+@Immutable
+public class TableMetadata {
+
+ private final String name;
+ private final String type;
+ private final String description;
+ private final String typeCatalogName;
+ private final String typeSchemaName;
+ private final String typeName;
+ private final String selfReferencingColumnName;
+ private final String referenceGenerationStrategyName;
+
+ public TableMetadata( String name,
+ String type,
+ String description,
+ String typeCatalogName,
+ String typeSchemaName,
+ String typeName,
+ String selfReferencingColumnName,
+ String referenceGenerationStrategyName ) {
+ super();
+ this.name = name;
+ this.type = type;
+ this.description = description;
+ this.typeCatalogName = typeCatalogName;
+ this.typeSchemaName = typeSchemaName;
+ this.typeName = typeName;
+ this.selfReferencingColumnName = selfReferencingColumnName;
+ this.referenceGenerationStrategyName = referenceGenerationStrategyName;
+ }
+
+ /**
+ * @return the table name (TABLE_NAME in the {@link DatabaseMetaData#getTables(String, String, String, String[])} result set).
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the table type (TABLE_TYPE in the {@link DatabaseMetaData#getTables(String, String, String, String[])} result set).
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @return the table description (REMARKS in the {@link DatabaseMetaData#getTables(String, String, String, String[])} result
+ * set).
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the table types catalog name (TYPE_CAT in the {@link DatabaseMetaData#getTables(String, String, String, String[])}
+ * result set).
+ */
+ public String getTypeCatalogName() {
+ return typeCatalogName;
+ }
+
+ /**
+ * @return the table types schema name (TYPE_SCHEM in the {@link DatabaseMetaData#getTables(String, String, String, String[])}
+ * result set).
+ */
+ public String getTypeSchemaName() {
+ return typeSchemaName;
+ }
+
+ /**
+ * @return the table type name (TYPE_NAME in the {@link DatabaseMetaData#getTables(String, String, String, String[])} result
+ * set).
+ */
+ public String getTypeName() {
+ return typeName;
+ }
+
+ /**
+ * @return per the Javadoc for the DatabaseMetaData method, "the name of the designated 'identifier' column of a typed table"
+ * (SELF_REFERENCING_COL_NAME in the {@link DatabaseMetaData#getTables(String, String, String, String[])} result set).
+ */
+ public String getSelfReferencingColumnName() {
+ return selfReferencingColumnName;
+ }
+
+ /**
+ * @return the strategy for creating the values in the self-referencing column (REF_GENERATION in the
+ * {@link DatabaseMetaData#getTables(String, String, String, String[])} result set).
+ */
+ public String getReferenceGenerationStrategyName() {
+ return referenceGenerationStrategyName;
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\main\java\org\jboss\dna\connector\meta\jdbc\TableMetadata.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18n.properties
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18n.properties (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18n.properties (revision 0)
@@ -0,0 +1,42 @@
+#
+# JBoss DNA (http://www.jboss.org/dna)
+# See the COPYRIGHT.txt file distributed with this work for information
+# regarding copyright ownership. Some portions may be licensed
+# to Red Hat, Inc. under one or more contributor license agreements.
+# See the AUTHORS.txt file in the distribution for a full listing of
+# individual contributors.
+#
+# JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+# is licensed to you 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.
+#
+# JBoss DNA 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.
+#
+
+errorClosingConnection = Error closing SQL connection
+errorObtainingConnection = Error obtaining SQL connection
+
+couldNotGetDatabaseMetadata = Could not obtain database-level metadata
+couldNotGetCatalogNames = Could not obtain catalog names for database
+couldNotGetSchemaNames = Could not obtain schema names for catalog "{0}"
+couldNotGetTableNames = Could not get the table names for schema "{1}" in catalog "{0}"
+couldNotGetTable = Could not get metadata for the table named "{2}" in schema "{1}" in catalog "{0}"
+couldNotGetColumn = Could not get metadata for the column named "{3}" in the table named "{2}" in schema "{1}" in catalog "{0}"
+duplicateTablesWithSameName = Multiple tables named "{2}" in catalog "{0}" and schema "{1}"
+couldNotGetProcedureNames = Could not get the procedure names for schema "{1}" in catalog "{0}"
+couldNotGetProcedure = Could not get metadata for the procedure named "{2}" in schema "{1}" in catalog "{0}"
+
+repositorySourceMustHaveName = The JDBC Metadata Store repository source must have a name
+errorFindingDataSourceInJndi = JDBC Metadata repository source {0} unable to find DataSource in JNDI at {1}
+errorSettingContextClassLoader = Error while setting the current context class loader for JDBC Metadata repository source {0} to classloader name {1}
+driverClassNameAndUrlAreRequired = Since no valid JNDI name for a data source was provided, a JDBC driver class name ({0}) and a JDBC driver URL ({1}) must both be provided
+couldNotSetDriverProperties = Could not set driver properties on c3p0 data source
Index: extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataConnectorTest.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataConnectorTest.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataConnectorTest.java (revision 0)
@@ -0,0 +1,72 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import java.io.IOException;
+import javax.naming.NamingException;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.ReadableConnectorTest;
+import org.junit.After;
+import org.xml.sax.SAXException;
+
+public class JdbcMetadataConnectorTest extends ReadableConnectorTest {
+
+ private JdbcMetadataSource source;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws NamingException {
+ this.source = TestEnvironment.configureJdbcMetadataSource("Test Repository", this);
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws SAXException
+ * @throws IOException
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws Exception {
+ TestEnvironment.executeDdl(this.source.getDataSource(), "/create.ddl");
+
+ graph = Graph.create(source, context);
+ }
+
+ @Override
+ @After
+ public void afterEach() throws Exception {
+ TestEnvironment.executeDdl(this.source.getDataSource(), "/drop.ddl");
+
+ this.source.close();
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\test\java\org\jboss\dna\connector\meta\jdbc\JdbcMetadataConnectorTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18nTest.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18nTest.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataI18nTest.java (revision 0)
@@ -0,0 +1,34 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+public class JdbcMetadataI18nTest extends AbstractI18nTest {
+
+ public JdbcMetadataI18nTest() {
+ super(JdbcMetadataI18nTest.class);
+ }
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\test\java\org\jboss\dna\connector\meta\jdbc\JdbcMetadataI18nTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataRepositoryTest.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataRepositoryTest.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataRepositoryTest.java (revision 0)
@@ -0,0 +1,487 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.Types;
+import java.util.Map;
+import java.util.Set;
+import javax.sql.DataSource;
+import org.jboss.dna.graph.DnaLexicon;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.path.PathNode;
+import org.jboss.dna.graph.connector.path.PathWorkspace;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NameFactory;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.PathFactory;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.ValueFactory;
+import org.jboss.dna.graph.property.Path.Segment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+public class JdbcMetadataRepositoryTest {
+
+ private JdbcMetadataSource source;
+ @Mock
+ private RepositoryContext repositoryContext;
+ private ExecutionContext context;
+ private JdbcMetadataRepository repository;
+ private PathWorkspace workspace;
+ private PathFactory pathFactory;
+ private NameFactory nameFactory;
+ private ValueFactory longFactory;
+ private ValueFactory stringFactory;
+
+ /*
+ * The catalog in schema into which the test DDL was loaded
+ */
+ private String loadedCatalogName;
+ private String loadedSchemaName;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ context = new ExecutionContext();
+ pathFactory = context.getValueFactories().getPathFactory();
+ nameFactory = context.getValueFactories().getNameFactory();
+ longFactory = context.getValueFactories().getLongFactory();
+ stringFactory = context.getValueFactories().getStringFactory();
+
+ stub(repositoryContext.getExecutionContext()).toReturn(context);
+
+ // Set the connection properties using the environment defined in the POM files ...
+ this.source = TestEnvironment.configureJdbcMetadataSource("Test Repository", this);
+ this.source.initialize(repositoryContext);
+
+ source.getConnection().close(); // Need to call this once to instantiate the repository
+ this.repository = source.repository();
+ workspace = repository.getWorkspace(source.getDefaultWorkspaceName());
+ assertThat(workspace, is(notNullValue()));
+
+ TestEnvironment.executeDdl(this.source.getDataSource(), "/create.ddl");
+
+ DataSource dataSource = source.getDataSource();
+ Connection conn = dataSource.getConnection();
+ DatabaseMetaData dmd = conn.getMetaData();
+
+ // Look up one of the tables that was just loaded to figure out which catalog and schema it's in
+ ResultSet rs = dmd.getTables(null, null, "DISTRICT", null);
+
+ try {
+ if (!rs.next()) {
+ throw new IllegalStateException("Table creation failed -- Can't determine which catalog and schema to use");
+ }
+
+ loadedCatalogName = rs.getString("TABLE_CAT");
+ if (rs.wasNull()) loadedCatalogName = null;
+
+ loadedSchemaName = rs.getString("TABLE_SCHEM");
+ if (rs.wasNull()) loadedSchemaName = null;
+
+ if (rs.next()) {
+ throw new IllegalStateException(
+ "There is more than one table named DISTRICT in this database -- Can't determine which catalog and schema to use");
+ }
+ } finally {
+ rs.close();
+ conn.close();
+ }
+
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ TestEnvironment.executeDdl(this.source.getDataSource(), "/drop.ddl");
+
+ this.source.close();
+ }
+
+ @Test
+ public void shouldOnlyHaveDefaultWorkspace() {
+ Set workspaceNames = repository.getWorkspaceNames();
+
+ assertThat(workspaceNames, is(notNullValue()));
+ assertThat(workspaceNames.size(), is(1));
+ assertThat(workspaceNames.iterator().next(), is(source.getDefaultWorkspaceName()));
+
+ }
+
+ @Test
+ public void shouldNotReturnInvalidWorkspace() {
+ workspace = repository.getWorkspace(source.getDefaultWorkspaceName() + "Invalid");
+ assertThat(workspace, is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnRootNode() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+ Map properties = rootNode.getProperties();
+
+ assertThat(rootNode.getPath(), is(rootPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size(), is(6));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(DnaLexicon.ROOT));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.DATABASE_ROOT));
+ assertThat(properties.get(JdbcMetadataLexicon.DATABASE_PRODUCT_NAME), is(notNullValue()));
+ assertThat(properties.get(JdbcMetadataLexicon.DATABASE_PRODUCT_VERSION), is(notNullValue()));
+ assertThat(properties.get(JdbcMetadataLexicon.DATABASE_MAJOR_VERSION), is(notNullValue()));
+ assertThat(properties.get(JdbcMetadataLexicon.DATABASE_MINOR_VERSION), is(notNullValue()));
+
+ assertThat(rootNode.getChildSegments().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldReturnCatalogNode() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Map properties = catalogNode.getProperties();
+
+ assertThat(catalogNode.getPath(), is(catalogPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size(), is(2));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.CATALOG));
+
+ assertThat(rootNode.getChildSegments().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldNotReturnInvalidCatalogNode() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+
+ Name invalidCatalogName = nameFactory.create(catalogSegment.getName().getLocalName() + "-InvalidCatalog");
+ Path catalogPath = pathFactory.createAbsolutePath(invalidCatalogName);
+ assertThat(workspace.getNode(catalogPath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnSchemaNode() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Path schemaPath = pathFactory.createAbsolutePath(catalogSegment, schemaSegment);
+ PathNode schemaNode = workspace.getNode(schemaPath);
+
+ Map properties = schemaNode.getProperties();
+
+ assertThat(schemaNode.getPath(), is(schemaPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size(), is(2));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.SCHEMA));
+
+ assertThat(rootNode.getChildSegments().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldNotReturnInvalidSchemaNode() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Name invalidSchemaName = nameFactory.create(schemaSegment.getName().getLocalName() + "-InvalidSchema");
+ Path invalidSchemaPath = pathFactory.createAbsolutePath(catalogSegment.getName(), invalidSchemaName);
+ assertThat(workspace.getNode(invalidSchemaPath), is(nullValue()));
+
+ }
+
+ @Test
+ public void shouldReturnTablesNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path tablesPath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME));
+ PathNode tablesNode = workspace.getNode(tablesPath);
+
+ Map properties = tablesNode.getProperties();
+
+ assertThat(tablesNode.getPath(), is(tablesPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size(), is(2));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.TABLES));
+
+ assertThat(tablesNode.getChildSegments().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldNotReturnTablesNodeForInvalidSchema() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Name invalidSchemaName = nameFactory.create(schemaSegment.getName().getLocalName() + "-InvalidSchema");
+ Path invalidSchemaPath = pathFactory.createAbsolutePath(catalogSegment.getName(),
+ invalidSchemaName,
+ nameFactory.create(JdbcMetadataRepository.TABLES_SEGMENT_NAME));
+ assertThat(workspace.getNode(invalidSchemaPath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnTableNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path tablePath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ pathFactory.createSegment("SALES"));
+ PathNode tableNode = workspace.getNode(tablePath);
+
+ Map properties = tableNode.getProperties();
+
+ assertThat(tableNode.getPath(), is(tablePath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size() >= 2, is(true));
+ assertThat(properties.size() <= 9, is(true));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.TABLE));
+
+ assertThat(tableNode.getChildSegments().size(), is(4));
+ }
+
+ @Test
+ public void shouldNotReturnTableNodeForInvalidSchema() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Name invalidSchemaName = nameFactory.create(schemaSegment.getName().getLocalName() + "-InvalidSchema");
+ Path invalidSchemaPath = pathFactory.createAbsolutePath(catalogSegment.getName(),
+ invalidSchemaName,
+ nameFactory.create(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ nameFactory.create("SALES"));
+ assertThat(workspace.getNode(invalidSchemaPath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotReturnInvalidTableNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path invalidTablePath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ pathFactory.createSegment("NOT_A_VALID_TABLE"));
+
+ assertThat(workspace.getNode(invalidTablePath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnColumnNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path columnPath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ pathFactory.createSegment("SALES"),
+ pathFactory.createSegment("AMOUNT"));
+ PathNode columnNode = workspace.getNode(columnPath);
+
+ Map properties = columnNode.getProperties();
+
+ assertThat(columnNode.getPath(), is(columnPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size() >= 9, is(true));
+ assertThat(properties.size() <= 16, is(true));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.COLUMN));
+
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.JDBC_DATA_TYPE)), is((long)Types.NUMERIC));
+ assertThat(stringFor(properties.get(JdbcMetadataLexicon.TYPE_NAME)), is(notNullValue()));
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.COLUMN_SIZE)), is(notNullValue()));
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.DECIMAL_DIGITS)), is(notNullValue()));
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.RADIX)), is(notNullValue()));
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.LENGTH)), is(notNullValue()));
+ assertThat(longFor(properties.get(JdbcMetadataLexicon.ORDINAL_POSITION)), is(4L));
+
+ assertThat(columnNode.getChildSegments().isEmpty(), is(true));
+ }
+
+ @Test
+ public void shouldNotReturnColumnNodeForInvalidSchema() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Name invalidSchemaName = nameFactory.create(schemaSegment.getName().getLocalName() + "-InvalidSchema");
+ Path invalidSchemaPath = pathFactory.createAbsolutePath(catalogSegment.getName(),
+ invalidSchemaName,
+ nameFactory.create(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ nameFactory.create("SALES"),
+ nameFactory.create("AMOUNT"));
+ assertThat(workspace.getNode(invalidSchemaPath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotReturnColumnNodeForInvalidTable() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path invalidTablePath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ pathFactory.createSegment("INVALID_TABLE_NAME"),
+ pathFactory.createSegment("ID"));
+
+ assertThat(workspace.getNode(invalidTablePath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotReturnInvalidColumnNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path invalidColumnPath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.TABLES_SEGMENT_NAME),
+ pathFactory.createSegment("SALES"),
+ pathFactory.createSegment("INVALID_COLUMN_NAME"));
+
+ assertThat(workspace.getNode(invalidColumnPath), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnProceduresNode() {
+ String nullSafeCatalogName = loadedCatalogName == null ? source.getDefaultCatalogName() : loadedCatalogName;
+ String nullSafeSchemaName = loadedSchemaName == null ? source.getDefaultSchemaName() : loadedSchemaName;
+
+ Path tablesPath = pathFactory.createAbsolutePath(pathFactory.createSegment(nullSafeCatalogName),
+ pathFactory.createSegment(nullSafeSchemaName),
+ pathFactory.createSegment(JdbcMetadataRepository.PROCEDURES_SEGMENT_NAME));
+ PathNode tablesNode = workspace.getNode(tablesPath);
+
+ Map properties = tablesNode.getProperties();
+
+ assertThat(tablesNode.getPath(), is(tablesPath));
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.size(), is(2));
+ assertThat(nameFor(properties.get(JcrLexicon.PRIMARY_TYPE)), is(JcrNtLexicon.UNSTRUCTURED));
+ assertThat(nameFor(properties.get(JcrLexicon.MIXIN_TYPES)), is(JdbcMetadataLexicon.PROCEDURES));
+
+ assertThat(tablesNode.getChildSegments().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldNotReturnProceduresNodeForInvalidSchema() {
+ Path rootPath = pathFactory.createRootPath();
+ PathNode rootNode = workspace.getNode(rootPath);
+
+ Segment catalogSegment = rootNode.getChildSegments().get(0);
+ Path catalogPath = pathFactory.createAbsolutePath(catalogSegment);
+ PathNode catalogNode = workspace.getNode(catalogPath);
+
+ Segment schemaSegment = catalogNode.getChildSegments().get(0);
+ Name invalidSchemaName = nameFactory.create(schemaSegment.getName().getLocalName() + "-InvalidSchema");
+ Path invalidSchemaPath = pathFactory.createAbsolutePath(catalogSegment.getName(),
+ invalidSchemaName,
+ nameFactory.create(JdbcMetadataRepository.PROCEDURES_SEGMENT_NAME));
+ assertThat(workspace.getNode(invalidSchemaPath), is(nullValue()));
+ }
+
+ private Name nameFor( Property property ) {
+ if (property == null) {
+ return null;
+ }
+
+ if (property.isEmpty()) {
+ return null;
+ }
+
+ return nameFactory.create(property.getFirstValue());
+ }
+
+ private Long longFor( Property property ) {
+ if (property == null) {
+ return null;
+ }
+
+ if (property.isEmpty()) {
+ return null;
+ }
+
+ return longFactory.create(property.getFirstValue());
+ }
+
+ private String stringFor( Property property ) {
+ if (property == null) {
+ return null;
+ }
+
+ if (property.isEmpty()) {
+ return null;
+ }
+
+ return stringFactory.create(property.getFirstValue());
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\test\java\org\jboss\dna\connector\meta\jdbc\JdbcMetadataRepositoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataSourceTest.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataSourceTest.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/JdbcMetadataSourceTest.java (revision 0)
@@ -0,0 +1,102 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+public class JdbcMetadataSourceTest {
+
+ private JdbcMetadataSource source;
+ private RepositoryConnection connection;
+ @Mock
+ private RepositoryContext repositoryContext;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ stub(repositoryContext.getExecutionContext()).toReturn(new ExecutionContext());
+
+ // Set the connection properties using the environment defined in the POM files ...
+ this.source = TestEnvironment.configureJdbcMetadataSource("Test Repository", this);
+ this.source.initialize(repositoryContext);
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (this.connection != null) {
+ this.connection.close();
+ }
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldFailToCreateConnectionIfSourceHasNoName() {
+ source.setName(null);
+ source.getConnection();
+ }
+
+ @Test
+ public void shouldCreateConnection() throws Exception {
+ connection = source.getConnection();
+ assertThat(connection, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldAllowMultipleConnectionsToBeOpenAtTheSameTime() throws Exception {
+ List connections = new ArrayList();
+ try {
+ for (int i = 0; i != 10; ++i) {
+ RepositoryConnection conn = source.getConnection();
+ assertThat(conn, is(notNullValue()));
+ connections.add(conn);
+ }
+ } finally {
+ // Close all open connections ...
+ for (RepositoryConnection conn : connections) {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\test\java\org\jboss\dna\connector\meta\jdbc\JdbcMetadataSourceTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/TestEnvironment.java
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/TestEnvironment.java (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/java/org/jboss/dna/connector/meta/jdbc/TestEnvironment.java (revision 0)
@@ -0,0 +1,128 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.meta.jdbc;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.Properties;
+import javax.sql.DataSource;
+import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.connector.meta.jdbc.JdbcMetadataSource;
+
+public class TestEnvironment {
+
+ public static JdbcMetadataSource configureJdbcMetadataSource( String sourceName,
+ Object testCase ) {
+ Properties properties = new Properties();
+ ClassLoader loader = testCase instanceof Class> ? ((Class>)testCase).getClassLoader() : testCase.getClass().getClassLoader();
+ try {
+ properties.load(loader.getResourceAsStream("database.properties"));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ JdbcMetadataSource source = new JdbcMetadataSource();
+ source.setName(sourceName);
+ source.setDriverClassName(properties.getProperty("jpaSource.driverClassName"));
+ source.setUsername(properties.getProperty("jpaSource.username"));
+ source.setPassword(properties.getProperty("jpaSource.password"));
+ source.setUrl(properties.getProperty("jpaSource.url"));
+
+ String value = properties.getProperty("jpaSource.maximumConnectionsInPool");
+ if (isValue(value)) source.setMaximumConnectionsInPool(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.minimumConnectionsInPool");
+ if (isValue(value)) source.setMinimumConnectionsInPool(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.maximumSizeOfStatementCache");
+ if (isValue(value)) source.setMaximumSizeOfStatementCache(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.maximumConnectionIdleTimeInSeconds");
+ if (isValue(value)) source.setMaximumConnectionIdleTimeInSeconds(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.cacheTimeToLiveInMilliseconds");
+ if (isValue(value)) source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.defaultWorkspaceName");
+ if (isValue(value)) source.setDefaultWorkspaceName(value);
+
+ value = properties.getProperty("jpaSource.numberOfConnectionsToAcquireAsNeeded");
+ if (isValue(value)) source.setNumberOfConnectionsToAcquireAsNeeded(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.retryLimit");
+ if (isValue(value)) source.setRetryLimit(Integer.parseInt(value));
+
+ value = properties.getProperty("jpaSource.rootNodeUuid");
+ if (isValue(value)) source.setRootNodeUuid(value);
+
+ return source;
+ }
+
+ protected static boolean isValue( String value ) {
+ return value != null && value.trim().length() != 0;
+ }
+
+ protected static String[] splitValues( String value ) {
+ String[] results = value.split(", ");
+ for (int i = 0; i != results.length; ++i) {
+ results[i] = results[i].trim();
+ // Remove leading and trailing quotes, if there are any ...
+ results[i] = results[i].replaceFirst("^['\"]+", "").replaceAll("['\"]+$", "").trim();
+ }
+ return results;
+ }
+
+ public static void executeDdl( DataSource dataSource,
+ String pathToDdl ) throws Exception {
+ Connection conn = null;
+ Statement stmt = null;
+ InputStream is = null;
+
+
+ try {
+ conn = dataSource.getConnection();
+ is = TestEnvironment.class.getResourceAsStream(pathToDdl);
+ String ddl = IoUtil.read(is);
+
+ stmt = conn.createStatement();
+ stmt.execute(ddl);
+
+ } finally {
+ if (stmt != null) try {
+ stmt.close();
+ } catch (Exception ignore) {
+ }
+ if (conn != null) try {
+ conn.close();
+ } catch (Exception ignore) {
+ }
+ if (is != null) try {
+ is.close();
+ } catch (Exception ignore) {
+ }
+ }
+ }
+}
Property changes on: extensions\dna-connector-jdbc-metadata\src\test\java\org\jboss\dna\connector\meta\jdbc\TestEnvironment.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-jdbc-metadata/src/test/resources/create.ddl
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/resources/create.ddl (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/resources/create.ddl (revision 0)
@@ -0,0 +1,33 @@
+-- JBoss DNA (http://www.jboss.org/dna)
+-- See the COPYRIGHT.txt file distributed with this work for information
+-- regarding copyright ownership. Some portions may be licensed
+-- to Red Hat, Inc. under one or more contributor license agreements.
+-- See the AUTHORS.txt file in the distribution for a full listing of
+-- individual contributors.
+--
+-- JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+-- is licensed to you 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.
+--
+-- JBoss DNA 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.
+
+CREATE TABLE CHAIN (ID NUMERIC NOT NULL PRIMARY KEY, NAME VARCHAR(30) NOT NULL)
+CREATE TABLE AREA (ID NUMERIC NOT NULL PRIMARY KEY, NAME VARCHAR(30) NOT NULL, CHAIN_ID NUMERIC NOT NULL)
+CREATE TABLE REGION (ID NUMERIC NOT NULL PRIMARY KEY, NAME VARCHAR(30) NOT NULL, AREA_ID NUMERIC NOT NULL)
+CREATE TABLE DISTRICT (ID NUMERIC NOT NULL PRIMARY KEY, NAME VARCHAR(30) NOT NULL, REGION_ID NUMERIC NOT NULL)
+
+CREATE TABLE SALES (ID NUMERIC NOT NULL, SALES_DATE DATETIME NOT NULL, DISTRICT_ID NUMERIC NOT NULL, AMOUNT NUMERIC(10, 2) NULL)
+ALTER TABLE SALES ADD CONSTRAINT PK_SALES PRIMARY KEY (ID, SALES_DATE)
+
+ALTER TABLE AREA ADD CONSTRAINT FK_CHAIN FOREIGN KEY(CHAIN_ID) REFERENCES CHAIN(ID) ON DELETE CASCADE
+ALTER TABLE REGION ADD CONSTRAINT FK_AREA FOREIGN KEY(AREA_ID) REFERENCES AREA(ID) ON DELETE CASCADE
+ALTER TABLE DISTRICT ADD CONSTRAINT FK_REGION FOREIGN KEY(REGION_ID) REFERENCES REGION(ID) ON DELETE CASCADE
Index: extensions/dna-connector-jdbc-metadata/src/test/resources/database.properties
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/resources/database.properties (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/resources/database.properties (revision 0)
@@ -0,0 +1,42 @@
+#
+# JBoss DNA (http://www.jboss.org/dna)
+# See the COPYRIGHT.txt file distributed with this work for information
+# regarding copyright ownership. Some portions may be licensed
+# to Red Hat, Inc. under one or more contributor license agreements.
+# See the AUTHORS.txt file in the distribution for a full listing of
+# individual contributors.
+#
+# JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+# is licensed to you 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.
+#
+# JBoss DNA 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.
+#
+
+# All of these properties are or can be set in the parent POM in the different profiles.
+# The property names are designed to match those used in the POM.
+# Any property that does not have a non-empty value set by Maven will not be set on the JpaSource.
+jpaSource.driverClassName = ${jpaSource.driverClassName}
+jpaSource.url = ${jpaSource.url}
+jpaSource.username = ${jpaSource.username}
+jpaSource.password = ${jpaSource.password}
+jpaSource.maximumConnectionsInPool = ${jpaSource.maximumConnectionsInPool}
+jpaSource.minimumConnectionsInPool = ${jpaSource.minimumConnectionsInPool}
+jpaSource.numberOfConnectionsToAcquireAsNeeded = ${jpaSource.numberOfConnectionsToAcquireAsNeeded}
+jpaSource.maximumSizeOfStatementCache = ${jpaSource.maximumSizeOfStatementCache}
+jpaSource.maximumConnectionIdleTimeInSeconds = ${jpaSource.maximumConnectionIdleTimeInSeconds}
+jpaSource.cacheTimeToLiveInMilliseconds = ${jpaSource.cacheTimeToLiveInMilliseconds}
+jpaSource.defaultWorkspaceName = ${jpaSource.defaultWorkspaceName}
+jpaSource.numberOfConnectionsToAcquireAsNeeded = ${jpaSource.numberOfConnectionsToAcquireAsNeeded}
+jpaSource.retryLimit = ${jpaSource.retryLimit}
+jpaSource.rootNodeUuid = ${jpaSource.rootNodeUuid}
+
Index: extensions/dna-connector-jdbc-metadata/src/test/resources/drop.ddl
===================================================================
--- extensions/dna-connector-jdbc-metadata/src/test/resources/drop.ddl (revision 0)
+++ extensions/dna-connector-jdbc-metadata/src/test/resources/drop.ddl (revision 0)
@@ -0,0 +1,27 @@
+-- JBoss DNA (http://www.jboss.org/dna)
+-- See the COPYRIGHT.txt file distributed with this work for information
+-- regarding copyright ownership. Some portions may be licensed
+-- to Red Hat, Inc. under one or more contributor license agreements.
+-- See the AUTHORS.txt file in the distribution for a full listing of
+-- individual contributors.
+--
+-- JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+-- is licensed to you 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.
+--
+-- JBoss DNA 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.
+
+DROP TABLE SALES
+DROP TABLE DISTRICT
+DROP TABLE REGION
+DROP TABLE AREA
+DROP TABLE CHAIN