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

com.scalar.db.sql.SqlStatementExecutable Maven / Gradle / Ivy

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.sql;

import com.scalar.db.sql.exception.SqlException;
import com.scalar.db.sql.exception.TransactionRetryableException;
import com.scalar.db.sql.statement.Statement;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

/**
 * An interface for executing SQL statements. Only DDLs and DMLs are supported. For the details of
 * the grammar, see ScalarDB SQL
 * Grammar.
 */
public interface SqlStatementExecutable {

  /**
   * Executes the specified SQL statement.
   *
   * @param sql an SQL statement to execute
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(String sql) {
    return execute(sql, (List) null, null);
  }

  /**
   * Executes the specified SQL statement.
   *
   * @param sql an SQL statement to execute
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the SQL statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(String sql, @Nullable String defaultNamespaceName) {
    return execute(sql, (List) null, defaultNamespaceName);
  }

  /**
   * Executes the specified SQL statement with the specified positional values.
   *
   * @param sql an SQL statement to execute
   * @param positionalValues parameter values for the positional bind markers in the SQL statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(String sql, List positionalValues) {
    return execute(sql, positionalValues, null);
  }

  /**
   * Executes the specified SQL statement with the specified positional values.
   *
   * @param sql an SQL statement to execute
   * @param positionalValues parameter values for the positional bind markers in the SQL statement
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the SQL statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  ResultSet execute(
      String sql, @Nullable List positionalValues, @Nullable String defaultNamespaceName);

  /**
   * Executes the specified SQL statement with the specified named values.
   *
   * @param sql an SQL statement to execute
   * @param namedValues parameter values for the named bind markers in the SQL statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(String sql, Map namedValues) {
    return execute(sql, namedValues, null);
  }

  /**
   * Executes the specified SQL statement with the specified named values.
   *
   * @param sql an SQL statement to execute
   * @param namedValues parameter values for the named bind markers in the SQL statement
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the SQL statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  ResultSet execute(
      String sql, @Nullable Map namedValues, @Nullable String defaultNamespaceName);

  /**
   * Executes the specified statement.
   *
   * @param statement a statement to execute
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(Statement statement) {
    return execute(statement, (List) null, null);
  }

  /**
   * Executes the specified statement.
   *
   * @param statement a statement to execute
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(Statement statement, @Nullable String defaultNamespaceName) {
    return execute(statement, (List) null, defaultNamespaceName);
  }

  /**
   * Executes the specified statement with the specified positional values.
   *
   * @param statement a statement to execute
   * @param positionalValues parameter values for the positional bind markers in the statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(Statement statement, List positionalValues) {
    return execute(statement, positionalValues, null);
  }

  /**
   * Executes the specified statement with the specified positional values.
   *
   * @param statement a statement to execute
   * @param positionalValues parameter values for the positional bind markers in the statement
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  ResultSet execute(
      Statement statement,
      @Nullable List positionalValues,
      @Nullable String defaultNamespaceName);

  /**
   * Executes the specified statement with the specified named values.
   *
   * @param statement a statement to execute
   * @param namedValues parameter values for the named bind markers in the statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  default ResultSet execute(Statement statement, Map namedValues) {
    return execute(statement, namedValues, null);
  }

  /**
   * Executes the specified statement with the specified named values.
   *
   * @param statement a statement to execute
   * @param namedValues parameter values for the named bind markers in the statement
   * @param defaultNamespaceName the default namespace name used if a namespace is not specified in
   *     the statement
   * @return a {@link ResultSet} object that contains the data produced by the query
   * @throws TransactionRetryableException if the transaction operation execution fails due to
   *     retryable faults (e.g., a transaction conflict). You can retry the transaction from the
   *     beginning.
   * @throws SqlException if the transaction operation execution fails due to transient or
   *     nontransient faults. You can try retrying the transaction from the beginning, but the
   *     transaction may still fail if the cause is nontranient
   */
  ResultSet execute(
      Statement statement,
      @Nullable Map namedValues,
      @Nullable String defaultNamespaceName);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy