1 7 package winstone.jndi.resourceFactories; 8 9 import java.sql.CallableStatement ; 10 import java.sql.Connection ; 11 import java.sql.DatabaseMetaData ; 12 import java.sql.PreparedStatement ; 13 import java.sql.SQLException ; 14 import java.sql.SQLWarning ; 15 import java.sql.Savepoint ; 16 import java.sql.Statement ; 17 import java.util.Map ; 18 19 import winstone.Logger; 20 21 28 public class WinstoneConnection implements Connection { 29 private Connection realConnection; 30 private WinstoneDataSource datasource; 31 32 35 public WinstoneConnection(Connection connection, 36 WinstoneDataSource datasource) { 37 this.realConnection = connection; 38 this.datasource = datasource; 39 } 40 41 public void close() throws SQLException { 42 if ((this.datasource != null) && (this.datasource.getLogWriter() != null)) { 43 this.datasource.getLogWriter().println( 44 WinstoneDataSource.DS_RESOURCES.getString( 45 "WinstoneConnection.ReleaseRollback")); 46 } else { 47 Logger.log(Logger.FULL_DEBUG, WinstoneDataSource.DS_RESOURCES, 48 "WinstoneConnection.ReleaseRollback"); 49 } 50 51 Connection realConnectionHolder = null; 52 try { 53 if (this.realConnection != null) { 54 realConnectionHolder = this.realConnection; 55 this.realConnection = null; 56 57 if (!realConnectionHolder.getAutoCommit()) 58 realConnectionHolder.rollback(); 59 } 60 } finally { 61 if ((this.datasource != null) && (realConnectionHolder != null)) { 62 this.datasource.releaseConnection(this, realConnectionHolder); 63 this.datasource = null; 64 } 65 } 66 } 67 68 public boolean isClosed() throws SQLException { 69 return (this.realConnection == null); 70 } 71 72 public void commit() throws SQLException { 73 this.realConnection.commit(); 74 } 75 76 public void rollback() throws SQLException { 77 this.realConnection.rollback(); 78 } 79 80 public void rollback(Savepoint sp) throws SQLException { 81 this.realConnection.rollback(sp); 82 } 83 84 public boolean getAutoCommit() throws SQLException { 85 return this.realConnection.getAutoCommit(); 86 } 87 88 public void setAutoCommit(boolean autoCommit) throws SQLException { 89 this.realConnection.setAutoCommit(autoCommit); 90 } 91 92 public int getHoldability() throws SQLException { 93 return this.realConnection.getHoldability(); 94 } 95 96 public void setHoldability(int hold) throws SQLException { 97 this.realConnection.setHoldability(hold); 98 } 99 100 public int getTransactionIsolation() throws SQLException { 101 return this.realConnection.getTransactionIsolation(); 102 } 103 104 public void setTransactionIsolation(int level) throws SQLException { 105 this.realConnection.setTransactionIsolation(level); 106 } 107 108 public void clearWarnings() throws SQLException { 109 this.realConnection.clearWarnings(); 110 } 111 112 public SQLWarning getWarnings() throws SQLException { 113 return this.realConnection.getWarnings(); 114 } 115 116 public boolean isReadOnly() throws SQLException { 117 return this.realConnection.isReadOnly(); 118 } 119 120 public void setReadOnly(boolean ro) throws SQLException { 121 this.realConnection.setReadOnly(ro); 122 } 123 124 public String getCatalog() throws SQLException { 125 return this.realConnection.getCatalog(); 126 } 127 128 public void setCatalog(String catalog) throws SQLException { 129 this.realConnection.setCatalog(catalog); 130 } 131 132 public DatabaseMetaData getMetaData() throws SQLException { 133 return this.realConnection.getMetaData(); 134 } 135 136 public Savepoint setSavepoint() throws SQLException { 137 return this.realConnection.setSavepoint(); 138 } 139 140 public Savepoint setSavepoint(String name) throws SQLException { 141 return this.realConnection.setSavepoint(name); 142 } 143 144 public void releaseSavepoint(Savepoint sp) throws SQLException { 145 this.realConnection.releaseSavepoint(sp); 146 } 147 148 public Map getTypeMap() throws SQLException { 149 return this.realConnection.getTypeMap(); 150 } 151 152 public void setTypeMap(Map map) throws SQLException { 153 this.realConnection.setTypeMap(map); 154 } 155 156 public String nativeSQL(String sql) throws SQLException { 157 return this.realConnection.nativeSQL(sql); 158 } 159 160 public CallableStatement prepareCall(String sql) throws SQLException { 161 return this.realConnection.prepareCall(sql); 162 } 163 164 public CallableStatement prepareCall(String sql, int resultSetType, 165 int resultSetConcurrency) throws SQLException { 166 return this.realConnection.prepareCall(sql, resultSetType, 167 resultSetConcurrency); 168 } 169 170 public CallableStatement prepareCall(String sql, int resultSetType, 171 int resultSetConcurrency, int resultSetHoldability) 172 throws SQLException { 173 return this.realConnection.prepareCall(sql, resultSetType, 174 resultSetConcurrency, resultSetHoldability); 175 } 176 177 public Statement createStatement() throws SQLException { 178 return this.realConnection.createStatement(); 179 } 180 181 public Statement createStatement(int resultSetType, int resultSetConcurrency) 182 throws SQLException { 183 return this.realConnection.createStatement(resultSetType, 184 resultSetConcurrency); 185 } 186 187 public Statement createStatement(int resultSetType, 188 int resultSetConcurrency, int resultSetHoldability) 189 throws SQLException { 190 return this.realConnection.createStatement(resultSetType, 191 resultSetConcurrency, resultSetHoldability); 192 } 193 194 public PreparedStatement prepareStatement(String sql) throws SQLException { 195 return this.realConnection.prepareStatement(sql); 196 } 197 198 public PreparedStatement prepareStatement(String sql, int autogeneratedKeys) 199 throws SQLException { 200 return this.realConnection.prepareStatement(sql, autogeneratedKeys); 201 } 202 203 public PreparedStatement prepareStatement(String sql, int resultSetType, 204 int resultSetConcurrency) throws SQLException { 205 return this.realConnection.prepareStatement(sql, resultSetType, 206 resultSetConcurrency); 207 } 208 209 public PreparedStatement prepareStatement(String sql, int resultSetType, 210 int resultSetConcurrency, int resultSetHoldability) 211 throws SQLException { 212 return this.realConnection.prepareStatement(sql, resultSetType, 213 resultSetConcurrency, resultSetHoldability); 214 } 215 216 public PreparedStatement prepareStatement(String sql, int[] columnIndexes) 217 throws SQLException { 218 return this.realConnection.prepareStatement(sql, columnIndexes); 219 } 220 221 public PreparedStatement prepareStatement(String sql, String [] columnNames) 222 throws SQLException { 223 return this.realConnection.prepareStatement(sql, columnNames); 224 } 225 } 226 | Popular Tags |