SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

com.solarmetric.kodo.impl.jdbc
Class SQLExecutionManagerImpl

java.lang.Object
  |
  +--com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl
All Implemented Interfaces:
SQLExecutionManager

public class SQLExecutionManagerImpl
extends Object
implements SQLExecutionManager

Implementation of SQLExecutionManager that supports PreparedStatements and Statements, and has support for batching together similiar statements.

This class maintains an internal list of SQLBuffers to execute, so that similiar consecutive ones can be batched together for efficiency. Any invocations of executeNow() or executeQuery() will immediately flush the list, since otherwise it would would not be possible to maintain SQL execution order.

Implementation Note: This class does not do any caching of statements itself. Great performance benefits will be yielded from using a DataSource implementation that does caching of PreparedStatements.

Since:
2.4
See Also:
SQLExecutionManager, SQLBuffer

Inner Class Summary
(package private)  class SQLExecutionManagerImpl.SQLExecutionEventImpl
          Internal implementation of the SQLExecutionEvent event interface.
 
Constructor Summary
SQLExecutionManagerImpl()
           
 
Method Summary
 boolean addSQLExecutionListener(SQLExecutionListener listener)
          Adds a listerer to be notified whenever a SQL event occurs.
 void close()
          Close the Connection, if there is one currently open.
 void close(ResultSet rs)
          Indicate to the manager that this ResultSet is no longer needed.
 void commit()
          Flush any remaining queued statements and commit to the data store.
 void execute(NonSelectingSQL statement)
          Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement.
 void execute(NonSelectingSQL statement, SQLExecutionCallback callback)
          Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement.
 void execute(SQLBuffer buffer)
          Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement.
 void execute(SQLBuffer buffer, SQLExecutionCallback callback)
           
 int executeNow(NonSelectingSQL statement)
          Execute the given NonSelectingSQL immediately, returning the number of updates made.
 int executeNow(SQLBuffer buffer)
          Execute the given SQLBuffer update the specified Connection, either in a in a non-batched Statement or PreparedStatement.
(package private)  ResultSet executePreparedQueryInternal(SQLBuffer buffer, int type, int concur)
          Execute the specified SQLBuffer as a PreparedStatement.
 int[] executePreparedStatement(SQLBuffer[] buffer)
           Execute the array of SQLBuffer statements as PreparedStatements and return an array of the update counts.
(package private)  int[] executePreparedStatementBatch(SQLBuffer[] buffer)
          Execute a set of SQLBuffers as a batch.
(package private)  int[] executePreparedStatementNonBatch(SQLBuffer[] buffer)
          Execute a set of SQLBuffers without doing any batching.
 ResultSet executeQuery(Select select)
          Execute the given Select statement on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
 ResultSet executeQuery(Select select, int type, int concur)
          Execute the given Select statement on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
 ResultSet executeQuery(SQLBuffer buffer)
          Execute the given SQLBuffer on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
 ResultSet executeQuery(SQLBuffer buffer, int type, int concur)
          Execute the given SQLBuffer on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
 int[] flush()
          Flush any pending statements in the queue and retun an array of the number of update counts.
 Collection getCallbackExceptions()
          Return all user exceptions thrown by callbacks since the end of the last transaction.
 JDBCConfiguration getConfiguration()
          Returns the JDBCConfiguration set in this object upon creation.
 Connection getConnection()
          Returns the Connection that is being used for this manager.
 Connection getConnectionFromFactory()
          Obtain a Connection from the connection factory, after validating it against the DBDictionary.isClosed(java.sql.Connection) method.
 Connector getConnector()
          Return the Connector in use by the SQLExecutionManager.
 DBDictionary getDictionary()
          Returns the DBDictionary to use when creating SQL statements.
 boolean getManaged()
          Returns true if this SQLExecutionManager is managed.
(package private)  SQLBuffer[] getMatchingBuffers(List buffers)
          Returns the first N elements of the List of SQLBuffers whose PreparedStatement SQL commands are all identical.
 boolean removeSQLExecutionListener(SQLExecutionListener listener)
          Removes a listerer to be notified whenever a SQL event occurs.
 void rollback()
          Rolls back the underlying connection.
 void setConfiguration(JDBCConfiguration config)
          Set the Configuration for this object.
 void setConnector(Connector connector)
          Set the Connector to be used for this manager.
 void setManaged(boolean managed)
          Set whether this SQLExecutionManager is managed.
(package private)  ResultSet wrapResultSet(ResultSet rs, Statement stmnt)
          Wrap the ResultSet in something that will return the correct value for ResultSet.getStatement() (which isn't available in JDBC 1 implementations, and gets around the behavior of some other connection wrappers that do not wrap the ResultSet implementation, which prevents ResultSet.getStatement().close() from working as expected).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLExecutionManagerImpl

public SQLExecutionManagerImpl()
Method Detail

setConfiguration

public void setConfiguration(JDBCConfiguration config)
Description copied from interface: SQLExecutionManager
Set the Configuration for this object.
Specified by:
setConfiguration in interface SQLExecutionManager

getConfiguration

public JDBCConfiguration getConfiguration()
Description copied from interface: SQLExecutionManager
Returns the JDBCConfiguration set in this object upon creation. It may never be null.
Specified by:
getConfiguration in interface SQLExecutionManager

setConnector

public void setConnector(Connector connector)
Description copied from interface: SQLExecutionManager
Set the Connector to be used for this manager.
Specified by:
setConnector in interface SQLExecutionManager

getConnector

public Connector getConnector()
Description copied from interface: SQLExecutionManager
Return the Connector in use by the SQLExecutionManager.
Specified by:
getConnector in interface SQLExecutionManager

getConnection

public Connection getConnection()
                         throws SQLException
Description copied from interface: SQLExecutionManager
Returns the Connection that is being used for this manager. The life cycle of this connection will be managed by the SQLExecutionManager.
Specified by:
getConnection in interface SQLExecutionManager

getConnectionFromFactory

public Connection getConnectionFromFactory()
                                    throws SQLException
Obtain a Connection from the connection factory, after validating it against the DBDictionary.isClosed(java.sql.Connection) method.
Returns:
a newly obtained Connection

getDictionary

public DBDictionary getDictionary()
Description copied from interface: SQLExecutionManager
Returns the DBDictionary to use when creating SQL statements.
Specified by:
getDictionary in interface SQLExecutionManager

execute

public void execute(NonSelectingSQL statement)
             throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement. After calling a sequence of multiple execute() methods, flush() should be invoked in order to ensure that statements are flushed to the data store. For immediate execution, call the executeNow method.
Specified by:
execute in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
See Also:
SQLExecutionManager.executeNow(com.solarmetric.kodo.impl.jdbc.sql.NonSelectingSQL)

execute

public void execute(NonSelectingSQL statement,
                    SQLExecutionCallback callback)
             throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement. After calling a sequence of multiple execute() methods, flush() should be invoked in order to ensure that statements are flushed to the data store. For immediate execution, call the executeNow method.
Specified by:
execute in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
Parameters:
statement - the Statement to execute
callback - the callback to invoke after the update occurs
See Also:
SQLExecutionManager.executeNow(com.solarmetric.kodo.impl.jdbc.sql.NonSelectingSQL)

execute

public void execute(SQLBuffer buffer)
             throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer on the Connection, either in a batched or non-batched Statement or PreparedStatement. After calling a sequence of multiple execute() methods, flush() should be invoked in order to ensure that statements are flushed to the data store. For immediate execution, call the executeNow method.
Specified by:
execute in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
See Also:
SQLExecutionManager.executeNow(com.solarmetric.kodo.impl.jdbc.sql.SQLBuffer)

execute

public void execute(SQLBuffer buffer,
                    SQLExecutionCallback callback)
             throws SQLExceptionWrapper

flush

public int[] flush()
            throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Flush any pending statements in the queue and retun an array of the number of update counts.
Specified by:
flush in interface SQLExecutionManager

getMatchingBuffers

SQLBuffer[] getMatchingBuffers(List buffers)
Returns the first N elements of the List of SQLBuffers whose PreparedStatement SQL commands are all identical. Used for batching together similiar SQL statements. The passed in List will be modified to remove all the buffers that are returned by this method.

executeNow

public int executeNow(NonSelectingSQL statement)
               throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given NonSelectingSQL immediately, returning the number of updates made.
Specified by:
executeNow in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
See Also:
SQLExecutionManager.executeNow(com.solarmetric.kodo.impl.jdbc.sql.NonSelectingSQL)

executeNow

public int executeNow(SQLBuffer buffer)
               throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer update the specified Connection, either in a in a non-batched Statement or PreparedStatement.
Specified by:
executeNow in interface SQLExecutionManager

executeQuery

public ResultSet executeQuery(Select select)
                       throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given Select statement on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
Specified by:
executeQuery in interface SQLExecutionManager

executeQuery

public ResultSet executeQuery(Select select,
                              int type,
                              int concur)
                       throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given Select statement on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
Specified by:
executeQuery in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
Parameters:
type - the type of ResultSet to return
concur - the concurrency of the ResultSet

executeQuery

public ResultSet executeQuery(SQLBuffer buffer)
                       throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
Specified by:
executeQuery in interface SQLExecutionManager

executeQuery

public ResultSet executeQuery(SQLBuffer buffer,
                              int type,
                              int concur)
                       throws SQLExceptionWrapper
Description copied from interface: SQLExecutionManager
Execute the given SQLBuffer on the specified Connection, either in a batched or non-batched Statement or PreparedStatement.
Specified by:
executeQuery in interface SQLExecutionManager
Following copied from interface: com.solarmetric.kodo.impl.jdbc.SQLExecutionManager
Parameters:
type - the type of ResultSet to return
concur - the concurrency of the ResultSet

executePreparedStatement

public int[] executePreparedStatement(SQLBuffer[] buffer)
                               throws SQLException

Execute the array of SQLBuffer statements as PreparedStatements and return an array of the update counts.

This implementation decides to batch together the statements or not depending on the setting of JDBCConfiguration.getUseBatchedStatements()


executePreparedStatementNonBatch

int[] executePreparedStatementNonBatch(SQLBuffer[] buffer)
                                 throws SQLException
Execute a set of SQLBuffers without doing any batching.

executePreparedStatementBatch

int[] executePreparedStatementBatch(SQLBuffer[] buffer)
                              throws SQLException
Execute a set of SQLBuffers as a batch. It is essential that all of the SQLBuffer objects have an identical PreparedStatement String. Thus, the list of buffers to pass should have been gathered by getMatchingBuffers(java.util.List)

wrapResultSet

ResultSet wrapResultSet(ResultSet rs,
                        Statement stmnt)
Wrap the ResultSet in something that will return the correct value for ResultSet.getStatement() (which isn't available in JDBC 1 implementations, and gets around the behavior of some other connection wrappers that do not wrap the ResultSet implementation, which prevents ResultSet.getStatement().close() from working as expected).

executePreparedQueryInternal

ResultSet executePreparedQueryInternal(SQLBuffer buffer,
                                       int type,
                                       int concur)
                                 throws SQLException
Execute the specified SQLBuffer as a PreparedStatement.

getCallbackExceptions

public Collection getCallbackExceptions()
Description copied from interface: SQLExecutionManager
Return all user exceptions thrown by callbacks since the end of the last transaction.
Specified by:
getCallbackExceptions in interface SQLExecutionManager

commit

public void commit()
            throws SQLException
Description copied from interface: SQLExecutionManager
Flush any remaining queued statements and commit to the data store. If the transaction is an XA transaction, then this method will only flush, but not commit the connection.
Specified by:
commit in interface SQLExecutionManager

rollback

public void rollback()
              throws SQLException
Description copied from interface: SQLExecutionManager
Rolls back the underlying connection.
Specified by:
rollback in interface SQLExecutionManager

close

public void close()
Close the Connection, if there is one currently open. This method will never throw an exception.
Specified by:
close in interface SQLExecutionManager

close

public void close(ResultSet rs)
           throws SQLException
Description copied from interface: SQLExecutionManager
Indicate to the manager that this ResultSet is no longer needed. The Statement that was used to create the ResultSet should no longer be used, as the implementation may choose to close it or return it to a pool for later reuse.
Specified by:
close in interface SQLExecutionManager

addSQLExecutionListener

public boolean addSQLExecutionListener(SQLExecutionListener listener)
Adds a listerer to be notified whenever a SQL event occurs.
Specified by:
addSQLExecutionListener in interface SQLExecutionManager

removeSQLExecutionListener

public boolean removeSQLExecutionListener(SQLExecutionListener listener)
Removes a listerer to be notified whenever a SQL event occurs.
Specified by:
removeSQLExecutionListener in interface SQLExecutionManager

setManaged

public void setManaged(boolean managed)
Set whether this SQLExecutionManager is managed. E.g., if it's connection is being enlisted in a distributed XA transaction.
Specified by:
setManaged in interface SQLExecutionManager
Parameters:
managed - if true, the SQLExecutionManager will be managed, and explicit Connection.commit(), Connection.rollback(), and Connection.close() methods will not be invoked on the Connection.

getManaged

public boolean getManaged()
Returns true if this SQLExecutionManager is managed.
Specified by:
getManaged in interface SQLExecutionManager

SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.