Class Selection
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:
 
- corresponding rows known to exist in the database,
- corresponding created rows not yet flushed to database,
- corresponding rows not yet flushed to database.
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.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected booleanThis istruewhen complete information about the existing ids is known.protected final PersistenceContextThe context used to fetch fragments.protected Set<Serializable>The row ids created and not yet flushed to database.protected Set<Serializable>The row ids deleted (or for which the clause column changed value) and not yet flushed to database.protected Set<Serializable>The row ids known in the database and not deleted.protected final StringThe key to use to filter.
- 
Constructor SummaryConstructorsConstructorDescriptionSelection(Serializable selId, String tableName, boolean empty, String filterKey, PersistenceContext context, Map<Serializable, Selection> softMap, Map<Serializable, Selection> hardMap) Constructs aSelectionfor the given selection id.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds a created row corresponding to the clause.voidAdds a known row corresponding to the clause.voidaddExistingComplete(List<Serializable> actualExisting) Adds ids actually read from the backend, and mark this complete.voidflush()Flushes to database.protected SerializablefragmentValue(SimpleFragment fragment) getFragmentByValue(Serializable filter) Gets a fragment given its filtered value.getFragmentsByValue(Serializable filter) Gets all the fragments, if the selection is complete.getIds()Gets the ids in that fragment, if complete (otherwise returnsnull).booleanvoidremove(Serializable id) Removes a known child id.voidMarks as incomplete.protected voidwarnIfBig(int added) 
- 
Field Details- 
contextThe context used to fetch fragments.
- 
filterKeyThe key to use to filter.For instance for a children selection this is the child name. 
- 
completeprotected boolean completeThis istruewhen 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). 
- 
existingThe row ids known in the database and not deleted.
- 
createdThe row ids created and not yet flushed to database.
- 
deletedThe row ids deleted (or for which the clause column changed value) and not yet flushed to database.
 
- 
- 
Constructor Details- 
Selectionpublic Selection(Serializable selId, String tableName, boolean empty, String filterKey, PersistenceContext context, Map<Serializable, Selection> softMap, Map<Serializable, Selection> hardMap) Constructs aSelectionfor the given selection id.It is automatically put in the soft map. - Parameters:
- selId- the selection key (used in the soft/hard maps)
- tableName- the table name to fetch fragments
- empty- if the new instance is created empty
- filterKey- the key to use to additionally filter on fragment values
- context- the context from which to fetch fragments
- softMap- the soft map, when the selection is pristine
- hardMap- the hard map, when there are modifications to flush
 
 
- 
- 
Method Details- 
getIdsGets the ids in that fragment, if complete (otherwise returnsnull).- Since:
- 9.2
 
- 
fragmentValue
- 
addExistingAdds a known row corresponding to the clause.- Parameters:
- id- the fragment id
 
- 
addCreatedAdds a created row corresponding to the clause.- Parameters:
- id- the fragment id
 
- 
addExistingCompleteAdds ids actually read from the backend, and mark this complete.Note that when adding a complete list of ids retrieved from the database, the deleted ids have already been removed in the result set. - Parameters:
- actualExisting- the existing database ids (the list must be mutable)
 
- 
setIncompletepublic void setIncomplete()Marks as incomplete.Called after a database operation added rows corresponding to the clause with unknown ids (restore of complex properties). 
- 
removeRemoves a known child id.- Parameters:
- id- the id to remove
 
- 
flushpublic void flush()Flushes to database. Clears created and deleted map.Puts this in the soft map. Caller must remove from hard map. 
- 
warnIfBigprotected void warnIfBig(int added) 
- 
isFlushedpublic boolean isFlushed()
- 
getFragmentByValueGets a fragment given its filtered value.Returns nullif there is no such fragment.Returns SimpleFragment.UNKNOWNif there's no info about it.- Parameters:
- filter- the value to filter on (cannot be- null)
- Returns:
- the fragment, or null, orSimpleFragment.UNKNOWN
 
- 
getFragmentsByValueGets all the fragments, if the selection is complete.- Parameters:
- filter- the value to filter on, or- nullfor the whole selection
- Returns:
- the fragments, or nullif the list is not known to be complete
 
 
-