Nuxeo ECM Projects 5.4.3-SNAPSHOT

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

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

public class PersistenceContext
extends Object

This class holds persistence context information.

All non-saved modified data is referenced here. At save time, the data is sent to the database by the Mapper. The database will at some time later be committed by the external transaction manager in effect.

Internally a fragment can be in at most one of the "pristine" or "modified" map. After a save() all the fragments are pristine, and may be partially invalidated after commit by other local or clustered contexts that committed too.

Depending on the table, the context may hold SimpleFragments, which represent one row, CollectionFragments, which represent several rows.

This class is not thread-safe, it should be tied to a single session and the session itself should not be used concurrently.


Nested Class Summary
static class PersistenceContext.PathAndId
           
 
Field Summary
 SelectionContext hierNonComplex
           
 
Constructor Summary
PersistenceContext(Model model, RowMapper mapper, SessionImpl session)
           
 
Method Summary
 void addedProxyTarget(SimpleFragment fragment)
           
 Serializable checkIn(Node node, String label, String checkinComment)
          Checks in a node (creates a version).
 void checkInvalidationsConflict()
           
 void checkOut(Node node)
          Checks out a node.
 Serializable copy(Node source, Serializable parentId, String name)
          Copy a child to a new parent with a new name.
 void createdProxyFragment(SimpleFragment fragment)
           
 SimpleFragment createHierarchyFragment(Row row)
           
 SimpleFragment getChildHierByName(Serializable parentId, String name, boolean complexProp)
           
 List<SimpleFragment> getChildren(Serializable parentId, String name, boolean complexProp)
          Gets hier fragments for children.
 Serializable getContainingDocument(Serializable id)
          Finds the id of the enclosing non-complex-property node.
 List<Fragment> getMulti(Collection<RowId> rowIds, boolean allowAbsent)
          Gets a list of fragments.
 Long getNextPos(Serializable nodeId, boolean complexProp)
          Gets the next pos value for a new child in a folder.
 String getPath(SimpleFragment hierFragment)
          Gets the path by recursing up the hierarchy.
 PersistenceContext.PathAndId getPathOrMissingParentId(SimpleFragment hierFragment, boolean fetch)
          Gets the full path, or the closest parent id which we don't have in cache.
 List<Serializable> getSeriesProxyIds(Serializable versionSeriesId)
           
 List<Serializable> getTargetProxyIds(Serializable targetId)
           
 List<Serializable> getVersionIds(Serializable versionSeriesId)
          Gets the version ids for a version series, ordered by creation time.
 boolean isDeleted(Serializable id)
          Recursively checks if any of a fragment's parents has been deleted.
 void move(Node source, Serializable parentId, String name)
          Move a child to a new parent with a new name.
 void orderBefore(Serializable parentId, Serializable sourceId, Serializable destId)
          Order a child before another.
 void processReceivedInvalidations()
          Applies all invalidations accumulated.
 void recomputeVersionSeries(Serializable versionSeriesId)
          Recomputes isLatest / isLatestMajor on all versions.
 void removedProxyTarget(SimpleFragment fragment)
           
 void removeFragment(Fragment fragment, boolean primary)
          Deletes a fragment from the context.
 void removeNode(SimpleFragment hierFragment)
          Removes a document node and its children.
 void removePropertyNode(SimpleFragment hierFragment)
          Removes a property node and its children.
 void restoreVersion(Node node, Node version)
          Restores a node to a given version.
 void sendInvalidationsToOthers()
          Post-transaction invalidations notification.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hierNonComplex

public final SelectionContext hierNonComplex
Constructor Detail

PersistenceContext

public PersistenceContext(Model model,
                          RowMapper mapper,
                          SessionImpl session)
                   throws StorageException
Throws:
StorageException
Method Detail

sendInvalidationsToOthers

public void sendInvalidationsToOthers()
                               throws StorageException
Post-transaction invalidations notification.

Called post-transaction by session commit/rollback or transactionless save.

Throws:
StorageException

processReceivedInvalidations

public void processReceivedInvalidations()
                                  throws StorageException
Applies all invalidations accumulated.

Called pre-transaction by start or transactionless save;

Throws:
StorageException

checkInvalidationsConflict

public void checkInvalidationsConflict()

getMulti

public List<Fragment> getMulti(Collection<RowId> rowIds,
                               boolean allowAbsent)
                        throws StorageException
Gets a list of fragments.

If a fragment is not in the context, fetch it from the mapper. If it's not in the database, use an absent fragment or skip it.

Deleted fragments are skipped.

Parameters:
id - the fragment id
allowAbsent - true to return an absent fragment as an object instead of skipping it
Returns:
the fragments, in arbitrary order (no nulls)
Throws:
StorageException

createHierarchyFragment

public SimpleFragment createHierarchyFragment(Row row)
                                       throws StorageException
Throws:
StorageException

createdProxyFragment

public void createdProxyFragment(SimpleFragment fragment)
                          throws StorageException
Throws:
StorageException

removedProxyTarget

public void removedProxyTarget(SimpleFragment fragment)
                        throws StorageException
Throws:
StorageException

addedProxyTarget

public void addedProxyTarget(SimpleFragment fragment)
                      throws StorageException
Throws:
StorageException

removePropertyNode

public void removePropertyNode(SimpleFragment hierFragment)
                        throws StorageException
Removes a property node and its children.

There's less work to do than when we have to remove a generic document node (less selections, and we can assume the depth is small so recurse).

Throws:
StorageException

removeNode

public void removeNode(SimpleFragment hierFragment)
                throws StorageException
Removes a document node and its children.

Assumes a full flush was done.

Throws:
StorageException

removeFragment

public void removeFragment(Fragment fragment,
                           boolean primary)
                    throws StorageException
Deletes a fragment from the context. May generate a database DELETE if primary is true, otherwise consider that database removal will be a cascade-induced consequence of another DELETE.

Throws:
StorageException

recomputeVersionSeries

public void recomputeVersionSeries(Serializable versionSeriesId)
                            throws StorageException
Recomputes isLatest / isLatestMajor on all versions.

Throws:
StorageException

getVersionIds

public List<Serializable> getVersionIds(Serializable versionSeriesId)
                                 throws StorageException
Gets the version ids for a version series, ordered by creation time.

Throws:
StorageException

getSeriesProxyIds

public List<Serializable> getSeriesProxyIds(Serializable versionSeriesId)
                                     throws StorageException
Throws:
StorageException

getTargetProxyIds

public List<Serializable> getTargetProxyIds(Serializable targetId)
                                     throws StorageException
Throws:
StorageException

getPath

public String getPath(SimpleFragment hierFragment)
               throws StorageException
Gets the path by recursing up the hierarchy.

Throws:
StorageException

getPathOrMissingParentId

public PersistenceContext.PathAndId getPathOrMissingParentId(SimpleFragment hierFragment,
                                                             boolean fetch)
                                                      throws StorageException
Gets the full path, or the closest parent id which we don't have in cache.

If fetch is true, returns the full path.

If fetch is false, does not touch the mapper, only the context, therefore may return a missing parent id instead of the path.

Parameters:
fetch - true if we can use the mapper
Throws:
StorageException

getContainingDocument

public Serializable getContainingDocument(Serializable id)
                                   throws StorageException
Finds the id of the enclosing non-complex-property node.

Parameters:
id - the id
Returns:
the id of the containing document, or null if there is no parent or the parent has been deleted.
Throws:
StorageException

isDeleted

public boolean isDeleted(Serializable id)
                  throws StorageException
Recursively checks if any of a fragment's parents has been deleted.

Throws:
StorageException

getNextPos

public Long getNextPos(Serializable nodeId,
                       boolean complexProp)
                throws StorageException
Gets the next pos value for a new child in a folder.

Parameters:
nodeId - the folder node id
complexProp - whether to deal with complex properties or regular children
Returns:
the next pos, or null if not orderable
Throws:
StorageException

orderBefore

public void orderBefore(Serializable parentId,
                        Serializable sourceId,
                        Serializable destId)
                 throws StorageException
Order a child before another.

Parameters:
parentId - the parent id
sourceId - the node id to move
destId - the node id before which to place the source node, if null then move the source to the end
Throws:
StorageException

getChildHierByName

public SimpleFragment getChildHierByName(Serializable parentId,
                                         String name,
                                         boolean complexProp)
                                  throws StorageException
Throws:
StorageException

getChildren

public List<SimpleFragment> getChildren(Serializable parentId,
                                        String name,
                                        boolean complexProp)
                                 throws StorageException
Gets hier fragments for children.

Throws:
StorageException

move

public void move(Node source,
                 Serializable parentId,
                 String name)
          throws StorageException
Move a child to a new parent with a new name.

Parameters:
source - the source
parentId - the destination parent id
name - the new name
Throws:
StorageException

copy

public Serializable copy(Node source,
                         Serializable parentId,
                         String name)
                  throws StorageException
Copy a child to a new parent with a new name.

Parameters:
source - the source of the copy
parentId - the destination parent id
name - the new name
Returns:
the id of the copy
Throws:
StorageException

checkIn

public Serializable checkIn(Node node,
                            String label,
                            String checkinComment)
                     throws StorageException
Checks in a node (creates a version).

Parameters:
node - the node to check in
label - the version label
checkinComment - the version description
Returns:
the created version id
Throws:
StorageException

checkOut

public void checkOut(Node node)
              throws StorageException
Checks out a node.

Parameters:
node - the node to check out
Throws:
StorageException

restoreVersion

public void restoreVersion(Node node,
                           Node version)
                    throws StorageException
Restores a node to a given version.

The restored node is checked in.

Parameters:
node - the node
version - the version to restore on this node
Throws:
StorageException

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.