1 55 package org.lateralnz.c3d; 56 57 import java.io.Serializable ; 58 import java.sql.CallableStatement ; 59 import java.sql.Connection ; 60 import java.sql.DatabaseMetaData ; 61 import java.sql.PreparedStatement ; 62 import java.sql.Savepoint ; 63 import java.sql.SQLException ; 64 import java.sql.SQLWarning ; 65 import java.sql.Statement ; 66 import java.util.Map ; 67 68 import org.apache.log4j.Logger; 69 70 import org.lateralnz.common.util.DAOUtils; 71 72 80 public class DCConnection implements Connection , Serializable { 81 private static final Logger log = Logger.getLogger(DCConnection.class.getName()); 82 83 private boolean autocommit = false; 84 private boolean closed = false; 85 protected boolean blockCache = false; 86 private Connection conn; 87 private DatabaseEngine dbengine; 88 89 public DCConnection(Connection conn, DatabaseEngine dbengine) throws SQLException { 90 this.conn = conn; 91 this.dbengine = dbengine; 92 } 93 94 protected Connection getRealConnection() { 95 return conn; 96 } 97 98 DatabaseEngine getDatabaseEngine() { 99 return dbengine; 100 } 101 102 public void clearWarnings() throws SQLException { 103 conn.clearWarnings(); 104 } 105 106 public void close() throws SQLException { 107 blockCache = false; 108 dbengine.commit(this); 109 DAOUtils.close(conn); 110 closed = true; 111 } 112 113 public void commit() throws SQLException { 114 boolean commit = true; 115 blockCache = false; 116 117 try { 118 conn.commit(); 119 } 120 catch (SQLException se) { 121 commit = false; 122 throw se; 123 } 124 finally { 125 if (commit) { 126 dbengine.commit(this); 127 } 128 else { 129 dbengine.rollback(this); 130 } 131 } 132 } 133 134 public Statement createStatement() throws SQLException { 135 return createStatement(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); 136 } 137 138 public Statement createStatement(int resultsetType, int resultsetConcurrency) throws SQLException { 139 return createStatement(resultsetType, resultsetConcurrency, Integer.MIN_VALUE); 140 } 141 142 public Statement createStatement(int resultsetType, int resultsetConcurrency, int resultsetHoldability) throws SQLException { 143 return new DCStatement(this, resultsetType, resultsetConcurrency, resultsetHoldability); 144 } 145 146 public void finalize() throws SQLException { 147 close(); 148 } 149 150 public boolean getAutoCommit() throws SQLException { 151 return conn.getAutoCommit(); 152 } 153 154 public String getCatalog() throws SQLException { 155 return conn.getCatalog(); 156 } 157 158 public int getHoldability() throws SQLException { 159 return conn.getHoldability(); 160 } 161 162 public DatabaseMetaData getMetaData() throws SQLException { 163 return conn.getMetaData(); 164 } 165 166 public int getTransactionIsolation() throws SQLException { 167 return conn.getTransactionIsolation(); 168 } 169 170 public Map getTypeMap() throws SQLException { 171 return conn.getTypeMap(); 172 } 173 174 public SQLWarning getWarnings() throws SQLException { 175 return conn.getWarnings(); 176 } 177 178 public boolean isClosed() throws SQLException { 179 return closed; 180 } 181 182 public boolean isReadOnly() throws SQLException { 183 return conn.isReadOnly(); 184 } 185 186 public String nativeSQL(String str) throws SQLException { 187 throw new SQLException ("operation not supported"); 188 } 189 190 public CallableStatement prepareCall(String str) throws SQLException { 191 return conn.prepareCall(str); 192 } 194 195 public CallableStatement prepareCall(String str, int resultsetType, int resultsetConcurrency) throws SQLException { 196 return conn.prepareCall(str, resultsetType, resultsetConcurrency); 197 } 199 200 public CallableStatement prepareCall(String str, int resultsetType, int resultsetConcurrency, int resultsetHoldability) throws SQLException { 201 return conn.prepareCall(str, resultsetType, resultsetConcurrency, resultsetHoldability); 202 } 204 205 public PreparedStatement prepareStatement(String str) throws SQLException { 206 return new DCPreparedStatement(this, str, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, null, null); 207 } 208 209 public PreparedStatement prepareStatement(String str, int autoGeneratedKeys) throws SQLException { 210 return new DCPreparedStatement(this, str, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, autoGeneratedKeys, null, null); 211 } 212 213 public PreparedStatement prepareStatement(String str, int[] columnIndexes) throws SQLException { 214 return new DCPreparedStatement(this, str, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, columnIndexes, null); 215 } 216 217 public PreparedStatement prepareStatement(String str, String [] columnNames) throws SQLException { 218 return new DCPreparedStatement(this, str, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, null, columnNames); 219 } 220 221 public PreparedStatement prepareStatement(String str, int resultsetType, int resultsetConcurrency) throws SQLException { 222 return new DCPreparedStatement(this, str, resultsetType, resultsetConcurrency, Integer.MIN_VALUE, Integer.MIN_VALUE, null, null); 223 } 224 225 public PreparedStatement prepareStatement(String str, int resultsetType, int resultsetConcurrency, int resultsetHoldability) throws SQLException { 226 return new DCPreparedStatement(this, str, resultsetType, resultsetConcurrency, resultsetHoldability, Integer.MIN_VALUE, null, null); 227 } 228 229 public void releaseSavepoint(Savepoint savepoint) throws SQLException { 230 throw new SQLException ("operation not supported"); 231 } 232 233 public void rollback() throws SQLException { 234 blockCache = false; 235 try { 236 conn.rollback(); 237 } 238 finally { 239 dbengine.rollback(this); 240 } 241 } 242 243 246 public void rollback(Savepoint savepoint) throws SQLException { 247 throw new SQLException ("operation not supported"); 248 } 249 250 public void setAutoCommit(boolean param) throws SQLException { 251 this.autocommit = param; 252 conn.setAutoCommit(param); 253 } 254 255 public void setCatalog(String str) throws SQLException { 256 conn.setCatalog(str); 257 } 258 259 public void setHoldability(int param) throws SQLException { 260 conn.setHoldability(param); 261 } 262 263 public void setReadOnly(boolean param) throws SQLException { 264 conn.setReadOnly(param); 265 } 266 267 public Savepoint setSavepoint() throws SQLException { 268 throw new SQLException ("operation not supported"); 269 } 270 271 public Savepoint setSavepoint(String str) throws SQLException { 272 throw new SQLException ("operation not supported"); 273 } 274 275 public void setTransactionIsolation(int param) throws SQLException { 276 conn.setTransactionIsolation(param); 277 } 278 279 public void setTypeMap(Map map) throws SQLException { 280 conn.setTypeMap(map); 281 } 282 283 } | Popular Tags |