Class NaturalSQLLayout

java.lang.Object
fr.inria.rules.integraal.storage.external.rdbms.layout.NaturalSQLLayout
All Implemented Interfaces:
RDBMSStorageLayout

public class NaturalSQLLayout extends Object implements RDBMSStorageLayout
The NaturalSQLLayout stores atoms using table names that exactly match the predicate names. No additional tables for terms or predicates are created. This layout is intended to be used with a pre-existing database schema, or it can create tables dynamically if they don't exist. It assumes that predicate names are compatible with table names in the target database.
  • Field Details

    • driver

      protected RDBMSDriver driver
      Driver used to inspect and manipulate the underlying relational schema.
    • runner

      protected org.apache.commons.dbutils.QueryRunner runner
      Query runner bound to the current driver datasource.
  • Constructor Details

    • NaturalSQLLayout

      public NaturalSQLLayout(RDBMSDriver driver)
      Creates a layout that maps predicates directly to database table names.
      Parameters:
      driver - the relational driver backing the layout
  • Method Details

    • canHandleFiltering

      public boolean canHandleFiltering()
      Description copied from interface: RDBMSStorageLayout
      Filtering of the query is represented by the WHERE conditions in SQL. If the strategy can generate the conditions in every case, then this method should return true. Otherwise, it should return false and additional filtering will be needed
      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
    • handleTerms

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

      public String getColumnName(String table, int termIndex)
      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
      termIndex - 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)
      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
    • createDatabaseSchema

      public void createDatabaseSchema(RDBMSDriver driver)
      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
    • 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
    • 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
    • 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