Class AdHocSQLLayout

java.lang.Object
fr.inria.rules.integraal.storage.external.rdbms.layout.AdHocSQLLayout
All Implemented Interfaces:
RDBMSStorageLayout
Direct Known Subclasses:
EncodingAdHocSQLLayout

public class AdHocSQLLayout extends Object implements RDBMSStorageLayout
The AdHoc strategy stores atoms as follows
A predicate table stores all the predicates associated with their arity and the corresponding table Each predicate is associated to an SQL table A term table stores all the terms and their corresponding type (variable, literal or constant)
For each predicate, the associated table contains its arity number of columns Each column represents a position in the atom Each row stores a tuple representing a list of terms corresponding to an atom.
  • Field Details

    • driver

      protected final RDBMSDriver driver
      RDBMS Driver
    • runner

      protected final org.apache.commons.dbutils.QueryRunner runner
      Apache runner to execute SQL queries
  • Constructor Details

    • AdHocSQLLayout

      public AdHocSQLLayout(RDBMSDriver driver)
      Creates a new Strategy over the given driver
      Parameters:
      driver - the database driver
  • Method Details

    • getType

      protected static String getType(Term t)
      Determine with which letter to store the type of the given term in the database
      Parameters:
      t - a term
      Returns:
      the encoding letter of the type of t
    • canHandleFiltering

      public boolean canHandleFiltering()
      //////////////////////////////////////////////
      Specified by:
      canHandleFiltering in interface RDBMSStorageLayout
      Returns:
      true iff this strategy can handle complete filtering of the query
    • getTableName

      public String getTableName(Atom atom) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Returns the atom table name for the supplied atom, creating it if needed.

      If the table in which the given atom does not exist, this method creates it and return its name

      Specified by:
      getTableName in interface RDBMSStorageLayout
      Parameters:
      atom - the atom for which to get the table name
      Returns:
      The name of the table in which the given atom is stored
      Throws:
      SQLException - if an exception occur
    • getAllTableNames

      public Collection<String> getAllTableNames() throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Returns the names of all atom tables.
      Specified by:
      getAllTableNames in interface RDBMSStorageLayout
      Returns:
      the name of all the tables storing atoms
      Throws:
      SQLException - if an exception occur
    • getAllPredicates

      public Collection<Predicate> getAllPredicates(PredicateFactory factory) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Returns all predicates known to the underlying database.
      Specified by:
      getAllPredicates in interface RDBMSStorageLayout
      Parameters:
      factory - the predicate factory
      Returns:
      all the predicates stored in the database; even if no atom exists with this predicate
      Throws:
      SQLException - if an exception occur
    • handleTerms

      public void handleTerms(Set<Term> terms) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Handles the given terms, storing them if needed.
      Specified by:
      handleTerms in interface RDBMSStorageLayout
      Parameters:
      terms - the terms to handle
      Throws:
      SQLException - if an exception occur
    • createTerm

      public Term createTerm(String term, TermFactory factory) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Recreates a term from its stored representation.

      This is the reverse operation of getRepresentation

      Specified by:
      createTerm in interface RDBMSStorageLayout
      Parameters:
      term - string representation
      factory - to instantiate the term
      Returns:
      the term associated with the given string representation
      Throws:
      SQLException - if an exception occur
    • createPredicate

      public Predicate createPredicate(String predicate, int arity, PredicateFactory factory)
      Description copied from interface: RDBMSStorageLayout
      Recreates a predicate from its stored representation and arity.
      Specified by:
      createPredicate in interface RDBMSStorageLayout
      Parameters:
      predicate - string representation
      arity - predicate arity
      factory - to instantiate the predicate
      Returns:
      the predicate associated with the given string representation and arity
    • getColumnName

      public String getColumnName(String table, int term_index)
      Description copied from interface: RDBMSStorageLayout
      Returns the name of the column storing a term at a given position.
      Specified by:
      getColumnName in interface RDBMSStorageLayout
      Parameters:
      table - the name of the database table
      term_index - the column number
      Returns:
      The name of the column which store the term at the given index in the given table
    • addSpecificConditions

      public SQLParameterizedQuery addSpecificConditions(String sql_query, List<Object> arguments, FOQuery<?> q)
      Description copied from interface: RDBMSStorageLayout
      Adds layout-specific conditions to an SQL query.
      Specified by:
      addSpecificConditions in interface RDBMSStorageLayout
      Parameters:
      sql_query - an SQL query represented as string
      arguments - the arguments to add to the query
      q - the query for the conditions
      Returns:
      is not yet defined
    • hasCorrectDatabaseSchema

      public boolean hasCorrectDatabaseSchema(RDBMSDriver driver) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Checks whether the database schema matches this storage layout.
      Specified by:
      hasCorrectDatabaseSchema in interface RDBMSStorageLayout
      Parameters:
      driver - the database driver
      Returns:
      true iff the given driver's database have the correct schema of data for this strategy
      Throws:
      SQLException - if an exception occur
    • createDatabaseSchema

      public void createDatabaseSchema(RDBMSDriver driver) throws SQLException
      Description copied from interface: RDBMSStorageLayout
      Creates the schema associated with this layout on the given database.
      Specified by:
      createDatabaseSchema in interface RDBMSStorageLayout
      Parameters:
      driver - the database driver
      Throws:
      SQLException - if an exception occur
    • getTermsTableName

      public String getTermsTableName()
      Description copied from interface: RDBMSStorageLayout
      Returns the name of the terms table.
      Specified by:
      getTermsTableName in interface RDBMSStorageLayout
      Returns:
      The name of the terms table
    • get_predicate_table_name

      protected String get_predicate_table_name()
      Returns the name of the predicate metadata table.
      Returns:
      the name of the predicate table
    • get_create_predicate_table_query

      protected String get_create_predicate_table_query()
      Returns the SQL statement creating the predicate metadata table.
      Returns:
      the SQL query to create the predicate table
    • get_predicate_table_query

      protected String get_predicate_table_query()
      Returns the SQL statement retrieving the table bound to a predicate.
      Returns:
      the SQL query to get the table storing the parameterized predicate
    • get_all_predicates_query

      protected String get_all_predicates_query()
      Returns the SQL statement listing all predicates stored in the database.
      Returns:
      the SQL query to get all the predicates (label and arity) in the database
    • get_insert_predicate_query

      protected String get_insert_predicate_query()
      Returns the SQL statement inserting a predicate metadata row.
      Returns:
      the SQL query to insert a new predicate
    • get_count_predicate_query

      protected String get_count_predicate_query()
      Returns the SQL statement counting predicates.
      Returns:
      the SQL query to count the number of predicates
    • get_create_terms_table_query

      protected String get_create_terms_table_query()
      Returns the SQL statement creating the terms table.
      Returns:
      the SQL query to create the term table
    • get_term_table_query

      protected String get_term_table_query()
      Returns the SQL statement fetching a serialized term.
      Returns:
      the SQL query to get a term by its label
    • get_create_atom_table

      protected String get_create_atom_table()
      Returns the SQL statement template for creating an atom table.
      Returns:
      the SQL query to create the term table
    • get_atom_table_prefix

      protected String get_atom_table_prefix()
      Returns the prefix used when generating atom-table names.
      Returns:
      the prefix for the name of predicate tables