01: package com.completex.objective.components.persistency.transact.impl;
02:
03: import com.completex.objective.components.log.Log;
04: import com.completex.objective.components.cache.Cache;
05:
06: import java.sql.PreparedStatement;
07: import java.sql.SQLException;
08: import java.sql.Statement;
09: import java.sql.CallableStatement;
10: import java.sql.Connection;
11:
12: /**
13: * @author Gennady Krizhevsky
14: */
15: public class PrimitiveTransactionImpl extends AbstractTransactionImpl {
16:
17: private Cache statementCache;
18: private Cache callCache;
19: private boolean autoCommit;
20:
21: public PrimitiveTransactionImpl(Connection connection, Log logger,
22: Cache statementCache, Cache callCache) throws SQLException {
23: super (connection, logger);
24: this .statementCache = statementCache;
25: this .callCache = callCache;
26: setAutoCommit(connection.getAutoCommit());
27: connection.setAutoCommit(false);
28: }
29:
30: public PrimitiveTransactionImpl(Connection connection,
31: Cache statementCache, Cache callCache) throws SQLException {
32: this (connection, Log.NULL_LOGGER, statementCache, callCache);
33: }
34:
35: public PreparedStatement prepareStatement(String sql)
36: throws SQLException {
37: return (PreparedStatement) statementCache.acquire(
38: getConnection(), sql);
39: }
40:
41: public void releaseStatement(PreparedStatement statement)
42: throws SQLException {
43: if (statement instanceof CallableStatement) {
44: callCache.release(getConnection(), statement);
45: } else {
46: statementCache.release(getConnection(), statement);
47: }
48: }
49:
50: protected CallableStatement prepareCall(Connection connection,
51: String sql) throws SQLException {
52: return (CallableStatement) callCache.acquire(connection, sql);
53: }
54:
55: public Statement createStatement() throws SQLException {
56: return getConnection().createStatement();
57: }
58:
59: public CallableStatement prepareCall(String sql)
60: throws SQLException {
61: return getConnection().prepareCall(sql);
62: }
63:
64: public boolean isAutoCommit() {
65: return autoCommit;
66: }
67:
68: protected void setAutoCommit(boolean autoCommit) {
69: this .autoCommit = autoCommit;
70: }
71:
72: public void restoreAutoCommit() throws SQLException {
73: getConnection().setAutoCommit(autoCommit);
74: }
75: }
|