Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.core.storage.sql
Class Selection

java.lang.Object
  extended by org.nuxeo.ecm.core.storage.sql.Selection

public class Selection
extends Object

A 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:

Information about rows in the database may be complete, or just partial if only individual rows corresponding to the clause have been retrieved from the 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.


Constructor Summary
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.
 
Method Summary
 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.
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Selection

public 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.

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 Detail

addExisting

public void addExisting(Serializable id)
Adds a known row corresponding to the clause.

Parameters:
id - the fragment id

addCreated

public void addCreated(Serializable id)
Adds a created row corresponding to the clause.

Parameters:
id - the fragment id

addExistingComplete

public void addExistingComplete(List<Serializable> actualExisting)
Adds 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)

setIncomplete

public void setIncomplete()
Marks as incomplete.

Called after a database operation added rows corresponding to the clause with unknown ids (restore of complex properties).


remove

public void remove(Serializable id)
Removes a known child id.

Parameters:
id - the id to remove

flush

public void flush()
Flushes to database. Clears created and deleted map.

Puts this in the soft map. Caller must remove from hard map.


isFlushed

public boolean isFlushed()

getFragmentByValue

public SimpleFragment getFragmentByValue(Serializable filter)
Gets a fragment given its filtered value.

Returns null if there is no such fragment.

Returns SimpleFragment.UNKNOWN if there's no info about it.

Parameters:
filter - the value to filter on (cannot be null)
Returns:
the fragment, or null, or SimpleFragment.UNKNOWN

getFragmentsByValue

public List<SimpleFragment> getFragmentsByValue(Serializable filter)
Gets all the fragments, if the selection is complete.

Parameters:
filter - the value to filter on, or null for the whole selection
Returns:
the fragments, or null if the list is not known to be complete

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.