|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibatis.db.sqlmap.SqlMap
public class SqlMap
The SqlMap class ties everything together. It defines the ParameterMap objects, ResultMap objects, and MappedStatements that are used in the iBATIS database layer. It is generally configured in an XML file that is loaded at run time.
Field Summary | |
---|---|
private java.util.HashMap |
cacheMap
|
private boolean |
cacheModelsEnabled
|
private java.lang.String |
currentDataSourceName
|
private java.util.Map |
dataSourceMap
|
private boolean |
driverHintsEnabled
|
private Throttle |
executePerConnThrottle
|
private Throttle |
executeThrottle
|
private java.lang.ThreadLocal |
localBatch
|
private java.lang.ThreadLocal |
localTransaction
|
private java.io.PrintWriter |
logWriter
|
private java.util.Map |
mappedStatements
|
private java.util.Map |
parameterMaps
|
private java.util.Map |
resultMaps
|
private boolean |
startTransactionBeforeConnection
|
private StatementFactory |
statementFactory
|
private Throttle |
transactionThrottle
|
private boolean |
useFullyQualifiedStatementNames
|
private boolean |
useGlobalTransaction
|
private JtaTransaction |
userTransaction
|
private java.lang.String |
userTransactionJndiName
|
Constructor Summary | |
---|---|
SqlMap()
Creates new SqlMap |
Method Summary | |
---|---|
void |
addCache(CacheModel cache)
Adds a (named) cache. |
void |
addDataSource(java.lang.String name,
javax.sql.DataSource dataSource)
Adds a named datasource to the list of available datasources |
void |
addExecuteListener(ExecuteListener listener)
|
void |
addMappedStatement(MappedStatement mappedStatement)
Adds a (named) MappedStatement. |
void |
addParameterMap(ParameterMap parameterMap)
Adds a (named) ParameterMap. |
void |
addResultMap(ResultMap resultMap)
Adds a (named) ResultMap |
private void |
closeConnection(java.sql.Connection connection)
|
void |
commitTransaction()
Commits the current transaction |
(package private) void |
decrementExecutionThrottle(java.sql.Connection conn)
|
private void |
decrementTransactionThrottle()
|
void |
endBatch()
Executes a 'batch' of statements as a single transaction |
java.util.List |
executeQueryForList(java.lang.String statementName,
java.lang.Object parameterObject)
Executes the SQL and retuns all rows selected. |
java.util.List |
executeQueryForList(java.lang.String statementName,
java.lang.Object parameterObject,
int skipResults,
int maxResults)
Executes the SQL and retuns all rows selected. |
java.util.Map |
executeQueryForMap(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.String keyProperty)
Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. |
java.util.Map |
executeQueryForMap(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.String keyProperty,
java.lang.String valueProperty)
Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. |
java.lang.Object |
executeQueryForObject(java.lang.String statementName,
java.lang.Object parameterObject)
Executes a MappedStatement that returns a single object |
java.lang.Object |
executeQueryForObject(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.Object resultObject)
Executes a MappedStatement that returns a single object of the type of the resultObject parameter. |
PaginatedList |
executeQueryForPaginatedList(java.lang.String statementName,
java.lang.Object parameterObject,
int pageSize)
Executes the SQL and retuns a subset of the results in a dynamic PaginatedList that can be used to automatically scroll through results from a database table. |
void |
executeQueryWithRowHandler(java.lang.String statementName,
java.lang.Object parameterObject,
RowHandler rowHandler)
Runs a query with a custom object that gets a chance to deal with each row as it is processed. |
int |
executeUpdate(java.lang.String statementName,
java.lang.Object parameterObject)
Executes a update using a MappedStatement and a parameter object |
void |
flushCache()
Flushes all cached objects that belong to this SqlMap |
CacheModel |
getCache(java.lang.String name)
Gets a cache by name |
java.util.Iterator |
getCaches()
Returns an iterator to step through the available caches for the SqlMap |
private java.sql.Connection |
getConnectionFromCurrentDataSource()
|
javax.sql.DataSource |
getCurrentDataSource()
Returns the current data source |
java.lang.String |
getCurrentDataSourceName()
Getter for the current data source name |
java.sql.Connection |
getCurrentLocalConnection()
|
java.lang.String |
getDataCacheStats()
|
javax.sql.DataSource |
getDataSource(java.lang.String name)
Gets a named datasource from the list of available datasources |
java.io.PrintWriter |
getLogWriter()
Deprecated. Use commons-logging |
MappedStatement |
getMappedStatement(java.lang.String name)
Gets a MappedStatement by name |
java.util.Iterator |
getMappedStatementNames()
Returns a Iterator containing the names of the mapped statements owned by this SqlMap |
ParameterMap |
getParameterMap(java.lang.String name)
Gets a ParameterMap by name |
ResultMap |
getResultMap(java.lang.String name)
Gets a ResultMap by name |
java.lang.Double |
getStatementCacheHitRatio()
|
int |
getStatementCacheSize()
Getter for size of statement cache |
StatementFactory |
getStatementFactory()
Getter for the StatementFactory |
(package private) java.sql.PreparedStatement |
getStatementFromBatch(MappedStatement mappedStatement)
|
java.lang.String |
getUserTransactionJndiName()
|
(package private) void |
incrementExecutionThrottle(java.sql.Connection conn)
|
private void |
incrementTransactionThrottle()
|
boolean |
isCacheModelsEnabled()
A flag that determines whether cache models were enabled when this SqlMap was built. |
boolean |
isCachePreparedStatement()
Deprecated. Use getStatementCacheSize() |
boolean |
isDriverHintsEnabled()
Gets the status of whether executions should make use of driver hints for the size of result sets etc. |
boolean |
isInsideBatch()
Flag indicating that we are in the middle of creating or running a batch |
boolean |
isStartTransactionBeforeConnection()
When enabled (default), this property causes transactions to be retrieved within the context of a transaction. |
boolean |
isUseFullyQualifiedStatementNames()
Flag to determine whether fully qualified statement names are being used. |
boolean |
isUseGlobalTransaction()
Returns true if global transaction support is enabled. |
void |
log(java.lang.String s)
Deprecated. Use commons-logging |
(package private) void |
registerStatementWithBatch(MappedStatement mappedStatement,
java.sql.PreparedStatement ps)
|
private java.sql.Connection |
removeCurrentLocalConnection()
|
void |
rollbackTransaction()
Rolls back the current transaction |
void |
setCacheModelsEnabled(boolean cacheModelsEnabled)
This is set by the builder of the SqlMap to flag whether cache models were enabled at the time of configuration. |
void |
setCachePreparedStatement(boolean cachePreparedStatement)
Deprecated. Use setStatementCacheSize(int size) |
void |
setCurrentDataSourceName(java.lang.String currentDataSourceName)
Setter for the current data source |
private void |
setCurrentLocalConnection(java.sql.Connection connection)
|
void |
setDriverHintsEnabled(boolean driverHintsEnabled)
Sets the status of whether executions should make use of driver hints for the size of result sets etc. |
void |
setLogWriter(java.io.PrintWriter logWriter)
Deprecated. Use commons-logging |
void |
setMaxExecute(int limit)
|
void |
setMaxExecutePerConnection(int limit)
|
void |
setMaxTransactions(int limit)
|
void |
setStartTransactionBeforeConnection(boolean startTransactionBeforeConnection)
When enabled (default), this property causes transactions to be retrieved within the context of a transaction. |
void |
setStatementCacheSize(int statementCacheSize)
Setter for size of statement cache |
void |
setUseFullyQualifiedStatementNames(boolean useFullyQualifiedStatementNames)
Sets fully qualified names or not. |
void |
setUseGlobalTransaction(boolean useGlobalTransaction)
Set to true if global transactions are available and should be used. |
void |
setUserTransactionJndiName(java.lang.String userTransactionJndiName)
|
void |
startBatch()
Sets up a 'batch' of update statements to execute using a more efficient call to the database. |
void |
startTransaction()
Starts a new transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.util.Map mappedStatements
private java.util.Map resultMaps
private java.util.Map parameterMaps
private java.util.Map dataSourceMap
private java.lang.String currentDataSourceName
private StatementFactory statementFactory
private boolean useGlobalTransaction
private boolean useFullyQualifiedStatementNames
private boolean driverHintsEnabled
private boolean cacheModelsEnabled
private boolean startTransactionBeforeConnection
private java.lang.String userTransactionJndiName
private JtaTransaction userTransaction
private java.io.PrintWriter logWriter
private java.lang.ThreadLocal localTransaction
private java.lang.ThreadLocal localBatch
private java.util.HashMap cacheMap
private Throttle executePerConnThrottle
private Throttle executeThrottle
private Throttle transactionThrottle
Constructor Detail |
---|
public SqlMap()
Method Detail |
---|
public void setMaxExecutePerConnection(int limit)
public void setMaxExecute(int limit)
public void setMaxTransactions(int limit)
public java.lang.String getUserTransactionJndiName()
public void setUserTransactionJndiName(java.lang.String userTransactionJndiName)
public java.io.PrintWriter getLogWriter()
public void setLogWriter(java.io.PrintWriter logWriter)
logWriter
- The PrintWriter to use for loggingpublic boolean isStartTransactionBeforeConnection()
public void setStartTransactionBeforeConnection(boolean startTransactionBeforeConnection)
startTransactionBeforeConnection
- public void log(java.lang.String s)
s
- The message to logpublic boolean isCacheModelsEnabled()
public void setCacheModelsEnabled(boolean cacheModelsEnabled)
Important: Setting this property to true will not dynamically enable cache models. This will only be set by the builder at build time, as a flag to determine whether caching was enabled.
cacheModelsEnabled
- Will be set by the builder.public boolean isDriverHintsEnabled()
public void setDriverHintsEnabled(boolean driverHintsEnabled)
public boolean isUseGlobalTransaction()
public void setUseGlobalTransaction(boolean useGlobalTransaction)
useGlobalTransaction
- true or false to enable or disable global
transactions respectively.public boolean isUseFullyQualifiedStatementNames()
public void setUseFullyQualifiedStatementNames(boolean useFullyQualifiedStatementNames)
useFullyQualifiedStatementNames
- Set to true by SqlMap builder if statement names are fully qualified,
otherwise set to false.public boolean isCachePreparedStatement()
public void setCachePreparedStatement(boolean cachePreparedStatement)
cachePreparedStatement
- setStatementCacheSize(0) if false.public int getStatementCacheSize()
public void setStatementCacheSize(int statementCacheSize)
statementCacheSize
- New size for the cachepublic java.lang.String getDataCacheStats()
public java.lang.Double getStatementCacheHitRatio()
public void flushCache()
public void addExecuteListener(ExecuteListener listener)
public void addDataSource(java.lang.String name, javax.sql.DataSource dataSource)
name
- The name of the data sourcedataSource
- The data sourcepublic javax.sql.DataSource getDataSource(java.lang.String name)
name
- The name of the data source
public javax.sql.DataSource getCurrentDataSource()
public StatementFactory getStatementFactory()
public MappedStatement getMappedStatement(java.lang.String name)
name
- The name of the statement
public java.util.Iterator getMappedStatementNames()
public void addMappedStatement(MappedStatement mappedStatement)
mappedStatement
- The statement to addpublic CacheModel getCache(java.lang.String name)
name
- The name of the cache to get
public void addCache(CacheModel cache)
cache
- The cache to addpublic java.util.Iterator getCaches()
public ParameterMap getParameterMap(java.lang.String name)
name
- The name of the ParameterMap
public void addParameterMap(ParameterMap parameterMap)
parameterMap
- the ParameterMap to addpublic ResultMap getResultMap(java.lang.String name)
name
- The name of the result map
public void addResultMap(ResultMap resultMap)
resultMap
- The ResultMap to addpublic java.lang.String getCurrentDataSourceName()
public void setCurrentDataSourceName(java.lang.String currentDataSourceName)
currentDataSourceName
- The new current data sourceprivate java.sql.Connection getConnectionFromCurrentDataSource() throws java.sql.SQLException
java.sql.SQLException
private void closeConnection(java.sql.Connection connection) throws java.sql.SQLException
java.sql.SQLException
private void setCurrentLocalConnection(java.sql.Connection connection)
public java.sql.Connection getCurrentLocalConnection()
private java.sql.Connection removeCurrentLocalConnection()
public void startTransaction() throws java.sql.SQLException
java.sql.SQLException
- If a transaction has already been started, or if a database exception is thrown.public void commitTransaction() throws java.sql.SQLException
java.sql.SQLException
- If a database exception is thrown, or no transaction is in progresspublic void rollbackTransaction() throws java.sql.SQLException
java.sql.SQLException
- If a database exception is thrownpublic int executeUpdate(java.lang.String statementName, java.lang.Object parameterObject) throws java.sql.SQLException
statementName
- The name of the MappedStatement to executeparameterObject
- The parameter object used by the MappedStatement
java.sql.SQLException
- If a transaction has not been started, or a database exception is thrownpublic java.lang.Object executeQueryForObject(java.lang.String statementName, java.lang.Object parameterObject) throws java.sql.SQLException
statementName
- The name of the MappedStatementparameterObject
- The parameter object used by the MappedStatement
java.sql.SQLException
- If a transaction is not in progress, or the database throws an exceptionpublic java.lang.Object executeQueryForObject(java.lang.String statementName, java.lang.Object parameterObject, java.lang.Object resultObject) throws java.sql.SQLException
resultObject
- An object of the type to be returnedstatementName
- The name of the MappedStatementparameterObject
- The parameter object used by the MappedStatement
java.sql.SQLException
- If a transaction is not in progress, or the database throws an exceptionpublic java.util.Map executeQueryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty) throws java.sql.SQLException
parameterObject
- The object used to set the parameters in the SQLkeyProperty
- The property of the result object to be used as the key
java.sql.SQLException
- If an exception occurs in the databasepublic java.util.Map executeQueryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty, java.lang.String valueProperty) throws java.sql.SQLException
parameterObject
- The object used to set the parameters in the SQLkeyProperty
- The property of the result object to be used as the keyvalueProperty
- The property of the result object to be used as the value (or null)
java.sql.SQLException
- If an exception occurs in the databasepublic java.util.List executeQueryForList(java.lang.String statementName, java.lang.Object parameterObject) throws java.sql.SQLException
statementName
- The name of the MappedStatement to executeparameterObject
- The object used to set the parameters in the SQL
java.sql.SQLException
- If an exception occurs in the databasepublic java.util.List executeQueryForList(java.lang.String statementName, java.lang.Object parameterObject, int skipResults, int maxResults) throws java.sql.SQLException
statementName
- The name of the MappedStatement to executeparameterObject
- The object used to set the parameters in the SQLskipResults
- The number of rows to skip overmaxResults
- The maximum number of rows to return
java.sql.SQLException
- If an exception occurs in the databasepublic PaginatedList executeQueryForPaginatedList(java.lang.String statementName, java.lang.Object parameterObject, int pageSize) throws java.sql.SQLException
parameterObject
- The object used to set the parameters in the SQLpageSize
- The maximum number of objects to store in each page
java.sql.SQLException
- If an exception occurs in the databasepublic void executeQueryWithRowHandler(java.lang.String statementName, java.lang.Object parameterObject, RowHandler rowHandler) throws java.sql.SQLException
statementName
- The name of the MappedStatement to executeparameterObject
- The parameter object mapped the the statementrowHandler
- The custom row handler object
java.sql.SQLException
- If an exception occurs in the databasepublic void startBatch() throws java.sql.SQLException
java.sql.SQLException
- If the database throws an exceptionpublic void endBatch() throws java.sql.SQLException
java.sql.SQLException
- If the database throws an exceptionpublic boolean isInsideBatch()
private void incrementTransactionThrottle()
private void decrementTransactionThrottle()
void registerStatementWithBatch(MappedStatement mappedStatement, java.sql.PreparedStatement ps)
java.sql.PreparedStatement getStatementFromBatch(MappedStatement mappedStatement)
void incrementExecutionThrottle(java.sql.Connection conn)
void decrementExecutionThrottle(java.sql.Connection conn)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |