org.nsdl.mptstore.core
Class BasicTableManager

java.lang.Object
  extended by org.nsdl.mptstore.core.BasicTableManager
All Implemented Interfaces:
TableManager

public class BasicTableManager
extends java.lang.Object
implements TableManager

A TableManager designed to perform DDL operations on separate connections from those used for DML. The DDL-in-a-separate-connection strategy employed by this implementation should work with a wide variety of databases.

Author:
cwilper@cs.cornell.edu

Constructor Summary
BasicTableManager(javax.sql.DataSource dataSource, DDLGenerator ddlGenerator, java.lang.String mapTable, java.lang.String soTablePrefix)
          Initialize the table manager.
 
Method Summary
 int dropAllPredicateTables()
          Drop all predicate tables and mappings, effectively re-initializing the triplestore.
 int dropEmptyPredicateTables()
          Drop all unused predicate tables and mappings.
 java.lang.String getOrMapTableFor(PredicateNode predicate)
          Get the name of the table reserved for relationships of the given type.
 PredicateNode getPredicateFor(java.lang.String table)
          Get the predicate that's mapped to the given table, if such a mapping exists.
 java.util.Set<PredicateNode> getPredicates()
          Get the set of predicates for which a table mapping exists.
 java.lang.String getTableFor(PredicateNode predicate)
          Get the name of the table reserved for relationships of the given type, if it exists.
 java.util.Set<java.lang.String> getTables()
          Get the set of tables that store per-predicate relationships.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicTableManager

public BasicTableManager(javax.sql.DataSource dataSource,
                         DDLGenerator ddlGenerator,
                         java.lang.String mapTable,
                         java.lang.String soTablePrefix)
                  throws java.sql.SQLException
Initialize the table manager. This will create the map table if it doesn't yet exist, and will read the current mappings into memory.

Parameters:
dataSource - The DataSource from which to obtain connections for DDL operations.
ddlGenerator - The DDLGenerator to use when DDL is needed.
mapTable - The name of the table in which the table-to-predicate mappings are persisted.
soTablePrefix - The prefix for all predicate table names.
Throws:
java.sql.SQLException - if any kind of database error occurs.
Method Detail

getOrMapTableFor

public java.lang.String getOrMapTableFor(PredicateNode predicate)
                                  throws java.sql.SQLException
Get the name of the table reserved for relationships of the given type.

If such a table does not yet exist, it will be automatically created and permanently associated with the given predicate.

Specified by:
getOrMapTableFor in interface TableManager
Parameters:
predicate - The type of relationship.
Returns:
The table name for the given predicate, never null.
Throws:
java.sql.SQLException - if a database error occurs while the table is

getTableFor

public java.lang.String getTableFor(PredicateNode predicate)
Get the name of the table reserved for relationships of the given type, if it exists.

Specified by:
getTableFor in interface TableManager
Parameters:
predicate - The type of relationship.
Returns:
The table name for the given predicate, or null if no such predicate exists in the graph.

getPredicateFor

public PredicateNode getPredicateFor(java.lang.String table)
Get the predicate that's mapped to the given table, if such a mapping exists.

Specified by:
getPredicateFor in interface TableManager
Parameters:
table - The name of the table.
Returns:
The predicate, or null if no such mapping exists.

getTables

public java.util.Set<java.lang.String> getTables()
Get the set of tables that store per-predicate relationships.

Specified by:
getTables in interface TableManager
Returns:
A set with zero or more table names.

getPredicates

public java.util.Set<PredicateNode> getPredicates()
Get the set of predicates for which a table mapping exists.

Specified by:
getPredicates in interface TableManager
Returns:
A set with zero or more predicates.

dropEmptyPredicateTables

public int dropEmptyPredicateTables()
                             throws java.sql.SQLException
Drop all unused predicate tables and mappings.

Specified by:
dropEmptyPredicateTables in interface TableManager
Returns:
the number of dropped predicate tables.
Throws:
java.sql.SQLException - if a database error occured during the operation.

dropAllPredicateTables

public int dropAllPredicateTables()
                           throws java.sql.SQLException
Drop all predicate tables and mappings, effectively re-initializing the triplestore.

Specified by:
dropAllPredicateTables in interface TableManager
Returns:
the number of dropped predicate tables.
Throws:
java.sql.SQLException - if a database error occured during the operation.