Last active
August 29, 2015 14:02
-
-
Save sebersole/018de3d4226426ea20f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClientOfJdbcSession { | |
private SomeEntity loadTheEntity() { | |
JdbcSession jdbcSession = ...; | |
String sql = ...; | |
boolean callable; | |
Type[] parameterTypes = ...; | |
Object[] parameterValues = ...; | |
int offset = ...; | |
int limit = ...; | |
int timeout = ...; | |
return jdbcSession.accept( | |
new PreparedStatementQueryOperationSpec<SomeEntity>() { | |
@Override | |
public QueryStatementBuilder getQueryStatementBuilder() { | |
return callable | |
? CallableQueryStatementBuilderImpl.INSTANCE | |
: StandardQueryStatementBuilderImpl.INSTANCE | |
} | |
@Override | |
public String getSql() { | |
return sql; | |
} | |
@Override | |
public int getResultSetType() { | |
return ResultSet.TYPE_FORWARD_ONLY; | |
} | |
@Override | |
public int getResultSetConcurrency() { | |
return ResultSet.CONCUR_READ_ONLY; | |
} | |
@Override | |
public int getTimeout() { | |
return timeout; | |
} | |
... | |
} | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JdbcSessionImpl ... { | |
@Override | |
public <R> R accept(PreparedStatementQueryOperationSpec<R> spec) { | |
try { | |
Statement statement = spec.getQueryStatementBuilder().buildStatement( | |
spec.getSql(), | |
spec.getResultSetType(), | |
spec.getResultSetConcurrency() | |
); | |
statement.setQueryTimeout( spec.getTimeout() ); | |
// todo : register the statement | |
try { | |
ResultSet resultSet = ...; | |
// todo : register the resultset | |
try { | |
return ...; | |
} | |
finally { | |
if ( !operationSpec.holdOpenResources() ) { | |
release( resultSet, statement ); | |
} | |
} | |
} | |
finally { | |
if ( !operationSpec.holdOpenResources() ) { | |
release( statement ); | |
} | |
} | |
} | |
finally { | |
afterStatement( !operationSpec.holdOpenResources() ); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface QueryStatementBuilder { | |
PreparedStatement buildStatement(String sql, int resultSetType, int resultSetConcurrency, int timeout, ...); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment