com.ibatis.sqlmap.client
public interface SqlMapClient extends SqlMapExecutor, SqlMapTransactionManager
//
// autocommit simple query --these are just examples...not patterns
//
Employee emp = (Employee) sqlMap.queryForObject("getEmployee", new Integer(1));
//
// transaction --these are just examples...not patterns
//
try {
sqlMap.startTransaction()
Employee emp2 = new Employee();
// ...set emp2 data
Integer generatedKey = (Integer) sqlMap.insert ("insertEmployee", emp2);
emp2.setFavouriteColour ("green");
sqlMap.update("updateEmployee", emp2);
sqlMap.commitTransaction();
} finally {
sqlMap.endTransaction();
}
//
// session --these are just examples...not patterns
//
try {
SqlMapSession session = sqlMap.openSession()
session.startTransaction()
Employee emp2 = new Employee();
// ...set emp2 data
Integer generatedKey = (Integer) session.insert ("insertEmployee", emp2);
emp2.setFavouriteColour ("green");
session.update("updateEmployee", emp2);
session.commitTransaction();
} finally {
try {
session.endTransaction();
} finally {
session.close();
}
// Generally your session scope would be in a wider context and therefore the
// ugly nested finally block above would not be there. Realize that sessions
// MUST be closed if explicitly opened (via openSession()).
}
//
// batch --these are just examples...not patterns
//
try {
sqlMap.startTransaction()
List list = (Employee) sqlMap.queryForList("getFiredEmployees", null);
sqlMap.startBatch ();
for (int i=0, n=list.size(); i < n; i++) {
sqlMap.delete ("deleteEmployee", list.get(i));
}
sqlMap.executeBatch();
sqlMap.commitTransaction();
} finally {
sqlMap.endTransaction();
}
See Also: SqlMapClientBuilder SqlMapSession SqlMapExecutor
| Method Summary | |
|---|---|
| void | flushDataCache()
Flushes all data caches. |
| void | flushDataCache(String cacheId)
Flushes the data cache that matches the cache model ID provided.
|
| SqlMapSession | getSession()
TODO : Deprecated and will be removed.
|
| SqlMapSession | openSession()
Returns a single threaded SqlMapSession implementation for use by
one user. |
| SqlMapSession | openSession(Connection conn)
Returns a single threaded SqlMapSession implementation for use by
one user. |
Parameters: cacheId The cache model to flush
Deprecated: Use openSession() instead. THIS METHOD WILL BE REMOVED BEFORE FINAL RELEASE.
TODO : Deprecated and will be removed.Returns: A session (DEPRECATED)
Returns: An SqlMapSession instance.
try {
Connection connection = dataSource.getConnection();
SqlMapSession session = sqlMap.openSession(connection);
// do work
connection.commit();
} catch (SQLException e) {
try {
if (connection != null) commit.rollback();
} catch (SQLException ignored) {
// generally ignored
}
throw e; // rethrow the exception
} finally {
try {
if (connection != null) connection.close();
} catch (SQLException ignored) {
// generally ignored
}
}
Parameters: conn - the connection to use for the session
Returns: An SqlMapSession instance.