Interface DBStatement

All Superinterfaces:
AutoCloseable, DataAttributesHolder
All Known Implementing Classes:
StandardDBStatement

public interface DBStatement extends AutoCloseable, DataAttributesHolder
The class is an Interface that defines the operativity of a generic statement used to access the database
  • Field Details

  • Method Details

    • setSql

      void setSql(String sql)
      Sets the SQL string of the statement.
      The string contains variables like @field that can be properly converted in a DB field name or like ?value. Those must be different and must be expressly set by one of the method set(map) or set(key,value)
      Parameters:
      sql - The SQL string
    • setSqlOn

      void setSqlOn(String sql, String key)
      Sets conditionally the SQL string of the statement.
      The SQL string is inserted into the statement only if it will be set to the statement (with one of the methods set(map) or set(key,value)) a key that corresponds to the key passed as second parameter
      Parameters:
      sql - The SQL string
      key - The key that must be set to the statement
    • setSqlIn

      void setSqlIn(String sql, String key, Object[] objects)
      Sets conditionally the SQL string of the statement.
      The SQL string is inserted into the statement only if it will be set to the statement with one of the methods set(map) or set(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is equal to one of the objects passed as third parameter
      Parameters:
      sql - The SQL string
      key - The key that must be set to the statement
      objects - The array of Objects used for comparison
    • setSqlOut

      void setSqlOut(String sql, String key, Object[] objects)
      Sets conditionally the SQL string of the statement.
      The SQL string is inserted into the statement only if it will be set to the statement with one of the methods set(map) or set(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is different to all of the objects passed as third parameter
      Parameters:
      sql - The SQL string
      key - The key that must be set to the statement
      objects - The array of Objects used for comparison
    • setSqlIn

      void setSqlIn(String sql, String key, Collection<?> objects)
      Sets conditionally the SQL string of the statement.
      The SQL string is inserted into the statement only if it will be set to the statement with one of the methods set(map) or set(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is equal to one of the objects passed as third parameter
      Parameters:
      sql - The SQL string
      key - The key that must be set to the statement
      objects - The collection of Objects used for comparison
    • setSqlOut

      void setSqlOut(String sql, String key, Collection<?> objects)
      Sets conditionally the SQL string of the statement.
      The SQL string is inserted into the statement only if it will be set to the statement with one of the methods set(map) or set(key,value)) a key that corresponds to the key passed as second parameter and the object associated to the key is different to all of the objects passed as third parameter
      Parameters:
      sql - The SQL string
      key - The key that must be set to the statement
      objects - The collection of Objects used for comparison
    • setSql

      void setSql(Fragment sql)
      Sets the SQL Fragment of the statement.
      The string contains variables like @field that can be properly converted in a DB field name or like ?value. Those must be different and must be expressly set by one of the method set(map) or set(key,value)
      Parameters:
      sql - The SQL Fragment
    • setMaxRows

      void setMaxRows(int n)
      Sets the maximum number of rows to search
      Parameters:
      n - Maximum number of rows
    • setUpdatable

      void setUpdatable(boolean updatable)
      Sets if the ResultSet is updatable
      Parameters:
      updatable - if true the ResultSet is updatable, otherwise false
    • setSkipRows

      void setSkipRows(int n)
      Sets the number of initial rows to be skipped. Even these lines, although skipped, are counted in the maxrows parameter.
      Parameters:
      n - Number of rows to be skipped
    • set

      void set(String k, Object o)
      Sets the value of a variable ?value. With this method one value of an SQL statement is compiled. These value can be appropriately converted by a converter (like the DBObjectMap) before being passed to the DB
      Parameters:
      k - The name of the variable ?value in the SQL string
      o - The value of the variable ?value in the SQL string
    • set

      void set(Map<String,Object> map)
      Sets the values of all the variables ?value. With this method all the values of an SQL statement are compiled. These values can be appropriately converted by a converter (like the DBObjectMap) before being passed to the DB
      Parameters:
      map - The map in which each entry defines the value of a variable ?value
    • define

      void define(String field, DBObjectMap dbom)
      Specifies a DBObjectMap that must be used to load a column resulting from a SELECT
      Parameters:
      field - The name of the column of the ResultSet obtained from a query
      dbom - The object that can map every object in the column
    • defineParam

      void defineParam(String field, DBObjectMap dbom)
      Explicitly specifies a DBObjectMap that must be used to prepare the statement for a specific variable in the SQL string.
      Parameters:
      field - The name of the variable in the SQL string
      dbom - The object that can map every object specified for the variable
    • executeUpdate

      int executeUpdate() throws SQLException
      Translates the statement, compiles and execute it
      Returns:
      The number of the rows updated or inserted into the database
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • executeQuery

      DBView executeQuery() throws SQLException
      Translates the statement, compiles and execute it
      Returns:
      The view resulting for the SQL query, totally kept in RAM
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • executeQuery

      @Deprecated DBView executeQuery(boolean readonly) throws SQLException
      Deprecated.
      use dbStatement.executeQuery() or dbStatement.executeQuery().setRoData() instead
      Translates the statement, compiles and execute it
      Parameters:
      readonly - true if the result must be not modifiable, false otherwise
      Returns:
      The DBView resulting for the SQL query, totally kept in RAM
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • close

      void close() throws SQLException
      Closes the SQL statement
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • getStatement

      Statement getStatement() throws SQLException
      Returns the java.sql Statement on which the DBstatement acts
      Returns:
      SQL statement used to access the database
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • createStatement

      Statement createStatement() throws SQLException
      Explicitly creates a PreparedStatement. It is useful when you want to use a PreparedStatement and also have the same release mechanisms of the DBStatement
      Returns:
      The PreparedStatement created and used to access the database
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • addBatch

      void addBatch() throws SQLException
      Adds a set of parameters to the statement object's batch of commands. See Statement.addBatch(String)
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • addBatch

      void addBatch(int batchSize) throws SQLException
      Adds a set of parameters to the statement object's batch of commands. See Statement.addBatch(String).
      Parameters:
      batchSize - size of the batch (useful for executing the batch whenever the batch size reaches this value).
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller.
    • executeBatch

      int[] executeBatch() throws SQLException
      Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. See Statement.executeBatch()
      Returns:
      An array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • getResultSet

      ResultSet getResultSet() throws SQLException
      Executes the SQL query in this statement object and returns the ResultSet object generated by the query
      Returns:
      The ResultSet object that contains the data produced by the query
      Throws:
      SQLException - If the communication with the database throws an exception, that it is raised to the caller
    • scan

      void scan(DBScanner dbs) throws SQLException
      extracts a DBCursor from the statement and submits it to an explicit scanning prcedure
      Parameters:
      dbs - the scanning procedure
      Throws:
      SQLException - if some sql error happens in the scanning procedure
    • getRowMapFromResultSet

      HashGetter getRowMapFromResultSet(ResultSet rs) throws SQLException
      reads the result set raw at the current position and construct a key-value map af all the fields according to the statement specification
      Parameters:
      rs - the result set
      Returns:
      the key-value map
      Throws:
      SQLException - if some sql error happens in the record loading
    • createCall

      CallableStatement createCall(String call) throws SQLException
      Throws:
      SQLException
    • isUpdateInProgress

      boolean isUpdateInProgress()
      Returns true in case a SQL UPDATE query is in progress; false otherwise.
      Returns:
      true in case a SQL UPDATE query is in progress; false otherwise.
    • isInsertInProgress

      boolean isInsertInProgress()
      Returns true in case a SQL INSERT query is in progress; false otherwise.
      Returns:
      true in case a SQL INSERT query is in progress; false otherwise.
    • getDbType

      DBType getDbType()
      Returns the DBType associated to the PooledConnection currently in use.
      Returns:
      the DBType associated to the PooledConnection currently in use.