PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/db-diff/src/main/java/com/googlecode/hdbc/dbdiff/db/QueryExecutionTemplate.java

http://hdbc.googlecode.com/
Java | 39 lines | 35 code | 4 blank | 0 comment | 4 complexity | 0acd8d3c4d7b8993df0f532be4632dcf MD5 | raw file
 1package com.googlecode.hdbc.dbdiff.db;
 2
 3import java.sql.Connection;
 4import java.sql.PreparedStatement;
 5import java.sql.SQLException;
 6import javax.sql.DataSource;
 7
 8import com.googlecode.hdbc.dbdiff.db.IQueryDefinition;
 9import com.googlecode.hdbc.dbdiff.model.DbObjects;
10
11public class QueryExecutionTemplate<T> {
12
13	public final DbObjects<T> executeQuery(final IQueryDefinition<T> definition,
14	        final DataSource ods) throws SQLException {
15		Connection cnn = null;
16		PreparedStatement stmt = null;
17		try {
18		    cnn = ods.getConnection();
19			stmt = cnn.prepareStatement(definition.getParameterizedSQL());
20			definition.processStatement(stmt);
21			stmt.close();
22			stmt = null;
23		} catch (SQLException e) {
24		    throw new IllegalStateException(e);
25		} finally {
26			if (stmt != null) {
27				try {
28					stmt.close();
29				} catch (SQLException e) {	}
30			}
31			if (cnn != null) {
32				try {
33					cnn.close();
34				} catch (SQLException e) {	}
35			}
36		}
37		return definition.result();
38	}
39}