Interface RelationalDirectAccessStatement

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
RelationalStatement

public interface RelationalDirectAccessStatement extends AutoCloseable
  • Method Details

    • executeScan

      @Nonnull RelationalResultSet executeScan(@Nonnull String tableName, @Nonnull KeySet keyPrefix, @Nonnull Options options) throws SQLException
      Execute a multi-row scan against the database, returning a RelationalResultSet containing the results of the scan. This can be used to scan contiguous rows on a table based on a certain PK range. The range should be provided via a key prefix.
       Examples:
      
       CREATE TABLE FOO(a bigint, b bigint, c bigint, primary key(a, b))
       INSERT INTO FOO VALUES [
           {"A": 1, "B": 1, "C": 2},
           {"A": 1, "B": 2, "C": 3},
           {"A": 2, "B": 3, "C": 4}
       ]
      
       // Scans every row
       executeScan("FOO", new KeySet(), Options.NONE)
      
       // Scans the first two rows
       executeScan("FOO", new KeySet().setKeyColumn("A", 1), Options.NONE)
      
       // Scans only the first row
       executeScan("FOO", new KeySet().setKeyColumn("A", 1).setKeyColumn("B", 1), Options.NONE)
      
       // Fails because C is not part of the Primary Key
       executeScan("FOO", new KeySet().setKeyColumn("C", 2), Options.NONE)
      
       // Fails because B is not a prefix of the Primary Key
       executeScan("FOO", new KeySet().setKeyColumn("B", 1), Options.NONE)
       

      The caller can specify some execution-level options, which can be used to control the execution path that the execution. Specifically, the following options are honored:

      • use.index: the name of a specific index to use during scan
      • continuation: The value of the continuation to use for the scan
      Parameters:
      tableName - the name of the table.
      keyPrefix - the key prefix to use when scanning entries.
      options - options that can be used to configure the scan.
      Returns:
      a ResultSet containing the entire record in the underlying scan.
      Throws:
      SQLException - if something goes wrong. Use the Error code to determine exactly what.
    • executeGet

      @Nonnull RelationalResultSet executeGet(@Nonnull String tableName, @Nonnull KeySet key, @Nonnull Options options) throws SQLException
      Get a single record from the system by key.

      This constructs a primary key from the specified KeySet according to the table definition, and then performs a single-row lookup. This is equivalent to executing a scan on the range bounds, but can potentially be more efficiently executed.

      Parameters:
      tableName - the name of the table to get data from
      key - The constructor for the key to fetch by
      options - the options for the GET operation.
      Returns:
      a ResultSet containing the entire record from the resulting GET, either 1 row or 0. If the row does not exist the ResultSet will be empty
      Throws:
      SQLException - If something geos wrong. Use the error code to determine exactly what.
    • executeInsert

      default int executeInsert(@Nonnull String tableName, @Nonnull RelationalStruct data) throws SQLException
      Insert a record into the specified table, updating any indexes as necessary to maintain consistency.
      Parameters:
      tableName - the name of the table to insert into.
      data - the data to insert.
      Returns:
      the number of records inserted.
      Throws:
      SQLException - If something goes wrong. Use the error code to determine exactly what.
    • executeInsert

      default int executeInsert(@Nonnull String tableName, @Nonnull RelationalStruct data, @Nonnull Options options) throws SQLException
      Insert one or more records into the specified table, updating any indexes as necessary to maintain consistency.
      Parameters:
      tableName - the name of the table to insert into.
      data - the data to insert.
      Returns:
      the number of records inserted.
      Throws:
      SQLException - If something goes wrong. Use the error code to determine exactly what.
    • executeInsert

      default int executeInsert(@Nonnull String tableName, @Nonnull List<RelationalStruct> data) throws SQLException
      Insert one or more records into the specified table, updating any indexes as necessary to maintain consistency.
      Parameters:
      tableName - the name of the table to insert into.
      data - the data to insert.
      Returns:
      the number of records inserted.
      Throws:
      SQLException - If something goes wrong. Use the error code to determine exactly what.
    • executeInsert

      int executeInsert(@Nonnull String tableName, @Nonnull List<RelationalStruct> data, @Nonnull Options options) throws SQLException
      Insert one or more records into the specified table, updating any indexes as necessary to maintain consistency.
      Parameters:
      tableName - the name of the table to insert into.
      data - the data to insert.
      options - options to apply to the insert.
      Returns:
      the number of records inserted.
      Throws:
      SQLException - If something goes wrong. Use the error code to determine exactly what.
    • executeDelete

      default int executeDelete(@Nonnull String tableName, @Nonnull Iterable<KeySet> keys) throws SQLException
      Delete one or more records from the specified table, specified by key, if such records exist.

      equivalent to executeDelete(String, Iterator), but with a marginally nicer user experience of not needing to call .iterator()

      Parameters:
      tableName - the name of the table to delete from
      keys - the keys to delete
      Returns:
      the number of records deleted
      Throws:
      SQLException - if something goes wrong. Use the error code to determine exactly what.
    • executeDelete

      default int executeDelete(@Nonnull String tableName, @Nonnull Iterable<KeySet> keys, @Nonnull Options options) throws SQLException
      Throws:
      SQLException
    • executeDelete

      default int executeDelete(@Nonnull String tableName, @Nonnull Iterator<KeySet> keys) throws SQLException
      Delete one or more records from the specified table, specified by key, if such records exist.
      Parameters:
      tableName - the name of the table to delete from
      keys - the keys to delete
      Returns:
      the number of records deleted
      Throws:
      SQLException - if something goes wrong. Use the error code to determine exactly what.
    • executeDelete

      int executeDelete(@Nonnull String tableName, @Nonnull Iterator<KeySet> keys, @Nonnull Options options) throws SQLException
      Throws:
      SQLException
    • executeDeleteRange

      void executeDeleteRange(@Nonnull String tableName, @Nonnull KeySet keyPrefix, @Nonnull Options options) throws SQLException
      This can be used to delete contiguous rows on a table based on a certain PK range. The range should be provided via a key prefix.
       Examples:
      
       CREATE TABLE FOO(a bigint, b bigint, c bigint, primary key(a, b))
       INSERT INTO FOO VALUES [
           {"A": 1, "B": 1, "C": 2},
           {"A": 1, "B": 2, "C": 3},
           {"A": 2, "B": 3, "C": 4}
       ]
      
       // deletes every row
       executeDeleteRange("FOO", new KeySet(), Options.NONE)
      
       // deletes the first two rows
       executeDeleteRange("FOO", new KeySet().setKeyColumn("A", 1), Options.NONE)
      
       // deletes only the first row
       executeDeleteRange("FOO", new KeySet().setKeyColumn("A", 1).setKeyColumn("B", 1), Options.NONE)
      
       // Fails because C is not part of the Primary Key
       executeDeleteRange("FOO", new KeySet().setKeyColumn("C", 2), Options.NONE)
      
       // Fails because B is not a prefix of the Primary Key
       executeDeleteRange("FOO", new KeySet().setKeyColumn("B", 1), Options.NONE)
       
      Parameters:
      tableName - the name of the table to delete from
      keyPrefix - the key prefix to use when deleting entries
      options - options that can be used to configure the delete
      Throws:
      SQLException - if something goes wrong. Use the error code to determine exactly what.
    • close

      void close() throws SQLException
      Close method to free up resources managed by this statement.
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException - for errors encountered while closing