net.sourceforge.esw.collection
Class AJDBCTransducer

java.lang.Object
  |
  +--net.sourceforge.esw.collection.ATransducer
        |
        +--net.sourceforge.esw.collection.AJDBCTransducer
All Implemented Interfaces:
ITransactionalTransducer, ITransducer, java.io.Serializable
Direct Known Subclasses:
JDBCTransducer

public abstract class AJDBCTransducer
extends ATransducer
implements ITransducer, ITransactionalTransducer

Performs transduction between a JDBC data source and an IMetaCollection instance.

This transduction occurs both ways; put() takes data from the IMetaCollection instance to which this ITransducer instance is attached and places it into the data source represented by this ITransducer instance. The get() method takes data from the data source represented by this ITransducer instance and places it into the IMetaCollection instance to which this ITransducer instance is attached.

To enable transactional considerations, one must first call the setAutoCommit method passing in true. Otherwise, the default get or put code will automatially commit during their execution.

This AJDBCTransducer instance abstracts the JDBC connection methods and some convience methods for interacting with the JDBC data source.

This AJDBCTransducer instance pools the connections to the JDBC data source. See the net.sourceforge.esw.util.database.DBConnectionPoolManager class for more details of how to use the pooling outside of the AJDBCTransducer.

See Also:
DBConnectionPoolManager, IMetaCollection, INodeContextFactory, Serialized Form

Field Summary
protected  boolean bJDBCDriverAutoCommit
          The ITransactionalTransducer JDBC Driver autocommit property.
protected  boolean bTransducerAutoCommit
          The ITransactionalTransducer autocommit property.
protected  java.sql.Connection connection
          For non-AutoCommit mode, the Connection reference to commit or rollback when the transaction is complete or aborted.
static java.lang.String DELIMITER
          The delimiter used for replaceable parameters.
protected  java.lang.String password
          The password for the authorized JDBC data source user.
protected static java.lang.String QUESTION
          The ? character for Prepared Staements and Stored Procedures.
protected  java.lang.String url
          The URL for the JDBC data source.
protected  java.lang.String userid
          The User id for the authorized JDBC data source user.
 
Fields inherited from class net.sourceforge.esw.collection.ATransducer
contextFactory
 
Constructor Summary
AJDBCTransducer(java.lang.String aDriver, java.lang.String aURL)
          Creates a new AJDBCTransducer instance with all the JDBC paramters neccessary to create a JDBC connection.
AJDBCTransducer(java.lang.String aDriver, java.lang.String aURL, java.lang.String aUser, java.lang.String aPassword)
          Creates a new AJDBCTransducer instance with all the JDBC parameters neccessary to create a JDBC connection.
 
Method Summary
 void commit()
          Commits any get or put invocation up to the last (if any) commit previously invoked.
 boolean getAutoCommit()
          Returns whether any get or put invocations will automatically commit during their execution.
protected  java.sql.Connection getConnection()
          Returns a new Connection from the DB Connection Pooling.
 boolean getJDBCDriverAutoCommit()
          Returns whether any get or put invocations will automatically commit during their execution.
protected  java.util.List getReplaceableParameterNames(java.lang.String aStatement, java.lang.String aDelimiters)
          Returns the names of the replaceable parameters from the specified statement using the specified delimiters.
protected  void putResultSetIntoMetaCollection(java.sql.ResultSet aResultSet, IMetaCollection aCollection)
          Puts the specified ResultSet instance into the specified IMetaCollection instance.
protected  java.lang.String removeReplaceableParameters(java.lang.String aStatement, java.lang.String aDelimiters)
          Removes the replaceable parameters from the specified statement and replaces them with ?'s.
 void rollback()
          Rolls back any get or put invocation up to the last (if any) rollback previously invoked.
 void setAutoCommit(boolean aAutoCommit)
          Sets whether any get or put invocations will automatically commit during their execution.
 void setJDBCDriverAutoCommit(boolean aAutoCommit)
          Sets whether any get or put invocations will automatically commit during their execution.
 void setLog(boolean aLog)
          Sets if this AJDBCTransducer instance will log JDBC calls to System.out.
 
Methods inherited from class net.sourceforge.esw.collection.ATransducer
getContextFactory, setContextFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.esw.collection.ITransducer
get, getContextFactory, put, setContextFactory
 

Field Detail

url

protected java.lang.String url
The URL for the JDBC data source.

userid

protected java.lang.String userid
The User id for the authorized JDBC data source user.

password

protected java.lang.String password
The password for the authorized JDBC data source user.

bJDBCDriverAutoCommit

protected boolean bJDBCDriverAutoCommit
The ITransactionalTransducer JDBC Driver autocommit property. The default is true.

bTransducerAutoCommit

protected boolean bTransducerAutoCommit
The ITransactionalTransducer autocommit property. The default is true.

connection

protected java.sql.Connection connection
For non-AutoCommit mode, the Connection reference to commit or rollback when the transaction is complete or aborted.

QUESTION

protected static final java.lang.String QUESTION
The ? character for Prepared Staements and Stored Procedures.

DELIMITER

public static final java.lang.String DELIMITER
The delimiter used for replaceable parameters.
Constructor Detail

AJDBCTransducer

public AJDBCTransducer(java.lang.String aDriver,
                       java.lang.String aURL,
                       java.lang.String aUser,
                       java.lang.String aPassword)
                throws java.lang.IllegalArgumentException
Creates a new AJDBCTransducer instance with all the JDBC parameters neccessary to create a JDBC connection.
Parameters:
aDriver - the fully-qualified JDBC Driver class name.
aURL - the URL for the JDBC driver.
aUser - the authorized user for the JDBC data source.
aPassword - the password for the authoized user.
Throws:
java.lang.IllegalArgumentException - if the JDBC driver does not exist or does not properly register.

AJDBCTransducer

public AJDBCTransducer(java.lang.String aDriver,
                       java.lang.String aURL)
                throws java.lang.IllegalArgumentException
Creates a new AJDBCTransducer instance with all the JDBC paramters neccessary to create a JDBC connection.
Parameters:
aDriver - the fully-qualifed JDBC Driver class name.
aURL - the URL for the JDBC driver.
Throws:
java.lang.IllegalArgumentException - if the JDBC driver does not exist or does not properly register.
Method Detail

setLog

public void setLog(boolean aLog)
Sets if this AJDBCTransducer instance will log JDBC calls to System.out.
Parameters:
aLog - if true, will log JDBC calls from the driver.

commit

public void commit()
            throws TransducerException
Commits any get or put invocation up to the last (if any) commit previously invoked. This method must be called to complete the trnasduction if the setAutoCommit is set to true.
Specified by:
commit in interface ITransactionalTransducer
Following copied from interface: net.sourceforge.esw.collection.ITransactionalTransducer
Throws:
TransducerException - if an error occurred during the commit process.

rollback

public void rollback()
              throws TransducerException
Rolls back any get or put invocation up to the last (if any) rollback previously invoked.
Specified by:
rollback in interface ITransactionalTransducer
Following copied from interface: net.sourceforge.esw.collection.ITransactionalTransducer
Throws:
TransducerException - if an error occurred during the rollback process.

getJDBCDriverAutoCommit

public boolean getJDBCDriverAutoCommit()
Returns whether any get or put invocations will automatically commit during their execution.
Returns:
the JDBCDriverAutoCommit flag for the transducer.

getAutoCommit

public boolean getAutoCommit()
Returns whether any get or put invocations will automatically commit during their execution. This commit will occur after the entire put or get operation is complete.
Returns:
the TransducerAutoCommit flag for the transducer.

setJDBCDriverAutoCommit

public void setJDBCDriverAutoCommit(boolean aAutoCommit)
Sets whether any get or put invocations will automatically commit during their execution.
Parameters:
aAutoCommit - if true, will set the JDBC Driver to automatically commit the transduction during get or put execution. If false, then commit must be called to complete the transduction.

setAutoCommit

public void setAutoCommit(boolean aAutoCommit)
Sets whether any get or put invocations will automatically commit during their execution. This commit will occur after the entire put or get operation is complete. If the autocommit for the JDBC driver is set to true, then setting the Transducer Autocommit to true will set the driver Autocommit to false.
Specified by:
setAutoCommit in interface ITransactionalTransducer
Parameters:
aAutoCommit - if true, will automatically commit the transduction at the end of get or put execution. If false, then commit must be called to complete the transduction.

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Returns a new Connection from the DB Connection Pooling.
Throws:
java.sql.SQLException - if an error occurs while getting the connection.

putResultSetIntoMetaCollection

protected void putResultSetIntoMetaCollection(java.sql.ResultSet aResultSet,
                                              IMetaCollection aCollection)
                                       throws java.sql.SQLException
Puts the specified ResultSet instance into the specified IMetaCollection instance.
Parameters:
aResultSet - the ResultSet instance that contains the data being transduced into the specified IMetaCollection instance.
aCollection - the IMetaCollection instance that the specified ResultSet instance will be transduced.
Throws:
java.lang.Exception - if an error occurs during the transduction.

getReplaceableParameterNames

protected java.util.List getReplaceableParameterNames(java.lang.String aStatement,
                                                      java.lang.String aDelimiters)
Returns the names of the replaceable parameters from the specified statement using the specified delimiters.
Parameters:
aStatement - a SQL statement from which to peel the names of the replaceable parameters.
aDelimiters - the delimiters used for the replaceable parameters.
Returns:
a List of names that should match names of INode instances.

removeReplaceableParameters

protected java.lang.String removeReplaceableParameters(java.lang.String aStatement,
                                                       java.lang.String aDelimiters)
Removes the replaceable parameters from the specified statement and replaces them with ?'s.
Parameters:
aStatement - a SQL statement from which to remove the replaceable parameters.
aDelimiters - the delimiters used for the replaceable parameters.
Returns:
the original statement with ? in place of the replaceable parameters.


Copyright 2002 Free Software Foundation. All Rights Reserved.