Interface SQLStatement


public interface SQLStatement
An immutable adapter-compiled statement definition. Each call to prepare(IDBConnection, ReuseProbability) obtains a statement from the connection's existing cache; the returned statement remains caller-owned and must be released using the normal Net4j DB lifecycle. This definition retains neither connection nor statement. Configured parameter setters are retained through their parameter identities for the lifetime of this definition.
Since:
4.15
Author:
Eike Stepper
No Implement
This interface is not intended to be implemented by clients.
No Extend
This interface is not intended to be extended by clients.
  • Method Details

    • getSQL

      String getSQL()
      Returns the SQL text generated by compilation.
      Returns:
      compiled SQL text
    • getParameterCount

      int getParameterCount()
      Returns the number of JDBC placeholder occurrences in the statement.
      Returns:
      the placeholder count
    • getParameter

      SQLParameter getParameter(int index)
      Returns the logical parameter identity at a one-based JDBC placeholder position. Repeated uses of one identity return the same SQLParameter instance at each position.
      Parameters:
      index - the one-based JDBC parameter position
      Returns:
      the logical parameter identity for that occurrence
      Throws:
      IllegalArgumentException - if the index is outside the statement's parameter range
      Since:
      4.15
    • getParameters

      List<SQLParameter> getParameters()
      Returns the logical parameter identities in JDBC placeholder order. The returned list is immutable, contains one entry per placeholder occurrence, and preserves the identity of repeated parameters. Statements without placeholders return an empty list.
      Returns:
      immutable parameter occurrences in JDBC order
      Since:
      4.15
    • prepare

      Prepares this statement through the existing Net4j DB statement cache and supplied reuse policy. The caller owns the returned statement and must release it according to the connection's normal lifecycle.
      Parameters:
      connection - the connection to prepare on
      reuseProbability - the existing statement-cache reuse hint
      Returns:
      a prepared statement from the connection
      Throws:
      SQLException - if JDBC reports a preparation failure
    • prepare

      IDBPreparedStatement prepare(IDBConnection connection, int resultSetType, int resultSetConcurrency, IDBPreparedStatement.ReuseProbability reuseProbability) throws SQLException
      Prepares this statement with the requested JDBC result-set shape through the existing Net4j DB statement cache. The caller owns the returned statement and must release it according to the connection's normal lifecycle.
      Parameters:
      connection - the connection to prepare on
      resultSetType - the JDBC result-set type
      resultSetConcurrency - the JDBC result-set concurrency
      reuseProbability - the existing statement-cache reuse hint
      Returns:
      a prepared statement from the connection
      Throws:
      SQLException - if JDBC reports a preparation failure
      Since:
      4.15
    • binder

      Creates an independent sequential binding cursor starting at JDBC position 1. Cursor state belongs to the returned object and is not retained by this compiled definition.
      Parameters:
      stmt - the JDBC statement to bind
      Returns:
      a new cursor
      Throws:
      NullPointerException - if stmt is null
      Since:
      4.15
    • binderFrom

      SQLParameterBinder binderFrom(PreparedStatement stmt, int startIndex)
      Creates an independent sequential binding cursor at the specified JDBC position. Positions from 1 through parameter count plus one are valid; the final position supports empty sequences only.
      Parameters:
      stmt - the JDBC statement to bind
      startIndex - the one-based next position
      Returns:
      a new cursor
      Throws:
      IllegalArgumentException - if startIndex is outside the valid range
      NullPointerException - if stmt is null
      Since:
      4.15
    • bind

      int bind(PreparedStatement stmt, Object... values) throws SQLException
      Binds a sequence of values starting at JDBC position 1. Partial prefixes are allowed and the returned count is the number of bound positions. A single null value must be passed as (Object)null; a null varargs array is invalid. Existing bindings at other positions are unaffected, and callers must account for stale values when reusing statements.
      Parameters:
      stmt - the JDBC statement
      values - values in placeholder order
      Returns:
      the number of values bound
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the sequence exceeds the remaining parameter range
      NullPointerException - if stmt or values is null
      Since:
      4.15
    • bindFrom

      int bindFrom(PreparedStatement stmt, int startIndex, Object... values) throws SQLException
      Binds a partial sequence from the specified one-based position and returns its value count. The valid starting positions are 1 through the parameter count plus one; the final position is useful only for an empty sequence. Structural range checks happen before JDBC is changed.
      Parameters:
      stmt - the JDBC statement
      startIndex - the one-based first position
      values - the values to bind in occurrence order
      Returns:
      the number of values bound
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the position or range is invalid
      NullPointerException - if the statement or values array is null
      Since:
      4.15
    • bindAll

      int bindAll(PreparedStatement stmt, Object... values) throws SQLException
      Binds the complete statement and requires exactly getParameterCount() values. Structural count validation happens before JDBC is changed. A successful empty statement binding returns zero.
      Parameters:
      stmt - the JDBC statement
      values - one value for each placeholder occurrence
      Returns:
      the number of values bound
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the number of values differs from the parameter count
      NullPointerException - if the statement or values array is null
      Since:
      4.15
    • bindParameter

      void bindParameter(PreparedStatement stmt, int index, Object value) throws SQLException
      Binds one value at a one-based placeholder index. A configured setter receives the original value; otherwise default binding applies a configured converter to non-null values and uses explicit JDBC type before inferred field type for NULL. A failed operation leaves existing bindings untouched except for effects already made by JDBC.
      Parameters:
      stmt - the JDBC statement
      index - the one-based placeholder index
      value - the application value
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if index is outside the compiled parameter range
      NullPointerException - if stmt is null
      Since:
      4.15
    • bindParameter

      void bindParameter(PreparedStatement stmt, SQLParameter parameter, Object value) throws SQLException
      Binds a logical parameter identity at every occurrence in generated SQL order. Matching uses object identity. Each occurrence keeps its own inferred field type; a failure at a later occurrence can leave earlier occurrences bound.
      Parameters:
      stmt - the JDBC statement
      parameter - the identity returned by a particular SQL.param() call
      value - the application value to bind at each occurrence
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the parameter identity is absent from this statement
      NullPointerException - if a required argument is null
      Since:
      4.15
    • bindDefault

      void bindDefault(PreparedStatement stmt, int index, SQLDefaultSetter setter) throws SQLException
      Binds the implementation-defined default for one parameter occurrence at a one-based JDBC index. The setter performs the complete JDBC operation; configured parameter setters and converters are not consulted. This is distinct from binding a supplied value through bindParameter(stmt, index, value), including a supplied null. The default need not be SQL DEFAULT or SQL NULL. If the setter fails, any JDBC side effect it already performed is not rolled back.
      Parameters:
      stmt - the JDBC statement
      index - the one-based placeholder index
      setter - the complete default-value binding operation
      Throws:
      SQLException - if the setter reports a binding failure
      IllegalArgumentException - if index is outside the compiled parameter range
      NullPointerException - if stmt or setter is null
      Since:
      4.15
    • bindDefault

      void bindDefault(PreparedStatement stmt, SQLParameter parameter, SQLDefaultSetter setter) throws SQLException
      Binds the implementation-defined default at every occurrence of a logical parameter identity, in generated SQL order. Matching uses object identity, and each call to the setter receives that occurrence's actual one-based JDBC index. The setter performs the complete JDBC operation; configured parameter setters and converters are not consulted. This is distinct from binding a supplied value through bindParameter(stmt, parameter, value). The default need not be SQL DEFAULT or SQL NULL. If a later setter call fails, earlier JDBC effects are not rolled back.
      Parameters:
      stmt - the JDBC statement
      parameter - the logical parameter identity
      setter - the complete default-value binding operation
      Throws:
      SQLException - if the setter reports a binding failure
      IllegalArgumentException - if the identity is absent from this statement
      NullPointerException - if a required argument is null
      Since:
      4.15
    • bindParameter

      <JAVA> void bindParameter(PreparedStatement stmt, int index, JAVA value, SQLValueSetter<? super JAVA> setter) throws SQLException
      Binds one value with a caller-supplied JDBC binding strategy. The setter replaces any strategy configured on the parameter, receives the original value including null, and owns the complete JDBC operation. This override does not modify the parameter or compiled statement.
      Type Parameters:
      JAVA - the application value type
      Parameters:
      stmt - the JDBC statement
      index - the one-based placeholder index
      value - the application value
      setter - the complete JDBC binding strategy
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if index is outside the compiled parameter range
      NullPointerException - if a required argument is null
      Since:
      4.15
    • bindParameter

      <JAVA> void bindParameter(PreparedStatement stmt, SQLParameter parameter, JAVA value, SQLValueSetter<? super JAVA> setter) throws SQLException
      Binds a logical parameter identity at every occurrence in generated SQL order using a specialized setter. The setter receives the original value once per occurrence, including null, and completely controls JDBC binding.
      Type Parameters:
      JAVA - the application value type
      Parameters:
      stmt - the JDBC statement
      parameter - the identity returned by a particular SQL.param() call
      value - the application value to bind at each occurrence
      setter - the complete JDBC binding strategy
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the parameter identity is absent from this statement
      NullPointerException - if a required argument is null
      Since:
      4.15
    • bindParameter

      <JAVA, JDBC> void bindParameter(PreparedStatement stmt, int index, JAVA value, Function<JAVA,JDBC> converter) throws SQLException
      Binds one value after applying a call-specific converter, bypassing all parameter-configured strategies. A non-null input is converted before the usual JDBC binding. Null input bypasses conversion and uses the parameter's explicit or inferred JDBC NULL type.
      Type Parameters:
      JAVA - the application value type
      JDBC - the converted value type
      Parameters:
      stmt - the JDBC statement
      index - the one-based placeholder index
      value - the original application value
      converter - the call-specific converter
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if index is outside the parameter range
      NullPointerException - if a required argument is null
      Since:
      4.15
    • bindParameter

      <JAVA, JDBC> void bindParameter(PreparedStatement stmt, SQLParameter parameter, JAVA value, Function<JAVA,JDBC> converter) throws SQLException
      Binds every occurrence of an identity after applying a call-specific converter. The converter receives the original non-null application value once per occurrence; null bypasses conversion and follows the usual explicit or inferred JDBC NULL handling. The override does not change the parameter or compiled statement.
      Type Parameters:
      JAVA - the application value type
      JDBC - the converted value type
      Parameters:
      stmt - the JDBC statement
      parameter - the logical parameter identity
      value - the original application value
      converter - the call-specific converter
      Throws:
      SQLException - if JDBC binding fails
      IllegalArgumentException - if the identity is absent from this statement
      NullPointerException - if a required argument is null
      Since:
      4.15