1 45 package org.openejb.resource.jdbc; 46 47 import java.sql.CallableStatement ; 48 import java.sql.DatabaseMetaData ; 49 import java.sql.PreparedStatement ; 50 import java.sql.SQLException ; 51 import java.sql.SQLWarning ; 52 import java.sql.Statement ; 53 54 public class JdbcConnection implements java.sql.Connection { 55 private java.sql.Connection physicalConn; 56 private JdbcManagedConnection managedConn; 57 protected boolean isClosed = false; 58 59 protected JdbcConnection(JdbcManagedConnection managedConn, java.sql.Connection physicalConn){ 60 this.physicalConn = physicalConn; 61 this.managedConn = managedConn; 62 } 63 protected java.sql.Connection getPhysicalConnection(){ 64 return physicalConn; 65 } 66 protected JdbcManagedConnection getManagedConnection(){ 67 return managedConn; 68 } 69 74 protected void invalidate(){ 75 isClosed = true; 76 physicalConn = null; 77 managedConn = null; 78 } 79 protected void associate(JdbcManagedConnection mngdConn){ 80 isClosed = false; 81 managedConn = mngdConn; 82 physicalConn = mngdConn.getSQLConnection(); 83 } 84 public Statement createStatement() throws SQLException { 85 if(isClosed) throw new SQLException ("Connection is closed"); 86 try{ 87 synchronized(physicalConn){ 88 return physicalConn.createStatement(); 89 } 90 }catch(SQLException sqlE){ 91 managedConn.connectionErrorOccurred(this, sqlE); 92 throw sqlE; 93 } 94 } 95 public PreparedStatement prepareStatement(String sql) 96 throws SQLException { 97 if(isClosed) throw new SQLException ("Connection is closed"); 98 try{ 99 synchronized(physicalConn){ 100 return physicalConn.prepareStatement(sql); 101 } 102 }catch(SQLException sqlE){ 103 managedConn.connectionErrorOccurred(this, sqlE); 104 throw sqlE; 105 } 106 } 107 public CallableStatement prepareCall(String sql) throws SQLException { 108 if(isClosed) throw new SQLException ("Connection is closed"); 109 try{ 110 synchronized(physicalConn){ 111 return physicalConn.prepareCall(sql); 112 } 113 }catch(SQLException sqlE){ 114 managedConn.connectionErrorOccurred(this, sqlE); 115 throw sqlE; 116 } 117 } 118 public String nativeSQL(String sql) throws SQLException { 119 if(isClosed) throw new SQLException ("Connection is closed"); 120 try{ 121 synchronized(physicalConn){ 122 return physicalConn.nativeSQL(sql); 123 } 124 }catch(SQLException sqlE){ 125 managedConn.connectionErrorOccurred(this, sqlE); 126 throw sqlE; 127 } 128 } 129 public void setAutoCommit(boolean autoCommit) throws SQLException { 130 throw new java.sql.SQLException ("Method not supported. Commit is managed automatically by container provider"); 131 } 132 public boolean getAutoCommit() throws SQLException { 133 throw new java.sql.SQLException ("Method not supported. Commit is managed automatically by container provider"); 134 } 135 public void commit() throws SQLException { 136 throw new java.sql.SQLException ("Method not supported. Commit is managed automatically by container provider"); 137 } 138 public void rollback() throws SQLException { 139 throw new java.sql.SQLException ("Method not supported. Rollback is managed automatically by container provider"); 140 } 141 public void close() throws SQLException { 142 if(isClosed) 143 return; 144 else{ 145 managedConn.connectionClose(this); 148 } 149 } 150 public boolean isClosed() throws SQLException { 151 return isClosed; 152 } 153 public DatabaseMetaData getMetaData() throws SQLException { 154 if(isClosed) throw new SQLException ("Connection is closed"); 155 try{ 156 synchronized(physicalConn){ 157 return physicalConn.getMetaData(); 158 } 159 }catch(SQLException sqlE){ 160 managedConn.connectionErrorOccurred(this, sqlE); 161 throw sqlE; 162 } 163 } 164 public void setReadOnly(boolean readOnly) throws SQLException { 165 if(isClosed) throw new SQLException ("Connection is closed"); 166 try{ 167 synchronized(physicalConn){ 168 physicalConn.setReadOnly(readOnly); 169 } 170 }catch(SQLException sqlE){ 171 managedConn.connectionErrorOccurred(this, sqlE); 172 throw sqlE; 173 } 174 } 175 public boolean isReadOnly() throws SQLException { 176 if(isClosed) throw new SQLException ("Connection is closed"); 177 try{ 178 synchronized(physicalConn){ 179 return physicalConn.isReadOnly(); 180 } 181 }catch(SQLException sqlE){ 182 managedConn.connectionErrorOccurred(this, sqlE); 183 throw sqlE; 184 } 185 } 186 public void setCatalog(String catalog) throws SQLException { 187 if(isClosed) throw new SQLException ("Connection is closed"); 188 try{ 189 synchronized(physicalConn){ 190 physicalConn.setCatalog(catalog); 191 } 192 }catch(SQLException sqlE){ 193 managedConn.connectionErrorOccurred(this, sqlE); 194 throw sqlE; 195 } 196 } 197 public String getCatalog() throws SQLException { 198 if(isClosed) throw new SQLException ("Connection is closed"); 199 try{ 200 synchronized(physicalConn){ 201 return physicalConn.getCatalog(); 202 } 203 }catch(SQLException sqlE){ 204 managedConn.connectionErrorOccurred(this, sqlE); 205 throw sqlE; 206 } 207 } 208 public void setTransactionIsolation(int level) throws SQLException { 209 if(isClosed) throw new SQLException ("Connection is closed"); 210 try{ 211 synchronized(physicalConn){ 212 physicalConn.setTransactionIsolation(level); 213 } 214 }catch(SQLException sqlE){ 215 managedConn.connectionErrorOccurred(this, sqlE); 216 throw sqlE; 217 } 218 } 219 public int getTransactionIsolation() throws SQLException { 220 if(isClosed) throw new SQLException ("Connection is closed"); 221 try{ 222 synchronized(physicalConn){ 223 return physicalConn.getTransactionIsolation(); 224 } 225 }catch(SQLException sqlE){ 226 managedConn.connectionErrorOccurred(this, sqlE); 227 throw sqlE; 228 } 229 } 230 public SQLWarning getWarnings() throws SQLException { 231 if(isClosed) throw new SQLException ("Connection is closed"); 232 try{ 233 synchronized(physicalConn){ 234 return physicalConn.getWarnings(); 235 } 236 }catch(SQLException sqlE){ 237 managedConn.connectionErrorOccurred(this, sqlE); 238 throw sqlE; 239 } 240 } 241 public void clearWarnings() throws SQLException { 242 if(isClosed) throw new SQLException ("Connection is closed"); 243 try{ 244 synchronized(physicalConn){ 245 physicalConn.clearWarnings(); 246 } 247 }catch(SQLException sqlE){ 248 managedConn.connectionErrorOccurred(this, sqlE); 249 throw sqlE; 250 } 251 } 252 public Statement createStatement(int resultSetType, int resultSetConcurrency) 253 throws SQLException { 254 if(isClosed) throw new SQLException ("Connection is closed"); 255 try{ 256 synchronized(physicalConn){ 257 return physicalConn.createStatement(resultSetType, resultSetConcurrency); 258 } 259 }catch(SQLException sqlE){ 260 managedConn.connectionErrorOccurred(this, sqlE); 261 throw sqlE; 262 } 263 } 264 public PreparedStatement prepareStatement(String sql, int resultSetType,int resultSetConcurrency) 265 throws SQLException { 266 if(isClosed) throw new SQLException ("Connection is closed"); 267 try{ 268 synchronized(physicalConn){ 269 return physicalConn.prepareStatement(sql, resultSetType,resultSetConcurrency); 270 } 271 }catch(SQLException sqlE){ 272 managedConn.connectionErrorOccurred(this, sqlE); 273 throw sqlE; 274 } 275 } 276 public CallableStatement prepareCall(String sql, int resultSetType,int resultSetConcurrency) throws SQLException { 277 if(isClosed) throw new SQLException ("Connection is closed"); 278 try{ 279 synchronized(physicalConn){ 280 return physicalConn.prepareCall(sql, resultSetType,resultSetConcurrency) ; 281 } 282 }catch(SQLException sqlE){ 283 managedConn.connectionErrorOccurred(this, sqlE); 284 throw sqlE; 285 } 286 } 287 public java.util.Map getTypeMap() throws SQLException { 288 if(isClosed) throw new SQLException ("Connection is closed"); 289 try{ 290 synchronized(physicalConn){ 291 return physicalConn.getTypeMap(); 292 } 293 }catch(SQLException sqlE){ 294 managedConn.connectionErrorOccurred(this, sqlE); 295 throw sqlE; 296 } 297 } 298 public void setTypeMap(java.util.Map map) throws SQLException { 299 if(isClosed) throw new SQLException ("Connection is closed"); 300 try{ 301 synchronized(physicalConn){ 302 physicalConn.setTypeMap(map); 303 } 304 }catch(SQLException sqlE){ 305 managedConn.connectionErrorOccurred(this, sqlE); 306 throw sqlE; 307 } 308 } 309 310 313 public void setHoldability(int holdability) throws java.sql.SQLException { 314 throw new SQLException ("method setHoldability not implemented"); 315 } 316 public int getHoldability() throws java.sql.SQLException { 317 throw new SQLException ("method getHoldability not implemented"); 318 } 319 public java.sql.Savepoint setSavepoint() throws java.sql.SQLException { 320 throw new SQLException ("method not implemented"); 321 } 322 public java.sql.Savepoint setSavepoint(String name) throws java.sql.SQLException { 323 throw new SQLException ("method not implemented"); 324 } 325 public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException { 326 throw new SQLException ("method not implemented"); 327 } 328 public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException { 329 throw new SQLException ("method not implemented"); 330 } 331 public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException { 332 throw new SQLException ("method not implemented"); 333 } 334 public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException { 335 throw new SQLException ("method not implemented"); 336 } 337 public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws java.sql.SQLException { 338 throw new SQLException ("method not implemented"); 339 } 340 public java.sql.PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws java.sql.SQLException { 341 throw new SQLException ("method not implemented"); 342 } 343 public java.sql.PreparedStatement prepareStatement(String sql, String [] columnNames) throws java.sql.SQLException { 344 throw new SQLException ("method not implemented"); 345 } 346 public java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException { 347 throw new SQLException ("method not implemented"); 348 } 349 } 350 351 352 353 354 | Popular Tags |