Class NaturalSQLLayout
java.lang.Object
fr.inria.rules.integraal.storage.external.rdbms.layout.NaturalSQLLayout
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected RDBMSDriverDriver used to inspect and manipulate the underlying relational schema.protected org.apache.commons.dbutils.QueryRunnerQuery runner bound to the current driver datasource.Fields inherited from interface RDBMSStorageLayout
ATOM_TABLE_PREDICATE_PREFIX, INDEX_NAME_PREFIX, PREDICATE_TABLE_NAME, TERM_TABLE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionNaturalSQLLayout(RDBMSDriver driver) Creates a layout that maps predicates directly to database table names. -
Method Summary
Modifier and TypeMethodDescriptionaddSpecificConditions(String sql_query, List<Object> arguments, FOQuery<?> q) Adds layout-specific conditions to an SQL query.booleanFiltering of the query is represented by the WHERE conditions in SQL.voidcreateDatabaseSchema(RDBMSDriver driver) Creates the schema associated with this layout on the given database.createPredicate(String predicate, int arity, PredicateFactory factory) Recreates a predicate from its stored representation and arity.createTerm(String term, TermFactory factory) Recreates a term from its stored representation.getAllPredicates(PredicateFactory factory) Returns all predicates known to the underlying database.Returns the names of all atom tables.getColumnName(String table, int termIndex) Returns the name of the column storing a term at a given position.getTableName(Atom atom) Returns the atom table name for the supplied atom, creating it if needed.Returns the name of the terms table.voidhandleTerms(Set<Term> all_terms) Handles the given terms, storing them if needed.booleanhasCorrectDatabaseSchema(RDBMSDriver driver) Checks whether the database schema matches this storage layout.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RDBMSStorageLayout
getRepresentation
-
Field Details
-
driver
Driver used to inspect and manipulate the underlying relational schema. -
runner
protected org.apache.commons.dbutils.QueryRunner runnerQuery runner bound to the current driver datasource.
-
-
Constructor Details
-
NaturalSQLLayout
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:RDBMSStorageLayoutFiltering 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:
canHandleFilteringin interfaceRDBMSStorageLayout- Returns:
- true iff this strategy can handle complete filtering of the query
-
getTableName
Description copied from interface:RDBMSStorageLayoutReturns 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:
getTableNamein interfaceRDBMSStorageLayout- 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
Description copied from interface:RDBMSStorageLayoutHandles the given terms, storing them if needed.- Specified by:
handleTermsin interfaceRDBMSStorageLayout- Parameters:
all_terms- the terms to handle- Throws:
SQLException- if an exception occur
-
getColumnName
Description copied from interface:RDBMSStorageLayoutReturns the name of the column storing a term at a given position.- Specified by:
getColumnNamein interfaceRDBMSStorageLayout- Parameters:
table- the name of the database tabletermIndex- 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:RDBMSStorageLayoutAdds layout-specific conditions to an SQL query.- Specified by:
addSpecificConditionsin interfaceRDBMSStorageLayout- Parameters:
sql_query- an SQL query represented as stringarguments- the arguments to add to the queryq- the query for the conditions- Returns:
- is not yet defined
-
hasCorrectDatabaseSchema
Description copied from interface:RDBMSStorageLayoutChecks whether the database schema matches this storage layout.- Specified by:
hasCorrectDatabaseSchemain interfaceRDBMSStorageLayout- Parameters:
driver- the database driver- Returns:
- true iff the given driver's database have the correct schema of data for this strategy
-
createDatabaseSchema
Description copied from interface:RDBMSStorageLayoutCreates the schema associated with this layout on the given database.- Specified by:
createDatabaseSchemain interfaceRDBMSStorageLayout- Parameters:
driver- the database driver
-
getAllTableNames
Description copied from interface:RDBMSStorageLayoutReturns the names of all atom tables.- Specified by:
getAllTableNamesin interfaceRDBMSStorageLayout- Returns:
- the name of all the tables storing atoms
- Throws:
SQLException- if an exception occur
-
getAllPredicates
Description copied from interface:RDBMSStorageLayoutReturns all predicates known to the underlying database.- Specified by:
getAllPredicatesin interfaceRDBMSStorageLayout- 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
Description copied from interface:RDBMSStorageLayoutRecreates a term from its stored representation.This is the reverse operation of getRepresentation
- Specified by:
createTermin interfaceRDBMSStorageLayout- Parameters:
term- string representationfactory- to instantiate the term- Returns:
- the term associated with the given string representation
- Throws:
SQLException- if an exception occur
-
createPredicate
Description copied from interface:RDBMSStorageLayoutRecreates a predicate from its stored representation and arity.- Specified by:
createPredicatein interfaceRDBMSStorageLayout- Parameters:
predicate- string representationarity- predicate arityfactory- to instantiate the predicate- Returns:
- the predicate associated with the given string representation and arity
-
getTermsTableName
Description copied from interface:RDBMSStorageLayoutReturns the name of the terms table.- Specified by:
getTermsTableNamein interfaceRDBMSStorageLayout- Returns:
- The name of the terms table
-