Package org.projectbarbel.histo
Class BarbelHistoCore<T>
- java.lang.Object
-
- org.projectbarbel.histo.BarbelHistoCore<T>
-
- Type Parameters:
T
- the business object type to manage
- All Implemented Interfaces:
BarbelHisto<T>
public final class BarbelHistoCore<T> extends Object implements BarbelHisto<T>
The core component ofBarbelHisto
. SeeBarbelHisto
for details.- Author:
- Niklas Schlimm
-
-
Field Summary
Fields Modifier and Type Field Description static ThreadLocal<BarbelHistoContext>
CONSTRUCTION_CONTEXT
-
Constructor Summary
Constructors Modifier Constructor Description protected
BarbelHistoCore(BarbelHistoContext context)
-
Method Summary
Modifier and Type Method Description boolean
contains(Object documentId)
Check ifBarbelHisto
contains data for the given document ID.BarbelHistoContext
getContext()
DocumentJournal
getDocumentJournal(Object id)
void
load(Collection<Bitemporal> bitemporals)
Method for clients that use a custom data store.void
loadQuiet(Collection<Bitemporal> bitemporals)
String
prettyPrintJournal(Object id)
Pretty print the journal for the given document ID.List<T>
retrieve(com.googlecode.cqengine.query.Query<T> query)
Retrieve data fromBarbelHisto
using cqengine like queries.List<T>
retrieve(com.googlecode.cqengine.query.Query<T> query, com.googlecode.cqengine.query.option.QueryOptions options)
Retrieve data fromBarbelHisto
using cqengine like queries.T
retrieveOne(com.googlecode.cqengine.query.Query<T> query)
Retrieve data fromBarbelHisto
using cqengine like queries.T
retrieveOne(com.googlecode.cqengine.query.Query<T> query, com.googlecode.cqengine.query.option.QueryOptions options)
Retrieve data fromBarbelHisto
using cqengine like queries.BitemporalUpdate<T>
save(T newVersion, ZonedDateTime from, ZonedDateTime until)
Save objects toBarbelHisto
.int
size()
DocumentJournal
timeshift(Object id, ZonedDateTime time)
Turn back time to see how document journals looked like in the past.Collection<Bitemporal>
unload(Object... documentIDs)
Unloads the journal data of the given document IDs into a collection and return that to the client.Collection<Bitemporal>
unloadAll()
Unloads the complete backbone.Collection<Bitemporal>
unloadQuiet(Object... documentIDs)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.projectbarbel.histo.BarbelHisto
save, save, save
-
-
-
-
Field Detail
-
CONSTRUCTION_CONTEXT
public static final ThreadLocal<BarbelHistoContext> CONSTRUCTION_CONTEXT
-
-
Constructor Detail
-
BarbelHistoCore
protected BarbelHistoCore(BarbelHistoContext context)
-
-
Method Detail
-
save
public BitemporalUpdate<T> save(T newVersion, ZonedDateTime from, ZonedDateTime until)
Description copied from interface:BarbelHisto
Save objects toBarbelHisto
. Creates snapshots of state. Clients can safely continue to work on passed instances. Thread safe, applies lock to journals of document IDs (not the complete backbone). This allows concurrent work on different document IDs. If clients try to update the same document Id, this method throwsConcurrentModificationException
. The method returns a copy of the object saved including the version data. In inBarbelMode.POJO
cast the returned object toBitemporal
to read the version data.- Specified by:
save
in interfaceBarbelHisto<T>
- Parameters:
newVersion
- the object state to savefrom
- effective time of object stateuntil
- effective until of the state- Returns:
- the
BitemporalUpdate
performed by this save operation
-
retrieve
public List<T> retrieve(com.googlecode.cqengine.query.Query<T> query)
Description copied from interface:BarbelHisto
Retrieve data fromBarbelHisto
using cqengine like queries. Clients want to useBarbelQueries
for there convenience here.BarbelQueries
can be combined with additional queries fromQueryFactory
.- Specified by:
retrieve
in interfaceBarbelHisto<T>
- Parameters:
query
- the client query fromBarbelQueries
and/orQueryFactory
- Returns:
- the copies returned, maybe empty, never null
-
retrieve
public List<T> retrieve(com.googlecode.cqengine.query.Query<T> query, com.googlecode.cqengine.query.option.QueryOptions options)
Description copied from interface:BarbelHisto
Retrieve data fromBarbelHisto
using cqengine like queries. Clients want to useBarbelQueries
andBarbelQueryOptions
for there convenience here.BarbelQueries
can be combined with additional queries fromQueryFactory
.- Specified by:
retrieve
in interfaceBarbelHisto<T>
- Parameters:
query
- the client query fromBarbelQueries
and/orQueryFactory
options
- the options fromBarbelQueryOptions
orQueryFactory
- Returns:
- the copies returned, maybe empty, never null
-
prettyPrintJournal
public String prettyPrintJournal(Object id)
Description copied from interface:BarbelHisto
Pretty print the journal for the given document ID.- Specified by:
prettyPrintJournal
in interfaceBarbelHisto<T>
- Parameters:
id
- the document ID- Returns:
- the journal as pretty print out
-
getContext
public BarbelHistoContext getContext()
-
getDocumentJournal
public DocumentJournal getDocumentJournal(Object id)
-
load
public void load(Collection<Bitemporal> bitemporals)
Description copied from interface:BarbelHisto
Method for clients that use a custom data store. Only add complete set of versions for one or more document IDs. Usually used in conjunction withBarbelHisto.unload(Object...)
.
InBarbelMode.POJO
(default) clients have to pass a collection ofBitemporalVersion
. InBarbelMode.BITEMPORAL
mode clients can add objects that implementBitemporal
.
- Specified by:
load
in interfaceBarbelHisto<T>
- Parameters:
bitemporals
- consistent list ofBitemporal
versions- See Also:
- https://github.com/npgall/cqengine
-
loadQuiet
public void loadQuiet(Collection<Bitemporal> bitemporals)
-
unload
public Collection<Bitemporal> unload(Object... documentIDs)
Description copied from interface:BarbelHisto
Unloads the journal data of the given document IDs into a collection and return that to the client. The journal data of the given document IDs will be deleted from the backbone. This method is used when client uses custom data store. Clients may store the returned collection to the data store of their choice. Used in conjunction withBarbelHisto.load(Collection)
to re-load that stored journals back intoBarbelHisto
to continue bitemporal processing.
InBarbelMode.POJO
(default) clients receive a collection ofBitemporalVersion
objects. InBarbelMode.BITEMPORAL
clients receive objects that implementBitemporal
.
- Specified by:
unload
in interfaceBarbelHisto<T>
- Parameters:
documentIDs
- the document IDs to unload- Returns:
- the collection of
Bitemporal
objects to store into an arbitrary data store - See Also:
- https://github.com/npgall/cqengine
-
unloadQuiet
public Collection<Bitemporal> unloadQuiet(Object... documentIDs)
-
unloadAll
public Collection<Bitemporal> unloadAll()
Unloads the complete backbone.- Returns:
- the complete backbone versions.
-
timeshift
public DocumentJournal timeshift(Object id, ZonedDateTime time)
Description copied from interface:BarbelHisto
Turn back time to see how document journals looked like in the past. If clients passLocalDateTime.now()
the actual journal is returned. Time shift does not change the backbone collection of theBarbelHisto
instance, instead it returns an instance ofDocumentJournal
with copies of managedBitemporal
objects.- Specified by:
timeshift
in interfaceBarbelHisto<T>
- Parameters:
id
- the document Idtime
- the time, must be in the past- Returns:
- the document journal at that given time
-
size
public int size()
-
retrieveOne
public T retrieveOne(com.googlecode.cqengine.query.Query<T> query)
Description copied from interface:BarbelHisto
Retrieve data fromBarbelHisto
using cqengine like queries. Clients want to useBarbelQueries
for there convenience here.BarbelQueries
can be combined with additional queries fromQueryFactory
. ThrowsIllegalStateException
when query returns more then one result,NoSuchElementException
if nothing was found.- Specified by:
retrieveOne
in interfaceBarbelHisto<T>
- Parameters:
query
- the client query fromBarbelQueries
and/orQueryFactory
- Returns:
- the returned copy
-
retrieveOne
public T retrieveOne(com.googlecode.cqengine.query.Query<T> query, com.googlecode.cqengine.query.option.QueryOptions options)
Description copied from interface:BarbelHisto
Retrieve data fromBarbelHisto
using cqengine like queries. Clients want to useBarbelQueries
andBarbelQueryOptions
for there convenience here.BarbelQueries
can be combined with additional queries fromQueryFactory
. ThrowsIllegalStateException
when query returns more then one result,NoSuchElementException
if nothing was found.- Specified by:
retrieveOne
in interfaceBarbelHisto<T>
- Parameters:
query
- the client query fromBarbelQueries
and/orQueryFactory
options
- the options fromBarbelQueryOptions
orQueryFactory
- Returns:
- the returned copy
-
contains
public boolean contains(Object documentId)
Description copied from interface:BarbelHisto
Check ifBarbelHisto
contains data for the given document ID.- Specified by:
contains
in interfaceBarbelHisto<T>
- Parameters:
documentId
- the document id to check- Returns:
- true if
BarbelHisto
contains data otherwise false
-
-