FileDocCategorySizeDatePackage
BaseWrapperManagedConnectionFactory.javaAPI DocJBoss 4.2.115578Fri Jul 13 21:01:14 BST 2007org.jboss.resource.adapter.jdbc

BaseWrapperManagedConnectionFactory

public abstract class BaseWrapperManagedConnectionFactory extends Object implements javax.resource.spi.ManagedConnectionFactory, Serializable, javax.resource.spi.ValidatingManagedConnectionFactory
BaseWrapperManagedConnectionFactory
author
David Jencks
author
Adrian Brock
author
Weston Price
version
$Revision: 57189 $

Fields Summary
static final long
serialVersionUID
public static final int
TRACK_STATEMENTS_FALSE_INT
public static final int
TRACK_STATEMENTS_TRUE_INT
public static final int
TRACK_STATEMENTS_NOWARN_INT
public static final String
TRACK_STATEMENTS_FALSE
public static final String
TRACK_STATEMENTS_TRUE
public static final String
TRACK_STATEMENTS_NOWARN
protected final Logger
log
protected String
userName
protected String
password
protected final Properties
connectionProps
protected int
transactionIsolation
protected int
preparedStatementCacheSize
protected boolean
doQueryTimeout
protected String
newConnectionSQL
The variable newConnectionSQL holds an SQL statement which if not null is executed when a new Connection is obtained for a new ManagedConnection.
protected String
checkValidConnectionSQL
The variable checkValidConnectionSQL holds an sql statement that may be executed whenever a managed connection is removed from the pool, to check that it is still valid. This requires setting up an mbean to execute it when notified by the ConnectionManager.
protected String
validConnectionCheckerClassName
The classname used to check whether a connection is valid
protected ValidConnectionChecker
connectionChecker
The instance of the valid connection checker
private String
exceptionSorterClassName
private ExceptionSorter
exceptionSorter
protected int
trackStatements
protected boolean
sharePS
Whether to share cached prepared statements
protected boolean
isTransactionQueryTimeout
protected int
queryTimeout
private boolean
validateOnMatch
Constructors Summary
public BaseWrapperManagedConnectionFactory()

   
     
   

   
Methods Summary
public java.lang.ObjectcreateConnectionFactory(javax.resource.spi.ConnectionManager cm)

      return new WrapperDataSource(this, cm);
   
public java.lang.ObjectcreateConnectionFactory()

      throw new JBossResourceException("NYI");
   
public java.lang.StringgetCheckValidConnectionSQL()

      return checkValidConnectionSQL;
   
protected java.util.PropertiesgetConnectionProperties(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cri)
Gets full set of connection properties, i.e. whatever is provided in config plus "user" and "password" from subject/cri.

Note that the set is used to match connections to datasources as well as to create new managed connections.

In fact, we have a problem here. Theoretically, there is a possible name collision between config properties and "user"/"password".

      if (cri != null && cri.getClass() != WrappedConnectionRequestInfo.class)
         throw new JBossResourceException("Wrong kind of ConnectionRequestInfo: " + cri.getClass());

      Properties props = new Properties();
      props.putAll(connectionProps);
      if (subject != null)
      {
         if (SubjectActions.addMatchingProperties(subject, props, this) == true)
            return props;
         throw new JBossResourceException("No matching credentials in Subject!");
      }
      WrappedConnectionRequestInfo lcri = (WrappedConnectionRequestInfo)cri;
      if (lcri != null)
      {
         props.setProperty("user", (lcri.getUserName() == null)? "": lcri.getUserName());
         props.setProperty("password", (lcri.getPassword() == null)? "": lcri.getPassword());
         return props;
      }
      if (userName != null)
      {
         props.setProperty("user", userName);
         props.setProperty("password", (password == null) ? "" : password);
      }
      return props;
   
public java.lang.StringgetExceptionSorterClassName()

      return exceptionSorterClassName;
   
public java.util.SetgetInvalidConnections(java.util.Set connectionSet)

      
      final Set invalid = new HashSet();
      
      for(Iterator iter = connectionSet.iterator(); iter.hasNext();){
         
         Object anonymous = iter.next();
         
         if (anonymous instanceof BaseWrapperManagedConnection)
         {
            BaseWrapperManagedConnection mc = (BaseWrapperManagedConnection) anonymous;
            
            if(!mc.checkValid()){
               
               invalid.add(mc);
            }
            
         }
         
      }
   
      return invalid;
   
public java.io.PrintWritergetLogWriter()

      // TODO: implement this javax.resource.spi.ManagedConnectionFactory method
      return null;
   
public java.lang.StringgetNewConnectionSQL()

      return newConnectionSQL;
   
public java.lang.StringgetPassword()

      return password;
   
public intgetPreparedStatementCacheSize()

      return preparedStatementCacheSize;
   
public intgetQueryTimeout()

      return queryTimeout;
   
public booleangetSharePreparedStatements()

      return sharePS;
   
public java.lang.StringgetTrackStatements()

      if (trackStatements == TRACK_STATEMENTS_FALSE_INT)
         return TRACK_STATEMENTS_FALSE;
      else if (trackStatements == TRACK_STATEMENTS_TRUE_INT)
         return TRACK_STATEMENTS_TRUE;
      return TRACK_STATEMENTS_NOWARN;
   
public java.lang.StringgetTransactionIsolation()

      switch (this.transactionIsolation)
      {
         case Connection.TRANSACTION_NONE:
            return "TRANSACTION_NONE";
         case Connection.TRANSACTION_READ_COMMITTED:
            return "TRANSACTION_READ_COMMITTED";
         case Connection.TRANSACTION_READ_UNCOMMITTED:
            return "TRANSACTION_READ_UNCOMMITTED";
         case Connection.TRANSACTION_REPEATABLE_READ:
            return "TRANSACTION_REPEATABLE_READ";
         case Connection.TRANSACTION_SERIALIZABLE:
            return "TRANSACTION_SERIALIZABLE";
         case -1:
            return "DEFAULT";
         default:
            return Integer.toString(transactionIsolation);
      }
   
public java.lang.StringgetUserName()

      return userName;
   
public java.lang.StringgetValidConnectionCheckerClassName()

      return validConnectionCheckerClassName;
   
public booleangetValidateOnMatch()

      
      return this.validateOnMatch;
      
   
booleanisExceptionFatal(java.sql.SQLException e)

      try
      {
         if (exceptionSorter != null)
            return exceptionSorter.isExceptionFatal(e);

         if (exceptionSorterClassName != null)
         {
            try
            {
               ClassLoader cl = Thread.currentThread().getContextClassLoader();
               Class clazz = cl.loadClass(exceptionSorterClassName);
               exceptionSorter = (ExceptionSorter)clazz.newInstance();
               return exceptionSorter.isExceptionFatal(e);
            }
            catch (Exception e2)
            {
               log.warn("exception trying to create exception sorter (disabling):", e2);
               exceptionSorter = new NullExceptionSorter();
            }
         }
      }
      catch (Throwable t)
      {
         log.warn("Error checking exception fatality: ", t);
      }
      return false;
   
public booleanisTransactionQueryTimeout()

      return isTransactionQueryTimeout;
   
java.sql.SQLExceptionisValidConnection(java.sql.Connection c)
Checks whether a connection is valid

      // Already got a checker
      if (connectionChecker != null)
         return connectionChecker.isValidConnection(c);

      // Class specified
      if (validConnectionCheckerClassName != null)
      {
         try
         {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Class clazz = cl.loadClass(validConnectionCheckerClassName);
            connectionChecker = (ValidConnectionChecker) clazz.newInstance();
            return connectionChecker.isValidConnection(c);
         }
         catch (Exception e)
         {
            log.warn("Exception trying to create connection checker (disabling):", e);
            connectionChecker = new NullValidConnectionChecker();
         }
      }

      // SQL statement specified
      if (checkValidConnectionSQL != null)
      {
         connectionChecker = new CheckValidConnectionSQL(checkValidConnectionSQL);
         return connectionChecker.isValidConnection(c);
      }

      // No Check
      return null;
   
public voidsetCheckValidConnectionSQL(java.lang.String checkValidConnectionSQL)

      this.checkValidConnectionSQL = checkValidConnectionSQL;
   
public voidsetExceptionSorterClassName(java.lang.String exceptionSorterClassName)

      this.exceptionSorterClassName = exceptionSorterClassName;
   
public voidsetLogWriter(java.io.PrintWriter param1)

      // TODO: implement this javax.resource.spi.ManagedConnectionFactory method
   
public voidsetNewConnectionSQL(java.lang.String newConnectionSQL)

      this.newConnectionSQL = newConnectionSQL;
   
public voidsetPassword(java.lang.String password)

      this.password = password;
   
public voidsetPreparedStatementCacheSize(int size)

      preparedStatementCacheSize = size;
   
public voidsetQueryTimeout(int timeout)

      queryTimeout = timeout;
   
public voidsetSharePreparedStatements(boolean sharePS)

      this.sharePS = sharePS;
   
public voidsetTrackStatements(java.lang.String value)

      if (value == null)
         throw new IllegalArgumentException("Null value for trackStatements"); 
      String trimmed = value.trim();
      if (trimmed.equalsIgnoreCase(TRACK_STATEMENTS_FALSE))
         trackStatements = TRACK_STATEMENTS_FALSE_INT;
      else if (trimmed.equalsIgnoreCase(TRACK_STATEMENTS_TRUE))
         trackStatements = TRACK_STATEMENTS_TRUE_INT;
      else
         trackStatements = TRACK_STATEMENTS_NOWARN_INT;
   
public voidsetTransactionIsolation(java.lang.String transactionIsolation)

      if (transactionIsolation.equals("TRANSACTION_NONE"))
         this.transactionIsolation = Connection.TRANSACTION_NONE;
      else if (transactionIsolation.equals("TRANSACTION_READ_COMMITTED"))
         this.transactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
      else if (transactionIsolation.equals("TRANSACTION_READ_UNCOMMITTED"))
         this.transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
      else if (transactionIsolation.equals("TRANSACTION_REPEATABLE_READ"))
         this.transactionIsolation = Connection.TRANSACTION_REPEATABLE_READ;
      else if (transactionIsolation.equals("TRANSACTION_SERIALIZABLE"))
         this.transactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
      else
      {
         try
         {
            this.transactionIsolation = Integer.parseInt(transactionIsolation);
         }
         catch (NumberFormatException nfe)
         {
            throw new IllegalArgumentException("Setting Isolation level to unknown state: " + transactionIsolation);
         }
      }
   
public voidsetTransactionQueryTimeout(boolean value)

      isTransactionQueryTimeout = value;
   
public voidsetUserName(java.lang.String userName)

      this.userName = userName;
   
public voidsetValidConnectionCheckerClassName(java.lang.String value)

      validConnectionCheckerClassName = value;
   
public voidsetValidateOnMatch(boolean validateOnMatch)

      
      this.validateOnMatch = validateOnMatch;