![JAR search and dependency download from the Maven repository](/logo.png)
djdbc.Statement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of djdbc Show documentation
Show all versions of djdbc Show documentation
Declarative abstraction over JDBC
package djdbc;
import java.sql.*;
/**
* Statement specification.
*/
public interface Statement {
result run(ExtendedConnection connection, params params) throws SQLException;
class Unpreparable implements Statement {
final String sql;
final Decoder decoder;
public Unpreparable(String sql, Decoder decoder) {
this.sql = sql;
this.decoder = decoder;
}
@Override
public result run(ExtendedConnection connection, Void aVoid) throws SQLException {
final java.sql.Statement statement = connection.jdbcConnection.createStatement();
try {
decoder.execute(statement, sql);
return decoder.decode(statement);
} finally {
statement.close();
}
}
}
class Preparable implements Statement {
final String sql;
final Encoder encoder;
final Decoder decoder;
public Preparable(String sql, Encoder encoder, Decoder decoder) {
this.sql = sql;
this.encoder = encoder;
this.decoder = decoder;
}
@Override
public result run(ExtendedConnection connection, params params) throws SQLException {
final PreparedStatement preparedStatement =
connection.preparedStatementCache.get(sql, decoder.getPreparedStatementFactory(connection.jdbcConnection));
encoder.encodeParams(preparedStatement, params);
preparedStatement.execute();
return decoder.decode(preparedStatement);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy