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
AnSailSource
that keeps a delta of its state from a backingSailSource
.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoFlush
If thisSailSource
should be flushed to the backingSailSource
when it is not in use.private SailSource
backingSource
The underlySailSource
thisSailSource
is derived from.private java.util.ArrayDeque<Changeset>
changes
The difference between thisSailSource
and the backingSailSource
.private static org.slf4j.Logger
logger
private ModelFactory
modelFactory
TheModel
instances that should be used to storeSailSink.approve(Resource, IRI, Value, Resource)
andSailSink.deprecate(Resource, IRI, Value, Resource)
statements.private java.util.Collection<SailDataset>
observers
Set of openSailDataset
for thisSailSource
.private java.util.Set<Changeset>
pending
private SailSink
prepared
private java.util.concurrent.locks.ReentrantLock
semaphore
Used to prevent changes to this object's field from multiple threads.private SailSink
serializable
Non-null when inIsolationLevels.SERIALIZABLE
(or higher) mode.private SailDataset
snapshot
Non-null when inIsolationLevels.SNAPSHOT
(or higher) mode.
-
Constructor Summary
Constructors Constructor Description SailSourceBranch(SailSource backingSource)
Creates a new in-memorySailSource
derived from the givenSailSource
.SailSourceBranch(SailSource backingSource, ModelFactory modelFactory)
Creates a newSailSource
derived from the givenSailSource
.SailSourceBranch(SailSource backingSource, ModelFactory modelFactory, boolean autoFlush)
Creates a newSailSource
derived from the givenSailSource
and ifautoFlush
is true, will automatically callflush()
when not in use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
autoFlush()
void
close()
Closes this resource, relinquishing any underlying resources.(package private) void
closeChangeset(Changeset changeset)
(package private) void
compressChanges()
SailDataset
dataset(IsolationLevel level)
Create an observableSailDataset
of the current state of thisSailSource
.private SailDataset
derivedFromSerializable(IsolationLevel level)
private SailDataset
derivedFromSnapshot(IsolationLevel level)
void
flush()
Apply all the changes to this branch to the backingSailSource
, if applicable.private void
flush(Changeset change, SailSink sink)
private void
flush(SailSink sink)
SailSource
fork()
Creates a new branch of this source.boolean
isChanged()
private boolean
isChanged(Changeset change)
(package private) void
merge(Changeset change)
void
prepare()
Check the consistency of this branch and throws aSailConflictException
ifSailSource.flush()
ing this branch would cause the backingSailSource
to be inconsistent, if applicable.private void
prepare(Changeset change, SailSink sink)
private void
prepare(SailSink sink)
(package private) void
preparedChangeset(Changeset changeset)
SailSink
sink(IsolationLevel level)
Create aSailSink
that when when itsSailSource.flush()
is called, the changes are applied to this source.java.lang.String
toString()
-
-
-
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 thisSailSource
and the backingSailSource
.
-
pending
private final java.util.Set<Changeset> pending
-
observers
private final java.util.Collection<SailDataset> observers
Set of openSailDataset
for thisSailSource
.
-
backingSource
private final SailSource backingSource
The underlySailSource
thisSailSource
is derived from.
-
modelFactory
private final ModelFactory modelFactory
TheModel
instances that should be used to storeSailSink.approve(Resource, IRI, Value, Resource)
andSailSink.deprecate(Resource, IRI, Value, Resource)
statements.
-
autoFlush
private final boolean autoFlush
If thisSailSource
should be flushed to the backingSailSource
when 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-memorySailSource
derived from the givenSailSource
.- Parameters:
backingSource
-
-
SailSourceBranch
public SailSourceBranch(SailSource backingSource, ModelFactory modelFactory)
Creates a newSailSource
derived from the givenSailSource
.- Parameters:
backingSource
-modelFactory
-
-
SailSourceBranch
public SailSourceBranch(SailSource backingSource, ModelFactory modelFactory, boolean autoFlush)
Creates a newSailSource
derived from the givenSailSource
and ifautoFlush
is true, will automatically callflush()
when not in use.- Parameters:
backingSource
-modelFactory
-autoFlush
-
-
-
Method Detail
-
close
public void close() throws SailException
Description copied from interface:SailClosable
Closes this resource, relinquishing any underlying resources.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceSailClosable
- Throws:
SailException
- if this resource cannot be closed
-
sink
public SailSink sink(IsolationLevel level) throws SailException
Description copied from interface:SailSource
Create aSailSink
that when when itsSailSource.flush()
is called, the changes are applied to this source.- Specified by:
sink
in interfaceSailSource
- Parameters:
level
- If this level is compatible withIsolationLevels.SERIALIZABLE
then aSailSink.prepare()
can throw aSailConflictException
.- Returns:
- Newly created
SailSink
- Throws:
SailException
-
dataset
public SailDataset dataset(IsolationLevel level) throws SailException
Description copied from interface:SailSource
Create an observableSailDataset
of the current state of thisSailSource
. Repeatedly calling with methods withIsolationLevels.SNAPSHOT
(or higher) isolation levels will result inSailDataset
s that are all derived from the same state of the backingSailSource
(if applicable), that is the only difference between the states of theSailDataset
will be from changes using thisSailSource.sink(IsolationLevel)
.- Specified by:
dataset
in interfaceSailSource
- Parameters:
level
- If this is compatible withIsolationLevels.SNAPSHOT_READ
the resultingSailDataset
will observe a single state of thisSailSource
.- Returns:
- an
SailDataset
of the current state - Throws:
SailException
-
fork
public SailSource fork()
Description copied from interface:SailSource
Creates a new branch of this source. When it'sSailSource.flush()
is called the changes are applied to this backing source.- Specified by:
fork
in interfaceSailSource
- Returns:
- a branched
SailSource
.
-
prepare
public void prepare() throws SailException
Description copied from interface:SailSource
Check the consistency of this branch and throws aSailConflictException
ifSailSource.flush()
ing this branch would cause the backingSailSource
to be inconsistent, if applicable. If this is the final backingSailSource
calling this method has no effect.- Specified by:
prepare
in interfaceSailSource
- Throws:
SailException
-
flush
public void flush() throws SailException
Description copied from interface:SailSource
Apply all the changes to this branch to the backingSailSource
, if applicable. If this is the final backingSailSource
calling this method has no effect.- Specified by:
flush
in interfaceSailSource
- Throws:
SailException
-
isChanged
public boolean isChanged()
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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
-
-