Class AdHocSQLLayout
java.lang.Object
fr.inria.rules.integraal.storage.external.rdbms.layout.AdHocSQLLayout
- All Implemented Interfaces:
RDBMSStorageLayout
- Direct Known Subclasses:
EncodingAdHocSQLLayout
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.
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final RDBMSDriverRDBMS Driverprotected final org.apache.commons.dbutils.QueryRunnerApache runner to execute SQL queriesFields inherited from interface RDBMSStorageLayout
ATOM_TABLE_PREDICATE_PREFIX, INDEX_NAME_PREFIX, PREDICATE_TABLE_NAME, TERM_TABLE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionAdHocSQLLayout(RDBMSDriver driver) Creates a new Strategy over the given driver -
Method Summary
Modifier and TypeMethodDescriptionaddSpecificConditions(String sql_query, List<Object> arguments, FOQuery<?> q) Adds layout-specific conditions to an SQL query.boolean//////////////////////////////////////////////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.protected StringReturns the SQL statement listing all predicates stored in the database.protected StringReturns the prefix used when generating atom-table names.protected StringReturns the SQL statement counting predicates.protected StringReturns the SQL statement template for creating an atom table.protected StringReturns the SQL statement creating the predicate metadata table.protected StringReturns the SQL statement creating the terms table.protected StringReturns the SQL statement inserting a predicate metadata row.protected StringReturns the name of the predicate metadata table.protected StringReturns the SQL statement retrieving the table bound to a predicate.protected StringReturns the SQL statement fetching a serialized term.getAllPredicates(PredicateFactory factory) Returns all predicates known to the underlying database.Returns the names of all atom tables.getColumnName(String table, int term_index) 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.protected static StringDetermine with which letter to store the type of the given term in the databasevoidhandleTerms(Set<Term> 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
RDBMS Driver -
runner
protected final org.apache.commons.dbutils.QueryRunner runnerApache runner to execute SQL queries
-
-
Constructor Details
-
AdHocSQLLayout
Creates a new Strategy over the given driver- Parameters:
driver- the database driver
-
-
Method Details
-
getType
-
canHandleFiltering
public boolean canHandleFiltering()//////////////////////////////////////////////- 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
-
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
-
handleTerms
Description copied from interface:RDBMSStorageLayoutHandles the given terms, storing them if needed.- Specified by:
handleTermsin interfaceRDBMSStorageLayout- Parameters:
terms- the terms to handle- 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
-
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 tableterm_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: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
- Throws:
SQLException- if an exception occur
-
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- Throws:
SQLException- if an exception occur
-
getTermsTableName
Description copied from interface:RDBMSStorageLayoutReturns the name of the terms table.- Specified by:
getTermsTableNamein interfaceRDBMSStorageLayout- Returns:
- The name of the terms table
-
get_predicate_table_name
Returns the name of the predicate metadata table.- Returns:
- the name of the predicate table
-
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
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
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
Returns the SQL statement inserting a predicate metadata row.- Returns:
- the SQL query to insert a new predicate
-
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
Returns the SQL statement creating the terms table.- Returns:
- the SQL query to create the term table
-
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
Returns the SQL statement template for creating an atom table.- Returns:
- the SQL query to create the term table
-
get_atom_table_prefix
Returns the prefix used when generating atom-table names.- Returns:
- the prefix for the name of predicate tables
-