Class SQLParameterizedQueryEvaluator

java.lang.Object
fr.inria.rules.integraal.storage.external.evaluator.SQLParameterizedQueryEvaluator
All Implemented Interfaces:
NativeQueryEvaluator<SQLParameterizedQuery, List<Object[]>>

public class SQLParameterizedQueryEvaluator extends Object implements NativeQueryEvaluator<SQLParameterizedQuery, List<Object[]>>
Evaluates a SQL query using the associated driver. This evaluator uses Apache's QueryRunner to execute the query on the database The result is a List<Object[]> which represents the list of all resulting tuples.
This evaluator also provides additional methods for inserting data on the database.
  • Constructor Details

    • SQLParameterizedQueryEvaluator

      public SQLParameterizedQueryEvaluator(RDBMSDriver driver) throws SQLException
      Construct a new evaluator over the database represented by the given driver
      Parameters:
      driver - representing the database to connect to
      Throws:
      SQLException - if the initial connection to the database cannot be performed
  • Method Details

    • evaluate

      public Optional<List<Object[]>> evaluate(SQLParameterizedQuery query)
      Description copied from interface: NativeQueryEvaluator
      Evaluate the given query and returns the result This should not do anymore work
      Specified by:
      evaluate in interface NativeQueryEvaluator<SQLParameterizedQuery, List<Object[]>>
      Parameters:
      query - to evaluate
      Returns:
      an optional which contains the results of the query if everything went right, an empty optional otherwise
    • insert

      public boolean insert(SQLParameterizedQuery query)
      Execute the given insert query
      Parameters:
      query - to execute, representing an insert query
      Returns:
      true iff the query has been executed without problem
    • insertBatch

      public boolean insertBatch(String query, List<Object[]> parameters)
      Insert the given values, using a batch insert and parameters for the query This is more efficient than looping over the parameters and executing each query at a time
      Parameters:
      query - the parameterized query
      parameters - The query replacement parameters
      Returns:
      true iff the queries have been executed without problem
    • copy

      public boolean copy(String sqlCopyQuery) throws SQLException
      Copies CSV data using the supplied SQL copy statement.
      Parameters:
      sqlCopyQuery - sql query to copy csv data
      Returns:
      true iff the copy succeeded
      Throws:
      SQLException - iff an SQL exception occur
    • copyFromSTDIn

      public boolean copyFromSTDIn(String sqlCopyQuery, String csvFileName) throws SQLException
      Copies CSV data from standard input using the supplied SQL copy statement.
      Parameters:
      sqlCopyQuery - sql query to copy csv data
      csvFileName - csv file to copy
      Returns:
      true iff the copy succeeded
      Throws:
      SQLException - iff an SQL exception occur
    • execute

      public boolean execute(String sqlFilePath)
      Executes the SQL statements stored in the supplied file.
      Parameters:
      sqlFilePath - path to a file containing SQL queries
      Returns:
      true iff the copy succeeded