com.hp.hpl.jena.db.impl
Class PSet_TripleStore_RDB

java.lang.Object
  extended bycom.hp.hpl.jena.db.impl.PSet_TripleStore_RDB
All Implemented Interfaces:
IPSet

public class PSet_TripleStore_RDB
extends Object
implements IPSet

Handles Physical storage for implementing SpecializedGraphs. Different PSet classes are needed for different databases and different layout schemes.

This class is a base implemention from which database-specific drivers can inherit. It is not generic in the sense that it will work on any minimal SQL store and so should be treated as if it were an abstract class.

The SQL statements which implement each of the functions are loaded in a separate file etc/[layout]_[database].sql from the classpath. See SQLCache documentation for more information on the format of this file. Based on Driver* classes by Dave Reynolds.

Version:
$Revision: 1.1 $ on $Date: 2003/10/16 11:36:33 $
Author:
Harumi Kuno

Field Summary
protected  boolean CACHE_PREPARED_STATEMENTS
          Set to true to enable cache of pre-prepared statements
protected static int DEFAULT_CACHE
          default size for literal and resource caches
protected  String ID_SQL_TYPE
          The SQL type to use for storing ids (compatible with wrapDBID)
protected  ICache literalCache
          Cache of literals
protected static org.apache.log4j.Logger logger
           
protected  IRDBDriver m_driver
          The IRDBDriver for the database.
protected  SQLCache m_sql
          The table of sql driver statements
 String m_tblName
          Holds name of AssertedStatement table (defaults to JENA_SYS_AssStatements).
protected  ICache resourceCache
          Cache of resources
protected  boolean SKIP_DUPLICATE_CHECK
          Set to true if the insert operations already check for duplications
 
Constructor Summary
PSet_TripleStore_RDB()
          Constructor.
 
Method Summary
 void cleanDB()
          Remove all RDF information about this pset from a database.
 void close()
          Close this PSet
 void deleteTriple(Triple t, IDBID graphID)
          Attempt to remove a statement from an Asserted_Statement table, if it is present.
 void deleteTriple(Triple t, IDBID graphID, boolean isBatch, Hashtable batchedPreparedStatements)
          Attempt to remove a statement from an Asserted_Statement table, if it is present.
 void deleteTripleAR(Triple t, IDBID graphID, Node reifNode, boolean isBatch, Hashtable batchedPreparedStatements)
          Attempt to remove a statement from an Asserted_Statement table, if it is present.
 void deleteTripleList(List triples, IDBID my_GID)
          Attempt to remove a list of triples from the specialized graph.
 IRDBDriver driver()
           
 Triple extractTripleFromRowData(String subj, String pred, String obj)
          Convert the current row of a result set from a ResultSet to a Triple.
 ExtendedIterator find(TripleMatch t, IDBID graphID)
           
 Node_Literal getLiteralFromCache(IDBID id)
          Fetch a literal from the cache just knowing its literal rdb-id.
 PreparedStatement getPreparedStatement(String op, String tableName, boolean isBatch, Hashtable batchedPreparedStatements)
          Given an operation name, a table name, whether or not this operation is part of a batched update, and a table of batched prepared statements, find or create an appropriate PreparedStatement.
 SQLCache getSQLCache()
           
 String getTblName()
          Accessor for m_tblName.
 void removeStatementsFromDB(IDBID graphID)
           
 int rowCount(String tName)
          Compute the number of rows in a table.
 void setCachePreparedStatements(boolean value)
           
 void setDriver(IRDBDriver driver)
          Link an existing instance of the IPSet to a specific driver
 void setSkipDuplicateCheck(boolean value)
           
 void setSQLCache(SQLCache cache)
           
 void setSQLType(String value)
           
 void setTblName(String tblName)
          Sets m_tblName variable.
 boolean statementTableContains(IDBID graphID, Triple t)
          Tests if a triple is contained in the specialized graph.
 void storeTriple(Triple t, IDBID graphID)
          Attempt to store a statement into an Asserted_Statement table.
 void storeTriple(Triple t, IDBID graphID, boolean isBatch, Hashtable batchedPreparedStatements)
          Attempt to store a statement into an Asserted_Statement table.
 void storeTripleAR(Triple t, IDBID graphID, Node reifNode, boolean hasType, boolean isBatch, Hashtable batchedPreparedStatements)
          Attempt to store a statement into an Asserted_Statement table.
 void storeTripleList(List triples, IDBID my_GID)
          Attempt to add a list of triples to the specialized graph.
 String toString()
          Printable name for the driver configuration
 int tripleCount()
          Compute the number of unique triples added to the Specialized Graph.
 IDBID wrapDBID(Object id)
          Convert the raw SQL object used to store a database identifier into a java object which meets the IDBID interface.
 Object wrapFlag(boolean flag)
          Wrap up a boolean flag as a object which the jdbc driver can assert into a boolean/short column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_tblName

public String m_tblName
Holds name of AssertedStatement table (defaults to JENA_SYS_AssStatements). Every triple store has at least one tables for AssertedStatements.


ID_SQL_TYPE

protected String ID_SQL_TYPE
The SQL type to use for storing ids (compatible with wrapDBID)


SKIP_DUPLICATE_CHECK

protected boolean SKIP_DUPLICATE_CHECK
Set to true if the insert operations already check for duplications


CACHE_PREPARED_STATEMENTS

protected boolean CACHE_PREPARED_STATEMENTS
Set to true to enable cache of pre-prepared statements


m_sql

protected SQLCache m_sql
The table of sql driver statements


DEFAULT_CACHE

protected static final int DEFAULT_CACHE
default size for literal and resource caches

See Also:
Constant Field Values

literalCache

protected ICache literalCache
Cache of literals


resourceCache

protected ICache resourceCache
Cache of resources


m_driver

protected IRDBDriver m_driver
The IRDBDriver for the database.


logger

protected static org.apache.log4j.Logger logger
Constructor Detail

PSet_TripleStore_RDB

public PSet_TripleStore_RDB()
Constructor.

Method Detail

setDriver

public void setDriver(IRDBDriver driver)
               throws RDFRDBException
Link an existing instance of the IPSet to a specific driver

Specified by:
setDriver in interface IPSet
Throws:
RDFRDBException

setSQLType

public void setSQLType(String value)
Specified by:
setSQLType in interface IPSet

setSkipDuplicateCheck

public void setSkipDuplicateCheck(boolean value)
Specified by:
setSkipDuplicateCheck in interface IPSet

setSQLCache

public void setSQLCache(SQLCache cache)
Specified by:
setSQLCache in interface IPSet

getSQLCache

public SQLCache getSQLCache()
Specified by:
getSQLCache in interface IPSet

setCachePreparedStatements

public void setCachePreparedStatements(boolean value)
Specified by:
setCachePreparedStatements in interface IPSet

setTblName

public void setTblName(String tblName)
Sets m_tblName variable.

Specified by:
setTblName in interface IPSet
Parameters:
tblName - the name of the Statement Table

getTblName

public String getTblName()
Accessor for m_tblName.

Specified by:
getTblName in interface IPSet
Returns:
name of the Statement table.

close

public void close()
Close this PSet

Specified by:
close in interface IPSet

driver

public IRDBDriver driver()
Specified by:
driver in interface IPSet
Returns:
the database driver.

cleanDB

public void cleanDB()
Remove all RDF information about this pset from a database.

Specified by:
cleanDB in interface IPSet

toString

public String toString()
Printable name for the driver configuration


getLiteralFromCache

public Node_Literal getLiteralFromCache(IDBID id)
Fetch a literal from the cache just knowing its literal rdb-id. If it is not in the cache, do not attempt to retrieve it from the database.


wrapDBID

public IDBID wrapDBID(Object id)
                                       throws RDFRDBException
Convert the raw SQL object used to store a database identifier into a java object which meets the IDBID interface.

Throws:
RDFRDBException

rowCount

public int rowCount(String tName)
Compute the number of rows in a table.

Specified by:
rowCount in interface IPSet
Returns:
int count.

extractTripleFromRowData

public Triple extractTripleFromRowData(String subj,
                                       String pred,
                                       String obj)
Convert the current row of a result set from a ResultSet to a Triple. Expects row to contain: S.SubjRes, S.PropRes, S.ObjRes, S.ObjStr, S.ObjLiteral

Specified by:
extractTripleFromRowData in interface IPSet

wrapFlag

public Object wrapFlag(boolean flag)
Wrap up a boolean flag as a object which the jdbc driver can assert into a boolean/short column.


deleteTriple

public void deleteTriple(Triple t,
                         IDBID graphID)
Attempt to remove a statement from an Asserted_Statement table, if it is present. Return without error if the statement is not present.

Specified by:
deleteTriple in interface IPSet
Parameters:
graphID - is the ID of the graph

deleteTriple

public void deleteTriple(Triple t,
                         IDBID graphID,
                         boolean isBatch,
                         Hashtable batchedPreparedStatements)
Attempt to remove a statement from an Asserted_Statement table, if it is present. Return without error if the statement is not present.

Parameters:
graphID - is the ID of the graph

deleteTripleAR

public void deleteTripleAR(Triple t,
                           IDBID graphID,
                           Node reifNode,
                           boolean isBatch,
                           Hashtable batchedPreparedStatements)
Attempt to remove a statement from an Asserted_Statement table, if it is present. Return without error if the statement is not present.

Parameters:
graphID - is the ID of the graph

storeTriple

public void storeTriple(Triple t,
                        IDBID graphID)
Attempt to store a statement into an Asserted_Statement table.

Specified by:
storeTriple in interface IPSet
Parameters:
graphID - is the ID of the graph

getPreparedStatement

public PreparedStatement getPreparedStatement(String op,
                                              String tableName,
                                              boolean isBatch,
                                              Hashtable batchedPreparedStatements)
                                       throws SQLException
Given an operation name, a table name, whether or not this operation is part of a batched update, and a table of batched prepared statements, find or create an appropriate PreparedStatement.

Parameters:
op -
tableName -
isBatch -
batchedPreparedStatements -
Returns:
the prepared statement
Throws:
SQLException

storeTriple

public void storeTriple(Triple t,
                        IDBID graphID,
                        boolean isBatch,
                        Hashtable batchedPreparedStatements)
Attempt to store a statement into an Asserted_Statement table.

Parameters:
graphID - is the ID of the graph
isBatch - is true if this request is part of a batch operation.

storeTripleAR

public void storeTripleAR(Triple t,
                          IDBID graphID,
                          Node reifNode,
                          boolean hasType,
                          boolean isBatch,
                          Hashtable batchedPreparedStatements)
Attempt to store a statement into an Asserted_Statement table.

Parameters:
hasType - is true if the hasType flag should be set for a reified stmt
graphID - is the ID of the graph
isBatch - is true if this request is part of a batch operation.

storeTripleList

public void storeTripleList(List triples,
                            IDBID my_GID)
Attempt to add a list of triples to the specialized graph. As each triple is successfully added it is removed from the List. If complete is true then the entire List was added and the List will be empty upon return. if complete is false, then at least one triple remains in the List. If a triple can't be stored for any reason other than incompatability (for example, a lack of disk space) then the implemenation should throw a runtime exception.

Specified by:
storeTripleList in interface IPSet
Parameters:
triples - List of triples to be added. This is modified by the call.
my_GID - ID of the graph.

deleteTripleList

public void deleteTripleList(List triples,
                             IDBID my_GID)
Attempt to remove a list of triples from the specialized graph. As each triple is successfully deleted it is removed from the List. If complete is true then the entire List was added and the List will be empty upon return. if complete is false, then at least one triple remains in the List. If a triple can't be stored for any reason other than incompatability (for example, a lack of disk space) then the implemenation should throw a runtime exception.

Specified by:
deleteTripleList in interface IPSet
Parameters:
triples - List of triples to be added. This is modified by the call.
my_GID - ID of the graph.

tripleCount

public int tripleCount()
Compute the number of unique triples added to the Specialized Graph.

Specified by:
tripleCount in interface IPSet
Returns:
int count.

statementTableContains

public boolean statementTableContains(IDBID graphID,
                                      Triple t)
Tests if a triple is contained in the specialized graph.

Specified by:
statementTableContains in interface IPSet
Parameters:
t - is the triple to be tested
graphID - is the id of the graph.
Returns:
boolean result to indicte if the tripple was contained

find

public ExtendedIterator find(TripleMatch t,
                             IDBID graphID)
Specified by:
find in interface IPSet

removeStatementsFromDB

public void removeStatementsFromDB(IDBID graphID)
Specified by:
removeStatementsFromDB in interface IPSet


Copyright © 2003 SCAM. All Rights Reserved.