protected List<Map<String, String>> executeQueryThrowable(
String query, ExecuteResultSet<ResultSet> executeResultSet, FillPreparedStatement fillStatement) throws SQLException {
- try {
- final Connection connection = this.dataSource.getConnection();
-
- return this.doExecuteQuery(
- query,
- connection,
- preparedStatement ->
- {
- fillStatement.doFill(preparedStatement);
-
- return preparedStatement.executeQuery();
- },
- executeResultSet
- );
- } finally {
- dataSource.getConnection().close();
- }
+
+ final Connection connection = this.dataSource.getConnection();
+ try {
+ return this.doExecuteQuery(
+ query,
+ connection,
+ preparedStatement ->
+ {
+ fillStatement.doFill(preparedStatement);
+
+ return preparedStatement.executeQuery();
+ },
+ executeResultSet);
+ } finally {
+ connection.close();
+ }
}
protected List<Map<String, String>> doExecuteQuery (
protected void executeUpdateThrowable(
String query, FillPreparedStatement fillStatement) throws SQLException {
- try {
- final Connection connection = this.dataSource.getConnection();
-
- this.doExecuteUpdate(
- query,
- connection,
- preparedStatement ->
- {
- fillStatement.doFill(preparedStatement);
-
- preparedStatement.executeUpdate();
- });
- } finally {
- dataSource.getConnection().close();
- }
+
+ final Connection connection = this.dataSource.getConnection();
+ try {
+ this.doExecuteUpdate(
+ query,
+ connection,
+ preparedStatement ->
+ {
+ fillStatement.doFill(preparedStatement);
+
+ preparedStatement.executeUpdate();
+ });
+ } finally {
+ connection.close();
+ }
}
protected void doExecuteUpdate (
private static final String USERNAME = "sa";
private static final String PASSWORD = "";
- private final ComboPooledDataSource pool;
+ private final DataSource dataSource;
- private DoDataSourceContext(ComboPooledDataSource pool) {
- this.pool = pool;
+ private DoDataSourceContext() {
+ this.dataSource = doDataSource();
}
private static class DoDataSourceContextHolder {
- private static final DoDataSourceContext INSTANCE = new DoDataSourceContext(new ComboPooledDataSource());
+ private static final DoDataSourceContext INSTANCE = new DoDataSourceContext();
}
public static DoDataSource getInstance() {
@Override
public DataSource getDataSource() {
-
+ return this.dataSource;
+ }
+
+ protected DataSource doDataSource() {
DataSource dataSource = null;
try {
dataSource = doDataSourceThrowable();
}
return dataSource;
- }
-
+ }
+
private DataSource doDataSourceThrowable() throws PropertyVetoException {
+ final ComboPooledDataSource pool = new ComboPooledDataSource();
pool.setUser(USERNAME);
pool.setPassword(PASSWORD);
pool.setDriverClass(DRIVER_CLASS);