Package org.eclipse.rdf4j.sail.base
Class SailSourceBranch
- java.lang.Object
-
- org.eclipse.rdf4j.sail.base.SailSourceBranch
-
- All Implemented Interfaces:
java.lang.AutoCloseable,SailClosable,SailSource
class SailSourceBranch extends java.lang.Object implements SailSource
AnSailSourcethat keeps a delta of its state from a backingSailSource.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoFlushIf thisSailSourceshould be flushed to the backingSailSourcewhen it is not in use.private SailSourcebackingSourceThe underlySailSourcethisSailSourceis derived from.private java.util.ArrayDeque<Changeset>changesThe difference between thisSailSourceand the backingSailSource.private static org.slf4j.Loggerloggerprivate ModelFactorymodelFactoryTheModelinstances that should be used to storeSailSink.approve(Resource, IRI, Value, Resource)andSailSink.deprecate(Resource, IRI, Value, Resource)statements.private java.util.Collection<SailDataset>observersSet of openSailDatasetfor thisSailSource.private java.util.Set<Changeset>pendingprivate SailSinkpreparedprivate java.util.concurrent.locks.ReentrantLocksemaphoreUsed to prevent changes to this object's field from multiple threads.private SailSinkserializableNon-null when inIsolationLevels.SERIALIZABLE(or higher) mode.private SailDatasetsnapshotNon-null when inIsolationLevels.SNAPSHOT(or higher) mode.
-
Constructor Summary
Constructors Constructor Description SailSourceBranch(SailSource backingSource)Creates a new in-memorySailSourcederived from the givenSailSource.SailSourceBranch(SailSource backingSource, ModelFactory modelFactory)Creates a newSailSourcederived from the givenSailSource.SailSourceBranch(SailSource backingSource, ModelFactory modelFactory, boolean autoFlush)Creates a newSailSourcederived from the givenSailSourceand ifautoFlushis true, will automatically callflush()when not in use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidautoFlush()voidclose()Closes this resource, relinquishing any underlying resources.(package private) voidcloseChangeset(Changeset changeset)(package private) voidcompressChanges()SailDatasetdataset(IsolationLevel level)Create an observableSailDatasetof the current state of thisSailSource.private SailDatasetderivedFromSerializable(IsolationLevel level)private SailDatasetderivedFromSnapshot(IsolationLevel level)voidflush()Apply all the changes to this branch to the backingSailSource, if applicable.private voidflush(Changeset change, SailSink sink)private voidflush(SailSink sink)SailSourcefork()Creates a new branch of this source.booleanisChanged()private booleanisChanged(Changeset change)(package private) voidmerge(Changeset change)voidprepare()Check the consistency of this branch and throws aSailConflictExceptionifSailSource.flush()ing this branch would cause the backingSailSourceto be inconsistent, if applicable.private voidprepare(Changeset change, SailSink sink)private voidprepare(SailSink sink)(package private) voidpreparedChangeset(Changeset changeset)SailSinksink(IsolationLevel level)Create aSailSinkthat when when itsSailSource.flush()is called, the changes are applied to this source.java.lang.StringtoString()
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
semaphore
private final java.util.concurrent.locks.ReentrantLock semaphore
Used to prevent changes to this object's field from multiple threads.
-
changes
private final java.util.ArrayDeque<Changeset> changes
The difference between thisSailSourceand the backingSailSource.
-
pending
private final java.util.Set<Changeset> pending
-
observers
private final java.util.Collection<SailDataset> observers
Set of openSailDatasetfor thisSailSource.
-
backingSource
private final SailSource backingSource
The underlySailSourcethisSailSourceis derived from.
-
modelFactory
private final ModelFactory modelFactory
TheModelinstances that should be used to storeSailSink.approve(Resource, IRI, Value, Resource)andSailSink.deprecate(Resource, IRI, Value, Resource)statements.
-
autoFlush
private final boolean autoFlush
If thisSailSourceshould be flushed to the backingSailSourcewhen it is not in use.
-
snapshot
private SailDataset snapshot
Non-null when inIsolationLevels.SNAPSHOT(or higher) mode.
-
serializable
private SailSink serializable
Non-null when inIsolationLevels.SERIALIZABLE(or higher) mode.
-
prepared
private SailSink prepared
-
-
Constructor Detail
-
SailSourceBranch
public SailSourceBranch(SailSource backingSource)
Creates a new in-memorySailSourcederived from the givenSailSource.- Parameters:
backingSource-
-
SailSourceBranch
public SailSourceBranch(SailSource backingSource, ModelFactory modelFactory)
Creates a newSailSourcederived from the givenSailSource.- Parameters:
backingSource-modelFactory-
-
SailSourceBranch
public SailSourceBranch(SailSource backingSource, ModelFactory modelFactory, boolean autoFlush)
Creates a newSailSourcederived from the givenSailSourceand ifautoFlushis true, will automatically callflush()when not in use.- Parameters:
backingSource-modelFactory-autoFlush-
-
-
Method Detail
-
close
public void close() throws SailExceptionDescription copied from interface:SailClosableCloses this resource, relinquishing any underlying resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceSailClosable- Throws:
SailException- if this resource cannot be closed
-
sink
public SailSink sink(IsolationLevel level) throws SailException
Description copied from interface:SailSourceCreate aSailSinkthat when when itsSailSource.flush()is called, the changes are applied to this source.- Specified by:
sinkin interfaceSailSource- Parameters:
level- If this level is compatible withIsolationLevels.SERIALIZABLEthen aSailSink.prepare()can throw aSailConflictException.- Returns:
- Newly created
SailSink - Throws:
SailException
-
dataset
public SailDataset dataset(IsolationLevel level) throws SailException
Description copied from interface:SailSourceCreate an observableSailDatasetof the current state of thisSailSource. Repeatedly calling with methods withIsolationLevels.SNAPSHOT(or higher) isolation levels will result inSailDatasets that are all derived from the same state of the backingSailSource(if applicable), that is the only difference between the states of theSailDatasetwill be from changes using thisSailSource.sink(IsolationLevel).- Specified by:
datasetin interfaceSailSource- Parameters:
level- If this is compatible withIsolationLevels.SNAPSHOT_READthe resultingSailDatasetwill observe a single state of thisSailSource.- Returns:
- an
SailDatasetof the current state - Throws:
SailException
-
fork
public SailSource fork()
Description copied from interface:SailSourceCreates a new branch of this source. When it'sSailSource.flush()is called the changes are applied to this backing source.- Specified by:
forkin interfaceSailSource- Returns:
- a branched
SailSource.
-
prepare
public void prepare() throws SailExceptionDescription copied from interface:SailSourceCheck the consistency of this branch and throws aSailConflictExceptionifSailSource.flush()ing this branch would cause the backingSailSourceto be inconsistent, if applicable. If this is the final backingSailSourcecalling this method has no effect.- Specified by:
preparein interfaceSailSource- Throws:
SailException
-
flush
public void flush() throws SailExceptionDescription copied from interface:SailSourceApply all the changes to this branch to the backingSailSource, if applicable. If this is the final backingSailSourcecalling this method has no effect.- Specified by:
flushin interfaceSailSource- Throws:
SailException
-
isChanged
public boolean isChanged()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
preparedChangeset
void preparedChangeset(Changeset changeset)
-
merge
void merge(Changeset change)
-
compressChanges
void compressChanges()
-
closeChangeset
void closeChangeset(Changeset changeset)
-
autoFlush
void autoFlush() throws SailException- Throws:
SailException
-
isChanged
private boolean isChanged(Changeset change)
-
derivedFromSerializable
private SailDataset derivedFromSerializable(IsolationLevel level) throws SailException
- Throws:
SailException
-
derivedFromSnapshot
private SailDataset derivedFromSnapshot(IsolationLevel level) throws SailException
- Throws:
SailException
-
prepare
private void prepare(SailSink sink) throws SailException
- Throws:
SailException
-
prepare
private void prepare(Changeset change, SailSink sink) throws SailException
- Throws:
SailException
-
flush
private void flush(SailSink sink) throws SailException
- Throws:
SailException
-
flush
private void flush(Changeset change, SailSink sink) throws SailException
- Throws:
SailException
-
-