|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap
org.apache.commons.collections.map.AbstractHashedMap
org.apache.commons.collections.map.AbstractLinkedMap
org.apache.commons.collections.map.LRUMap
org.openanzo.jdbc.utils.sqlcache.SQLCache
public class SQLCache
Provides a cache of JDBC statements. Statements can be accessed either as a JDBC PreparedStatement, in which case the statement is pooled, as a CallableStatement in which it may simple be desposed of after use or as a set of non-querying statements with no JDBC paramters that are executed together, such as DDL ('create table' calls, etc..). JDBC statements may be loaded from a java Properties file, a java Properties object or may be added using 'addPreparedStatement'. The key of each property is a string name for that prepared statement and the value is the SQL statement or, for non-querying statements with no JDBC paramters, a list of statements seperated ';;'. If a properties entry contains a list of statements as the value, only 'runSQLGroup' may be used to access these statements. Template variables may optionally be put in the JDBC statements using a '${varname}' syntax. These template variables should only be used to parameterize the tablenames or other values where it will be the same for a substantial number of calls. If the template variable is rarely the same value the cache will perform poorly, in which case it is better to use JDBC '?' parameters or dynamically generate the SQL and run it as a callable statement. Prepared statements should be pulled from the pool using 'getPreparedSQLStatement' and returned to the pool when they are no longer needed using 'returnPreparedSQLStatement', ideally the return call is put a finally clause to guarentee it is called.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
SQLCache(java.sql.Connection connection)
Create a new SQLCache for the given connection |
|
SQLCache(java.sql.Connection connection,
java.io.InputStream sqlFileInputStream)
Create a new SQLCache for the given connection |
|
SQLCache(java.sql.Connection connection,
java.util.Properties defaults)
Create a new SQLCache for the given connection |
|
SQLCache(java.sql.Connection connection,
java.lang.String sqlFilename)
Create a new SQLCache for the given connection |
|
SQLCache(java.sql.Connection connection,
java.lang.String sqlFilename,
java.util.Properties defaults)
Create a new SQLCache for the given connection |
|
| Method Summary | |
|---|---|
void |
addPreparedStatement(java.lang.String name,
java.lang.String statement)
Add a prepared statement with the given name, and text |
void |
clear()
|
static java.io.InputStream |
findSQLResource(java.lang.String sqlFilename)
Load the contents of a file as a resource stream using SQLCache.class.getClassLoader().getClassLoader().getResourceAsStream() |
java.sql.Connection |
getJDBCConnection()
Get the JDBC Connection object |
java.sql.PreparedStatement |
getPreparedSQLStatement(java.lang.String name)
Retrieve a prepared statement with the given name |
java.sql.PreparedStatement |
getPreparedSQLStatement(java.lang.String name,
java.lang.String[] templateParameters)
Get a preparedStatement with the given name. |
ClosableIterator<java.lang.String> |
listPreloadData(java.io.InputStream inputStream)
Retrieve data from file which will be used to preload some table |
ClosableIterator<java.lang.String> |
listPreloadData(java.lang.String sqlFilename)
Retrieve data from file which will be used to preload some table |
void |
loadSQLFile(java.io.InputStream sqlFileInputStream)
Load the contents of this file containing ddl and prepared statement text |
void |
loadSQLFile(java.lang.String sqlFilename)
Load the contents of this file containing ddl and prepared statement text |
void |
loadSQLFile(java.lang.String sqlFilename,
java.util.Properties defaults)
Load the contents of this file containing ddl and prepared statement definitions |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql)
Create a preparedStatement for the given SQL text |
java.sql.PreparedStatement |
prepareStatement(java.lang.String name,
java.lang.String[] templateParameters)
Create a preparedStatement with the given name |
java.lang.Object |
remove(java.lang.Object key)
|
void |
returnPreparedSQLStatement(java.sql.PreparedStatement ps)
Return the prepared statement to the cache |
void |
runSQLGroup(java.lang.String name,
java.lang.String[] templateParameters)
Execute a group of sql statements, usually used to initialize tables and indexes |
void |
setJDBCConnection(java.sql.Connection connection)
Set the JDBC connection. |
void |
setResultSetParams(java.lang.Integer resultSetType,
java.lang.Integer resultSetConcurrency,
java.lang.Integer resultSetHoldability)
Set the resultSet parameters for the connection |
| Methods inherited from class org.apache.commons.collections.map.LRUMap |
|---|
clone, get, isFull, isScanUntilRemovable, maxSize |
| Methods inherited from class org.apache.commons.collections.map.AbstractLinkedMap |
|---|
containsValue, firstKey, lastKey, mapIterator, nextKey, orderedMapIterator, previousKey |
| Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap |
|---|
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, size, toString, values |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, size, values |
| Constructor Detail |
|---|
public SQLCache(java.sql.Connection connection)
connection - connection for which to cache statements
public SQLCache(java.sql.Connection connection,
java.lang.String sqlFilename)
throws RdbException
connection - connection for which to cache statementssqlFilename - name of file containing initialization ddl data, and prepared statement definitions
RdbException - if there was an error loading the initialization file
public SQLCache(java.sql.Connection connection,
java.io.InputStream sqlFileInputStream)
throws RdbException
connection - connection for which to cache statementssqlFileInputStream - input stream containing initialization ddl data, and prepared statement definitions
RdbException - if there was an error loading the initialization file
public SQLCache(java.sql.Connection connection,
java.lang.String sqlFilename,
java.util.Properties defaults)
throws RdbException
connection - connection for which to cache statementssqlFilename - name of file containing initialization ddl data, and prepared statement definitionsdefaults - default text for ddl operations and prepared statement definitions
RdbException - if there was an error loading the initialization file
public SQLCache(java.sql.Connection connection,
java.util.Properties defaults)
connection - connection for which to cache statementsdefaults - default text for ddl operations and prepared statement definitions| Method Detail |
|---|
public void setResultSetParams(java.lang.Integer resultSetType,
java.lang.Integer resultSetConcurrency,
java.lang.Integer resultSetHoldability)
resultSetType - resultSetTyperesultSetConcurrency - type of concurrency to useresultSetHoldability - result set holdability setting
public void loadSQLFile(java.lang.String sqlFilename)
throws RdbException
sqlFilename - file containing ddl and prepared statement text
RdbException
public void loadSQLFile(java.io.InputStream sqlFileInputStream)
throws RdbException
sqlFileInputStream - input stream containing ddl and prepared statement text
RdbException
public void loadSQLFile(java.lang.String sqlFilename,
java.util.Properties defaults)
throws RdbException
sqlFilename - name of file containing initialization ddl data, and prepared statement definitionsdefaults - default text for ddl operations and prepared statement definitions
RdbException
public static java.io.InputStream findSQLResource(java.lang.String sqlFilename)
throws RdbException
sqlFilename - name of file containing initialization ddl data, and prepared statement definitions
RdbExceptionpublic java.sql.Connection getJDBCConnection()
public void setJDBCConnection(java.sql.Connection connection)
connection -
public void addPreparedStatement(java.lang.String name,
java.lang.String statement)
name - name of statementstatement - definition of prepared statement
public void runSQLGroup(java.lang.String name,
java.lang.String[] templateParameters)
throws java.sql.SQLException
name - name of grouptemplateParameters - arguments to the statement templates
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
throws java.sql.SQLException
prepareStatement in interface PreparedStatementCachesql - text of statement
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String name,
java.lang.String[] templateParameters)
throws java.sql.SQLException
name - name of prepared statementtemplateParameters - parameters to the statement template
java.sql.SQLException
public java.sql.PreparedStatement getPreparedSQLStatement(java.lang.String name,
java.lang.String[] templateParameters)
throws java.sql.SQLException
getPreparedSQLStatement in interface PreparedStatementCachename - name of prepared statementtemplateParameters - parameters to the statement template
java.sql.SQLException
public java.sql.PreparedStatement getPreparedSQLStatement(java.lang.String name)
throws java.sql.SQLException
PreparedStatementCache
getPreparedSQLStatement in interface PreparedStatementCachename - name of the prepared statement
java.sql.SQLExceptionpublic void returnPreparedSQLStatement(java.sql.PreparedStatement ps)
PreparedStatementCache
returnPreparedSQLStatement in interface PreparedStatementCacheps - prepared statement to returnpublic java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapremove in class org.apache.commons.collections.map.AbstractHashedMap
public ClosableIterator<java.lang.String> listPreloadData(java.lang.String sqlFilename)
throws RdbException
sqlFilename - name of file containing data
RdbExceptionpublic ClosableIterator<java.lang.String> listPreloadData(java.io.InputStream inputStream)
inputStream - inputStream containing data
public void clear()
clear in interface java.util.Mapclear in class org.apache.commons.collections.map.AbstractLinkedMap
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||