[jboss-cvs] JBossAS SVN: r109269 - in projects/jboss-jca/trunk: adapters/src/main/java/org/jboss/jca/adapters and 26 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 11 03:24:40 EST 2010
Author: maeste
Date: 2010-11-11 03:24:37 -0500 (Thu, 11 Nov 2010)
New Revision: 109269
Added:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2StaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/InformixExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/MSSQLValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReplicationValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullStaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleStaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/URLSelectorStrategy.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/package.html
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/LRUCachePolicy.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/package.html
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorterTestCase.java
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionCheckerTestCase.java
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/package.html
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestStaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/package.html
projects/jboss-jca/trunk/adapters/src/test/resources/h2-exception-sorter-ds.xml
projects/jboss-jca/trunk/adapters/src/test/resources/h2-stale-connection-checker-ds.xml
projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/JdbcAdapterExtension.java
Removed:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullExceptionSorter.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullStaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/StaleConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/URLSelectorStrategy.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ValidConnectionChecker.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/
Modified:
projects/jboss-jca/trunk/adapters/build.xml
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/CheckValidConnectionSQL.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/JBossWrapper.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrappedConnection.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrapperDataSource.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/xa/XAManagedConnectionFactory.java
projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml
projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/xa/META-INF/ra.xml
projects/jboss-jca/trunk/adapters/src/test/resources/logging.properties
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Validation.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/ValidationImpl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java
projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
Log:
JBJCA-469 create a jdbc vendor extensions spi
Modified: projects/jboss-jca/trunk/adapters/build.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/build.xml 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/build.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -127,6 +127,7 @@
<classpath>
<pathelement location="${build.adapters.dir}/test"/>
<fileset dir="${target.dir}" includes="*.jar"/>
+ <fileset dir="${build.adapters.dir}" includes="*.jar"/>
<fileset dir="${lib.dir}/common" includes="*.jar" />
<fileset dir="${lib.dir}/embedded" includes="*.jar" />
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
@@ -176,6 +177,7 @@
<classpath>
<pathelement location="${build.adapters.dir}/test"/>
<fileset dir="${target.dir}" includes="*.jar"/>
+ <fileset dir="${build.adapters.dir}" includes="*.jar"/>
<fileset dir="${lib.dir}/common" includes="*.jar" />
<fileset dir="${lib.dir}/embedded" includes="*.jar" />
<fileset dir="${lib.dir}/arquillian" includes="*.jar" />
@@ -200,9 +202,13 @@
<mkdir dir="${build.adapters.dir}" />
<mkdir dir="${build.adapters.dir}/test" />
+ <path id="adapters.test.lib.path.id">
+ <path refid="test.lib.path.id"/>
+ <pathelement location="${build.adapters.dir}/${name}-jdbc.jar"/>
+ </path>
<javac srcdir="src/test"
destdir="${build.adapters.dir}/test"
- classpathref="test.lib.path.id"
+ classpathref="adapters.test.lib.path.id"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
optimize="${javac.optimize}">
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -22,17 +22,28 @@
package org.jboss.jca.adapters.jdbc;
+import org.jboss.jca.adapters.jdbc.extensions.novendor.NullExceptionSorter;
+import org.jboss.jca.adapters.jdbc.extensions.novendor.NullStaleConnectionChecker;
+import org.jboss.jca.adapters.jdbc.extensions.novendor.NullValidConnectionChecker;
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
+import org.jboss.jca.adapters.jdbc.spi.URLSelectorStrategy;
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
@@ -46,17 +57,19 @@
import org.jboss.logging.Logger;
+import com.github.fungal.api.util.Injection;
+
/**
* BaseWrapperManagedConnectionFactory
*
* @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
* @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
* @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
- *
+ *
* @version $Revision: 105426 $
*/
-public abstract class BaseWrapperManagedConnectionFactory
+public abstract class BaseWrapperManagedConnectionFactory
implements ManagedConnectionFactory, ValidatingManagedConnectionFactory, Serializable
{
/** @since 4.0.1 */
@@ -125,19 +138,38 @@
*/
protected String validConnectionCheckerClassName;
+ private String validConnectionCheckerProperties;
+
/**
+ * The properties injected in the class used to check whether a connection is valid
+ */
+ protected final Properties validConnectionCheckerProps = new Properties();
+
+ /**
* The instance of the valid connection checker
*/
protected ValidConnectionChecker connectionChecker;
+
/** The instance of the stale connection checker */
protected StaleConnectionChecker staleConnectionChecker;
-
+
/** The staleConnectionCheckerClassName */
private String staleConnectionCheckerClassName;
+ private String staleConnectionCheckerProperties;
+
+ /**
+ * The properties injected in the stale connection checker
+ */
+ protected final Properties staleConnectionCheckerProps = new Properties();
+
private String exceptionSorterClassName;
+ private String exceptionSorterProperties;
+
+ private final Properties exceptionSorterProps = new Properties();
+
private ExceptionSorter exceptionSorter;
/** Track statement */
@@ -145,19 +177,19 @@
/** Whether to share cached prepared statements */
protected Boolean sharePS = Boolean.FALSE;
-
+
/** Transaction query timeout */
protected Boolean isTransactionQueryTimeout = Boolean.FALSE;
-
+
/** Query timeout */
protected Integer queryTimeout = Integer.valueOf(0);
-
- /**
- * The variable <code>urlDelimiter</code> holds the url delimiter
+
+ /**
+ * The variable <code>urlDelimiter</code> holds the url delimiter
* information to be used for HA DS configuration .
*/
protected String urlDelimiter;
-
+
/** URL selector strategy class name */
protected String urlSelectorStrategyClassName;
@@ -397,7 +429,7 @@
{
staleConnectionCheckerClassName = value;
}
-
+
/**
* Get the track statement value
* @return The value
@@ -423,7 +455,7 @@
public void setTrackStatements(String value)
{
if (value == null)
- throw new IllegalArgumentException("Null value for trackStatements");
+ throw new IllegalArgumentException("Null value for trackStatements");
String trimmed = value.trim();
@@ -459,7 +491,7 @@
if (validateOnMatch != null)
this.validateOnMatch = validateOnMatch;
}
-
+
/**
* Get the exception sorter class name
* @return The value
@@ -496,6 +528,8 @@
validConnectionCheckerClassName = value;
}
+
+
/**
* Is transaction query timeout set
* @return The value
@@ -533,7 +567,7 @@
if (timeout != null)
queryTimeout = timeout;
}
-
+
/**
* Get the use try lock value
* @return The value
@@ -552,7 +586,7 @@
if (useTryLock != null)
this.useTryLock = useTryLock;
}
-
+
/**
* Get the url delimiter
* @return The vlaue
@@ -570,7 +604,7 @@
public void setURLDelimiter(String urlDelimiter) throws ResourceException
{
this.urlDelimiter = urlDelimiter;
- }
+ }
/**
* Get the url selector strategy class name
@@ -589,7 +623,7 @@
{
this.urlSelectorStrategyClassName = urlSelectorStrategyClassName;
}
-
+
/**
* Get the url selector strategy
* @return The value
@@ -605,7 +639,7 @@
* @param constructorParameter The parameter
* @return The URL selector strategy
*/
- public Object loadClass(String className, Object constructorParameter)
+ public Object loadClass(String className, Object constructorParameter)
{
Object result = null;
try
@@ -636,7 +670,7 @@
{
log.error("Constructor or Method mismatch in URLSelectorStrategy :" + className);
}
-
+
return result;
}
@@ -668,8 +702,8 @@
return invalid;
}
-
-
+
+
/**
* Gets full set of connection properties, i.e. whatever is provided
* in config plus "user" and "password" from subject/cri.
@@ -737,6 +771,11 @@
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> clazz = cl.loadClass(exceptionSorterClassName);
exceptionSorter = (ExceptionSorter)clazz.newInstance();
+ Injection injection = new Injection();
+ for (Entry<Object, Object> prop : exceptionSorterProps.entrySet())
+ {
+ injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), exceptionSorter);
+ }
return exceptionSorter.isExceptionFatal(e);
}
catch (Exception e2)
@@ -772,6 +811,11 @@
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> clazz = cl.loadClass(validConnectionCheckerClassName);
connectionChecker = (ValidConnectionChecker) clazz.newInstance();
+ Injection injection = new Injection();
+ for (Entry<Object, Object> prop : validConnectionCheckerProps.entrySet())
+ {
+ injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), connectionChecker);
+ }
return connectionChecker.isValidConnection(c);
}
catch (Exception e)
@@ -792,6 +836,7 @@
return null;
}
+
/**
* Is the connection stale
* @param e The exception
@@ -800,8 +845,8 @@
boolean isStaleConnection(SQLException e)
{
if (staleConnectionChecker != null)
- return staleConnectionChecker.isStaleConnection(e);
-
+ return staleConnectionChecker.isStaleConnection(e);
+
if (staleConnectionCheckerClassName != null)
{
try
@@ -809,20 +854,25 @@
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> clazz = cl.loadClass(staleConnectionCheckerClassName);
staleConnectionChecker = (StaleConnectionChecker)clazz.newInstance();
+ Injection injection = new Injection();
+ for (Entry<Object, Object> prop : staleConnectionCheckerProps.entrySet())
+ {
+ injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), staleConnectionChecker);
+ }
return staleConnectionChecker.isStaleConnection(e);
}
catch (Exception ex2)
{
- log.warn("exception trying to create stale connection checker (disabling) " +
+ log.warn("exception trying to create stale connection checker (disabling) " +
staleConnectionCheckerClassName, ex2);
staleConnectionChecker = new NullStaleConnectionChecker();
}
}
-
+
return false;
}
-
+
/**
* SubjectActions
*/
@@ -888,4 +938,148 @@
return matched.booleanValue();
}
}
+
+ /**
+ * Get the validConnectionCheckerProps.
+ *
+ * @return the validConnectionCheckerProps.
+ */
+ public final Properties getValidConnectionCheckerProps()
+ {
+ return validConnectionCheckerProps;
+ }
+
+ /**
+ * Get the staleConnectionCheckerProps.
+ *
+ * @return the staleConnectionCheckerProps.
+ */
+ public final Properties getStaleConnectionCheckerProps()
+ {
+ return staleConnectionCheckerProps;
+ }
+
+ /**
+ * Get the exceptionSorterProps.
+ *
+ * @return the exceptionSorterProps.
+ */
+ public final Properties getExceptionSorterProps()
+ {
+ return exceptionSorterProps;
+ }
+
+ /**
+ * Get the validConnectionCheckerProperties.
+ *
+ * @return the validConnectionCheckerProperties.
+ */
+ public final String getValidConnectionCheckerProperties()
+ {
+ return validConnectionCheckerProperties;
+ }
+
+ /**
+ * Set the validConnectionCheckerProperties.
+ *
+ * @param validConnectionCheckerProperties The validConnectionCheckerProperties to set.
+ */
+ public final void setValidConnectionCheckerProperties(String validConnectionCheckerProperties)
+ {
+ this.validConnectionCheckerProperties = validConnectionCheckerProperties;
+ validConnectionCheckerProps.clear();
+
+ if (validConnectionCheckerProperties != null)
+ {
+ // Map any \ to \\
+ validConnectionCheckerProperties = validConnectionCheckerProperties.replaceAll("\\\\", "\\\\\\\\");
+ validConnectionCheckerProperties = validConnectionCheckerProperties.replaceAll(";", "\n");
+
+ InputStream is = new ByteArrayInputStream(validConnectionCheckerProperties.getBytes());
+ try
+ {
+ validConnectionCheckerProps.load(is);
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Could not load connection properties", ioe);
+ }
+ }
+ }
+
+ /**
+ * Get the staleConnectionCheckerProperties.
+ *
+ * @return the staleConnectionCheckerProperties.
+ */
+ public final String getStaleConnectionCheckerProperties()
+ {
+ return staleConnectionCheckerProperties;
+ }
+
+ /**
+ * Set the staleConnectionCheckerProperties.
+ *
+ * @param staleConnectionCheckerProperties The staleConnectionCheckerProperties to set.
+ */
+ public final void setStaleConnectionCheckerProperties(String staleConnectionCheckerProperties)
+ {
+ this.staleConnectionCheckerProperties = staleConnectionCheckerProperties;
+ staleConnectionCheckerProps.clear();
+
+ if (staleConnectionCheckerProperties != null)
+ {
+ // Map any \ to \\
+ staleConnectionCheckerProperties = staleConnectionCheckerProperties.replaceAll("\\\\", "\\\\\\\\");
+ staleConnectionCheckerProperties = staleConnectionCheckerProperties.replaceAll(";", "\n");
+
+ InputStream is = new ByteArrayInputStream(staleConnectionCheckerProperties.getBytes());
+ try
+ {
+ staleConnectionCheckerProps.load(is);
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Could not load connection properties", ioe);
+ }
+ }
+ }
+
+ /**
+ * Get the exceptionSorterProperties.
+ *
+ * @return the exceptionSorterProperties.
+ */
+ public final String getExceptionSorterProperties()
+ {
+ return exceptionSorterProperties;
+ }
+
+ /**
+ * Set the exceptionSorterProperties.
+ *
+ * @param exceptionSorterProperties The exceptionSorterProperties to set.
+ */
+ public final void setExceptionSorterProperties(String exceptionSorterProperties)
+ {
+ this.exceptionSorterProperties = exceptionSorterProperties;
+ exceptionSorterProps.clear();
+
+ if (exceptionSorterProperties != null)
+ {
+ // Map any \ to \\
+ exceptionSorterProperties = exceptionSorterProperties.replaceAll("\\\\", "\\\\\\\\");
+ exceptionSorterProperties = exceptionSorterProperties.replaceAll(";", "\n");
+
+ InputStream is = new ByteArrayInputStream(exceptionSorterProperties.getBytes());
+ try
+ {
+ exceptionSorterProps.load(is);
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Could not load connection properties", ioe);
+ }
+ }
+ }
}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/CheckValidConnectionSQL.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/CheckValidConnectionSQL.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/CheckValidConnectionSQL.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -22,6 +22,8 @@
package org.jboss.jca.adapters.jdbc;
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
@@ -36,7 +38,7 @@
public class CheckValidConnectionSQL implements ValidConnectionChecker, Serializable
{
private static final long serialVersionUID = -222752863430216887L;
-
+
private String sql;
/**
@@ -58,12 +60,13 @@
/**
* {@inheritDoc}
*/
+ @Override
public SQLException isValidConnection(Connection c)
{
if (sql == null)
return null;
- try
+ try
{
Statement s = c.createStatement();
try
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ExceptionSorter.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ExceptionSorter.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.sql.SQLException;
-
-/**
- * The ExceptionSorter interface allows for <code>java.sql.SQLException</code>
- * evaluation to determine if an error is fatal.
- *
- * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @author <a href="mailto:weston.price at jboss.com>Weston Price</a>
- *
- * @see ValidConnectionChecker
- * @see CheckValidConnectionSQL
- *
- * @version $Revision: 71554 $
- */
-
-public interface ExceptionSorter
-{
-
-
- /**
- * Evaluates a <code>java.sql.SQLException</code> to determine if
- * the error was fatal
- *
- * @param e the <code>java.sql.SQLException</code>
- *
- * @return whether or not the exception is vatal.
- */
- boolean isExceptionFatal(SQLException e);
-}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/JBossWrapper.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/JBossWrapper.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/JBossWrapper.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -27,7 +27,7 @@
/**
* JBossWrapper.
- *
+ *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 85945 $
*/
@@ -64,6 +64,7 @@
/**
* Unwrap
+ * @param <T> the type
* @param iface The interface
* @return The object
* @exception SQLException Thrown if an error occurs
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullExceptionSorter.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullExceptionSorter.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.io.Serializable;
-import java.sql.SQLException;
-
-/**
- * Does not check the exception. Used if the named exception sorter cannot be instantiated.
- *
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
- *
- * @version $Revision: 75423 $
- */
-public class NullExceptionSorter implements ExceptionSorter, Serializable
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 202928214888283717L;
-
- /**
- * Constructor
- */
- public NullExceptionSorter()
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isExceptionFatal(SQLException e)
- {
- return false;
- }
-}
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullStaleConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullStaleConnectionChecker.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullStaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.sql.SQLException;
-
-/**
- * A NullStaleConnectionChecker.
- *
- * @author <a href="weston.price at jboss.com">Weston Price</a>
- * @version $Revision: 71554 $
- */
-public class NullStaleConnectionChecker implements StaleConnectionChecker
-{
-
- /**
- * Constructor
- */
- public NullStaleConnectionChecker()
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isStaleConnection(SQLException e)
- {
- return false;
- }
-}
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullValidConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullValidConnectionChecker.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Does not check the connection
- *
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 71554 $
- */
-public class NullValidConnectionChecker implements ValidConnectionChecker, Serializable
-{
- private static final long serialVersionUID = -223752863430216887L;
-
- /**
- * Constructor
- */
- public NullValidConnectionChecker()
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public SQLException isValidConnection(Connection c)
- {
- return null;
- }
-}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -22,18 +22,20 @@
package org.jboss.jca.adapters.jdbc;
+import org.jboss.jca.adapters.util.LRUCachePolicy;
+
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jboss.logging.Logger;
-import org.jboss.util.LRUCachePolicy;
+
/**
* LRU cache for PreparedStatements. When ps ages out, close it.
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
+ * @author Scott.Stark at jboss.org
* @version $Revision: 73034 $
*/
public class PreparedStatementCache extends LRUCachePolicy
@@ -55,7 +57,7 @@
private final int type;
private final int resultSetType;
private final int resultSetConcurrency;
-
+
/**
* Constructor
* @param sql The SQL string
@@ -83,13 +85,14 @@
/**
* {@inheritDoc}
*/
+ @Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || !(o instanceof Key)) return false;
final Key key = (Key) o;
-
+
if (resultSetConcurrency != key.resultSetConcurrency) return false;
if (resultSetType != key.resultSetType) return false;
if (type != key.type) return false;
@@ -99,6 +102,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public int hashCode()
{
int result;
@@ -112,6 +116,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public String toString()
{
StringBuffer tmp = new StringBuffer(super.toString());
@@ -176,11 +181,12 @@
* Age out an entry
* @param entry The entry
*/
+ @Override
protected void ageOut(LRUCachePolicy.LRUCacheEntry entry)
{
try
{
- CachedPreparedStatement ws = (CachedPreparedStatement) entry.m_object;
+ CachedPreparedStatement ws = (CachedPreparedStatement) entry.getObject();
ws.agedOut();
}
catch (SQLException e)
@@ -192,17 +198,18 @@
super.ageOut(entry);
}
}
-
+
/**
* {@inheritDoc}
*/
+ @Override
public String toString()
{
- String s = " PreparedStatementCache size: " + m_list.m_count;
- for (LRUCacheEntry entry = m_list.m_head; entry != null; entry = entry.m_next)
+ String s = " PreparedStatementCache size: " + lruList.getCount();
+ for (LRUCacheEntry entry = lruList.getHead(); entry != null; entry = entry.getNext())
{
- CachedPreparedStatement ws = (CachedPreparedStatement) entry.m_object;
- PreparedStatementCache.Key key = (PreparedStatementCache.Key) entry.m_key;
+ CachedPreparedStatement ws = (CachedPreparedStatement) entry.getObject();
+ PreparedStatementCache.Key key = (PreparedStatementCache.Key) entry.getKey();
s += "[" + key.getSql() + "] ";
}
return s + "\n";
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/StaleConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/StaleConnectionChecker.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/StaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.sql.SQLException;
-
-/**
- * A StaleConnectionChecker.
- *
- * @author <a href="weston.price at jboss.com">Weston Price</a>
- * @version $Revision: 71554 $
- */
-public interface StaleConnectionChecker
-{
-
- /**
- * Is the connection stale
- *
- * @param e the <code>java.sql.SQLException</code>
- * @return is the connection stale
- */
- public boolean isStaleConnection(SQLException e);
-
-}
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/URLSelectorStrategy.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/URLSelectorStrategy.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/URLSelectorStrategy.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.util.List;
-
-/**
- * URLSelectorStrategy
- *
- * @author <a href="mailto:vkak at redhat.com">Vicky Kak</a>
- */
-public interface URLSelectorStrategy
-{
- /**
- * Get all url objects
- * @return The value
- */
- public List<?> getAllUrlObjects();
-
- /**
- * Failed url object
- * @param urlObject The value
- */
- public void failedUrlObject(Object urlObject);
-
- /**
- * Get all custom url objects
- * @return The value
- */
- public List<?> getCustomSortedUrls();
-
- /**
- * Get url object
- * @return The value
- */
- public Object getUrlObject();
-}
Deleted: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ValidConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ValidConnectionChecker.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.adapters.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Checks that a connection is valid
- *
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 71554 $
- */
-public interface ValidConnectionChecker
-{
- /**
- * Checks the connection is valid
- *
- * @param c the connection
- * @return Exception when not valid, null when valid
- */
- SQLException isValidConnection(Connection c);
-}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrappedConnection.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrappedConnection.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrappedConnection.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -37,11 +37,10 @@
import java.util.Map;
import org.jboss.logging.Logger;
-import org.jboss.util.NestedSQLException;
/**
* A wrapper for a connection.
- *
+ *
* @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
* @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 96595 $
@@ -53,7 +52,7 @@
private BaseWrapperManagedConnection mc;
private WrapperDataSource dataSource;
-
+
private HashMap<WrappedStatement, Throwable> statements;
private boolean closed = false;
@@ -68,7 +67,7 @@
{
setManagedConnection(mc);
}
-
+
/**
* Set the managed connection
* @param mc The managed connection
@@ -119,7 +118,7 @@
{
return dataSource;
}
-
+
/**
* Set the datasource
* @param dataSource The value
@@ -128,7 +127,7 @@
{
this.dataSource = dataSource;
}
-
+
/**
* {@inheritDoc}
*/
@@ -169,7 +168,7 @@
{
if (statements != null)
{
- for (Iterator<Map.Entry<WrappedStatement, Throwable>> i = statements.entrySet().iterator();
+ for (Iterator<Map.Entry<WrappedStatement, Throwable>> i = statements.entrySet().iterator();
i.hasNext();)
{
Map.Entry<WrappedStatement, Throwable> entry = i.next();
@@ -211,7 +210,7 @@
* @return The wrapped statement
*/
protected abstract WrappedStatement wrapStatement(Statement statement);
-
+
/**
* {@inheritDoc}
*/
@@ -304,7 +303,7 @@
checkTransaction();
try
{
- return wrapPreparedStatement(mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
+ return wrapPreparedStatement(mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY));
}
catch (Throwable t)
@@ -975,6 +974,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected Connection getWrappedObject() throws SQLException
{
return getUnderlyingConnection();
@@ -1002,7 +1002,7 @@
/**
* The checkStatus method checks that the handle has not been closed and
* that it is associated with a managed connection.
- *
+ *
* @exception SQLException if an error occurs
*/
protected void checkStatus() throws SQLException
@@ -1018,7 +1018,7 @@
* The base checkException method rethrows the supplied exception, informing
* the ManagedConnection of the error. Subclasses may override this to
* filter exceptions based on their severity.
- *
+ *
* @param t a throwable
* @return the sql exception
* @exception SQLException if an error occurs
@@ -1040,9 +1040,9 @@
}
else
{
- throw new NestedSQLException("Error", result);
+ throw new SQLException("Error", result);
}
-
+
}
/**
@@ -1053,7 +1053,7 @@
{
return trackStatements;
}
-
+
/**
* Register a statement
* @param ws The statement
@@ -1062,12 +1062,12 @@
{
if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
return;
-
+
synchronized (this)
{
if (statements == null)
statements = new HashMap<WrappedStatement, Throwable>();
-
+
if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
statements.put(ws, new Throwable("STACKTRACE"));
else
@@ -1100,20 +1100,20 @@
if (mc == null || dataSource == null)
return;
- int timeout = 0;
-
+ int timeout = 0;
+
// Use the transaction timeout
if (mc.isTransactionQueryTimeout())
timeout = dataSource.getTimeLeftBeforeTransactionTimeout();
-
+
// Look for a configured value
if (timeout <= 0)
timeout = mc.getQueryTimeout();
-
+
if (timeout > 0)
ws.setQueryTimeout(timeout);
}
-
+
/**
* Get the logger
* @return The value
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrapperDataSource.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrapperDataSource.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrapperDataSource.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -38,7 +38,6 @@
import javax.transaction.RollbackException;
import org.jboss.tm.TransactionTimeoutConfiguration;
-import org.jboss.util.NestedSQLException;
/**
* WrapperDataSource
@@ -47,10 +46,10 @@
* @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 71788 $
*/
-public class WrapperDataSource extends JBossWrapper implements Referenceable, DataSource, Serializable
+public class WrapperDataSource extends JBossWrapper implements Referenceable, DataSource, Serializable
{
private static final long serialVersionUID = 3570285419164793501L;
-
+
private final BaseWrapperManagedConnectionFactory mcf;
private final ConnectionManager cm;
@@ -65,7 +64,7 @@
protected WrapperDataSource(final BaseWrapperManagedConnectionFactory mcf, final ConnectionManager cm)
{
this.mcf = mcf;
- this.cm = cm;
+ this.cm = cm;
}
/**
@@ -98,13 +97,13 @@
public void setLoginTimeout(int param1) throws SQLException
{
}
-
+
/**
* {@inheritDoc}
*/
public Connection getConnection() throws SQLException
{
- try
+ try
{
WrappedConnection wc = (WrappedConnection) cm.allocateConnection(mcf, null);
wc.setDataSource(this);
@@ -112,7 +111,7 @@
}
catch (ResourceException re)
{
- throw new NestedSQLException(re);
+ throw new SQLException(re);
}
}
@@ -122,7 +121,7 @@
public Connection getConnection(String user, String password) throws SQLException
{
ConnectionRequestInfo cri = new WrappedConnectionRequestInfo(user, password);
- try
+ try
{
WrappedConnection wc = (WrappedConnection) cm.allocateConnection(mcf, cri);
wc.setDataSource(this);
@@ -130,7 +129,7 @@
}
catch (ResourceException re)
{
- throw new NestedSQLException(re);
+ throw new SQLException(re);
}
}
@@ -149,7 +148,7 @@
{
return reference;
}
-
+
/**
* Get the time left before a transaction timeout
* @return The amount in seconds; <code>-1</code> if no timeout
@@ -176,14 +175,14 @@
}
catch (RollbackException e)
{
- throw new NestedSQLException(e);
+ throw new SQLException(e);
}
}
-
+
/**
* Check whether a tranasction is active
*
- * @throws SQLException if the transaction is not active, preparing, prepared or committing or
+ * @throws SQLException if the transaction is not active, preparing, prepared or committing or
* for any error in the transaction manager
*/
protected void checkTransactionActive() throws SQLException
@@ -197,7 +196,7 @@
}
catch (Exception e)
{
- throw new NestedSQLException(e);
+ throw new SQLException(e);
}
}
}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/DB2ExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.db2;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A DB2ExceptionSorter current only supporting the Type 4 Universal driver.
+ * Note, currently the DB2 JDBC developers guide only reports a few error codes.
+ * The code -9999 implies that the condition does not have a related code.
+ *
+ * TODO DB2 CLI
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public class DB2ExceptionSorter implements ExceptionSorter, Serializable
+{
+
+ /** The logger */
+ private static Logger logger = Logger.getLogger(DB2ExceptionSorter.class);
+
+ /** The trace */
+ private static boolean trace = logger.isTraceEnabled();
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -4724550353693159378L;
+
+ /**
+ * Constructor
+ */
+ public DB2ExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(final SQLException e)
+ {
+ final int code = Math.abs(e.getErrorCode());
+ boolean isFatal = false;
+
+ if (code == 4499)
+ {
+ isFatal = true;
+ }
+
+ if (trace)
+ {
+ logger.trace("Evaluated SQL error code " + code + " isException returned " + isFatal);
+ }
+
+ return isFatal;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2StaleConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/DB2StaleConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2StaleConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2StaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.db2;
+
+import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
+
+import java.sql.SQLException;
+
+/**
+ * A DB2StaleConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 85945 $
+ */
+public class DB2StaleConnectionChecker implements StaleConnectionChecker
+{
+ /**
+ * Constructor
+ */
+ public DB2StaleConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isStaleConnection(SQLException e)
+ {
+ final int code = Math.abs(e.getErrorCode());
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/DB2ValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/DB2ValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.db2;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * A DB2ValidConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public class DB2ValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1256537245822198702L;
+
+ /** The VALID_QUERY */
+ private static final String VALID_QUERY = "SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1";
+
+ /**
+ * Constructor
+ */
+ public DB2ValidConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(final Connection c)
+ {
+ SQLException theResult = null;
+ Statement s = null;
+
+ try
+ {
+ s = c.createStatement();
+ s.execute(VALID_QUERY);
+ }
+ catch (SQLException e)
+ {
+ theResult = e;
+ }
+ finally
+ {
+ try
+ {
+ if (s != null)
+ s.close();
+ }
+ catch (SQLException e)
+ {
+ // Ignore
+ }
+ }
+
+ return theResult;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/db2/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+DB2 specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/InformixExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/InformixExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/InformixExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/InformixExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.informix;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+/**
+ * InformixExceptionSorter.java
+ *
+ * This is a basic exception sorter for the IBM INFORMIX 9.4 RDBMS. All error
+ * codes are taken from the IBM INFORMIX JDBC driver programmer's guide of the
+ * 2.21.JC6 JDBC driver.
+ *
+ * @author <a href="mailto:u.schroeter at mobilcom.de">Ulf Schroeter</a>
+ */
+public class InformixExceptionSorter implements ExceptionSorter, Serializable
+{
+ private static final long serialVersionUID = -7135889081050258852L;
+
+ /**
+ * Constructor
+ */
+ public InformixExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(SQLException e)
+ {
+ switch (e.getErrorCode())
+ {
+ case -79716: // System or internal error
+ case -79730: // Connection noit established
+ case -79734: // INFORMIXSERVER has to be specified
+ case -79735: // Can't instantiate protocol
+ case -79736: // No connection/statement established yet
+ case -79756: // Invalid connection URL
+ case -79757: // Invalid subprotocol
+ case -79758: // Invalid IP address
+ case -79759: // Invalid port nnumber
+ case -79760: // Invalid database name
+ case -79788: // User name must be specified
+ case -79811: // Connection without user/password not supported
+ case -79812: // User/password does not match with datasource
+ case -79836: // Proxy error: no database connection
+ case -79837: // Proxy error: IO error
+ case -79879: // Unexpected exception
+
+ return true;
+ }
+
+ return false;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/informix/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Informix specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/MSSQLValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/MSSQLValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/MSSQLValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/MSSQLValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.mssql;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.jboss.logging.Logger;
+/**
+ * A MSSQLValidConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 85945 $
+ */
+public class MSSQLValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ private static final String QUERY = "SELECT 1";
+ private static Logger log = Logger.getLogger(MSSQLValidConnectionChecker.class);
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 3995516551833725723L;
+
+ /**
+ * Constructor
+ */
+ public MSSQLValidConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(final Connection c)
+ {
+ SQLException sqe = null;
+ Statement stmt = null;
+
+ try
+ {
+ stmt = c.createStatement();
+ stmt.execute(QUERY);
+ }
+ catch (SQLException e)
+ {
+ log.warn("warning: connection validation failed for current managed connection.");
+ sqe = e;
+ }
+ finally
+ {
+ try
+ {
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ log.warn("simple close failed for managed connection", e);
+ }
+ }
+
+ return sqe;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mssql/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+MSSQL specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/MySQLExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.mysql;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+
+/**
+ * MySQLExceptionSorter
+ *
+ * This is a basic exception sorter for the MySQL RDBMS. All error
+ * codes are taken from the MySQL Connector Java 3.0.16 SQLError class.
+ *
+ * @author <a href="mailto:u.schroeter at mobilcom.de">Ulf Schroeter</a>
+ */
+public class MySQLExceptionSorter implements ExceptionSorter, Serializable
+{
+ private static final long serialVersionUID = 2375890129763721017L;
+
+ /**
+ * Constructor
+ */
+ public MySQLExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(SQLException e)
+ {
+ if (e.getSQLState() != null)
+ {
+ if (e.getSQLState().startsWith("08"))
+ {
+ return true;
+ }
+ }
+
+ switch (e.getErrorCode())
+ {
+ // Communications Errors
+ case 1040: // ER_CON_COUNT_ERROR
+ case 1042: // ER_BAD_HOST_ERROR
+ case 1043: // ER_HANDSHAKE_ERROR
+ case 1047: // ER_UNKNOWN_COM_ERROR
+ case 1081: // ER_IPSOCK_ERROR
+ case 1129: // ER_HOST_IS_BLOCKED
+ case 1130: // ER_HOST_NOT_PRIVILEGED
+
+ // Authentication Errors
+ case 1045: // ER_ACCESS_DENIED_ERROR
+
+ // Resource errors
+ case 1004: // ER_CANT_CREATE_FILE
+ case 1005: // ER_CANT_CREATE_TABLE
+ case 1015: // ER_CANT_LOCK
+ case 1021: // ER_DISK_FULL
+ case 1041: // ER_OUT_OF_RESOURCES
+
+ // Out-of-memory errors
+ case 1037: // ER_OUTOFMEMORY
+ case 1038: // ER_OUT_OF_SORTMEMORY
+
+ return true;
+ }
+
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReplicationValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/MySQLReplicationValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReplicationValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReplicationValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,266 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.mysql;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.jboss.logging.Logger;
+
+/**
+ * <p>This class is an implementation of ValidConnectionChecker for MySQL
+ * ReplicatedDriver. It supports both isValid and ping methods on the
+ * connection object.
+ *
+ * <p>Please note that the isValid method requires java 6 classes to be present.
+ *
+ * <p>The code was inspired by MySQLValidConnectionChecker. See it's javadoc for
+ * authors info. This code is released under the LGPL license.
+ *
+ * @author Luc Boudreau (lucboudreau att gmail dott com)
+ *
+ */
+public class MySQLReplicationValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ /**
+ * Serial version ID
+ */
+ private static final long serialVersionUID = 2658231045989623858L;
+
+ /**
+ * Tells if the connection supports the isValid method.
+ * (Java 6 only)
+ */
+ private boolean driverHasIsValidMethod;
+
+ private transient Method isValid;
+
+ /**
+ * Tells if the connection supports the ping method.
+ */
+ private boolean driverHasPingMethod;
+
+ private transient Method ping;
+
+ /**
+ * Classname of the supported connection
+ */
+ protected static final String CONNECTION_CLASS = "com.mysql.jdbc.ReplicationConnection";
+
+ /**
+ * Log access object
+ */
+ private static transient Logger log;
+
+ // The timeout (apparently the timeout is ignored?)
+ private static Object[] timeoutParam = new Object[] {};
+
+ /**
+ * Initiates the ValidConnectionChecker implementation.
+ */
+ public MySQLReplicationValidConnectionChecker()
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ log.warn("Cannot find the driver class defined in CONNECTION_CLASS. Will use 'SELECT 1' instead.", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+ if (driverHasIsValidMethod)
+ {
+ try
+ {
+ isValid.invoke(c, timeoutParam);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping", e);
+ return new SQLException("ping failed: " + e.toString());
+ }
+ }
+ }
+ else if (driverHasPingMethod)
+ {
+ //if there is a ping method then use it
+ try
+ {
+ ping.invoke(c, timeoutParam);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping", e);
+ return new SQLException("ping failed: " + e.toString());
+ }
+ }
+ }
+ else
+ {
+ //otherwise just use a 'SELECT 1' statement
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try
+ {
+ stmt = c.createStatement();
+ rs = stmt.executeQuery("SELECT 1");
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping (SELECT 1)", e);
+ return new SQLException("ping (SELECT 1) failed: " + e.toString());
+ }
+ }
+ finally
+ {
+ // Cleanup everything and make sure to handle
+ // sql exceptions occuring
+ try
+ {
+ if (rs != null)
+ rs.close();
+ }
+ catch (SQLException e)
+ {
+ // Ignore
+ }
+ try
+ {
+ if (stmt != null)
+ stmt.close();
+ }
+ catch (SQLException e)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void initPing() throws ClassNotFoundException, NoSuchMethodException
+ {
+ driverHasIsValidMethod = false;
+ driverHasPingMethod = false;
+
+ log = Logger.getLogger(MySQLReplicationValidConnectionChecker.class);
+
+ // Load connection class
+ Class<?> mysqlConnection = Thread.currentThread().getContextClassLoader().loadClass(CONNECTION_CLASS);
+
+ // Check for Java 6 compatibility and use isValid on the connection
+ try
+ {
+ isValid = mysqlConnection.getMethod("isValid", new Class<?>[] {});
+ driverHasIsValidMethod = true;
+ }
+ catch (NoSuchMethodException e)
+ {
+ // Notify someone
+ log.info("Cannot resolve com.mysq.jdbc.ReplicationConnection.isValid method. Fallback to ping.", e);
+ }
+ catch (SecurityException e)
+ {
+ // Notify someone
+ log.info("Cannot resolve com.mysq.jdbc.ReplicationConnection.isValid method. Fallback to ping.", e);
+ }
+
+ if (!driverHasIsValidMethod)
+ {
+ try
+ {
+ // Check for ping method
+ ping = mysqlConnection.getMethod("ping", new Class<?>[] {});
+ driverHasPingMethod = true;
+ }
+ catch (NoSuchMethodException e)
+ {
+ // Notify someone
+ log.warn("Cannot resolve com.mysq.jdbc.ReplicationConnection.ping method. Will use 'SELECT 1' instead.", e);
+ }
+ catch (SecurityException e)
+ {
+ // Notify someone
+ log.info("Cannot resolve com.mysq.jdbc.ReplicationConnection.ping method. Will use 'SELECT 1' instead.", e);
+ }
+ }
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
+ // nothing
+ }
+
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ IOException ioe = new IOException("Unable to resolve ping method: " + e.getMessage());
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/MySQLValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.mysql;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Implements check valid connection sql Requires MySQL driver 3.1.8 or later.
+ * This should work on just about any version of the database itself but will
+ * only be "fast" on version 3.22.1 and later. Prior to that version it just
+ * does "SELECT 1" anyhow.
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:acoliver ot jbosss dat org">Andrew C. Oliver</a>
+ * @author <a href="mailto:jim.moran at jboss.org">Jim Moran</a>
+ * @version $Revision: 78074 $
+ */
+public class MySQLValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ private static transient Logger log;
+
+ private static final long serialVersionUID = 1323747853035005642L;
+
+ private boolean driverHasPingMethod;
+
+ private final Integer pingTimeOut = null;
+
+ private transient Method ping;
+
+ /**
+ * Constructor
+ */
+ public MySQLValidConnectionChecker()
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ log.warn("Cannot resolve com.mysq.jdbc.Connection.ping method. Will use 'SELECT 1' instead.", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+
+ //if there is a ping method then use it, otherwise just use a 'SELECT 1' statement
+ if (driverHasPingMethod)
+ {
+ Object[] params = new Object[]{pingTimeOut};
+
+ try
+ {
+ ping.invoke(c, params);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping", e);
+ return new SQLException("ping failed: " + e.toString());
+ }
+ }
+ }
+ else
+ {
+ Statement stmt = null;
+ ResultSet rs = null;
+ try
+ {
+ stmt = c.createStatement();
+ rs = stmt.executeQuery("SELECT 1");
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping (SELECT 1)", e);
+ return new SQLException("ping (SELECT 1) failed: " + e.toString());
+ }
+ }
+ finally
+ {
+ try
+ {
+ if (rs != null)
+ rs.close();
+ }
+ catch (SQLException ignore)
+ {
+ // Ignore
+ }
+ try
+ {
+ if (stmt != null)
+ stmt.close();
+ }
+ catch (SQLException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initPing() throws ClassNotFoundException, NoSuchMethodException
+ {
+ log = Logger.getLogger(MySQLValidConnectionChecker.class);
+ driverHasPingMethod = false;
+
+ Class<?> mysqlConnection =
+ Thread.currentThread().getContextClassLoader().loadClass("com.mysql.jdbc.Connection");
+
+ ping = mysqlConnection.getMethod("ping", new Class<?>[] {});
+
+ if (ping != null)
+ {
+ driverHasPingMethod = true;
+ }
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
+ // nothing
+ }
+
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ IOException ioe = new IOException("Unable to resolve ping method: " + e.getMessage());
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ /**
+ * Get the pingTimeOut.
+ *
+ * @return the pingTimeOut.
+ */
+ public final Integer getPingTimeOut()
+ {
+ return pingTimeOut;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+MySQL specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.novendor;
+
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+/**
+ * Does not check the exception. Used if the named exception sorter cannot be instantiated.
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
+ *
+ * @version $Revision: 75423 $
+ */
+public class NullExceptionSorter implements ExceptionSorter, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 202928214888283717L;
+
+ /**
+ * Constructor
+ */
+ public NullExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(SQLException e)
+ {
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullStaleConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullStaleConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullStaleConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullStaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.novendor;
+
+import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
+
+import java.sql.SQLException;
+
+/**
+ * A NullStaleConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public class NullStaleConnectionChecker implements StaleConnectionChecker
+{
+
+ /**
+ * Constructor
+ */
+ public NullStaleConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isStaleConnection(SQLException e)
+ {
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/NullValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/NullValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.novendor;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Does not check the connection
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 71554 $
+ */
+public class NullValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ private static final long serialVersionUID = -223752863430216887L;
+
+ /**
+ * Constructor
+ */
+ public NullValidConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+ return null;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/novendor/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+NoVendor extensions used a do-nothing-implementation<
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/OracleExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.oracle;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+/**
+ * OracleExceptionSorter.java
+ *
+ *
+ * Created: Fri Mar 14 21:54:23 2003
+ *
+ * @author <a href="mailto:an_test at mail.ru">Andrey Demchenko</a>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
+ * @version 1.0
+ */
+public class OracleExceptionSorter implements ExceptionSorter, Serializable
+{
+ private static final long serialVersionUID = 573723525408205079L;
+
+ /**
+ * Constructor
+ */
+ public OracleExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(final SQLException e)
+ {
+ final int errorCode = Math.abs(e.getErrorCode());
+
+ if ((errorCode == 28) //session has been killed
+ || (errorCode == 600) //Internal oracle error
+ || (errorCode == 1012) //not logged on
+ || (errorCode == 1014) //Oracle shutdown in progress
+ || (errorCode == 1033) //Oracle initialization or shutdown in progress
+ || (errorCode == 1034) //Oracle not available
+ || (errorCode == 1035) //ORACLE only available to users with RESTRICTED SESSION privilege
+ || (errorCode == 1089) //immediate shutdown in progress - no operations are permitted
+ || (errorCode == 1090) //shutdown in progress - connection is not permitted
+ || (errorCode == 1092) //ORACLE instance terminated. Disconnection forced
+ || (errorCode == 1094) //ALTER DATABASE CLOSE in progress. Connections not permitted
+ || (errorCode == 2396) //exceeded maximum idle time, please connect again
+ || (errorCode == 3106) //fatal two-task communication protocol error
+ || (errorCode == 3111) //break received on communication channel
+ || (errorCode == 3113) //end-of-file on communication channel
+ || (errorCode == 3114) //not connected to ORACLE
+ || (errorCode >= 12100 && errorCode <= 12299) // TNS issues
+ || (errorCode == 17002) //connection reset
+ || (errorCode == 17008) //connection closed
+ || (errorCode == 17410) //No more data to read from socket
+ || (errorCode == 17447) //OALL8 is in an inconsistent state
+ )
+ {
+ return true;
+ }
+
+ final String errorText = (e.getMessage()).toUpperCase();
+
+ // Exclude oracle user defined error codes (20000 through 20999) from consideration when looking for
+ // certain strings.
+
+ if ((errorCode < 20000 || errorCode >= 21000) &&
+ ((errorText.indexOf("SOCKET") > -1) //for control socket error
+ || (errorText.indexOf("CONNECTION HAS ALREADY BEEN CLOSED") > -1)
+ || (errorText.indexOf("BROKEN PIPE") > -1)))
+ {
+ return true;
+ }
+
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleStaleConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/OracleStaleConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleStaleConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleStaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.oracle;
+
+import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
+
+import java.sql.SQLException;
+
+/**
+ * A OracleStaleConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 85945 $
+ */
+public class OracleStaleConnectionChecker implements StaleConnectionChecker
+{
+ /**
+ * Constructor
+ */
+ public OracleStaleConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isStaleConnection(SQLException e)
+ {
+ final int errorCode = Math.abs(e.getErrorCode());
+
+ if ((errorCode == 1014) ||
+ (errorCode == 1033) ||
+ (errorCode == 1034))
+ {
+ return true;
+ }
+
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/OracleValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/OracleValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.oracle;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Implements check valid connection sql
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 105425 $
+ */
+public class OracleValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ private static final long serialVersionUID = 5379340663276548636L;
+
+ private static transient Logger log;
+
+ // The timeout in seconds (apparently the timeout is ignored?)
+ private Integer pingTimeOut = new Integer(5);
+
+ private transient Method ping;
+
+ /**
+ * Constructor
+ */
+ public OracleValidConnectionChecker()
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to resolve pingDatabase method:", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+ Object[] params = new Object[]{pingTimeOut};
+
+ try
+ {
+ Integer status = (Integer) ping.invoke(c, params);
+
+ // Error
+ if (status == null || status.intValue() < 0)
+ return new SQLException("pingDatabase failed status=" + status);
+ }
+ catch (Exception e)
+ {
+ // What do we do here? Assume it is a misconfiguration
+ log.warn("Unexpected error in pingDatabase", e);
+ }
+
+ // OK
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initPing() throws ClassNotFoundException, NoSuchMethodException
+ {
+ log = Logger.getLogger(OracleValidConnectionChecker.class);
+
+ Class<?> oracleConnection =
+ Thread.currentThread().getContextClassLoader().loadClass("oracle.jdbc.driver.OracleConnection");
+ ping = oracleConnection.getMethod("pingDatabase", new Class<?>[] {Integer.TYPE});
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
+ // nothing
+ }
+
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
+ {
+ try
+ {
+ initPing();
+ }
+ catch (Exception e)
+ {
+ IOException ioe = new IOException("Unable to resolve pingDatabase method: " + e.getMessage());
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ /**
+ * Get the pingTimeOut.
+ *
+ * @return the pingTimeOut.
+ */
+ public final Integer getPingTimeOut()
+ {
+ return pingTimeOut;
+ }
+
+ /**
+ * Set the pingTimeOut.
+ *
+ * @param pingTimeOut The pingTimeOut to set.
+ */
+ public final void setPingTimeOut(Integer pingTimeOut)
+ {
+ this.pingTimeOut = pingTimeOut;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/oracle/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Oracle specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/package.html (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/package.html)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Vendor specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/PostgreSQLExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.postgres;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+/**
+ * A PostgreSQLExceptionSorter.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public class PostgreSQLExceptionSorter implements ExceptionSorter, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 8961250260772836448L;
+
+ /**
+ * Constructor
+ */
+ public PostgreSQLExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(SQLException e)
+ {
+ return false;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/PostgreSQLValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/PostgreSQLValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.postgres;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * A PostgreSQLValidConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public class PostgreSQLValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4867167301823753925L;
+
+ /**
+ * Constructor
+ */
+ public PostgreSQLValidConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SQLException isValidConnection(Connection c)
+ {
+ Statement stmt = null;
+ SQLException sqe = null;
+
+ try
+ {
+ stmt = c.createStatement();
+ stmt.execute("");
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ sqe = (SQLException)e;
+ }
+ }
+ finally
+ {
+ if (stmt != null)
+ {
+ try
+ {
+ stmt.close();
+ }
+ catch (SQLException e)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ return sqe;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/postgres/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Postgres specific extensions
+</body>
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/SybaseExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.sybase;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+
+/**
+ * SybaseExceptionSorter.java
+ *
+ * Created: Wed May 12 11:46:23 2003
+ *
+ * @author <a href="mailto:corby3000 at hotmail.com">Corby Page</a>
+ * @author <a href="mailto:an_test at mail.ru">Andrey Demchenko</a>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ */
+public class SybaseExceptionSorter implements ExceptionSorter, Serializable
+{
+ private static final long serialVersionUID = 3539640818722639055L;
+
+ /**
+ * Constructor
+ */
+ public SybaseExceptionSorter()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isExceptionFatal(SQLException e)
+ {
+ boolean result = false;
+
+ String errorText = (e.getMessage()).toUpperCase();
+
+ if ((errorText.indexOf("JZ0C0") > -1) || // ERR_CONNECTION_DEAD
+ (errorText.indexOf("JZ0C1") > -1)) // ERR_IOE_KILLED_CONNECTION
+ {
+ result = true;
+ }
+
+ return result;
+ }
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/vendor/SybaseValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/SybaseValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.sybase;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A SybaseValidConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 85945 $
+ */
+public class SybaseValidConnectionChecker implements ValidConnectionChecker, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4179707462244257791L;
+
+ /** The logger */
+ private static Logger log = Logger.getLogger(SybaseValidConnectionChecker.class);
+
+ /** The VALID_QUERY */
+ private static final String VALID_QUERY = "SELECT getdate()";
+
+ /**
+ * Constructor
+ */
+ public SybaseValidConnectionChecker()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+ SQLException sqe = null;
+ Statement s = null;
+ ResultSet rs = null;
+
+ try
+ {
+ s = c.createStatement();
+ rs = s.executeQuery(VALID_QUERY);
+ }
+ catch (SQLException e)
+ {
+ sqe = e;
+ }
+ finally
+ {
+ try
+ {
+ if (rs != null)
+ rs.close();
+ }
+ catch (SQLException ignore)
+ {
+ log.warn("JDBC resource for " + this + " could not be closed");
+ }
+
+ try
+ {
+ if (s != null)
+ s.close();
+ }
+ catch (SQLException ignore)
+ {
+ log.warn("JDBC resource for " + this + " could not be closed");
+ }
+ }
+
+ return sqe;
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/sybase/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Sybase specific extensions
+</body>
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -23,7 +23,7 @@
package org.jboss.jca.adapters.jdbc.local;
import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory;
-import org.jboss.jca.adapters.jdbc.URLSelectorStrategy;
+import org.jboss.jca.adapters.jdbc.spi.URLSelectorStrategy;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -44,7 +44,6 @@
import javax.resource.spi.ManagedConnection;
import javax.security.auth.Subject;
-import org.jboss.util.NestedRuntimeException;
/**
* LocalManagedConnectionFactory
@@ -62,7 +61,7 @@
private transient Driver driver;
private String connectionURL;
-
+
private URLSelectorStrategy urlSelector;
/** The connection properties */
@@ -84,16 +83,16 @@
// check some invariants before they come back to haunt us
if (driverClass == null)
throw new ResourceException("driverClass is null");
-
+
if (connectionURL == null)
throw new ResourceException("connectionURL is null");
-
+
return super.createConnectionFactory(cm);
}
-
+
/**
* Get the value of ConnectionURL.
- *
+ *
* @return value of ConnectionURL.
*/
public String getConnectionURL()
@@ -103,7 +102,7 @@
/**
* Set the value of ConnectionURL.
- *
+ *
* @param connectionURL Value to assign to ConnectionURL.
*/
public void setConnectionURL(final String connectionURL) //throws ResourceException
@@ -116,7 +115,7 @@
/**
* Get the DriverClass value.
- *
+ *
* @return the DriverClass value.
*/
public String getDriverClass()
@@ -126,7 +125,7 @@
/**
* Set the DriverClass value.
- *
+ *
* @param driverClass The new DriverClass value.
*/
public synchronized void setDriverClass(final String driverClass)
@@ -137,7 +136,7 @@
/**
* Get the value of connectionProperties.
- *
+ *
* @return value of connectionProperties.
*/
public String getConnectionProperties()
@@ -147,7 +146,7 @@
/**
* Set the value of connectionProperties.
- *
+ *
* @param connectionProperties Value to assign to connectionProperties.
*/
public void setConnectionProperties(String connectionProperties)
@@ -159,6 +158,7 @@
{
// Map any \ to \\
connectionProperties = connectionProperties.replaceAll("\\\\", "\\\\\\\\");
+ connectionProperties = connectionProperties.replaceAll(";", "\n");
InputStream is = new ByteArrayInputStream(connectionProperties.getBytes());
try
@@ -167,7 +167,7 @@
}
catch (IOException ioe)
{
- throw new NestedRuntimeException("Could not load connection properties", ioe);
+ throw new RuntimeException("Could not load connection properties", ioe);
}
}
}
@@ -195,7 +195,7 @@
}
log.trace("Using properties: " + logCopy);
}
-
+
if (urlSelector != null)
{
return getHALocalManagedConnection(props, copy);
@@ -206,14 +206,14 @@
}
}
- private LocalManagedConnection getLocalManagedConnection(Properties props, Properties copy)
+ private LocalManagedConnection getLocalManagedConnection(Properties props, Properties copy)
throws ResourceException
{
Connection con = null;
try
{
String url = getConnectionURL();
- Driver d = getDriver(url);
+ Driver d = getDriver(url);
con = d.connect(url, copy);
if (con == null)
throw new ResourceException("Wrong driver class for this connection URL");
@@ -254,7 +254,7 @@
Connection con = null;
try
{
- Driver d = getDriver(url);
+ Driver d = getDriver(url);
con = d.connect(url, copy);
if (con == null)
{
@@ -283,16 +283,17 @@
urlSelector.failedUrlObject(url);
}
}
-
+
// we have supposedly tried all the urls
- throw new ResourceException("Could not create connection using any of the URLs: " +
+ throw new ResourceException("Could not create connection using any of the URLs: " +
urlSelector.getAllUrlObjects());
}
-
+
/**
* Set the URL delimiter
* @param urlDelimiter The value
*/
+ @Override
public void setURLDelimiter(String urlDelimiter) //throws ResourceException
{
super.urlDelimiter = urlDelimiter;
@@ -301,14 +302,14 @@
initUrlSelector();
}
}
-
+
/**
* Init URL selector
*/
protected void initUrlSelector() //throws ResourceException
{
boolean trace = log.isTraceEnabled();
-
+
List<String> urlsList = new ArrayList<String>();
String urlsStr = getConnectionURL();
String url;
@@ -346,7 +347,7 @@
log.debug("Customized URLSelectorStrategy is being used : " + urlSelector);
}
}
-
+
/**
* Default implementation
*/
@@ -355,7 +356,7 @@
private final List<String> urls;
private int urlIndex;
private String url;
-
+
/**
* Constructor
* @param urls The urls
@@ -443,7 +444,7 @@
final ConnectionRequestInfo cri) throws ResourceException
{
Properties newProps = getConnectionProperties(subject, cri);
-
+
for (Iterator<?> i = mcs.iterator(); i.hasNext();)
{
Object o = i.next();
@@ -470,6 +471,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public int hashCode()
{
int result = 17;
@@ -484,6 +486,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public boolean equals(Object other)
{
if (this == other)
@@ -511,7 +514,7 @@
protected synchronized Driver getDriver(final String url) throws ResourceException
{
boolean trace = log.isTraceEnabled();
-
+
// don't bother if it is loaded already
if (driver != null)
{
@@ -553,14 +556,14 @@
throw new ResourceException("Failed to register driver for: " + driverClass, e);
}
- throw new ResourceException("Apparently wrong driver class specified for URL: class: " + driverClass +
+ throw new ResourceException("Apparently wrong driver class specified for URL: class: " + driverClass +
", url: " + url);
}
private boolean isDriverLoadedForURL(String url)
{
boolean trace = log.isTraceEnabled();
-
+
try
{
driver = DriverManager.getDriver(url);
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorter.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ExceptionSorter.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.spi;
+
+import java.sql.SQLException;
+
+/**
+ * The ExceptionSorter interface allows for <code>java.sql.SQLException</code>
+ * evaluation to determine if an error is fatal.
+ *
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:weston.price at jboss.com>Weston Price</a>
+ *
+ * @see ValidConnectionChecker
+ *
+ * @version $Revision: 71554 $
+ */
+
+public interface ExceptionSorter
+{
+
+
+ /**
+ * Evaluates a <code>java.sql.SQLException</code> to determine if
+ * the error was fatal
+ *
+ * @param e the <code>java.sql.SQLException</code>
+ *
+ * @return whether or not the exception is vatal.
+ */
+ boolean isExceptionFatal(SQLException e);
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/StaleConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.spi;
+
+import java.sql.SQLException;
+
+/**
+ * A StaleConnectionChecker.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public interface StaleConnectionChecker
+{
+
+ /**
+ * Is the connection stale
+ *
+ * @param e the <code>java.sql.SQLException</code>
+ * @return is the connection stale
+ */
+ public boolean isStaleConnection(SQLException e);
+
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/URLSelectorStrategy.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/URLSelectorStrategy.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/URLSelectorStrategy.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/URLSelectorStrategy.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.spi;
+
+import java.util.List;
+
+/**
+ * URLSelectorStrategy
+ *
+ * @author <a href="mailto:vkak at redhat.com">Vicky Kak</a>
+ */
+public interface URLSelectorStrategy
+{
+ /**
+ * Get all url objects
+ * @return The value
+ */
+ public List<?> getAllUrlObjects();
+
+ /**
+ * Failed url object
+ * @param urlObject The value
+ */
+ public void failedUrlObject(Object urlObject);
+
+ /**
+ * Get all custom url objects
+ * @return The value
+ */
+ public List<?> getCustomSortedUrls();
+
+ /**
+ * Get url object
+ * @return The value
+ */
+ public Object getUrlObject();
+}
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionChecker.java (from rev 109267, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ValidConnectionChecker.java)
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.spi;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Checks that a connection is valid
+ *
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 71554 $
+ */
+public interface ValidConnectionChecker
+{
+ /**
+ * Checks the connection is valid
+ *
+ * @param c the connection
+ * @return Exception when not valid, null when valid
+ */
+ SQLException isValidConnection(Connection c);
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/spi/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+The JDBC resource adapter spi
+</body>
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/xa/XAManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/xa/XAManagedConnectionFactory.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/xa/XAManagedConnectionFactory.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -23,7 +23,7 @@
package org.jboss.jca.adapters.jdbc.xa;
import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory;
-import org.jboss.jca.adapters.jdbc.URLSelectorStrategy;
+import org.jboss.jca.adapters.jdbc.spi.URLSelectorStrategy;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/LRUCachePolicy.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/LRUCachePolicy.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/LRUCachePolicy.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,878 @@
+/*
+ * 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.adapters.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Implementation of a Least Recently Used cache policy.
+ *
+ * @author <a href="mailto:stefano.maestri at redhat.com">Stefano Maestri</a>
+ * @version $Revision$
+ */
+ at SuppressWarnings("unchecked")
+public class LRUCachePolicy
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ /**
+ * The map holding the cached objects
+ */
+ protected Map map;
+
+ /**
+ * The linked list used to implement the LRU algorithm
+ */
+ protected LRUList lruList;
+
+ /**
+ * The maximum capacity of this cache
+ */
+ protected int maxCapacity;
+
+ /**
+ * The minimum capacity of this cache
+ */
+ protected int minCapacity;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+ /**
+ * Creates a LRU cache policy object with zero cache capacity.
+ *
+ * @see #create
+ */
+ public LRUCachePolicy()
+ {
+ }
+
+ /**
+ * Creates a LRU cache policy object with the specified minimum
+ * and maximum capacity.
+ * @param min min
+ * @param max max
+ *
+ * @see #create
+ */
+ public LRUCachePolicy(int min, int max)
+ {
+ if (min < 2 || min > max)
+ {
+ throw new IllegalArgumentException("Illegal cache capacities");
+ }
+ minCapacity = min;
+ maxCapacity = max;
+ }
+
+ /**
+ * Create map holding entries.
+ *
+ * @return the map
+ */
+ protected Map createMap()
+ {
+ return new HashMap();
+ }
+
+ // Public --------------------------------------------------------
+
+ // Service implementation ----------------------------------------------
+ /**
+ * Initializes the cache, creating all required objects and initializing their
+ * values.
+ * @see #start
+ * @see #destroy
+ */
+ public void create()
+ {
+ map = createMap();
+ lruList = createList();
+ lruList.maxCapacity = maxCapacity;
+ lruList.minCapacity = minCapacity;
+ lruList.capacity = maxCapacity;
+ }
+
+ /**
+ * Starts this cache that is now ready to be used.
+ * @see #create
+ * @see #stop
+ */
+ public void start()
+ {
+ }
+
+ /**
+ * Stops this cache thus {@link #flush}ing all cached objects. <br>
+ * After this method is called, a call to {@link #start} will restart the cache.
+ * @see #start
+ * @see #destroy
+ */
+ public void stop()
+ {
+ if (lruList != null)
+ {
+ flush();
+ }
+ }
+
+ /**
+ * Destroys the cache that is now unusable. <br>
+ * To have it working again it must be re-{@link #create}ed and
+ * re-{@link #start}ed.
+ *
+ * @see #create
+ */
+ public void destroy()
+ {
+ if (map != null)
+ map.clear();
+ if (lruList != null)
+ lruList.clear();
+ }
+
+ /**
+ *
+ * get method
+ *
+ * @param key key
+ * @return the value
+ */
+ public Object get(Object key)
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Requesting an object using a null key");
+ }
+
+ LRUCacheEntry value = (LRUCacheEntry) map.get(key);
+ if (value != null)
+ {
+ lruList.promote(value);
+ return value.object;
+ }
+ else
+ {
+ cacheMiss();
+ return null;
+ }
+ }
+
+ /**
+ *
+ * peek
+ *
+ * @param key the key
+ * @return the value
+ */
+ public Object peek(Object key)
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Requesting an object using a null key");
+ }
+
+ LRUCacheEntry value = (LRUCacheEntry) map.get(key);
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ return value.object;
+ }
+ }
+
+ /**
+ *
+ * insert
+ *
+ * @param key the key
+ * @param o value
+ */
+ public void insert(Object key, Object o)
+ {
+ if (o == null)
+ {
+ throw new IllegalArgumentException("Cannot insert a null object in the cache");
+ }
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Cannot insert an object in the cache with null key");
+ }
+ if (map.containsKey(key))
+ {
+ throw new IllegalStateException("Attempt to put in the cache an object that is already there");
+ }
+ lruList.demote();
+ LRUCacheEntry entry = createCacheEntry(key, o);
+ map.put(key, entry);
+ lruList.promote(entry);
+ }
+
+ /**
+ *
+ * remove
+ *
+ * @param key the key
+ */
+ public void remove(Object key)
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Removing an object using a null key");
+ }
+
+ Object value = map.remove(key);
+ if (value != null)
+ {
+ lruList.remove((LRUCacheEntry) value);
+ }
+ //else Do nothing, the object isn't in the cache list
+ }
+
+ /**
+ *
+ * flush
+ *
+ */
+ public void flush()
+ {
+ LRUCacheEntry entry = null;
+ while ((entry = lruList.tail) != null)
+ {
+ ageOut(entry);
+ }
+ }
+
+ /**
+ *
+ * size
+ *
+ * @return the size
+ */
+ public int size()
+ {
+ return lruList.count;
+ }
+
+ // Y overrides ---------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ /**
+ * Factory method for the linked list used by this cache implementation.
+ * @return the lru list
+ */
+ protected LRUList createList()
+ {
+ return new LRUList();
+ }
+
+ /**
+ * Callback method called when the cache algorithm ages out of the cache
+ * the given entry. <br>
+ * The implementation here is removing the given entry from the cache.
+ * @param entry entry
+ */
+ protected void ageOut(LRUCacheEntry entry)
+ {
+ remove(entry.key);
+ }
+
+ /**
+ * Callback method called when a cache miss happens.
+ */
+ protected void cacheMiss()
+ {
+ }
+
+ /**
+ * Factory method for cache entries
+ * @param key key
+ * @param value value
+ * @return the entry entry
+ */
+ protected LRUCacheEntry createCacheEntry(Object key, Object value)
+ {
+ return new LRUCacheEntry(key, value);
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+ /**
+ * Double queued list used to store cache entries.
+ */
+ public class LRUList
+ {
+ /** The maximum capacity of the cache list */
+ private int maxCapacity;
+
+ /** The minimum capacity of the cache list */
+ private int minCapacity;
+
+ /** The current capacity of the cache list */
+ private int capacity;
+
+ /** The number of cached objects */
+ private int count;
+
+ /** The head of the double linked list */
+ private LRUCacheEntry head;
+
+ /** The tail of the double linked list */
+ private LRUCacheEntry tail;
+
+ /** The cache misses happened */
+ private int cacheMiss;
+
+ /**
+ * Creates a new double queued list.
+ */
+ protected LRUList()
+ {
+ head = null;
+ tail = null;
+ count = 0;
+ }
+
+ /**
+ * Promotes the cache entry <code>entry</code> to the last used position
+ * of the list. <br>
+ * If the object is already there, does nothing.
+ * @param entry the object to be promoted, cannot be null
+ * @see #demote
+ * @throws IllegalStateException if this method is called with a full cache
+ */
+ protected void promote(LRUCacheEntry entry)
+ {
+ if (entry == null)
+ {
+ throw new IllegalArgumentException("Trying to promote a null object");
+ }
+ if (capacity < 1)
+ {
+ throw new IllegalStateException("Can't work with capacity < 1");
+ }
+
+ entryPromotion(entry);
+
+ entry.time = System.currentTimeMillis();
+ if (entry.prev == null)
+ {
+ if (entry.next == null)
+ {
+ // entry is new or there is only the head
+ if (count == 0) // cache is empty
+ {
+ head = entry;
+ tail = entry;
+ ++count;
+ entryAdded(entry);
+ }
+ else if (count == 1 && head == entry)
+ {
+ // there is only the head and I want to promote it, do nothing
+ }
+ else if (count < capacity)
+ {
+ entry.prev = null;
+ entry.next = head;
+ head.prev = entry;
+ head = entry;
+ ++count;
+ entryAdded(entry);
+ }
+ else if (count < maxCapacity)
+ {
+ entry.prev = null;
+ entry.next = head;
+ head.prev = entry;
+ head = entry;
+ ++count;
+ int oldCapacity = capacity;
+ ++capacity;
+ entryAdded(entry);
+ capacityChanged(oldCapacity);
+ }
+ else
+ {
+ throw new IllegalStateException("Attempt to put a new cache entry on a full cache");
+ }
+ }
+ else
+ {
+ // entry is the head, do nothing
+ }
+ }
+ else
+ {
+ if (entry.next == null) // entry is the tail
+ {
+ LRUCacheEntry beforeLast = entry.prev;
+ beforeLast.next = null;
+ entry.prev = null;
+ entry.next = head;
+ head.prev = entry;
+ head = entry;
+ tail = beforeLast;
+ }
+ else
+ // entry is in the middle of the list
+ {
+ LRUCacheEntry previous = entry.prev;
+ previous.next = entry.next;
+ entry.next.prev = previous;
+ entry.prev = null;
+ entry.next = head;
+ head.prev = entry;
+ head = entry;
+ }
+ }
+ }
+
+ /**
+ * Demotes from the cache the least used entry. <br>
+ * If the cache is not full, does nothing.
+ * @see #promote
+ */
+ protected void demote()
+ {
+ if (capacity < 1)
+ {
+ throw new IllegalStateException("Can't work with capacity < 1");
+ }
+ if (count > maxCapacity)
+ {
+ throw new IllegalStateException("Cache list entries number (" + count +
+ ") > than the maximum allowed (" + maxCapacity + ")");
+ }
+ if (count == maxCapacity)
+ {
+ LRUCacheEntry entry = tail;
+
+ // the entry will be removed by ageOut
+ ageOut(entry);
+ }
+ else
+ {
+ // cache is not full, do nothing
+ }
+ }
+
+ /**
+ * Removes from the cache list the specified entry.
+ * @param entry entry
+ */
+ protected void remove(LRUCacheEntry entry)
+ {
+ if (entry == null)
+ {
+ throw new IllegalArgumentException("Cannot remove a null entry from the cache");
+ }
+ if (count < 1)
+ {
+ throw new IllegalStateException("Trying to remove an entry from an empty cache");
+ }
+
+ entry.key = null;
+ entry.object = null;
+ if (count == 1)
+ {
+ head = null;
+ tail = null;
+ }
+ else
+ {
+ if (entry.prev == null) // the head
+ {
+ head = entry.next;
+ head.prev = null;
+ entry.next = null;
+ }
+ else if (entry.next == null) // the tail
+ {
+ tail = entry.prev;
+ tail.next = null;
+ entry.prev = null;
+ }
+ else
+ // in the middle
+ {
+ entry.next.prev = entry.prev;
+ entry.prev.next = entry.next;
+ entry.prev = null;
+ entry.next = null;
+ }
+ }
+ --count;
+ entryRemoved(entry);
+ }
+
+ /**
+ * Callback that signals that the given entry is just about to be added.
+ * @param entry entry
+ */
+ protected void entryPromotion(LRUCacheEntry entry)
+ {
+ }
+
+ /**
+ * Callback that signals that the given entry has been added to the cache.
+ * @param entry entry
+ */
+ protected void entryAdded(LRUCacheEntry entry)
+ {
+ }
+
+ /**
+ * Callback that signals that the given entry has been removed from the cache.
+ * @param entry entry
+ */
+ protected void entryRemoved(LRUCacheEntry entry)
+ {
+ }
+
+ /**
+ * Callback that signals that the capacity of the cache is changed.
+ * @param oldCapacity the capacity before the change happened
+ */
+ protected void capacityChanged(int oldCapacity)
+ {
+ }
+
+ /**
+ *
+ * clear
+ *
+ */
+ protected void clear()
+ {
+ LRUCacheEntry entry = head;
+ head = null;
+ tail = null;
+ count = 0;
+ for (; entry != null; entry = entry.next)
+ entryRemoved(entry);
+ }
+
+ @Override
+ public String toString()
+ {
+ String s = Integer.toHexString(super.hashCode());
+ s += " size: " + count;
+ for (LRUCacheEntry entry = head; entry != null; entry = entry.next)
+ {
+ s += "\n" + entry;
+ }
+ return s;
+ }
+
+ /**
+ * Get the maxCapacity.
+ *
+ * @return the maxCapacity.
+ */
+ public final int getMaxCapacity()
+ {
+ return maxCapacity;
+ }
+
+ /**
+ * Set the maxCapacity.
+ *
+ * @param maxCapacity The maxCapacity to set.
+ */
+ public final void setMaxCapacity(int maxCapacity)
+ {
+ this.maxCapacity = maxCapacity;
+ }
+
+ /**
+ * Get the minCapacity.
+ *
+ * @return the minCapacity.
+ */
+ public final int getMinCapacity()
+ {
+ return minCapacity;
+ }
+
+ /**
+ * Set the minCapacity.
+ *
+ * @param minCapacity The minCapacity to set.
+ */
+ public final void setMinCapacity(int minCapacity)
+ {
+ this.minCapacity = minCapacity;
+ }
+
+ /**
+ * Get the capacity.
+ *
+ * @return the capacity.
+ */
+ public final int getCapacity()
+ {
+ return capacity;
+ }
+
+ /**
+ * Set the capacity.
+ *
+ * @param capacity The capacity to set.
+ */
+ public final void setCapacity(int capacity)
+ {
+ this.capacity = capacity;
+ }
+
+ /**
+ * Get the count.
+ *
+ * @return the count.
+ */
+ public final int getCount()
+ {
+ return count;
+ }
+
+ /**
+ * Set the count.
+ *
+ * @param count The count to set.
+ */
+ public final void setCount(int count)
+ {
+ this.count = count;
+ }
+
+ /**
+ * Get the head.
+ *
+ * @return the head.
+ */
+ public final LRUCacheEntry getHead()
+ {
+ return head;
+ }
+
+ /**
+ * Set the head.
+ *
+ * @param head The head to set.
+ */
+ public final void setHead(LRUCacheEntry head)
+ {
+ this.head = head;
+ }
+
+ /**
+ * Get the tail.
+ *
+ * @return the tail.
+ */
+ public final LRUCacheEntry getTail()
+ {
+ return tail;
+ }
+
+ /**
+ * Set the tail.
+ *
+ * @param tail The tail to set.
+ */
+ public final void setTail(LRUCacheEntry tail)
+ {
+ this.tail = tail;
+ }
+
+ /**
+ * Get the cacheMiss.
+ *
+ * @return the cacheMiss.
+ */
+ public final int getCacheMiss()
+ {
+ return cacheMiss;
+ }
+
+ /**
+ * Set the cacheMiss.
+ *
+ * @param cacheMiss The cacheMiss to set.
+ */
+ public final void setCacheMiss(int cacheMiss)
+ {
+ this.cacheMiss = cacheMiss;
+ }
+ }
+
+ /**
+ * Double linked cell used as entry in the cache list.
+ */
+ public class LRUCacheEntry
+ {
+ /** Reference to the next cell in the list */
+ private LRUCacheEntry next;
+
+ /** Reference to the previous cell in the list */
+ private LRUCacheEntry prev;
+
+ /** The key used to retrieve the cached object */
+ private Object key;
+
+ /** The cached object */
+ private Object object;
+
+ /** The timestamp of the creation */
+ private long time;
+
+ /**
+ * Creates a new double linked cell, storing the object we
+ * want to cache and the key that is used to retrieve it.
+ * @param key key
+ * @param object object
+ */
+ protected LRUCacheEntry(Object key, Object object)
+ {
+ this.key = key;
+ this.object = object;
+ next = null;
+ prev = null;
+ time = 0; // Set when inserted in the list.
+ }
+
+ @Override
+ public String toString()
+ {
+ return "key: " + key + ", object: " +
+ (object == null ? "null" : Integer.toHexString(object.hashCode())) + ", entry: " +
+ Integer.toHexString(super.hashCode());
+ }
+
+ /**
+ * Get the next.
+ *
+ * @return the next.
+ */
+ public final LRUCacheEntry getNext()
+ {
+ return next;
+ }
+
+ /**
+ * Set the next.
+ *
+ * @param next The next to set.
+ */
+ public final void setNext(LRUCacheEntry next)
+ {
+ this.next = next;
+ }
+
+ /**
+ * Get the prev.
+ *
+ * @return the prev.
+ */
+ public final LRUCacheEntry getPrev()
+ {
+ return prev;
+ }
+
+ /**
+ * Set the prev.
+ *
+ * @param prev The prev to set.
+ */
+ public final void setPrev(LRUCacheEntry prev)
+ {
+ this.prev = prev;
+ }
+
+ /**
+ * Get the key.
+ *
+ * @return the key.
+ */
+ public final Object getKey()
+ {
+ return key;
+ }
+
+ /**
+ * Set the key.
+ *
+ * @param key The key to set.
+ */
+ public final void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ /**
+ * Get the object.
+ *
+ * @return the object.
+ */
+ public final Object getObject()
+ {
+ return object;
+ }
+
+ /**
+ * Set the object.
+ *
+ * @param object The object to set.
+ */
+ public final void setObject(Object object)
+ {
+ this.object = object;
+ }
+
+ /**
+ * Get the time.
+ *
+ * @return the time.
+ */
+ public final long getTime()
+ {
+ return time;
+ }
+
+ /**
+ * Set the time.
+ *
+ * @param time The time to set.
+ */
+ public final void setTime(long time)
+ {
+ this.time = time;
+ }
+ }
+}
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Util package with LRU Policy
+</body>
Modified: projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/local/META-INF/ra.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -108,16 +108,31 @@
<config-property-type>java.lang.String</config-property-type>
</config-property>
<config-property>
+ <description>TThe properties to inect into 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>ValidConnectionCheckerProperties</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>
+ <config-property>
+ <description>The properties to inect into 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>ExceptionSorterProperties</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>
<config-property>
+ <description>The properties to inect into 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>StaleConnectionCheckerProperties</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>
Modified: projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/xa/META-INF/ra.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/xa/META-INF/ra.xml 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/xa/META-INF/ra.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -108,16 +108,31 @@
<config-property-type>java.lang.String</config-property-type>
</config-property>
<config-property>
+ <description>TThe properties to inect into 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>ValidConnectionCheckerProperties</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>
+ <config-property>
+ <description>The properties to inect into 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>ExceptionSorterProperties</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>
<config-property>
+ <description>The properties to inect into 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>StaleConnectionCheckerProperties</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>
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorterTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorterTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ExceptionSorterTestCase.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,166 @@
+/*
+ * 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.adapters.jdbc.spi;
+
+import org.jboss.jca.adapters.jdbc.spi.testimpl.TestExceptionSorter;
+import org.jboss.jca.embedded.EmbeddedJCA;
+
+import java.io.File;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+
+/**
+ *
+ * A ExceptionSorterTestCase.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class ExceptionSorterTestCase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * shouldInjectCorrectExceptionSorter
+ * @throws Throwable in case of error
+ */
+ @Test
+ public void shouldInjectCorrectExceptionSorter() throws Throwable
+ {
+ /*
+ * Embedded
+ */
+ EmbeddedJCA embedded = null;
+
+ try
+ {
+ // Create and set an embedded JCA instance
+ embedded = new EmbeddedJCA();
+
+ // Startup
+ embedded.startup();
+
+ // Deploy jdbc-local.rar
+ embedded.deploy(getURL("jdbc-local.rar"));
+
+ // Deploy H2 datasource
+ URL url = getURL("test/h2-exception-sorter-ds.xml");
+
+ embedded.deploy(url);
+
+ Context context = null;
+
+ try
+ {
+ context = new InitialContext();
+
+ DataSource ds = (DataSource) context.lookup("java:/H2DS");
+ assertNotNull(ds);
+
+ Connection c = ds.getConnection();
+ assertNotNull(c);
+
+ Statement st = c.createStatement();
+ st.execute("dssd");
+
+ }
+ catch (SQLException e)
+ {
+ // nothing we need an exception ;)
+ }
+
+ finally
+ {
+ assertThat(TestExceptionSorter.isConstructorInvoked(), is(true));
+
+ assertThat(TestExceptionSorter.isMethodInvoked(), is(true));
+
+ assertThat(TestExceptionSorter.getStringInjected(), hasItems("MyTest", "MyTest2"));
+
+ if (context != null)
+ {
+ try
+ {
+ context.close();
+ }
+ catch (NamingException ne)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ }
+ finally
+ {
+ if (embedded != null)
+ {
+ // Undeploy H2 datasource
+ embedded.undeploy(getURL("test/h2-exception-sorter-ds.xml"));
+
+ // Undeploy jdbc-local.rar
+ embedded.undeploy(getURL("jdbc-local.rar"));
+
+ // Shutdown embedded
+ embedded.shutdown();
+
+ // Set embedded to null
+ embedded = null;
+ }
+ }
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Get the URL for a test archive
+ * @param archive The name of the test archive
+ * @return The URL to the archive
+ * @throws Throwable throwable exception
+ */
+ private static URL getURL(String archive) throws Throwable
+ {
+ File f = new File(System.getProperty("archives.dir") + File.separator + archive);
+ return f.toURI().toURL();
+ }
+
+}
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionCheckerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionCheckerTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/StaleConnectionCheckerTestCase.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -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.adapters.jdbc.spi;
+
+import org.jboss.jca.adapters.jdbc.spi.testimpl.TestStaleConnectionChecker;
+import org.jboss.jca.embedded.EmbeddedJCA;
+
+import java.io.File;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ *
+ * A StaleConectionCheckerTestCase.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class StaleConnectionCheckerTestCase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * shouldInjectCorrectStaleConnectionChecker
+ * @throws Throwable in case of error
+ */
+ @Test
+ public void shouldInjectCorrectStaleConnectionChecker() throws Throwable
+ {
+ /*
+ * Embedded
+ */
+ EmbeddedJCA embedded = null;
+
+ try
+ {
+ // Create and set an embedded JCA instance
+ embedded = new EmbeddedJCA();
+
+ // Startup
+ embedded.startup();
+
+ // Deploy jdbc-local.rar
+ embedded.deploy(getURL("jdbc-local.rar"));
+
+ // Deploy H2 datasource
+ URL url = getURL("test/h2-stale-connection-checker-ds.xml");
+
+ embedded.deploy(url);
+
+ Context context = null;
+
+ try
+ {
+ context = new InitialContext();
+
+ DataSource ds = (DataSource) context.lookup("java:/H2DS");
+ assertNotNull(ds);
+
+ Connection c = ds.getConnection();
+ assertNotNull(c);
+
+ Statement st = c.createStatement();
+ st.execute("dssd");
+
+ }
+ catch (SQLException e)
+ {
+ // nothing we need an exception ;)
+ }
+
+ finally
+ {
+ assertThat(TestStaleConnectionChecker.isConstructorInvoked(), is(true));
+
+ assertThat(TestStaleConnectionChecker.isMethodInvoked(), is(true));
+
+ assertThat(TestStaleConnectionChecker.getInjectedInteger(), is(100));
+
+ if (context != null)
+ {
+ try
+ {
+ context.close();
+ }
+ catch (NamingException ne)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ }
+ finally
+ {
+ if (embedded != null)
+ {
+ // Undeploy H2 datasource
+ embedded.undeploy(getURL("test/h2-stale-connection-checker-ds.xml"));
+
+ // Undeploy jdbc-local.rar
+ embedded.undeploy(getURL("jdbc-local.rar"));
+
+ // Shutdown embedded
+ embedded.shutdown();
+
+ // Set embedded to null
+ embedded = null;
+ }
+ }
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Get the URL for a test archive
+ * @param archive The name of the test archive
+ * @return The URL to the archive
+ * @throws Throwable throwable exception
+ */
+ private static URL getURL(String archive) throws Throwable
+ {
+ File f = new File(System.getProperty("archives.dir") + File.separator + archive);
+ return f.toURI().toURL();
+ }
+
+}
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Test cases for adapters spi using IronJacamar Embedded
+</body>
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestExceptionSorter.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestExceptionSorter.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestExceptionSorter.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,151 @@
+/*
+ * 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.adapters.jdbc.spi.testimpl;
+
+import org.jboss.jca.adapters.jdbc.spi.ExceptionSorter;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * A TestExceptionSorter.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class TestExceptionSorter implements ExceptionSorter
+{
+
+ /** constructorInvoked **/
+ private static boolean constructorInvoked = false;
+
+ /** methodInvoked **/
+ private static boolean methodInvoked = false;
+
+ private static List<String> stringInjected = new ArrayList<String>(2);
+
+ private String testString;
+
+ private String testString2;
+
+ /**
+ * Get the constructorInvoked.
+ *
+ * @return the constructorInvoked.
+ */
+ public static final boolean isConstructorInvoked()
+ {
+ return constructorInvoked;
+ }
+
+ /**
+ * Get the methodInvoked.
+ *
+ * @return the methodInvoked.
+ */
+ public static final boolean isMethodInvoked()
+ {
+ return methodInvoked;
+ }
+
+ /**
+ *
+ * Create a new TestExceptionSorter.
+ *
+ */
+ public TestExceptionSorter()
+ {
+ TestExceptionSorter.constructorInvoked = true;
+ }
+
+ @Override
+ public boolean isExceptionFatal(SQLException e)
+ {
+ TestExceptionSorter.methodInvoked = true;
+ return false;
+ }
+
+ /**
+ * Get the testString.
+ *
+ * @return the testString.
+ */
+ public final String getTestString()
+ {
+ return testString;
+ }
+
+ /**
+ * Set the testString.
+ *
+ * @param testString The testString to set.
+ */
+ public final void setTestString(String testString)
+ {
+ this.testString = testString;
+ TestExceptionSorter.appendStringInjected(testString);
+ }
+
+ /**
+ * Get the stringInjected.
+ *
+ * @return the stringInjected.
+ */
+ public static final List<String> getStringInjected()
+ {
+ return stringInjected;
+ }
+
+ /**
+ * Set the stringInjected.
+ *
+ * @param stringInjected The stringInjected to set.
+ */
+ public static final void appendStringInjected(String stringInjected)
+ {
+ TestExceptionSorter.stringInjected.add(stringInjected);
+ }
+
+ /**
+ * Get the testString2.
+ *
+ * @return the testString2.
+ */
+ public final String getTestString2()
+ {
+ return testString2;
+ }
+
+ /**
+ * Set the testString2.
+ *
+ * @param testString2 The testString2 to set.
+ */
+ public final void setTestString2(String testString2)
+ {
+ this.testString2 = testString2;
+ TestExceptionSorter.appendStringInjected(testString2);
+ }
+
+}
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestStaleConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestStaleConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestStaleConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,126 @@
+/*
+ * 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.adapters.jdbc.spi.testimpl;
+
+import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
+
+import java.sql.SQLException;
+
+/**
+ *
+ * A TestStaleConnectionChecker.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class TestStaleConnectionChecker implements StaleConnectionChecker
+{
+
+ /** constructorInvoked **/
+ private static boolean constructorInvoked = false;
+
+ /** methodInvoked **/
+ private static boolean methodInvoked = false;
+
+ private static Integer injectedInteger = null;
+
+ private Integer integerTest;
+
+ /**
+ * Get the constructorInvoked.
+ *
+ * @return the constructorInvoked.
+ */
+ public static final boolean isConstructorInvoked()
+ {
+ return constructorInvoked;
+ }
+
+ /**
+ * Get the methodInvoked.
+ *
+ * @return the methodInvoked.
+ */
+ public static final boolean isMethodInvoked()
+ {
+ return methodInvoked;
+ }
+
+ /**
+ *
+ * Create a new TestStaleConnectionChecker.
+ *
+ */
+ public TestStaleConnectionChecker()
+ {
+ TestStaleConnectionChecker.constructorInvoked = true;
+ }
+
+ @Override
+ public boolean isStaleConnection(SQLException e)
+ {
+ TestStaleConnectionChecker.methodInvoked = true;
+ return false;
+ }
+
+ /**
+ * Get the integerTest.
+ *
+ * @return the integerTest.
+ */
+ public final Integer getIntegerTest()
+ {
+ return integerTest;
+ }
+
+ /**
+ * Get the injectedInteger.
+ *
+ * @return the injectedInteger.
+ */
+ public static final Integer getInjectedInteger()
+ {
+ return injectedInteger;
+ }
+
+ /**
+ * Set the injectedInteger.
+ *
+ * @param injectedInteger The injectedInteger to set.
+ */
+ public static final void setInjectedInteger(Integer injectedInteger)
+ {
+ TestStaleConnectionChecker.injectedInteger = injectedInteger;
+ }
+
+ /**
+ * Set the integerTest.
+ *
+ * @param integerTest The integerTest to set.
+ */
+ public final void setIntegerTest(Integer integerTest)
+ {
+ this.integerTest = integerTest;
+ TestStaleConnectionChecker.setInjectedInteger(integerTest);
+ }
+
+}
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestValidConnectionChecker.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestValidConnectionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/TestValidConnectionChecker.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,95 @@
+/*
+ * 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.adapters.jdbc.spi.testimpl;
+
+import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ *
+ * A TestValidConnectionChecker.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class TestValidConnectionChecker implements ValidConnectionChecker
+{
+ /** constructorInvoked **/
+ private static boolean constructorInvoked = false;
+
+ /** methodInvoked **/
+ private static boolean methodInvoked = false;
+
+ /** pingTimeOut **/
+ private final Integer pingTimeOut = null;
+
+ /**
+ * Get the constructorInvoked.
+ *
+ * @return the constructorInvoked.
+ */
+ public static final boolean isConstructorInvoked()
+ {
+ return constructorInvoked;
+ }
+
+ /**
+ * Get the methodInvoked.
+ *
+ * @return the methodInvoked.
+ */
+ public static final boolean isMethodInvoked()
+ {
+ return methodInvoked;
+ }
+
+ /**
+ * Get the pingTimeOut.
+ *
+ * @return the pingTimeOut.
+ */
+ public final Integer getPingTimeOut()
+ {
+ return pingTimeOut;
+ }
+
+ /**
+ *
+ * Create a new TestValidConnectionChecker.
+ *
+ */
+ public TestValidConnectionChecker()
+ {
+ TestValidConnectionChecker.constructorInvoked = true;
+ }
+
+ @Override
+ public SQLException isValidConnection(Connection c)
+ {
+ TestValidConnectionChecker.methodInvoked = true;
+
+ return null;
+ }
+
+}
Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/package.html
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/package.html (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/testimpl/package.html 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,3 @@
+<body>
+Mock Object for spi test cases
+</body>
Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-exception-sorter-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-exception-sorter-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-exception-sorter-ds.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
+ <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver-class>org.h2.Driver</driver-class>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ <validation>
+ <exception-sorter class-name="org.jboss.jca.adapters.jdbc.spi.testimpl.TestExceptionSorter">
+ <config-property name="testString">MyTest</config-property>
+ <config-property name="testString2">MyTest2</config-property>
+ </exception-sorter>
+ </validation>
+ </datasource>
+
+</datasources>
Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-stale-connection-checker-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-stale-connection-checker-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-stale-connection-checker-ds.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
+ <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver-class>org.h2.Driver</driver-class>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ <validation>
+ <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.spi.testimpl.TestStaleConnectionChecker">
+ <config-property name="integerTest">100</config-property>
+ </stale-connection-checker>
+ </validation>
+ </datasource>
+
+</datasources>
\ No newline at end of file
Added: projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.jboss.org/jee/schema/ironjacamar/datasources_1_0.xsd">
+ <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver-class>org.h2.Driver</driver-class>
+ <pool>
+ <min-pool-size>1</min-pool-size>
+ <max-pool-size>2</max-pool-size>
+ </pool>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ <validation>
+ <valid-connection-checker-class-name>org.jboss.jca.adapters.jdbc.spi.testimpl.TestValidConnectionChecker
+ </valid-connection-checker-class-name>
+ <validate-on-match>true</validate-on-match>
+ <background-validation>true</background-validation>
+ <background-validation-minutes>1</background-validation-minutes>
+ <ping-time-out>5</ping-time-out>
+ </validation>
+ </datasource>
+</datasources>
\ No newline at end of file
Modified: projects/jboss-jca/trunk/adapters/src/test/resources/logging.properties
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/logging.properties 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/logging.properties 2010-11-11 08:24:37 UTC (rev 109269)
@@ -26,7 +26,7 @@
loggers=org.jboss.jca,org.jboss,org.jnp,com.arjuna
# Root logger level
-logger.level=${iron.jacamar.log.level:INFO}
+logger.level=${iron.jacamar.log.level:DEBUG}
logger.handlers=CONSOLE, FILE
# org.jboss.jca
@@ -44,7 +44,7 @@
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
-handler.CONSOLE.level=${iron.jacamar.log.console.level:INFO}
+handler.CONSOLE.level=${iron.jacamar.log.console.level:DEBUG}
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN
Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/JdbcAdapterExtension.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/JdbcAdapterExtension.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/JdbcAdapterExtension.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -0,0 +1,246 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.api.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.JCAMetadata;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * A JdbcAdapterExtension.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public final class JdbcAdapterExtension implements JCAMetadata
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -6275984008991105644L;
+
+ private final String className;
+
+ private final Map<String, String> configPropertiesMap;
+
+ /**
+ * Create a new JdbcAdapterExtension.
+ *
+ * @param className the className
+ * @param configPropertiesMap configPropertiesMap
+ */
+ public JdbcAdapterExtension(String className, Map<String, String> configPropertiesMap)
+ {
+ super();
+ this.className = className;
+ if (configPropertiesMap != null)
+ {
+ this.configPropertiesMap = new HashMap<String, String>(configPropertiesMap.size());
+ this.configPropertiesMap.putAll(configPropertiesMap);
+ }
+ else
+ {
+ this.configPropertiesMap = Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Get the className.
+ *
+ * @return the className.
+ */
+ public final String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * Get the configPropertiesMap.
+ *
+ * @return the configPropertiesMap.
+ */
+ public final Map<String, String> getConfigPropertiesMap()
+ {
+ return Collections.unmodifiableMap(configPropertiesMap);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "JdbcAdapterExtension [className=" + className + ", configPropertiesMap=" + configPropertiesMap + "]";
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((className == null) ? 0 : className.hashCode());
+ result = prime * result + ((configPropertiesMap == null) ? 0 : configPropertiesMap.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof JdbcAdapterExtension))
+ return false;
+ JdbcAdapterExtension other = (JdbcAdapterExtension) obj;
+ if (className == null)
+ {
+ if (other.className != null)
+ return false;
+ }
+ else if (!className.equals(other.className))
+ return false;
+ if (configPropertiesMap == null)
+ {
+ if (other.configPropertiesMap != null)
+ return false;
+ }
+ else if (!configPropertiesMap.equals(other.configPropertiesMap))
+ return false;
+ return true;
+ }
+
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /**
+ * pool tag
+
+ /**
+ * config-property tag
+ */
+ CONFIG_PROPERTY("config-property");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName XsdString
+ *
+ * @param localName a XsdString used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
+ /**
+ *
+ * A Attribute.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Attribute
+ {
+
+ /** class-name attribute
+ *
+ */
+ CLASS_NAME("class-name");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Attribute(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ }
+
+}
+
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Validation.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Validation.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/Validation.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -36,11 +36,11 @@
{
/**
- * Get the validConnectionCheckerClassName.
+ * Get the validConnectionChecker
*
- * @return the validConnectionCheckerClassName.
+ * @return the validConnectionChecker
*/
- public String getValidConnectionCheckerClassName();
+ public JdbcAdapterExtension getValidConnectionChecker();
/**
* Get the checkValidConnectionSql.
@@ -57,19 +57,20 @@
public Boolean isValidateOnMatch();
/**
- * Get the staleConnectionCheckerClassName.
+ * Get the staleConnectionChecker
*
- * @return the staleConnectionCheckerClassName.
+ * @return the staleConnectionChecker
*/
- public String getStaleConnectionCheckerClassName();
+ public JdbcAdapterExtension getStaleConnectionChecker();
/**
- * Get the exceptionSorterClassName.
+ * Get the exceptionSorter
*
- * @return the exceptionSorterClassName.
+ * @return the exceptionSorter
*/
- public String getExceptionSorterClassName();
+ public JdbcAdapterExtension getExceptionSorter();
+
/**
*
* A Tag.
@@ -87,7 +88,8 @@
/**
* validConnectionCheckerClassName tag
*/
- VALIDCONNECTIONCHECKERCLASSNAME("valid-connection-checker-class-name"),
+ VALIDCONNECTIONCHECKER("valid-connection-checker"),
+
/**
* checkValidConnectionSql tag
*/
@@ -111,11 +113,11 @@
/**
* staleConnectionCheckerClassName tag
*/
- STALECONNECTIONCHECKERCLASSNAME("stale-connection-checker-class-name"),
+ STALECONNECTIONCHECKER("stale-connection-checker"),
/**
* exceptionSorterClassName tag
*/
- EXCEPTIONSORTERCLASSNAME("exception-sorter-class-name");
+ EXCEPTIONSORTER("exception-sorter");
private final String name;
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -26,6 +26,7 @@
import org.jboss.jca.common.api.metadata.common.CommonXaPool;
import org.jboss.jca.common.api.metadata.ds.DataSource;
import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ds.JdbcAdapterExtension;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.Statement.TrackStatementsEnum;
import org.jboss.jca.common.api.metadata.ds.TimeOut;
@@ -445,11 +446,11 @@
boolean validateOnMatch = false;
boolean useFastFail = false;
Long backgroundValidationMinutes = null;
- String staleConnectionCheckerClassName = null;
+ JdbcAdapterExtension staleConnectionChecker = null;
boolean backgroundValidation = false;
String checkValidConnectionSql = null;
- String validConnectionCheckerClassName = null;
- String exceptionSorterClassName = null;
+ JdbcAdapterExtension validConnectionChecker = null;
+ JdbcAdapterExtension exceptionSorter = null;
while (reader.hasNext())
{
@@ -460,9 +461,8 @@
{
return new ValidationImpl(backgroundValidation, backgroundValidationMinutes, useFastFail,
- validConnectionCheckerClassName, checkValidConnectionSql,
- validateOnMatch, staleConnectionCheckerClassName,
- exceptionSorterClassName);
+ validConnectionChecker, checkValidConnectionSql, validateOnMatch,
+ staleConnectionChecker, exceptionSorter);
}
else
@@ -475,7 +475,8 @@
break;
}
case START_ELEMENT : {
- switch (Validation.Tag.forName(reader.getLocalName()))
+ Validation.Tag currTag = Validation.Tag.forName(reader.getLocalName());
+ switch (currTag)
{
case BACKGROUNDVALIDATION : {
backgroundValidation = elementAsBoolean(reader);
@@ -489,12 +490,12 @@
checkValidConnectionSql = elementAsString(reader);
break;
}
- case EXCEPTIONSORTERCLASSNAME : {
- exceptionSorterClassName = elementAsString(reader);
+ case EXCEPTIONSORTER : {
+ exceptionSorter = parseJdbcAdapterExtension(reader, currTag);
break;
}
- case STALECONNECTIONCHECKERCLASSNAME : {
- staleConnectionCheckerClassName = elementAsString(reader);
+ case STALECONNECTIONCHECKER : {
+ staleConnectionChecker = parseJdbcAdapterExtension(reader, currTag);
break;
}
case USEFASTFAIL : {
@@ -505,8 +506,8 @@
validateOnMatch = elementAsBoolean(reader);
break;
}
- case VALIDCONNECTIONCHECKERCLASSNAME : {
- validConnectionCheckerClassName = elementAsString(reader);
+ case VALIDCONNECTIONCHECKER : {
+ validConnectionChecker = parseJdbcAdapterExtension(reader, currTag);
break;
}
default :
@@ -519,6 +520,68 @@
throw new ParserException("Reached end of xml document unexpectedly");
}
+ private JdbcAdapterExtension parseJdbcAdapterExtension(XMLStreamReader reader, Validation.Tag enclosingTag)
+ throws XMLStreamException, ParserException
+ {
+
+ String className = null;
+ Map<String, String> properties = null;
+
+ for (JdbcAdapterExtension.Attribute attribute : JdbcAdapterExtension.Attribute.values())
+ {
+ switch (attribute)
+ {
+ case CLASS_NAME : {
+ className = attributeAsString(reader, attribute.getLocalName());
+ break;
+ }
+ default :
+ break;
+ }
+ }
+
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ if (Validation.Tag.forName(reader.getLocalName()) == enclosingTag)
+ {
+ if (className == null)
+ {
+ throw new ParserException("mandatory class-name attribute missing in " +
+ enclosingTag.getLocalName());
+ }
+
+ return new JdbcAdapterExtension(className, properties);
+ }
+ else
+ {
+ if (JdbcAdapterExtension.Tag.forName(reader.getLocalName()) == JdbcAdapterExtension.Tag.UNKNOWN)
+ {
+ throw new ParserException("unexpected end tag" + reader.getLocalName());
+ }
+ }
+ break;
+ }
+ case START_ELEMENT : {
+ switch (JdbcAdapterExtension.Tag.forName(reader.getLocalName()))
+ {
+ case CONFIG_PROPERTY : {
+ if (properties == null) properties = new HashMap<String, String>();
+ properties.put(attributeAsString(reader, "name"), elementAsString(reader));
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ throw new ParserException("Reached end of xml document unexpectedly");
+ }
+
+
+
private TimeOut parseTimeOutSettings(XMLStreamReader reader) throws XMLStreamException, ParserException
{
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/ValidationImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/ValidationImpl.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/ValidationImpl.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -21,6 +21,7 @@
*/
package org.jboss.jca.common.metadata.ds;
+import org.jboss.jca.common.api.metadata.ds.JdbcAdapterExtension;
import org.jboss.jca.common.api.metadata.ds.Validation;
@@ -33,18 +34,87 @@
*/
public class ValidationImpl extends org.jboss.jca.common.metadata.common.CommonValidationImpl implements Validation
{
+ @Override
+ public String toString()
+ {
+ return "ValidationImpl [validConnectionChecker=" + validConnectionChecker + ", checkValidConnectionSql=" +
+ checkValidConnectionSql + ", validateOnMatch=" + validateOnMatch + ", staleConnectionChecker=" +
+ staleConnectionChecker + ", exceptionSorter=" + exceptionSorter + "]";
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((checkValidConnectionSql == null) ? 0 : checkValidConnectionSql.hashCode());
+ result = prime * result + ((exceptionSorter == null) ? 0 : exceptionSorter.hashCode());
+ result = prime * result + ((staleConnectionChecker == null) ? 0 : staleConnectionChecker.hashCode());
+ result = prime * result + ((validConnectionChecker == null) ? 0 : validConnectionChecker.hashCode());
+ result = prime * result + ((validateOnMatch == null) ? 0 : validateOnMatch.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (!(obj instanceof ValidationImpl))
+ return false;
+ ValidationImpl other = (ValidationImpl) obj;
+ if (checkValidConnectionSql == null)
+ {
+ if (other.checkValidConnectionSql != null)
+ return false;
+ }
+ else if (!checkValidConnectionSql.equals(other.checkValidConnectionSql))
+ return false;
+ if (exceptionSorter == null)
+ {
+ if (other.exceptionSorter != null)
+ return false;
+ }
+ else if (!exceptionSorter.equals(other.exceptionSorter))
+ return false;
+ if (staleConnectionChecker == null)
+ {
+ if (other.staleConnectionChecker != null)
+ return false;
+ }
+ else if (!staleConnectionChecker.equals(other.staleConnectionChecker))
+ return false;
+ if (validConnectionChecker == null)
+ {
+ if (other.validConnectionChecker != null)
+ return false;
+ }
+ else if (!validConnectionChecker.equals(other.validConnectionChecker))
+ return false;
+ if (validateOnMatch == null)
+ {
+ if (other.validateOnMatch != null)
+ return false;
+ }
+ else if (!validateOnMatch.equals(other.validateOnMatch))
+ return false;
+ return true;
+ }
+
/** The serialVersionUID */
private static final long serialVersionUID = 7816717816552118419L;
- private final String validConnectionCheckerClassName;
+ private final JdbcAdapterExtension validConnectionChecker;
private final String checkValidConnectionSql;
private final Boolean validateOnMatch;
- private final String staleConnectionCheckerClassName;
+ private final JdbcAdapterExtension staleConnectionChecker;
- private final String exceptionSorterClassName;
+ private final JdbcAdapterExtension exceptionSorter;
/**
* Create a new ValidationImpl.
@@ -52,35 +122,26 @@
* @param backgroundValidation backgroundValidation
* @param backgroundValidationMinutes backgroundValidationMinutes
* @param useFastFail useFastFail
- * @param validConnectionCheckerClassName validConnectionCheckerClassName
+ * @param validConnectionChecker validConnectionChecker
* @param checkValidConnectionSql checkValidConnectionSql
* @param validateOnMatch validateOnMatch
- * @param staleConnectionCheckerClassName staleConnectionCheckerClassName
- * @param exceptionSorterClassName exceptionSorterClassName
+ * @param staleConnectionChecker staleConnectionChecker
+ * @param exceptionSorter exceptionSorter
*/
public ValidationImpl(Boolean backgroundValidation, Long backgroundValidationMinutes, Boolean useFastFail,
- String validConnectionCheckerClassName, String checkValidConnectionSql, Boolean validateOnMatch,
- String staleConnectionCheckerClassName, String exceptionSorterClassName)
+ JdbcAdapterExtension validConnectionChecker, String checkValidConnectionSql, Boolean validateOnMatch,
+ JdbcAdapterExtension staleConnectionChecker, JdbcAdapterExtension exceptionSorter)
{
super(backgroundValidation, backgroundValidationMinutes, useFastFail);
- this.validConnectionCheckerClassName = validConnectionCheckerClassName;
+ this.validConnectionChecker = validConnectionChecker;
this.checkValidConnectionSql = checkValidConnectionSql;
this.validateOnMatch = validateOnMatch;
- this.staleConnectionCheckerClassName = staleConnectionCheckerClassName;
- this.exceptionSorterClassName = exceptionSorterClassName;
+ this.staleConnectionChecker = staleConnectionChecker;
+ this.exceptionSorter = exceptionSorter;
}
- /**
- * Get the validConnectionCheckerClassName.
- *
- * @return the validConnectionCheckerClassName.
- */
- @Override
- public final String getValidConnectionCheckerClassName()
- {
- return validConnectionCheckerClassName;
- }
+
/**
* Get the checkValidConnectionSql.
*
@@ -103,100 +164,47 @@
return validateOnMatch;
}
+
+
/**
- * Get the staleConnectionCheckerClassName.
+ * Get the validConnectionChecker.
*
- * @return the staleConnectionCheckerClassName.
+ * @return the validConnectionChecker.
*/
- @Override
- public final String getStaleConnectionCheckerClassName()
+ public final JdbcAdapterExtension getValidConnectionChecker()
{
- return staleConnectionCheckerClassName;
+ return validConnectionChecker;
}
/**
- * Get the exceptionSorterClassName.
+ * Get the validateOnMatch.
*
- * @return the exceptionSorterClassName.
+ * @return the validateOnMatch.
*/
- @Override
- public final String getExceptionSorterClassName()
+ public final Boolean getValidateOnMatch()
{
- return exceptionSorterClassName;
+ return validateOnMatch;
}
- @Override
- public int hashCode()
+ /**
+ * Get the staleConnectionChecker.
+ *
+ * @return the staleConnectionChecker.
+ */
+ public final JdbcAdapterExtension getStaleConnectionChecker()
{
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((checkValidConnectionSql == null) ? 0 : checkValidConnectionSql.hashCode());
- result = prime * result + ((exceptionSorterClassName == null) ? 0 : exceptionSorterClassName.hashCode());
- result = prime * result +
- ((staleConnectionCheckerClassName == null) ? 0 : staleConnectionCheckerClassName.hashCode());
- result = prime * result +
- ((validConnectionCheckerClassName == null) ? 0 : validConnectionCheckerClassName.hashCode());
- result = prime * result + ((validateOnMatch == null) ? 0 : validateOnMatch.hashCode());
- return result;
+ return staleConnectionChecker;
}
- @Override
- public boolean equals(Object obj)
+ /**
+ * Get the exceptionSorter.
+ *
+ * @return the exceptionSorter.
+ */
+ public final JdbcAdapterExtension getExceptionSorter()
{
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof ValidationImpl))
- return false;
- ValidationImpl other = (ValidationImpl) obj;
- if (checkValidConnectionSql == null)
- {
- if (other.checkValidConnectionSql != null)
- return false;
- }
- else if (!checkValidConnectionSql.equals(other.checkValidConnectionSql))
- return false;
- if (exceptionSorterClassName == null)
- {
- if (other.exceptionSorterClassName != null)
- return false;
- }
- else if (!exceptionSorterClassName.equals(other.exceptionSorterClassName))
- return false;
- if (staleConnectionCheckerClassName == null)
- {
- if (other.staleConnectionCheckerClassName != null)
- return false;
- }
- else if (!staleConnectionCheckerClassName.equals(other.staleConnectionCheckerClassName))
- return false;
- if (validConnectionCheckerClassName == null)
- {
- if (other.validConnectionCheckerClassName != null)
- return false;
- }
- else if (!validConnectionCheckerClassName.equals(other.validConnectionCheckerClassName))
- return false;
- if (validateOnMatch == null)
- {
- if (other.validateOnMatch != null)
- return false;
- }
- else if (!validateOnMatch.equals(other.validateOnMatch))
- return false;
- return true;
+ return exceptionSorter;
}
- @Override
- public String toString()
- {
- return "ValidationImpl [validConnectionCheckerClassName=" + validConnectionCheckerClassName +
- ", checkValidConnectionSql=" + checkValidConnectionSql + ", validateOnMatch=" + validateOnMatch +
- ", staleConnectionCheckerClassName=" + staleConnectionCheckerClassName +
- ", exceptionSorterClassName=" + exceptionSorterClassName + ", backgroundValidation=" +
- backgroundValidation + ", backgroundValidationMinutes=" + backgroundValidationMinutes +
- ", useFastFail=" + useFastFail + "]";
- }
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/merge/Merger.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -165,8 +165,7 @@
// merge RA onfigProperties;
List<? extends ConfigProperty> original = conn.getResourceadapter().getConfigProperties();
- List<? extends ConfigProperty> newProperties = this
- .mergeConfigProperties(ij.getConfigProperties(), original);
+ List<? extends ConfigProperty> newProperties = this.mergeConfigProperties(ij.getConfigProperties(), original);
((AbstractResourceAdapetrImpl) conn.getResourceadapter()).forceNewConfigPropertiesContent(newProperties);
@@ -233,8 +232,7 @@
{
// merge ConnectionDefinition onfigProperties;
List<? extends ConfigProperty> original = conDef.getConfigProperties();
- List<ConfigProperty> newProperties = this
- .mergeConfigProperties(commonConDef.getConfigProperties(), original);
+ List<ConfigProperty> newProperties = this.mergeConfigProperties(commonConDef.getConfigProperties(), original);
CommonSecurity security = commonConDef.getSecurity();
if (security != null && security.getUserName() != null && !security.getUserName().trim().equals(""))
@@ -256,8 +254,8 @@
{
// merge AdminObject onfigProperties;
List<? extends ConfigProperty> original = adminObj.getConfigProperties();
- List<? extends ConfigProperty> newProperties = this.mergeConfigProperties(
- commonAdminObj.getConfigProperties(), original);
+ List<? extends ConfigProperty> newProperties = this.mergeConfigProperties(commonAdminObj.getConfigProperties(),
+ original);
((AdminObjectImpl) adminObj).forceNewConfigPropertiesContent(newProperties);
return adminObj;
@@ -270,8 +268,7 @@
{
if (conn.getVersion() == Version.V_10 && conn.getResourceadapter() != null)
{
- ((ResourceAdapter10Impl) conn.getResourceadapter()).forceNewTrasactionSupport(ij
- .getTransactionSupport());
+ ((ResourceAdapter10Impl) conn.getResourceadapter()).forceNewTrasactionSupport(ij.getTransactionSupport());
}
else
{
@@ -300,8 +297,8 @@
* @throws IllegalArgumentException if version is't 1.0, 1.5 or 1.6
* @throws Exception in case of error
*/
- public Connector mergeConnectorAndDs(CommonDataSource cds, Connector connector)
- throws IllegalArgumentException, Exception
+ public Connector mergeConnectorAndDs(CommonDataSource cds, Connector connector) throws IllegalArgumentException,
+ Exception
{
if (cds == null)
{
@@ -314,9 +311,8 @@
}
}
- private Connector mergeConnectorWithProperties(Connector connector,
- List<ConfigProperty> connectioDefProperties, List<ConfigProperty> raConfigProperties)
- throws IllegalArgumentException, Exception
+ private Connector mergeConnectorWithProperties(Connector connector, List<ConfigProperty> connectioDefProperties,
+ List<ConfigProperty> raConfigProperties) throws IllegalArgumentException, Exception
{
XsdString managedconnectionfactoryClass = null;
@@ -357,16 +353,13 @@
}
ResourceAdapter resourceadapter = new ResourceAdapter10Impl(managedconnectionfactoryClass,
connectionfactoryInterface,
- connectionfactoryImplClass,
- connectionInterface, connectionImplClass,
- transactionSupport, authenticationMechanism,
- connectioDefProperties,
- reauthenticationSupport, securityPermissions,
- id);
+ connectionfactoryImplClass, connectionInterface,
+ connectionImplClass, transactionSupport,
+ authenticationMechanism, connectioDefProperties,
+ reauthenticationSupport, securityPermissions, id);
Connector newConnector = new Connector10Impl(moduleName, vendorName, eisType, resourceadapterVersion,
- license, resourceadapter, description, displayNames, icons,
- id);
+ license, resourceadapter, description, displayNames, icons, id);
return newConnector.merge(connector);
}
@@ -380,16 +373,14 @@
connectionInterface,
connectionImplClass, id);
connectionDefinitions.add(connectionDefinition);
- OutboundResourceAdapter outboundResourceadapter = new OutboundResourceAdapterImpl(
- connectionDefinitions,
+ OutboundResourceAdapter outboundResourceadapter = new OutboundResourceAdapterImpl(connectionDefinitions,
transactionSupport,
authenticationMechanism,
reauthenticationSupport,
id);
String resourceadapterClass = null;
InboundResourceAdapter inboundResourceadapter = null;
- ResourceAdapter1516 resourceadapter = new ResourceAdapter1516Impl(resourceadapterClass,
- raConfigProperties,
+ ResourceAdapter1516 resourceadapter = new ResourceAdapter1516Impl(resourceadapterClass, raConfigProperties,
outboundResourceadapter,
inboundResourceadapter, adminobjects,
securityPermissions, id);
@@ -428,8 +419,7 @@
else
{
- if (connector.getResourceadapter() != null &&
- connector.getResourceadapter() instanceof ResourceAdapter1516)
+ if (connector.getResourceadapter() != null && connector.getResourceadapter() instanceof ResourceAdapter1516)
{
ResourceAdapter1516 ra1516 = ((ResourceAdapter1516) connector.getResourceadapter());
if (ra1516.getOutboundResourceadapter() != null &&
@@ -506,8 +496,7 @@
valueBuf.append(xaConfigProperty.getValue());
valueBuf.append(";");
}
- configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
- valueBuf.toString()));
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
}
@@ -517,8 +506,8 @@
case URLDELIMITER : {
if (ds != null && ds.getUrlDelimiter() != null && !ds.getUrlDelimiter().trim().equals(""))
{
- configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
- ds.getUrlDelimiter()));
+ configProperties
+ .add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getUrlDelimiter()));
}
break;
@@ -600,37 +589,95 @@
case VALIDCONNECTIONCHECKERCLASSNAME : {
if (ds != null && ds.getValidation() != null &&
- ds.getValidation().getCheckValidConnectionSql() != null)
+ ds.getValidation().getValidConnectionChecker() != null &&
+ ds.getValidation().getValidConnectionChecker().getClassName() != null)
{
configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
- .getCheckValidConnectionSql()));
+ .getValidConnectionChecker().getClassName()));
}
break;
}
+ case VALIDCONNECTIONCHECKERPROPERTIES : {
+ if (ds != null && ds.getValidation() != null &&
+ ds.getValidation().getValidConnectionChecker() != null &&
+ ds.getValidation().getValidConnectionChecker().getClassName() != null)
+ {
+ StringBuffer valueBuf = new StringBuffer();
+ for (Entry<String, String> connProperty : ds.getValidation().getValidConnectionChecker()
+ .getConfigPropertiesMap().entrySet())
+ {
+ valueBuf.append(connProperty.getKey());
+ valueBuf.append("=");
+ valueBuf.append(connProperty.getValue());
+ valueBuf.append(";");
+ }
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
+ }
+ break;
+ }
+
case EXCEPTIONSORTERCLASSNAME : {
- if (ds != null && ds.getValidation() != null &&
- ds.getValidation().getExceptionSorterClassName() != null)
+ if (ds != null && ds.getValidation() != null && ds.getValidation().getExceptionSorter() != null &&
+ ds.getValidation().getExceptionSorter().getClassName() != null)
{
configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
- .getExceptionSorterClassName()));
+ .getExceptionSorter().getClassName()));
}
break;
}
+ case EXCEPTIONSORTERPROPERTIES : {
+ if (ds != null && ds.getValidation() != null && ds.getValidation().getExceptionSorter() != null &&
+ ds.getValidation().getExceptionSorter().getConfigPropertiesMap() != null)
+ {
+ StringBuffer valueBuf = new StringBuffer();
+ for (Entry<String, String> connProperty : ds.getValidation().getExceptionSorter()
+ .getConfigPropertiesMap().entrySet())
+ {
+ valueBuf.append(connProperty.getKey());
+ valueBuf.append("=");
+ valueBuf.append(connProperty.getValue());
+ valueBuf.append(";");
+ }
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
+ }
+ break;
+ }
+
case STALECONNECTIONCHECKERCLASSNAME : {
if (ds != null && ds.getValidation() != null &&
- ds.getValidation().getStaleConnectionCheckerClassName() != null)
+ ds.getValidation().getStaleConnectionChecker() != null &&
+ ds.getValidation().getStaleConnectionChecker().getClassName() != null)
{
configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getValidation()
- .getStaleConnectionCheckerClassName()));
+ .getStaleConnectionChecker().getClassName()));
}
break;
}
+ case STALECONNECTIONCHECKERPROPERTIES : {
+ if (ds != null && ds.getValidation() != null &&
+ ds.getValidation().getStaleConnectionChecker() != null &&
+ ds.getValidation().getStaleConnectionChecker().getConfigPropertiesMap() != null)
+ {
+ StringBuffer valueBuf = new StringBuffer();
+ for (Entry<String, String> connProperty : ds.getValidation().getStaleConnectionChecker()
+ .getConfigPropertiesMap().entrySet())
+ {
+ valueBuf.append(connProperty.getKey());
+ valueBuf.append("=");
+ valueBuf.append(connProperty.getValue());
+ valueBuf.append(";");
+ }
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
+ }
+ break;
+ }
+
case TRACKSTATEMENTS : {
if (ds != null && ds.getStatement() != null && ds.getStatement().getTrackStatements() != null)
{
@@ -683,8 +730,7 @@
case DRIVERCLASS : {
if (ds != null && ds.getDriverClass() != null)
{
- configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
- ds.getDriverClass()));
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getDriverClass()));
}
break;
}
@@ -700,8 +746,7 @@
valueBuf.append(connProperty.getValue());
valueBuf.append(";");
}
- configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
- valueBuf.toString()));
+ configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype, valueBuf.toString()));
}
break;
@@ -709,11 +754,12 @@
case CONNECTIONURL : {
if (ds != null && ds.getConnectionUrl() != null)
{
- configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
- ds.getConnectionUrl()));
+ configProperties
+ .add(ConfigPropertyFactory.createConfigProperty(prototype, ds.getConnectionUrl()));
}
break;
}
+
default :
break;
}
@@ -722,8 +768,8 @@
{
for (Entry<String, String> connectionProperty : ds.getConnectionProperties().entrySet())
{
- ConfigPropertyFactory.Prototype prototype = ConfigPropertyFactory.Prototype
- .forName(connectionProperty.getKey());
+ ConfigPropertyFactory.Prototype prototype = ConfigPropertyFactory.Prototype.forName(connectionProperty
+ .getKey());
if (prototype != ConfigPropertyFactory.Prototype.UNKNOWN)
{
configProperties.add(ConfigPropertyFactory.createConfigProperty(prototype,
@@ -809,8 +855,7 @@
/** CONNECTIONURL **/
CONNECTIONURL("ConnectionURL", "java.lang.String", "The jdbc connection url class."),
/** CONNECTIONPROPERTIES **/
- CONNECTIONPROPERTIES("ConnectionProperties", "java.lang.String",
- "Connection properties for the database."),
+ 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."),
@@ -851,15 +896,28 @@
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."),
+ /** VALIDCONNECTIONCHECKERPROPERTIES **/
+ VALIDCONNECTIONCHECKERPROPERTIES("ValidConnectionCheckerProperties", "java.lang.String",
+ "The properties to inect into 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."),
+ /** EXCEPTIONSORTERPROPERTIES **/
+ EXCEPTIONSORTERPROPERTIES("ExceptionSorterProperties", "java.lang.String",
+ "The properties to inect into 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."),
+ /** STALECONNECTIONCHECKERPROPERTIES **/
+ STALECONNECTIONCHECKERPROPERTIES("StaleConnectionCheckerProperties", "java.lang.String",
+ "The properties to inect into 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"),
Modified: projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
===================================================================
--- projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd 2010-11-11 08:24:37 UTC (rev 109269)
@@ -391,7 +391,7 @@
</xs:complexType>
<xs:complexType name="validationType">
<xs:sequence>
- <xs:element name="valid-connection-checker-class-name" type="xs:token" minOccurs="0">
+ <xs:element name="valid-connection-checker" type="jdbc-adapter-extensionType" minOccurs="0">
<xs:annotation>
<xs:documentation>
<![CDATA[[
@@ -404,6 +404,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
+
<xs:element name="check-valid-connection-sql " type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>
@@ -457,7 +458,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element minOccurs="0" name="stale-connection-checker-class-name" type="xs:token">
+ <xs:element minOccurs="0" name="stale-connection-checker" type="jdbc-adapter-extensionType">
<xs:annotation>
<xs:documentation>
<![CDATA[[
@@ -470,7 +471,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="exception-sorter-class-name" type="xs:token" minOccurs="0">
+ <xs:element name="exception-sorter" type="jdbc-adapter-extensionType" minOccurs="0">
<xs:annotation>
<xs:documentation>
<![CDATA[[
@@ -726,4 +727,34 @@
</xs:element>
</xs:sequence>
</xs:complexType>
+
+ <xs:complexType name="jdbc-adapter-extensionType">
+ <xs:sequence>
+ <xs:element name="config-property" type="config-propertyType"></xs:element>
+ </xs:sequence>
+ <xs:attribute name="class-name" type="xs:token" use="required"></xs:attribute>
+ </xs:complexType>
+
+ <xs:complexType name="config-propertyType" mixed="true">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies an override for a config-property element in ra.xml or a @ConfigProperty
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ <xs:simpleContent>
+ <xs:extension base="xs:token">
+ <xs:attribute use="required" name="name" type="xs:token">
+ <xs:annotation>
+ <xs:documentation>
+ <![CDATA[[
+ Specifies the name of the config-property
+ ]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
</xs:schema>
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/AbstractDsDeployer.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -43,7 +43,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
@@ -122,17 +121,18 @@
*
* @param url url
* @param deploymentName deploymentName
+ * @param uniqueJdbcLocalId uniqueJdbcLocalId
+ * @param uniqueJdbcXAId uniqueJdbcXAId
* @param parentClassLoader cl
- * @param raDeployments resource adapters deployments
* @param dataSources datasources metadata defined in xml
* @return return the exchange POJO with value useful for injection in the container (fungal or AS)
* @throws DeployException DeployException
*/
- protected CommonDeployment createObjectsAndInjectValue(URL url,
+ protected CommonDeployment createObjectsAndInjectValue(URL url,
String deploymentName,
String uniqueJdbcLocalId,
String uniqueJdbcXAId,
- DataSources dataSources,
+ DataSources dataSources,
ClassLoader parentClassLoader)
throws DeployException
{
@@ -430,7 +430,7 @@
/**
* Provide the classloader of the deployment identified by the unique id
- * @param uniqueId The
+ * @param uniqueId The
* @return The classloader used by this deployment
*/
protected abstract ClassLoader getDeploymentClassLoader(String uniqueId);
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -46,7 +46,6 @@
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-
import javax.transaction.TransactionManager;
import org.jboss.logging.Logger;
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2010-11-11 06:30:01 UTC (rev 109268)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2010-11-11 08:24:37 UTC (rev 109269)
@@ -176,7 +176,7 @@
}
}
- CommonDeployment c = createObjectsAndInjectValue(url, deploymentName,
+ CommonDeployment c = createObjectsAndInjectValue(url, deploymentName,
uniqueJdbcLocalId, uniqueJdbcXAId,
dataSources, parent);
More information about the jboss-cvs-commits
mailing list