public class Selection extends Object
Selection
holds information about row ids corresponding to a fixed clause for a given table.
A clause has the form: column = fixed value. The column can be the parent id, the versionable id, the target id.
The internal state of a Selection
instance reflects:
Row ids are stored in no particular order.
When this structure holds information all flushed to the database, then it can safely be GC'ed, so it lives in a memory-sensitive map (softMap), otherwise it's moved to a normal map (hardMap).
This class is not thread-safe and should be used only from a single-threaded session.
Modifier and Type | Field and Description |
---|---|
protected boolean |
complete
This is
true when complete information about the existing ids is known. |
protected PersistenceContext |
context
The context used to fetch fragments.
|
protected Set<Serializable> |
created
The row ids created and not yet flushed to database.
|
protected Set<Serializable> |
deleted
The row ids deleted (or for which the clause column changed value) and not yet flushed to database.
|
protected Set<Serializable> |
existing
The row ids known in the database and not deleted.
|
protected String |
filterKey
The key to use to filter.
|
Constructor and Description |
---|
Selection(Serializable selId,
String tableName,
boolean empty,
String filterKey,
PersistenceContext context,
Map<Serializable,Selection> softMap,
Map<Serializable,Selection> hardMap)
Constructs a
Selection for the given selection id. |
Modifier and Type | Method and Description |
---|---|
void |
addCreated(Serializable id)
Adds a created row corresponding to the clause.
|
void |
addExisting(Serializable id)
Adds a known row corresponding to the clause.
|
void |
addExistingComplete(List<Serializable> actualExisting)
Adds ids actually read from the backend, and mark this complete.
|
void |
flush()
Flushes to database.
|
protected Serializable |
fragmentValue(SimpleFragment fragment) |
SimpleFragment |
getFragmentByValue(Serializable filter)
Gets a fragment given its filtered value.
|
List<SimpleFragment> |
getFragmentsByValue(Serializable filter)
Gets all the fragments, if the selection is complete.
|
boolean |
isFlushed() |
void |
remove(Serializable id)
Removes a known child id.
|
void |
setIncomplete()
Marks as incomplete.
|
protected void |
warnIfBig(int added) |
protected final PersistenceContext context
protected final String filterKey
For instance for a children selection this is the child name.
protected boolean complete
true
when complete information about the existing ids is known.
This is the case when a query to the database has been made to fetch all rows with the clause, or when a new value for the clause has been created (applies for instance to a new parent id appearing when a folder is created).
protected Set<Serializable> existing
protected Set<Serializable> created
protected Set<Serializable> deleted
public Selection(Serializable selId, String tableName, boolean empty, String filterKey, PersistenceContext context, Map<Serializable,Selection> softMap, Map<Serializable,Selection> hardMap)
Selection
for the given selection id.
It is automatically put in the soft map.
selId
- the selection key (used in the soft/hard maps)tableName
- the table name to fetch fragmentsempty
- if the new instance is created emptyfilterKey
- the key to use to additionally filter on fragment valuescontext
- the context from which to fetch fragmentssoftMap
- the soft map, when the selection is pristinehardMap
- the hard map, when there are modifications to flushprotected Serializable fragmentValue(SimpleFragment fragment)
public void addExisting(Serializable id)
id
- the fragment idpublic void addCreated(Serializable id)
id
- the fragment idpublic void addExistingComplete(List<Serializable> actualExisting)
Note that when adding a complete list of ids retrieved from the database, the deleted ids have already been removed in the result set.
actualExisting
- the existing database ids (the list must be mutable)public void setIncomplete()
Called after a database operation added rows corresponding to the clause with unknown ids (restore of complex properties).
public void remove(Serializable id)
id
- the id to removepublic void flush()
Puts this in the soft map. Caller must remove from hard map.
protected void warnIfBig(int added)
public boolean isFlushed()
public SimpleFragment getFragmentByValue(Serializable filter)
Returns null
if there is no such fragment.
Returns SimpleFragment.UNKNOWN
if there's no info about it.
filter
- the value to filter on (cannot be null
)null
, or SimpleFragment.UNKNOWN
public List<SimpleFragment> getFragmentsByValue(Serializable filter)
filter
- the value to filter on, or null
for the whole selectionnull
if the list is not known to be completeCopyright © 2016 Nuxeo SA. All rights reserved.