org.openanzo.common.rdb.container
Class RDBConnection

java.lang.Object
  extended by org.openanzo.common.rdb.container.RDBConnection
All Implemented Interfaces:
IContainer, IResetListener

public class RDBConnection
extends java.lang.Object
implements IContainer, IResetListener

Connection to database

Author:
Stephen Evanchik, Joe Betz, Matthew Roy ( mroy@cambridgesemantics.com )

Field Summary
static int QUERY
          Constant for the Query type of connection
static int RW
          Constant for the Write type of connection
 
Constructor Summary
RDBConnection(org.apache.commons.pool.impl.GenericObjectPool connectionPool, CacheProvider cacheProvider, LiteralIndexer literalIndexer, int type, RDBConfiguration configuration, java.sql.Connection connection)
          Create a new RDBConnection
 
Method Summary
 void abort()
          Abort database transaction
 void add(java.util.Iterator<org.openrdf.model.Statement> statements)
          Add a set of statements from container
 void add(org.openrdf.model.Resource subj, org.openrdf.model.URI pred, org.openrdf.model.Value obj, org.openrdf.model.Resource context)
          Add a new statement with given subj,pred,obj,context
 void add(org.openrdf.model.Statement... statements)
          Add one or more statements to container
 void begin()
          Begin database transaction Note:Database already in transaction
 void clear()
          Delete all statements in container
 void clear(org.openrdf.model.Resource... context)
          Delete all statements in container for given contexts
 void clear(org.openrdf.model.URI namedGraphUri)
          Clear all statements from container for the given graph
 void clearDatabase()
          Delete all the tables for this container
 void close()
          Disconnect container from its source and close the container Note: Once a container is closed, it is based on the source of the container's data whether or not subsequent calls to connect will return the same data
 void commit()
          Commit database transaction
 void connect()
          Connect container to its source
 boolean contains(org.openrdf.model.Resource subj, org.openrdf.model.URI prop, org.openrdf.model.Value obj, org.openrdf.model.Resource... contexts)
          Tests if a statement is contained in the container.
 boolean contains(org.openrdf.model.Statement match)
          Tests if a statement is contained in the container.
 void delete(java.util.Iterator<org.openrdf.model.Statement> statements)
          Delete a set of statements from container
 void delete(org.openrdf.model.Resource subj, org.openrdf.model.URI pred, org.openrdf.model.Value obj, org.openrdf.model.Resource context)
          Delete a statement from container
 void delete(org.openrdf.model.Statement... statements)
          Delete a set of statements from container
 void deleteInferedObject(org.openrdf.model.URI ontology, org.openrdf.model.URI property, org.openrdf.model.URI object, org.openrdf.model.URI inferedObject)
          Delete an inferred object definition into the DB
 void deleteInferedProperty(org.openrdf.model.URI ontology, org.openrdf.model.URI property, org.openrdf.model.URI inferedProperty)
          Delete an inferred property definition into the DB
 QueryResult executeQuery(java.util.Set<org.openrdf.model.URI> defaultNamedGraphsIn, java.util.Set<org.openrdf.model.URI> namedGraphsIn, java.lang.String query)
          Execute a SPARQL query against the data within this container
 QueryResults executeQuery(java.util.Set<org.openrdf.model.URI> defaultNamedGraphsIn, java.util.Set<org.openrdf.model.URI> namedGraphsIn, java.lang.String query, boolean includeInferredStatements, org.openrdf.model.URI ontology)
          Execute a SPARQL query against the data within this container
 info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> find(org.openrdf.model.Resource subj, org.openrdf.model.URI prop, org.openrdf.model.Value obj, org.openrdf.model.Resource... namedGraphUri)
          Return an iterator over all statements that match the pattern of subj,prop,obj
 RDBConfiguration getConfiguration()
          Get the configuration
 java.sql.Connection getConnection()
          Get the underlying jdbc connection
 int getConnectionType()
          Is the JDBC connection set to readOnly
 java.lang.String getContainerName()
          Get the container's name
 java.util.Collection<org.openrdf.model.URI> getContexts()
          Get the set of Context URIs that are container within this Container
 INamedGraphEventManager getEventManager()
          Get the eventManager for this connection
 Engine getGlitter()
          Get the Glitter engine for this connection
 LiteralIndexer getLiteralIndexer()
          Get the literal indexer for this connection
 CompositeNodeLayout getNodeLayout()
          Get the nodeLayout
 SQLCache getSQLCache()
          Get the SQLCache for this connections
 info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> getStatements()
          Get an iterator over all statements within this container
 ITransactionManager getTransactionManager()
          Return ITransactionManager for this container
 org.openrdf.model.URI getURI()
          Get URI of IContainer
 void insertInferedObject(org.openrdf.model.URI ontology, org.openrdf.model.URI property, org.openrdf.model.URI object, org.openrdf.model.URI inferedObject)
          Insert an inferred object definition into the DB
 void insertInferedProperty(org.openrdf.model.URI ontology, org.openrdf.model.URI property, org.openrdf.model.URI inferedProperty)
          Insert an inferred property definition into the DB
 boolean isClosed()
          Return if container is closed
 boolean isConnected()
          Return if the container is connected to its source
 boolean isEmpty()
          Return if container is empty
 boolean isEmpty(org.openrdf.model.Resource... context)
          Return if container is empty for given contexts
 boolean isLocked()
          Determine if currently in a transaction
 boolean isReturned()
          Has this connection been returned to the ContainerConnectionPool
 void passivate()
          Passivate this object to its pool
 void populateValidGraphs(java.util.Map<org.openrdf.model.Value,java.lang.Long> graphIds, int includeAllNamedGraphsIn, java.lang.String destinationTable)
          Populate a temporary table with the ids of graphs that match the parameters
 void purgeOntology(org.openrdf.model.URI ontology)
          Purge inferred object definitions from db for a given ontology
 void reset()
          Reset the connections
 void reset(java.lang.Long id)
          Server was reset
 void setConnection(java.sql.Connection connection)
          Set the underlying jdbc connection
 void setContainerName(java.lang.String containerName)
          Set the container's name
 void setEventManager(INamedGraphEventManager eventManager)
          Set the event manager for this connection
 void setReturned(boolean returned)
          Set if connection has been returned to the ContainerConnectionPool
 void setTransactionManager(ITransactionManager transactionManager)
          Set ITransactionManager for this container
 void setURI(org.openrdf.model.URI uri)
          Set the URI for this container
 int size()
          Return number of statements in container
 int size(org.openrdf.model.Resource... namedGraphUri)
          Return number of statements in container
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUERY

public static final int QUERY
Constant for the Query type of connection

See Also:
Constant Field Values

RW

public static final int RW
Constant for the Write type of connection

See Also:
Constant Field Values
Constructor Detail

RDBConnection

public RDBConnection(org.apache.commons.pool.impl.GenericObjectPool connectionPool,
                     CacheProvider cacheProvider,
                     LiteralIndexer literalIndexer,
                     int type,
                     RDBConfiguration configuration,
                     java.sql.Connection connection)
Create a new RDBConnection

Parameters:
connectionPool - the connection pool creating this connection
cacheProvider - the cache provider for of caches of node values to their ids
literalIndexer - the literal indexer for like text queries
type - the type of connection
configuration - the configuration data for the connection
connection - the underlying jdbc connection
Method Detail

connect

public void connect()
Description copied from interface: IContainer
Connect container to its source

Specified by:
connect in interface IContainer

isConnected

public boolean isConnected()
Description copied from interface: IContainer
Return if the container is connected to its source

Specified by:
isConnected in interface IContainer
Returns:
if the container is connected to its source

setConnection

public void setConnection(java.sql.Connection connection)
Set the underlying jdbc connection

Parameters:
connection - the underlying jdbc connection

getConnection

public java.sql.Connection getConnection()
Get the underlying jdbc connection

Returns:
the underlying jdbc connection

getSQLCache

public SQLCache getSQLCache()
Get the SQLCache for this connections

Returns:
the SQLCache for this connections

setURI

public void setURI(org.openrdf.model.URI uri)
Set the URI for this container

Parameters:
uri - for this container

getContainerName

public java.lang.String getContainerName()
Get the container's name

Returns:
the container's name

setContainerName

public void setContainerName(java.lang.String containerName)
Set the container's name

Parameters:
containerName -

getURI

public org.openrdf.model.URI getURI()
Description copied from interface: IContainer
Get URI of IContainer

Specified by:
getURI in interface IContainer
Returns:
URI for this container

close

public void close()
Description copied from interface: IContainer
Disconnect container from its source and close the container Note: Once a container is closed, it is based on the source of the container's data whether or not subsequent calls to connect will return the same data

Specified by:
close in interface IContainer

isClosed

public boolean isClosed()
Description copied from interface: IContainer
Return if container is closed

Specified by:
isClosed in interface IContainer
Returns:
true if container is closed

clear

public void clear(org.openrdf.model.URI namedGraphUri)
Clear all statements from container for the given graph

Parameters:
namedGraphUri - of graph to clear

reset

public void reset()
Reset the connections


clearDatabase

public void clearDatabase()
Delete all the tables for this container


add

public void add(java.util.Iterator<org.openrdf.model.Statement> statements)
Description copied from interface: IContainer
Add a set of statements from container

Specified by:
add in interface IContainer
Parameters:
statements - statements to add to container

add

public void add(org.openrdf.model.Resource subj,
                org.openrdf.model.URI pred,
                org.openrdf.model.Value obj,
                org.openrdf.model.Resource context)
Description copied from interface: IContainer
Add a new statement with given subj,pred,obj,context

Specified by:
add in interface IContainer
Parameters:
subj - Subject of statement
pred - Predicate of statement
obj - Object of statement
context - Context of statement

clear

public void clear()
Description copied from interface: IContainer
Delete all statements in container

Specified by:
clear in interface IContainer

clear

public void clear(org.openrdf.model.Resource... context)
Description copied from interface: IContainer
Delete all statements in container for given contexts

Specified by:
clear in interface IContainer
Parameters:
context - Contexts to clear from container

delete

public void delete(org.openrdf.model.Resource subj,
                   org.openrdf.model.URI pred,
                   org.openrdf.model.Value obj,
                   org.openrdf.model.Resource context)
Description copied from interface: IContainer
Delete a statement from container

Specified by:
delete in interface IContainer
Parameters:
subj - Subject resource to match, or wildcard if null
pred - Predicate uri to match, or wildcard if null
obj - Object value to match, or wildcard if null
context - Context values to match, or wildcard if null

add

public void add(org.openrdf.model.Statement... statements)
Description copied from interface: IContainer
Add one or more statements to container

Specified by:
add in interface IContainer
Parameters:
statements - statements to add to container

delete

public void delete(org.openrdf.model.Statement... statements)
Description copied from interface: IContainer
Delete a set of statements from container

Specified by:
delete in interface IContainer
Parameters:
statements - statements to delete from container

delete

public void delete(java.util.Iterator<org.openrdf.model.Statement> statements)
Description copied from interface: IContainer
Delete a set of statements from container

Specified by:
delete in interface IContainer
Parameters:
statements - statements to delete from container

getStatements

public info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> getStatements()
Description copied from interface: IContainer
Get an iterator over all statements within this container

Specified by:
getStatements in interface IContainer
Returns:
CloseableIterator of all statements within this container

find

public info.aduna.collections.iterators.CloseableIterator<org.openrdf.model.Statement> find(org.openrdf.model.Resource subj,
                                                                                            org.openrdf.model.URI prop,
                                                                                            org.openrdf.model.Value obj,
                                                                                            org.openrdf.model.Resource... namedGraphUri)
Description copied from interface: IContainer
Return an iterator over all statements that match the pattern of subj,prop,obj

Specified by:
find in interface IContainer
Parameters:
subj - Subject resource to match, or wildcard if null
prop - Predicate uri to match, or wildcard if null
obj - Object value to match, or wildcard if null
namedGraphUri - Context values to match, or wildcard if null
Returns:
an iterator of all statements that match the pattern of subj,prop,obj,context

size

public int size()
Description copied from interface: IContainer
Return number of statements in container

Specified by:
size in interface IContainer
Returns:
number of statements in container

size

public int size(org.openrdf.model.Resource... namedGraphUri)
Description copied from interface: IContainer
Return number of statements in container

Specified by:
size in interface IContainer
Parameters:
namedGraphUri - Contexts of statements to count
Returns:
number of statements in container for given contexts

isEmpty

public boolean isEmpty()
Description copied from interface: IContainer
Return if container is empty

Specified by:
isEmpty in interface IContainer
Returns:
true if container is empty

isEmpty

public boolean isEmpty(org.openrdf.model.Resource... context)
Description copied from interface: IContainer
Return if container is empty for given contexts

Specified by:
isEmpty in interface IContainer
Parameters:
context - Contexts of statements to count
Returns:
true if container is empty

contains

public boolean contains(org.openrdf.model.Statement match)
Tests if a statement is contained in the container.

Specified by:
contains in interface IContainer
Parameters:
match - is the statement to be tested
Returns:
boolean result to indicate if the statement was contained

contains

public boolean contains(org.openrdf.model.Resource subj,
                        org.openrdf.model.URI prop,
                        org.openrdf.model.Value obj,
                        org.openrdf.model.Resource... contexts)
Tests if a statement is contained in the container.

Specified by:
contains in interface IContainer
Parameters:
subj - Subject resource to match, or wildcard if null
prop - Predicate uri to match, or wildcard if null
obj - Object value to match, or wildcard if null
contexts - Context values to match, or wildcard if null
Returns:
boolean result to indicate if the statement was contained

getConfiguration

public RDBConfiguration getConfiguration()
Get the configuration

Returns:
the configuration

getNodeLayout

public CompositeNodeLayout getNodeLayout()
Get the nodeLayout

Returns:
the nodeLayout

isLocked

public boolean isLocked()
Determine if currently in a transaction

Returns:
true if currently in a transaction

begin

public void begin()
           throws AnzoException
Begin database transaction Note:Database already in transaction

Throws:
AnzoException - if there was an error starting transaction

abort

public void abort()
           throws AnzoException
Abort database transaction

Throws:
AnzoException - if there was an error aborting transaction

commit

public void commit()
            throws AnzoException
Commit database transaction

Throws:
AnzoException - if there was an error committing transaction

executeQuery

public QueryResult executeQuery(java.util.Set<org.openrdf.model.URI> defaultNamedGraphsIn,
                                java.util.Set<org.openrdf.model.URI> namedGraphsIn,
                                java.lang.String query)
                         throws AnzoException
Description copied from interface: IContainer
Execute a SPARQL query against the data within this container

Specified by:
executeQuery in interface IContainer
Parameters:
defaultNamedGraphsIn - Set<URI> of URIs for NamedGraphs that will make up the default graph for this query
namedGraphsIn - Set<URI> of URIs for NamedGraphs that will make up the NamedGraphs for this query
query - SPARQL query string
Returns:
Results of running query
Throws:
AnzoException

executeQuery

public QueryResults executeQuery(java.util.Set<org.openrdf.model.URI> defaultNamedGraphsIn,
                                 java.util.Set<org.openrdf.model.URI> namedGraphsIn,
                                 java.lang.String query,
                                 boolean includeInferredStatements,
                                 org.openrdf.model.URI ontology)
                          throws AnzoException
Execute a SPARQL query against the data within this container

Parameters:
defaultNamedGraphsIn - Set<URI> of URIs for NamedGraphs that will make up the default graph for this query
namedGraphsIn - Set<URI> of URIs for NamedGraphs that will make up the NamedGraphs for this query
query - SPARQL query string
includeInferredStatements - should query include inferred statements in results
ontology - URI of ontology to use to determine inferred statements
Returns:
the Results of running query
Throws:
AnzoException

getTransactionManager

public ITransactionManager getTransactionManager()
Description copied from interface: IContainer
Return ITransactionManager for this container

Specified by:
getTransactionManager in interface IContainer
Returns:
ITransactionManager for this container

setTransactionManager

public void setTransactionManager(ITransactionManager transactionManager)
Description copied from interface: IContainer
Set ITransactionManager for this container

Specified by:
setTransactionManager in interface IContainer
Parameters:
transactionManager - set ITransactionManager for this container

getGlitter

public Engine getGlitter()
Get the Glitter engine for this connection

Returns:
the Glitter engine for this connection

purgeOntology

public void purgeOntology(org.openrdf.model.URI ontology)
                   throws AnzoException
Purge inferred object definitions from db for a given ontology

Parameters:
ontology - whose object definitions should be removed
Throws:
AnzoException - if there was an error purging objects from db

insertInferedProperty

public void insertInferedProperty(org.openrdf.model.URI ontology,
                                  org.openrdf.model.URI property,
                                  org.openrdf.model.URI inferedProperty)
                           throws AnzoException
Insert an inferred property definition into the DB

Parameters:
ontology - ontology to which the definition belongs
property - property name
inferedProperty - inferred property
Throws:
AnzoException - if there was an error inserting definition into the db

deleteInferedProperty

public void deleteInferedProperty(org.openrdf.model.URI ontology,
                                  org.openrdf.model.URI property,
                                  org.openrdf.model.URI inferedProperty)
                           throws AnzoException
Delete an inferred property definition into the DB

Parameters:
ontology - ontology to which the definition belongs
property - property name
inferedProperty - inferred property
Throws:
AnzoException - if there was an error deleting definition into the db

insertInferedObject

public void insertInferedObject(org.openrdf.model.URI ontology,
                                org.openrdf.model.URI property,
                                org.openrdf.model.URI object,
                                org.openrdf.model.URI inferedObject)
                         throws AnzoException
Insert an inferred object definition into the DB

Parameters:
ontology - ontology to which the definition belongs
property - property name
object - object value
inferedObject - inferred object value
Throws:
AnzoException - if there was an error inserting definition into the db

deleteInferedObject

public void deleteInferedObject(org.openrdf.model.URI ontology,
                                org.openrdf.model.URI property,
                                org.openrdf.model.URI object,
                                org.openrdf.model.URI inferedObject)
                         throws AnzoException
Delete an inferred object definition into the DB

Parameters:
ontology - ontology to which the definition belongs
property - property name
object - object value
inferedObject - inferred object value
Throws:
AnzoException - if there was an error deleting definition into the db

getEventManager

public INamedGraphEventManager getEventManager()
Get the eventManager for this connection

Specified by:
getEventManager in interface IContainer
Returns:
the eventManager for this connection

setEventManager

public void setEventManager(INamedGraphEventManager eventManager)
Set the event manager for this connection

Specified by:
setEventManager in interface IContainer
Parameters:
eventManager - the eventManager

populateValidGraphs

public void populateValidGraphs(java.util.Map<org.openrdf.model.Value,java.lang.Long> graphIds,
                                int includeAllNamedGraphsIn,
                                java.lang.String destinationTable)
                         throws java.sql.SQLException,
                                UnexpectedException
Populate a temporary table with the ids of graphs that match the parameters

Parameters:
graphIds - ids to add
includeAllNamedGraphsIn - should all namedgraph ids be added
destinationTable - name of temporary table to add into
Throws:
java.sql.SQLException - if there was an sql exception thrown inserting the graph ids
UnexpectedException - if there was an unexpected exception populating table

getContexts

public java.util.Collection<org.openrdf.model.URI> getContexts()
Description copied from interface: IContainer
Get the set of Context URIs that are container within this Container

Specified by:
getContexts in interface IContainer
Returns:
the set of Context URIs that are container within this Container

isReturned

public boolean isReturned()
Has this connection been returned to the ContainerConnectionPool

Returns:
true if the connection has been returned

setReturned

public void setReturned(boolean returned)
Set if connection has been returned to the ContainerConnectionPool

Parameters:
returned -

getConnectionType

public int getConnectionType()
Is the JDBC connection set to readOnly

Returns:
true if the JDBC connection is set to readOnly

passivate

public void passivate()
               throws java.lang.Exception
Passivate this object to its pool

Throws:
java.lang.Exception

reset

public void reset(java.lang.Long id)
Description copied from interface: IResetListener
Server was reset

Specified by:
reset in interface IResetListener
Parameters:
id - of server that was reset

getLiteralIndexer

public LiteralIndexer getLiteralIndexer()
Get the literal indexer for this connection

Returns:
the literal indexer for this connection


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.