1 21 22 package org.apache.derby.client.am; 23 import org.apache.derby.shared.common.reference.SQLState; 24 25 import java.sql.SQLException ; 26 27 28 36 public class LogicalConnection implements java.sql.Connection { 37 protected Connection physicalConnection_ = null; private org.apache.derby.client.ClientPooledConnection pooledConnection_ = null; 39 40 public LogicalConnection(Connection physicalConnection, 41 org.apache.derby.client.ClientPooledConnection pooledConnection) throws SqlException { 42 physicalConnection_ = physicalConnection; 43 pooledConnection_ = pooledConnection; 44 try { 45 checkForNullPhysicalConnection(); 46 } catch ( SQLException se ) { 47 throw new SqlException(se); 48 } 49 } 50 51 protected void finalize() throws java.lang.Throwable { 52 close(); 53 } 54 55 synchronized public void nullPhysicalConnection() { 57 physicalConnection_ = null; 58 } 59 60 63 synchronized public void close() throws SQLException { 64 try 65 { 66 if (physicalConnection_ == null) { 68 return; 69 } 70 if (physicalConnection_.agent_.loggingEnabled()) { 71 physicalConnection_.agent_.logWriter_.traceEntry(this, "close"); 72 } 73 74 if (physicalConnection_.isClosed()) { 76 pooledConnection_.trashConnection(new SqlException(null, 77 new ClientMessageId( 78 SQLState.PHYSICAL_CONNECTION_ALREADY_CLOSED))); 79 } else { 80 physicalConnection_.closeForReuse(); 81 if (!physicalConnection_.isGlobalPending_()) { 82 pooledConnection_.recycleConnection(); 83 } 84 } 85 physicalConnection_ = null; 86 pooledConnection_.nullLogicalConnection(); 87 } 88 catch ( SqlException se ) 89 { 90 throw se.getSQLException(); 91 } 92 } 93 94 synchronized public void closeWithoutRecyclingToPool() throws SqlException { 95 if (physicalConnection_ == null) { 96 return; 97 } 98 physicalConnection_.checkForTransactionInProgress(); 99 try { 100 if (physicalConnection_.isClosed()) { 102 throw new SqlException(null, 103 new ClientMessageId(SQLState.NO_CURRENT_CONNECTION)); } else { 105 ; } 107 } finally { 108 physicalConnection_.closeForReuse(); physicalConnection_ = null; 110 } 111 } 112 113 public boolean isClosed() throws SQLException { 114 if (physicalConnection_ == null) { 115 return true; 116 } 117 return physicalConnection_.isClosed(); 118 } 119 120 122 125 protected void checkForNullPhysicalConnection() throws SQLException { 126 if (physicalConnection_ == null) { 127 SqlException se = new SqlException(null, 128 new ClientMessageId(SQLState.NO_CURRENT_CONNECTION)); 129 throw se.getSQLException(); 130 } 131 } 132 133 136 synchronized public java.sql.Statement createStatement() throws SQLException { 137 checkForNullPhysicalConnection(); 138 return physicalConnection_.createStatement(); 139 } 140 141 synchronized public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException { 142 checkForNullPhysicalConnection(); 143 return physicalConnection_.prepareStatement(sql); 144 } 145 146 synchronized public PreparedStatement preparePositionedUpdateStatement(String sql, Section querySection) throws SqlException { 147 try { 148 checkForNullPhysicalConnection(); 149 } catch ( SQLException se ) { 150 throw new SqlException(se); 151 } 152 return physicalConnection_.preparePositionedUpdateStatement(sql, querySection); 153 } 154 155 synchronized public java.sql.CallableStatement prepareCall(String sql) throws SQLException { 156 checkForNullPhysicalConnection(); 157 return physicalConnection_.prepareCall(sql); 158 } 159 160 public String nativeSQL(String sql) throws SQLException { 161 checkForNullPhysicalConnection(); 162 return physicalConnection_.nativeSQL(sql); 163 } 164 165 synchronized public void setAutoCommit(boolean autoCommit) throws SQLException { 166 checkForNullPhysicalConnection(); 167 physicalConnection_.setAutoCommit(autoCommit); 168 } 169 170 public boolean getAutoCommit() throws SQLException { 171 checkForNullPhysicalConnection(); 172 return physicalConnection_.getAutoCommit(); 173 } 174 175 synchronized public void commit() throws SQLException { 176 checkForNullPhysicalConnection(); 177 physicalConnection_.commit(); 178 } 179 180 synchronized public void rollback() throws SQLException { 181 checkForNullPhysicalConnection(); 182 physicalConnection_.rollback(); 183 } 184 185 synchronized public void setTransactionIsolation(int level) throws SQLException { 186 checkForNullPhysicalConnection(); 187 physicalConnection_.setTransactionIsolation(level); 188 } 189 190 public int getTransactionIsolation() throws SQLException { 191 checkForNullPhysicalConnection(); 192 return physicalConnection_.getTransactionIsolation(); 193 } 194 195 public java.sql.SQLWarning getWarnings() throws SQLException { 196 checkForNullPhysicalConnection(); 197 return physicalConnection_.getWarnings(); 198 } 199 200 synchronized public void clearWarnings() throws SQLException { 201 checkForNullPhysicalConnection(); 202 physicalConnection_.clearWarnings(); 203 } 204 205 public java.sql.DatabaseMetaData getMetaData() throws SQLException { 206 checkForNullPhysicalConnection(); 207 return physicalConnection_.getMetaData(); 208 } 209 210 synchronized public void setReadOnly(boolean readOnly) throws SQLException { 211 checkForNullPhysicalConnection(); 212 physicalConnection_.setReadOnly(readOnly); 213 } 214 215 public boolean isReadOnly() throws SQLException { 216 checkForNullPhysicalConnection(); 217 return physicalConnection_.isReadOnly(); 218 } 219 220 synchronized public void setCatalog(String catalog) throws SQLException { 221 checkForNullPhysicalConnection(); 222 physicalConnection_.setCatalog(catalog); 223 } 224 225 public String getCatalog() throws SQLException { 226 checkForNullPhysicalConnection(); 227 return physicalConnection_.getCatalog(); 228 } 229 230 synchronized public java.sql.Statement createStatement(int resultSetType, 231 int resultSetConcurrency) throws SQLException { 232 checkForNullPhysicalConnection(); 233 return physicalConnection_.createStatement(resultSetType, resultSetConcurrency); 234 } 235 236 synchronized public java.sql.PreparedStatement prepareStatement(String sql, 237 int resultSetType, 238 int resultSetConcurrency) throws SQLException { 239 checkForNullPhysicalConnection(); 240 return physicalConnection_.prepareStatement(sql, resultSetType, resultSetConcurrency); 241 } 242 243 synchronized public java.sql.CallableStatement prepareCall(String sql, 244 int resultSetType, 245 int resultSetConcurrency) throws SQLException { 246 checkForNullPhysicalConnection(); 247 return physicalConnection_.prepareCall(sql, resultSetType, resultSetConcurrency); 248 } 249 250 public java.util.Map getTypeMap() throws SQLException { 251 checkForNullPhysicalConnection(); 252 return physicalConnection_.getTypeMap(); 253 } 254 255 synchronized public void setTypeMap(java.util.Map map) throws SQLException { 256 checkForNullPhysicalConnection(); 257 physicalConnection_.setTypeMap(map); 258 } 259 260 public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, 261 int resultSetHoldability) throws SQLException { 262 checkForNullPhysicalConnection(); 263 return physicalConnection_.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 264 } 265 266 public java.sql.CallableStatement prepareCall(String sql, int resultSetType, 267 int resultSetConcurrency, 268 int resultSetHoldability) throws SQLException { 269 checkForNullPhysicalConnection(); 270 return physicalConnection_.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 271 } 272 273 public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, 274 int resultSetConcurrency, int resultSetHoldability) 275 throws SQLException { 276 checkForNullPhysicalConnection(); 277 return physicalConnection_.prepareStatement(sql, resultSetType, resultSetConcurrency, 278 resultSetHoldability); 279 } 280 281 public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) 282 throws SQLException { 283 checkForNullPhysicalConnection(); 284 return physicalConnection_.prepareStatement(sql, autoGeneratedKeys); 285 } 286 287 public java.sql.PreparedStatement prepareStatement(String sql, int columnIndexes[]) 288 throws SQLException { 289 checkForNullPhysicalConnection(); 290 return physicalConnection_.prepareStatement(sql, columnIndexes); 291 } 292 293 public java.sql.PreparedStatement prepareStatement(String sql, String columnNames[]) 294 throws SQLException { 295 checkForNullPhysicalConnection(); 296 return physicalConnection_.prepareStatement(sql, columnNames); 297 } 298 299 public void setHoldability(int holdability) throws SQLException { 300 checkForNullPhysicalConnection(); 301 physicalConnection_.setHoldability(holdability); 302 } 303 304 public int getHoldability() throws SQLException { 305 checkForNullPhysicalConnection(); 306 return physicalConnection_.getHoldability(); 307 } 308 309 public java.sql.Savepoint setSavepoint() throws SQLException { 310 checkForNullPhysicalConnection(); 311 return physicalConnection_.setSavepoint(); 312 } 313 314 public java.sql.Savepoint setSavepoint(String name) throws SQLException { 315 checkForNullPhysicalConnection(); 316 return physicalConnection_.setSavepoint(name); 317 } 318 319 public void rollback(java.sql.Savepoint savepoint) throws SQLException { 320 checkForNullPhysicalConnection(); 321 physicalConnection_.rollback(savepoint); 322 } 323 324 public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException { 325 checkForNullPhysicalConnection(); 326 physicalConnection_.releaseSavepoint(savepoint); 327 } 328 329 331 public int getServerVersion() { 332 if (physicalConnection_ == null) { 333 return -1; 334 } else { 335 return physicalConnection_.getServerVersion(); 336 } 337 } 338 339 } 340 | Popular Tags |