001: package liquibase.database;
002:
003: import java.sql.*;
004: import java.util.Map;
005:
006: /**
007: * A ConnectionWrapper implementation which delegates completely to an
008: * underlying java.sql.connection.
009: *
010: * @author <a href="mailto:csuml@yahoo.co.uk">Paul Keeble</a>
011: */
012: public class SQLConnectionDelegate implements DatabaseConnection {
013: java.sql.Connection con;
014:
015: public SQLConnectionDelegate(java.sql.Connection connection) {
016: this .con = connection;
017: }
018:
019: /**
020: * Returns the connection that this Delegate is using.
021: *
022: * @return The connection originally passed in the constructor
023: */
024: public Connection getWrappedConnection() {
025: return con;
026: }
027:
028: public void clearWarnings() throws SQLException {
029: con.clearWarnings();
030: }
031:
032: public void close() throws SQLException {
033: con.rollback();
034: con.close();
035: }
036:
037: public void commit() throws SQLException {
038: if (!con.getAutoCommit()) {
039: con.commit();
040: }
041: }
042:
043: public Statement createStatement() throws SQLException {
044: return con.createStatement();
045: }
046:
047: public Statement createStatement(int resultSetType,
048: int resultSetConcurrency, int resultSetHoldability)
049: throws SQLException {
050: return con.createStatement(resultSetType, resultSetConcurrency,
051: resultSetHoldability);
052: }
053:
054: public Statement createStatement(int resultSetType,
055: int resultSetConcurrency) throws SQLException {
056: return con.createStatement(resultSetType, resultSetConcurrency);
057: }
058:
059: public boolean getAutoCommit() throws SQLException {
060: return con.getAutoCommit();
061: }
062:
063: public String getCatalog() throws SQLException {
064: return con.getCatalog();
065: }
066:
067: public int getHoldability() throws SQLException {
068: return con.getHoldability();
069: }
070:
071: public DatabaseMetaData getMetaData() throws SQLException {
072: return con.getMetaData();
073: }
074:
075: public int getTransactionIsolation() throws SQLException {
076: return con.getTransactionIsolation();
077: }
078:
079: public Map<String, Class<?>> getTypeMap() throws SQLException {
080: return con.getTypeMap();
081: }
082:
083: public SQLWarning getWarnings() throws SQLException {
084: return con.getWarnings();
085: }
086:
087: public boolean isClosed() throws SQLException {
088: return con.isClosed();
089: }
090:
091: public boolean isReadOnly() throws SQLException {
092: return con.isReadOnly();
093: }
094:
095: public String nativeSQL(String sql) throws SQLException {
096: return con.nativeSQL(sql);
097: }
098:
099: public CallableStatement prepareCall(String sql, int resultSetType,
100: int resultSetConcurrency, int resultSetHoldability)
101: throws SQLException {
102: return con.prepareCall(sql, resultSetType,
103: resultSetConcurrency, resultSetHoldability);
104: }
105:
106: public CallableStatement prepareCall(String sql, int resultSetType,
107: int resultSetConcurrency) throws SQLException {
108: return con
109: .prepareCall(sql, resultSetType, resultSetConcurrency);
110: }
111:
112: public CallableStatement prepareCall(String sql)
113: throws SQLException {
114: return con.prepareCall(sql);
115: }
116:
117: public PreparedStatement prepareStatement(String sql,
118: int resultSetType, int resultSetConcurrency,
119: int resultSetHoldability) throws SQLException {
120: return con.prepareStatement(sql, resultSetType,
121: resultSetConcurrency, resultSetHoldability);
122: }
123:
124: public PreparedStatement prepareStatement(String sql,
125: int resultSetType, int resultSetConcurrency)
126: throws SQLException {
127: return con.prepareStatement(sql, resultSetType,
128: resultSetConcurrency);
129: }
130:
131: public PreparedStatement prepareStatement(String sql,
132: int autoGeneratedKeys) throws SQLException {
133: return con.prepareStatement(sql, autoGeneratedKeys);
134: }
135:
136: public PreparedStatement prepareStatement(String sql,
137: int[] columnIndexes) throws SQLException {
138: return con.prepareStatement(sql, columnIndexes);
139: }
140:
141: public PreparedStatement prepareStatement(String sql,
142: String[] columnNames) throws SQLException {
143: return con.prepareStatement(sql, columnNames);
144: }
145:
146: public PreparedStatement prepareStatement(String sql)
147: throws SQLException {
148: return con.prepareStatement(sql);
149: }
150:
151: public void releaseSavepoint(Savepoint savepoint)
152: throws SQLException {
153: con.releaseSavepoint(savepoint);
154: }
155:
156: public void rollback() throws SQLException {
157: con.rollback();
158: }
159:
160: public void rollback(Savepoint savepoint) throws SQLException {
161: con.rollback(savepoint);
162: }
163:
164: public void setAutoCommit(boolean autoCommit) throws SQLException {
165: con.setAutoCommit(autoCommit);
166: }
167:
168: public void setCatalog(String catalog) throws SQLException {
169: con.setCatalog(catalog);
170: }
171:
172: public void setHoldability(int holdability) throws SQLException {
173: con.setHoldability(holdability);
174: }
175:
176: public void setReadOnly(boolean readOnly) throws SQLException {
177: con.setReadOnly(readOnly);
178: }
179:
180: public Savepoint setSavepoint() throws SQLException {
181: return con.setSavepoint();
182: }
183:
184: public Savepoint setSavepoint(String name) throws SQLException {
185: return con.setSavepoint(name);
186: }
187:
188: public void setTransactionIsolation(int level) throws SQLException {
189: con.setTransactionIsolation(level);
190: }
191:
192: public void setTypeMap(Map<String, Class<?>> map)
193: throws SQLException {
194: con.setTypeMap(map);
195: }
196:
197: public Connection getUnderlyingConnection() {
198: return con;
199: }
200:
201: public boolean equals(Object obj) {
202: if (!(obj instanceof SQLConnectionDelegate)) {
203: return false;
204: }
205:
206: SQLConnectionDelegate otherObj = (SQLConnectionDelegate) obj;
207: try {
208: return this .getUnderlyingConnection().getMetaData()
209: .getURL().equals(
210: otherObj.getUnderlyingConnection()
211: .getMetaData().getURL())
212: && this .getUnderlyingConnection().getMetaData()
213: .getUserName().equals(
214: otherObj.getUnderlyingConnection()
215: .getMetaData()
216: .getUserName());
217: } catch (SQLException e) {
218: throw new RuntimeException(e);
219: }
220: }
221:
222: public int hashCode() {
223: return this.getUnderlyingConnection().hashCode();
224: }
225: }
|