All Downloads are FREE. Search and download functionalities are using the official Maven repository.

djdbc.Statement Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
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