Clover Coverage Report - Liquibase Core 2.0.3-SNAPSHOT
Coverage timestamp: Sat Aug 6 2011 11:33:15 EDT
../../../img/srcFileCovDistChart0.png 69% of files have more coverage
135   420   93   2.87
6   354   0.69   47
47     1.98  
1    
 
  JdbcConnection       Line # 22 135 0% 93 188 0% 0.0
 
No Tests
 
1    package liquibase.database.jvm;
2   
3    import java.sql.CallableStatement;
4    import java.sql.Connection;
5    import java.sql.DatabaseMetaData;
6    import java.sql.PreparedStatement;
7    import java.sql.SQLException;
8    import java.sql.SQLWarning;
9    import java.sql.Savepoint;
10    import java.sql.Statement;
11    import java.util.Map;
12   
13    import liquibase.database.DatabaseConnection;
14    import liquibase.exception.DatabaseException;
15    import liquibase.exception.UnexpectedLiquibaseException;
16   
17    /**
18    * A ConnectionWrapper implementation which delegates completely to an underlying java.sql.connection.
19    *
20    * @author <a href="mailto:csuml@yahoo.co.uk">Paul Keeble</a>
21    */
 
22    public class JdbcConnection implements DatabaseConnection {
23    private java.sql.Connection con;
24   
 
25  0 toggle public JdbcConnection(java.sql.Connection connection) {
26  0 this.con = connection;
27    }
28   
 
29  0 toggle @Override
30    public String getDatabaseProductName() throws DatabaseException {
31  0 try {
32  0 return con.getMetaData().getDatabaseProductName();
33    } catch (SQLException e) {
34  0 throw new DatabaseException(e);
35    }
36    }
37   
 
38  0 toggle @Override
39    public String getDatabaseProductVersion() throws DatabaseException {
40  0 try {
41  0 return con.getMetaData().getDatabaseProductVersion();
42    } catch (SQLException e) {
43  0 throw new DatabaseException(e);
44    }
45    }
46   
 
47  0 toggle @Override
48    public int getDatabaseMajorVersion() throws DatabaseException {
49  0 try {
50  0 return con.getMetaData().getDatabaseMajorVersion();
51    } catch (SQLException e) {
52  0 throw new DatabaseException(e);
53    }
54    }
55   
 
56  0 toggle @Override
57    public int getDatabaseMinorVersion() throws DatabaseException {
58  0 try {
59  0 return con.getMetaData().getDatabaseMinorVersion();
60    } catch (SQLException e) {
61  0 throw new DatabaseException(e);
62    }
63    }
64   
 
65  0 toggle @Override
66    public String getURL() {
67  0 try {
68  0 return con.getMetaData().getURL();
69    } catch (SQLException e) {
70  0 throw new UnexpectedLiquibaseException(e);
71    }
72    }
73   
 
74  0 toggle @Override
75    public String getConnectionUserName() {
76  0 try {
77  0 return con.getMetaData().getUserName();
78    } catch (SQLException e) {
79  0 throw new UnexpectedLiquibaseException(e);
80    }
81    }
82   
83    /**
84    * Returns the connection that this Delegate is using.
85    *
86    * @return The connection originally passed in the constructor
87    */
 
88  0 toggle public Connection getWrappedConnection() {
89  0 return con;
90    }
91   
 
92  0 toggle public void clearWarnings() throws DatabaseException {
93  0 try {
94  0 con.clearWarnings();
95    } catch (SQLException e) {
96  0 throw new DatabaseException(e);
97    }
98    }
99   
 
100  0 toggle @Override
101    public void close() throws DatabaseException {
102  0 rollback();
103  0 try {
104  0 con.close();
105    } catch (SQLException e) {
106  0 throw new DatabaseException(e);
107    }
108    }
109   
 
110  0 toggle @Override
111    public void commit() throws DatabaseException {
112  0 try {
113  0 if (!con.getAutoCommit()) {
114  0 con.commit();
115    }
116    } catch (SQLException e) {
117  0 throw new DatabaseException(e);
118    }
119    }
120   
 
121  0 toggle public Statement createStatement() throws DatabaseException {
122  0 try {
123  0 return con.createStatement();
124    } catch (SQLException e) {
125  0 throw new DatabaseException(e);
126    }
127    }
128   
 
129  0 toggle public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
130    throws DatabaseException {
131  0 try {
132  0 return con.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
133    } catch (SQLException e) {
134  0 throw new DatabaseException(e);
135    }
136    }
137   
 
138  0 toggle public Statement createStatement(int resultSetType, int resultSetConcurrency) throws DatabaseException {
139  0 try {
140  0 return con.createStatement(resultSetType, resultSetConcurrency);
141    } catch (SQLException e) {
142  0 throw new DatabaseException(e);
143    }
144    }
145   
 
146  0 toggle @Override
147    public boolean getAutoCommit() throws DatabaseException {
148  0 try {
149  0 return con.getAutoCommit();
150    } catch (SQLException e) {
151  0 throw new DatabaseException(e);
152    }
153    }
154   
 
155  0 toggle @Override
156    public String getCatalog() throws DatabaseException {
157  0 try {
158  0 return con.getCatalog();
159    } catch (SQLException e) {
160  0 throw new DatabaseException(e);
161    }
162    }
163   
 
164  0 toggle public int getHoldability() throws DatabaseException {
165  0 try {
166  0 return con.getHoldability();
167    } catch (SQLException e) {
168  0 throw new DatabaseException(e);
169    }
170    }
171   
 
172  0 toggle public DatabaseMetaData getMetaData() throws DatabaseException {
173  0 try {
174  0 return con.getMetaData();
175    } catch (SQLException e) {
176  0 throw new DatabaseException(e);
177    }
178    }
179   
 
180  0 toggle public int getTransactionIsolation() throws DatabaseException {
181  0 try {
182  0 return con.getTransactionIsolation();
183    } catch (SQLException e) {
184  0 throw new DatabaseException(e);
185    }
186    }
187   
 
188  0 toggle public Map<String, Class<?>> getTypeMap() throws DatabaseException {
189  0 try {
190  0 return con.getTypeMap();
191    } catch (SQLException e) {
192  0 throw new DatabaseException(e);
193    }
194    }
195   
 
196  0 toggle public SQLWarning getWarnings() throws DatabaseException {
197  0 try {
198  0 return con.getWarnings();
199    } catch (SQLException e) {
200  0 throw new DatabaseException(e);
201    }
202    }
203   
 
204  0 toggle @Override
205    public boolean isClosed() throws DatabaseException {
206  0 try {
207  0 return con.isClosed();
208    } catch (SQLException e) {
209  0 throw new DatabaseException(e);
210    }
211    }
212   
 
213  0 toggle public boolean isReadOnly() throws DatabaseException {
214  0 try {
215  0 return con.isReadOnly();
216    } catch (SQLException e) {
217  0 throw new DatabaseException(e);
218    }
219    }
220   
 
221  0 toggle @Override
222    public String nativeSQL(String sql) throws DatabaseException {
223  0 try {
224  0 return con.nativeSQL(sql);
225    } catch (SQLException e) {
226  0 throw new DatabaseException(e);
227    }
228    }
229   
 
230  0 toggle public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
231    int resultSetHoldability) throws DatabaseException {
232  0 try {
233  0 return con.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
234    } catch (SQLException e) {
235  0 throw new DatabaseException(e);
236    }
237    }
238   
 
239  0 toggle public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
240    throws DatabaseException {
241  0 try {
242  0 return con.prepareCall(sql, resultSetType, resultSetConcurrency);
243    } catch (SQLException e) {
244  0 throw new DatabaseException(e);
245    }
246    }
247   
 
248  0 toggle public CallableStatement prepareCall(String sql) throws DatabaseException {
249  0 try {
250  0 return con.prepareCall(sql);
251    } catch (SQLException e) {
252  0 throw new DatabaseException(e);
253    }
254    }
255   
 
256  0 toggle public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
257    int resultSetHoldability) throws DatabaseException {
258  0 try {
259  0 return con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
260    } catch (SQLException e) {
261  0 throw new DatabaseException(e);
262    }
263    }
264   
 
265  0 toggle public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
266    throws DatabaseException {
267  0 try {
268  0 return con.prepareStatement(sql, resultSetType, resultSetConcurrency);
269    } catch (SQLException e) {
270  0 throw new DatabaseException(e);
271    }
272    }
273   
 
274  0 toggle public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws DatabaseException {
275  0 try {
276  0 return con.prepareStatement(sql, autoGeneratedKeys);
277    } catch (SQLException e) {
278  0 throw new DatabaseException(e);
279    }
280    }
281   
 
282  0 toggle public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws DatabaseException {
283  0 try {
284  0 return con.prepareStatement(sql, columnIndexes);
285    } catch (SQLException e) {
286  0 throw new DatabaseException(e);
287    }
288    }
289   
 
290  0 toggle public PreparedStatement prepareStatement(String sql, String[] columnNames) throws DatabaseException {
291  0 try {
292  0 return con.prepareStatement(sql, columnNames);
293    } catch (SQLException e) {
294  0 throw new DatabaseException(e);
295    }
296    }
297   
 
298  0 toggle public PreparedStatement prepareStatement(String sql) throws DatabaseException {
299  0 try {
300  0 return con.prepareStatement(sql);
301    } catch (SQLException e) {
302  0 throw new DatabaseException(e);
303    }
304    }
305   
 
306  0 toggle public void releaseSavepoint(Savepoint savepoint) throws DatabaseException {
307  0 try {
308  0 con.releaseSavepoint(savepoint);
309    } catch (SQLException e) {
310  0 throw new DatabaseException(e);
311    }
312    }
313   
 
314  0 toggle @Override
315    public void rollback() throws DatabaseException {
316  0 try {
317  0 if (!con.getAutoCommit() && !con.isClosed()) {
318  0 con.rollback();
319    }
320    } catch (SQLException e) {
321  0 throw new DatabaseException(e);
322    }
323    }
324   
 
325  0 toggle public void rollback(Savepoint savepoint) throws DatabaseException {
326  0 try {
327  0 if (!con.getAutoCommit()) {
328  0 con.rollback(savepoint);
329    }
330    } catch (SQLException e) {
331  0 throw new DatabaseException(e);
332    }
333    }
334   
 
335  0 toggle @Override
336    public void setAutoCommit(boolean autoCommit) throws DatabaseException {
337    // Fix for Sybase jConnect JDBC driver bug.
338    // Which throws DatabaseException(JZ016: The AutoCommit option is already set to false)
339    // if con.setAutoCommit(false) called twise or more times with value 'false'.
340    // if (con.getAutoCommit() != autoCommit) {
341  0 try {
342  0 con.setAutoCommit(autoCommit);
343    } catch (SQLException e) {
344  0 throw new DatabaseException(e);
345    }
346    // }
347    }
348   
 
349  0 toggle public void setCatalog(String catalog) throws DatabaseException {
350  0 try {
351  0 con.setCatalog(catalog);
352    } catch (SQLException e) {
353  0 throw new DatabaseException(e);
354    }
355    }
356   
 
357  0 toggle public void setHoldability(int holdability) throws DatabaseException {
358  0 try {
359  0 con.setHoldability(holdability);
360    } catch (SQLException e) {
361  0 throw new DatabaseException(e);
362    }
363    }
364   
 
365  0 toggle public void setReadOnly(boolean readOnly) throws DatabaseException {
366  0 try {
367  0 con.setReadOnly(readOnly);
368    } catch (SQLException e) {
369  0 throw new DatabaseException(e);
370    }
371    }
372   
 
373  0 toggle public Savepoint setSavepoint() throws DatabaseException {
374  0 try {
375  0 return con.setSavepoint();
376    } catch (SQLException e) {
377  0 throw new DatabaseException(e);
378    }
379    }
380   
 
381  0 toggle public Savepoint setSavepoint(String name) throws DatabaseException {
382  0 try {
383  0 return con.setSavepoint(name);
384    } catch (SQLException e) {
385  0 throw new DatabaseException(e);
386    }
387    }
388   
 
389  0 toggle public void setTransactionIsolation(int level) throws DatabaseException {
390  0 try {
391  0 con.setTransactionIsolation(level);
392    } catch (SQLException e) {
393  0 throw new DatabaseException(e);
394    }
395    }
396   
 
397  0 toggle public void setTypeMap(Map<String, Class<?>> map) throws DatabaseException {
398  0 try {
399  0 con.setTypeMap(map);
400    } catch (SQLException e) {
401  0 throw new DatabaseException(e);
402    }
403    }
404   
 
405  0 toggle public Connection getUnderlyingConnection() {
406  0 return con;
407    }
408   
 
409  0 toggle @Override
410    public boolean equals(Object obj) {
411  0 return obj instanceof JdbcConnection
412    && this.getUnderlyingConnection().equals(((JdbcConnection) obj).getUnderlyingConnection());
413   
414    }
415   
 
416  0 toggle @Override
417    public int hashCode() {
418  0 return this.getUnderlyingConnection().hashCode();
419    }
420    }