@Service(value={WeightedTcProvider.class,TcProvider.class,QueryableTcProvider.class}) @Properties(value={@Property(name="tdb-dir"),@Property(name="default-graph-name"),@Property(name="sync-interval",intValue=6),@Property(name="weight",intValue=105),@Property(name="general.purpose.tc",boolValue=true)}) public class SingleTdbDatasetTcProvider extends Object implements WeightedTcProvider
WeightedTcProvider
implementation for Jena TDB that uses a single
Dataset
to store all created
Graph
and MGraph
instances.
The TDB_DIR
is uses to configure the directory on the disc. It
supports property substitution '${property}'
based on properties defined
in the BundleContext.getProperty(String)
and
System.getProperty(String)
. This is to easily allow configurations
such as "${myHome}/myRdfStore"
The DEFAULT_GRAPH_NAME
property can be used to define the
name of the Graph that exposes the Dataset.getDefaultModel()
as
both TcProvider.getGraph(UriRef)
and TcProvider.getMGraph(UriRef)
.
This easily allows to access the union graph of the Jena TDB dataset.
This TcProvider
requires
an
configuration and uses the configuration factory
. Therefore it will be bot active until a valid
configuration is parsed to the ConfigurationAdmin
service. However
it supports multiple instances to be created.
Users that want to use multiple instances will need to use special filters
to ensure that the correct instance is injected to components. As by default
the instance with the highest WEIGHT
will be used by Clerezza
to create instances. A good practice to filter for multiple instances is
to add an additional user defined key to the configuration that can later
be used for filtering. Such additional keys will be savely ignored by
this implementation.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_GRAPH_NAME |
static int |
DEFAULT_SYNC_INTERVAL |
static int |
MIN_SYNC_INTERVAL |
static String |
SYNC_INTERVAL |
static String |
TDB_DIR |
static String |
USE_GRAPH_NAME_SUFFIXES |
static String |
WEIGHT |
Constructor and Description |
---|
SingleTdbDatasetTcProvider()
Default constructor used by OSGI
|
SingleTdbDatasetTcProvider(Dictionary<String,Object> config)
Creates a TDB single dataset
TcProvider based on the parsed
configuration. |
Modifier and Type | Method and Description |
---|---|
protected void |
activate(org.osgi.service.component.ComponentContext ctx)
Activate method used by OSGI
|
void |
close()
Closes this
TcProvider instance and frees up all system resources. |
Graph |
createGraph(UriRef name,
TripleCollection triples)
Creates a
Graph with a specified name |
MGraph |
createMGraph(UriRef name)
Creates an initially empty
MGraph with a specified name |
protected void |
deactivate(org.osgi.service.component.ComponentContext ctx)
Deactivates this component.
|
void |
deleteTripleCollection(UriRef name)
Deletes the
Graph or MGraph of a specified name. |
Object |
executeSparqlQuery(String query,
UriRef defaultGraph)
Executes any sparql query.
|
protected void |
finalize()
call close in finalisation
|
com.hp.hpl.jena.query.Dataset |
getDataset() |
Graph |
getGraph(UriRef name)
Get a
Graph by its name |
MGraph |
getMGraph(UriRef name)
Get an
MGraph by its name. |
Set<UriRef> |
getNames(Graph graph)
get a set of the names of a
Graph |
TripleCollection |
getTriples(UriRef name)
This method is used to get a
TripleCollection indifferently
whether it's a Graph or an MGraph. |
int |
getWeight()
Get the weight of this provider.
|
Set<UriRef> |
listGraphs()
Lists the name of the
Graph s available through this
TcProvider , implementations may take into account the
security context and omit Graph s for which access is not
allowed. |
Set<UriRef> |
listMGraphs()
Lists the name of the
MGraph s available through this
TcProvider , implementations may take into account the
security context and omit MGraph s for which access is not
allowed. |
Set<UriRef> |
listTripleCollections()
Lists the name of the
TripleCollection s available through this
TcProvider indifferently whether they are Graphs or an
MGraphs, implementations may take into account the security context and
omit TripleCollection s for which access is not allowed. |
void |
setDataset(com.hp.hpl.jena.query.Dataset dataset) |
public static final String TDB_DIR
public static final String DEFAULT_GRAPH_NAME
public static final String WEIGHT
public static final String SYNC_INTERVAL
public static final String USE_GRAPH_NAME_SUFFIXES
public static final int DEFAULT_SYNC_INTERVAL
public static final int MIN_SYNC_INTERVAL
public SingleTdbDatasetTcProvider()
public SingleTdbDatasetTcProvider(Dictionary<String,Object> config) throws org.osgi.service.cm.ConfigurationException, IOException
TcProvider
based on the parsed
configuration.The following properties are supported:
TDB_DIR
(required): The directory used by Jena TDB. Property
substitution "${property-name}" with System.getProperties()
is
supported.
DEFAULT_GRAPH_NAME
: The name (UriRef
) of the
Graph
that exports the union graph. This graph allows to query
triples in any named model managed by this TcProvider
.
SYNC_INTERVAL
: The sync interval that
is used to write changes in the graph to the file system. If missing
the DEFAULT_SYNC_INTERVAL
is used. Values lower than
MIN_SYNC_INTERVAL
are ignored
WEIGHT
: The weight of this TcProvider
. If missing
0
is used as weight.
close()
to free up system
resources when they are no longer need this instance.config
- The configurationIOException
- theorg.osgi.service.cm.ConfigurationException
@Activate protected void activate(org.osgi.service.component.ComponentContext ctx) throws org.osgi.service.cm.ConfigurationException, IOException
ctx
- org.osgi.service.cm.ConfigurationException
IOException
protected void finalize() throws Throwable
public void close()
TcProvider
instance and frees up all system resources.
This method needs only to be called when using this TcProvider outside
an OSGI environment.@Deactivate protected void deactivate(org.osgi.service.component.ComponentContext ctx)
ctx
- the ComponentContext. May be null
public Graph getGraph(UriRef name) throws NoSuchEntityException
TcProvider
Graph
by its namegetGraph
in interface TcProvider
name
- the name of the GraphGraph
with the specified nameNoSuchEntityException
- if there is no Graph
with the specified namepublic MGraph getMGraph(UriRef name) throws NoSuchEntityException
TcProvider
MGraph
by its name. The instances
returned in different invocations are equals
.getMGraph
in interface TcProvider
MGraph
with the specified nameNoSuchEntityException
- if there is no MGraph
with the specified namepublic TripleCollection getTriples(UriRef name) throws NoSuchEntityException
TcProvider
TripleCollection
indifferently
whether it's a Graph or an MGraph. If the name
names an
MGraph
the result is the same as when invoking
getMGraph
with that argument, analogously for
Graph
S the method returns an instance equals to what
getGraph
would return.getTriples
in interface TcProvider
name
- the name of the Graph
or MGraph
Graph
or MGraph
NoSuchEntityException
- if there is no Graph
or MGraph
with the specified namepublic Set<UriRef> listGraphs()
TcProvider
Graph
s available through this
TcProvider
, implementations may take into account the
security context and omit Graph
s for which access is not
allowed.listGraphs
in interface TcProvider
Graph
spublic Set<UriRef> listMGraphs()
TcProvider
MGraph
s available through this
TcProvider
, implementations may take into account the
security context and omit MGraph
s for which access is not
allowed.listMGraphs
in interface TcProvider
MGraph
spublic Set<UriRef> listTripleCollections()
TcProvider
TripleCollection
s available through this
TcProvider
indifferently whether they are Graphs or an
MGraphs, implementations may take into account the security context and
omit TripleCollection
s for which access is not allowed.listTripleCollections
in interface TcProvider
TripleCollection
spublic MGraph createMGraph(UriRef name) throws UnsupportedOperationException, EntityAlreadyExistsException
TcProvider
MGraph
with a specified namecreateMGraph
in interface TcProvider
name
- names the new MGraph
MGraph
UnsupportedOperationException
- if this provider doesn't support
creating MGraph
SEntityAlreadyExistsException
- if an MGraph with the specified name
already existspublic Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException, EntityAlreadyExistsException
TcProvider
Graph
with a specified namecreateGraph
in interface TcProvider
name
- the name of the Graph
to be createdtriples
- the triples of the new Graph
Graph
UnsupportedOperationException
- if this provider doesn't support
creating Graph
SEntityAlreadyExistsException
- if a Graph with the specified name
already existspublic void deleteTripleCollection(UriRef name) throws UnsupportedOperationException, NoSuchEntityException, EntityUndeletableException
TcProvider
Graph
or MGraph
of a specified name.
If name
references a Graph and the graph has other names, it
will still be available with those other names.deleteTripleCollection
in interface TcProvider
name
- the entity to be removedUnsupportedOperationException
- if this provider doesn't support
entities deletion.NoSuchEntityException
- if name
doesn't refer to a
Graph
or an MGraph
.EntityUndeletableException
- if the specified Graph is undeletablepublic Set<UriRef> getNames(Graph graph)
TcProvider
Graph
getNames
in interface TcProvider
Graph
, the set is empty if
Graph
is unknownpublic int getWeight()
WeightedTcProvider
TcManager
will prioritize
TcProvider
s with greater weight.getWeight
in interface WeightedTcProvider
public Object executeSparqlQuery(String query, UriRef defaultGraph)
QueryableTcProvider
executeSparqlQuery
in interface QueryableTcProvider
query
- the sparql query to executepublic com.hp.hpl.jena.query.Dataset getDataset()
public void setDataset(com.hp.hpl.jena.query.Dataset dataset)
Copyright © 2014 The Apache Software Foundation. All Rights Reserved.