Class DatasetImpl
- java.lang.Object
-
- org.apache.jena.sparql.core.DatasetImpl
-
- All Implemented Interfaces:
Dataset,Transactional
- Direct Known Subclasses:
DatasetOne
public class DatasetImpl extends java.lang.Object implements Dataset
An implementation of a Dataset. This is the "usual" implementation based on wrapping a DatasetGraph and providing an adapter layer from Model/Resource to Graph/Node The characteristics of this class depend on the characteristics of DatasetGraph.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.jena.sparql.core.Transactional
Transactional.Promote
-
-
Constructor Summary
Constructors Constructor Description DatasetImpl(Model model)Create a Dataset with the model as default model.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Abort a transaction - finish the transaction and undo any changes (if a "write" transaction)DatasetaddNamedModel(java.lang.String uri, Model model)Set a named graph.DatasetGraphasDatasetGraph()Get the dataset in graph formvoidbegin()Start a transaction which is READ mode and which will switch to WRITE if an update is attempted but only if no intermediate transaction has performed an update.voidbegin(ReadWrite mode)Start either a READ or WRITE transactionvoidbegin(TxnType txnType)Start a transaction.
READ or WRITE transactions start in that state and do not change for the lifetime of the transaction.voidclose()Close the dataset, potentially releasing any associated resources.voidcommit()Commit a transaction - finish the transaction and make any changes permanent (if a "write" transaction)booleancontainsNamedModel(java.lang.String uri)Does the dataset contain a model with the name supplied?voidend()Finish the transaction - if a write transaction and commit() has not been called, then abortContextgetContext()Get the context associated with this datasetModelgetDefaultModel()Get the default graph as a Jena ModelLockgetLock()Get the lock for this datasetModelgetNamedModel(java.lang.String uri)Get a graph by name as a Jena ModelModelgetUnionModel()Get the graph which is the union of all named graphs as a Jena ModelbooleanisEmpty()booleanisInTransaction()Say whether a transaction is activejava.util.Iterator<java.lang.String>listNames()List the namesbooleanpromote(Transactional.Promote txnType)Attempt to promote a transaction from "read" mode to "write" and the transaction.DatasetremoveNamedModel(java.lang.String uri)Remove a named graph.DatasetreplaceNamedModel(java.lang.String uri, Model model)Change a named graph for another using the same nameDatasetsetDefaultModel(Model model)Set the default graph.booleansupportsTransactionAbort()Declare whetherDataset.abort()is supported.booleansupportsTransactions()Does this dataset support transactions? Supporting transactions means that the dataset implementation providesDataset.begin(org.apache.jena.query.ReadWrite),Dataset.commit(),Dataset.end()which otherwise may throwUnsupportedOperationException.ReadWritetransactionMode()Return the current mode of the transaction - "read" or "write".TxnTypetransactionType()Return the transaction type used inbegin(TxnType).static Datasetwrap(DatasetGraph datasetGraph)Wrap an existing DatasetGraph-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jena.query.Dataset
getPrefixMapping
-
Methods inherited from interface org.apache.jena.sparql.core.Transactional
calc, calculate, calculateRead, calculateWrite, exec, execute, executeRead, executeWrite, promote
-
-
-
-
Constructor Detail
-
DatasetImpl
public DatasetImpl(Model model)
Create a Dataset with the model as default model. Named models must be explicitly added to identify the storage to be used.
-
-
Method Detail
-
wrap
public static Dataset wrap(DatasetGraph datasetGraph)
Wrap an existing DatasetGraph
-
getDefaultModel
public Model getDefaultModel()
Description copied from interface:DatasetGet the default graph as a Jena Model- Specified by:
getDefaultModelin interfaceDataset
-
getUnionModel
public Model getUnionModel()
Description copied from interface:DatasetGet the graph which is the union of all named graphs as a Jena Model- Specified by:
getUnionModelin interfaceDataset
-
getLock
public Lock getLock()
Description copied from interface:DatasetGet the lock for this dataset
-
getContext
public Context getContext()
Description copied from interface:DatasetGet the context associated with this dataset- Specified by:
getContextin interfaceDataset
-
supportsTransactions
public boolean supportsTransactions()
Description copied from interface:DatasetDoes this dataset support transactions? Supporting transactions means that the dataset implementation providesDataset.begin(org.apache.jena.query.ReadWrite),Dataset.commit(),Dataset.end()which otherwise may throwUnsupportedOperationException.See
Dataset.supportsTransactionAbort()forDataset.abort(). ADatasetthat provides functionality across independent systems can not provide all features strong guarantees. For example, they may use MRSW locking and some isolation control. Specifically, they do not necessarily provideDataset.abort().In addition, check details of a specific implementation.
- Specified by:
supportsTransactionsin interfaceDataset
-
supportsTransactionAbort
public boolean supportsTransactionAbort()
Description copied from interface:DatasetDeclare whetherDataset.abort()is supported. This goes along with clearing up after exceptions inside application transaction code.- Specified by:
supportsTransactionAbortin interfaceDataset
-
begin
public void begin()
Description copied from interface:TransactionalStart a transaction which is READ mode and which will switch to WRITE if an update is attempted but only if no intermediate transaction has performed an update.See
Transactional.begin(TxnType)for more details an options.May not be implemented. See
Transactional.begin(ReadWrite)is guaranteed to be provided.- Specified by:
beginin interfaceTransactional
-
begin
public void begin(TxnType txnType)
Description copied from interface:TransactionalStart a transaction.
READ or WRITE transactions start in that state and do not change for the lifetime of the transaction.WRITE: this guarantees a WRITE will complete ifcommit()is called. The same asbegin(ReadWrite.WRITE).READ: the transaction can not promote to WRITE,ensuring read-only access to the data. The same asbegin(ReadWrite.READ).READ_PROMOTE: the transaction will go from "read" to "write" if an update is attempted and if the dataset has not been changed by another write transaction. See alsoTransactional.promote().READ_COMMITTED_PROMOTE: Use this with care. The promotion will succeed but changes from other transactions become visible.
begin). IfREAD_PROMOTE, the dataset must not have changed; ifREAD_COMMITTED_PROMOTEany intermediate changes are visible but the application can not assume any data it has read in the transaction is the same as it was at the point the transaction started.This operation is optional and some implementations may throw a
JenaTransactionExceptionexception for some or allTxnTypevalues.See
Transactional.begin(ReadWrite)for a form that is required of implementations.- Specified by:
beginin interfaceTransactional
-
begin
public void begin(ReadWrite mode)
Description copied from interface:DatasetStart either a READ or WRITE transaction- Specified by:
beginin interfaceDataset- Specified by:
beginin interfaceTransactional
-
promote
public boolean promote(Transactional.Promote txnType)
Description copied from interface:TransactionalAttempt to promote a transaction from "read" mode to "write" and the transaction. This method allows the form of promotion to be specified. The transaction must not have been started withREAD, which is read-only.An argument of
READ_PROMOTEtreats the promotion as if the transaction was started withREAD_PROMOTE(any other writer commiting since the transaction started blocks promotion) andREAD_COMMITTED_PROMOTEtreats the promotion as if the transaction was started withREAD_COMMITTED_PROMOTE(intemediate writer commits become visible).Returns "true" if the transaction is in write mode after the call. The method always succeeds of the transaction is already "write".
This method returns true if a
READ_PROMOTEorREAD_COMMITTED_PROMOTEis promoted.This method returns false if a
READ_PROMOTEcan't be promoted - the transaction is still valid and in "read" mode.This method throws an exception if there is an attempt to promote a
READtransaction.- Specified by:
promotein interfaceTransactional
-
transactionMode
public ReadWrite transactionMode()
Description copied from interface:TransactionalReturn the current mode of the transaction - "read" or "write". If the caller is not in a transaction, this method returns null.- Specified by:
transactionModein interfaceTransactional
-
transactionType
public TxnType transactionType()
Description copied from interface:TransactionalReturn the transaction type used inbegin(TxnType). If the caller is not in a transaction, this method returns null.- Specified by:
transactionTypein interfaceTransactional
-
isInTransaction
public boolean isInTransaction()
Say whether a transaction is active- Specified by:
isInTransactionin interfaceDataset- Specified by:
isInTransactionin interfaceTransactional
-
commit
public void commit()
Description copied from interface:DatasetCommit a transaction - finish the transaction and make any changes permanent (if a "write" transaction)- Specified by:
commitin interfaceDataset- Specified by:
commitin interfaceTransactional
-
abort
public void abort()
Description copied from interface:DatasetAbort a transaction - finish the transaction and undo any changes (if a "write" transaction)- Specified by:
abortin interfaceDataset- Specified by:
abortin interfaceTransactional
-
end
public void end()
Description copied from interface:DatasetFinish the transaction - if a write transaction and commit() has not been called, then abort- Specified by:
endin interfaceDataset- Specified by:
endin interfaceTransactional
-
asDatasetGraph
public DatasetGraph asDatasetGraph()
Description copied from interface:DatasetGet the dataset in graph form- Specified by:
asDatasetGraphin interfaceDataset
-
getNamedModel
public Model getNamedModel(java.lang.String uri)
Description copied from interface:DatasetGet a graph by name as a Jena Model- Specified by:
getNamedModelin interfaceDataset
-
addNamedModel
public Dataset addNamedModel(java.lang.String uri, Model model)
Description copied from interface:DatasetSet a named graph.- Specified by:
addNamedModelin interfaceDataset- Parameters:
uri- the name of the graph to setmodel- the graph to set- Returns:
- this
Datasetfor continued usage
-
removeNamedModel
public Dataset removeNamedModel(java.lang.String uri)
Description copied from interface:DatasetRemove a named graph.- Specified by:
removeNamedModelin interfaceDataset- Parameters:
uri- the name of the gaph to remove- Returns:
- this
Datasetfor continued usage
-
replaceNamedModel
public Dataset replaceNamedModel(java.lang.String uri, Model model)
Description copied from interface:DatasetChange a named graph for another using the same name- Specified by:
replaceNamedModelin interfaceDataset- Parameters:
uri- the name of the graph to replacemodel- the graph with which to replace it- Returns:
- this
Datasetfor continued usage
-
setDefaultModel
public Dataset setDefaultModel(Model model)
Description copied from interface:DatasetSet the default graph. Can be set to null for none.- Specified by:
setDefaultModelin interfaceDataset- Parameters:
model- the default graph to set- Returns:
- this
Datasetfor continued usage
-
containsNamedModel
public boolean containsNamedModel(java.lang.String uri)
Description copied from interface:DatasetDoes the dataset contain a model with the name supplied?- Specified by:
containsNamedModelin interfaceDataset
-
listNames
public java.util.Iterator<java.lang.String> listNames()
Description copied from interface:DatasetList the names
-
close
public void close()
Description copied from interface:DatasetClose the dataset, potentially releasing any associated resources. The dataset can not be used for query after this call.
-
-