Nuxeo ECM Projects 5.4.3-SNAPSHOT

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

java.lang.Object
  extended by org.nuxeo.ecm.core.storage.sql.SessionImpl
All Implemented Interfaces:
Connection, XAResource, Session

public class SessionImpl
extends Object
implements Session, XAResource

The session is the main high level access point to data from the underlying database.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.storage.sql.Session
Session.PathResolver
 
Field Summary
 PersistenceContext context
           
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
SessionImpl(RepositoryImpl repository, Model model, Mapper mapper, Credentials credentials)
           
 
Method Summary
 Node addChildNode(Node parent, String name, Long pos, String typeName, boolean complexProp)
          Creates a new child node.
 Node addChildNode(Serializable id, Node parent, String name, Long pos, String typeName, boolean complexProp)
          Creates a new child node with given id (used for import).
 Node addProxy(Serializable targetId, Serializable versionableId, Node parent, String name, Long pos)
          Creates a proxy for a version node.
 Node checkIn(Node node, String label, String checkinComment)
          Checks in a checked-out node: creates a new version with a copy of its information.
 void checkOut(Node node)
          Checks out a checked-in node.
 void checkPermission(String absPath, String actions)
           
 void close()
           
 void commit(Xid xid, boolean onePhase)
           
 Node copy(Node source, Node parent, String name)
          Copies a node to a new location with a new name.
 Interaction createInteraction()
           
 void end(Xid xid, int flags)
           
 void forget(Xid xid)
           
 Binary getBinary(InputStream in)
          Creates a binary value given an input stream.
 Node getChildNode(Node parent, String name, boolean complexProp)
          Gets a child node given its parent and name.
 List<Node> getChildren(Node parent, String name, boolean complexProp)
          Gets the children of a node.
 Node getLastVersion(Serializable versionSeriesId)
          Gets the last version for a given version series id.
 LocalTransaction getLocalTransaction()
           
 Lock getLock(Serializable id)
          Gets the lock state of a document.
 Mapper getMapper()
          Gets the low-level Mapper for this session.
 ConnectionMetaData getMetaData()
           
 Model getModel()
          Gets the Model associated to this session.
 Node getNodeById(Serializable id)
          Gets a node given its id.
 Node getNodeByPath(String path, Node node)
          Gets a node given its absolute path, or given an existing node and a relative path.
 List<Node> getNodesByIds(List<Serializable> ids)
          Gets several nodes given their ids.
 List<Node> getNodesByIds(List<Serializable> ids, boolean prefetch)
           
 Node getParentNode(Node node)
          Gets the parent of a node.
 String getPath(Node node)
          Gets the absolute path of a node.
 List<Node> getProxies(Node document, Node parent)
          Finds the proxies for a document.
 String getRepositoryName()
          Gets the session repository name.
 ResultSetInfo getResultSetInfo()
           
 Node getRootNode()
          Gets the root node of the repository.
 int getTransactionTimeout()
           
 Node getVersionByLabel(Serializable versionSeriesId, String label)
          Gets a version given its version series id and label.
 List<Node> getVersions(Serializable versionSeriesId)
          Gets all the versions for a given version series id.
 XAResource getXAResource()
          Gets the XAResource.
 boolean hasChildNode(Node parent, String name, boolean complexProp)
          Checks if a child node with the given name exists.
 boolean hasChildren(Node parent, boolean complexProp)
          Checks it a node has children.
 boolean hasPendingChanges()
           
 boolean isLive()
          Checks if the session is live (not closed).
 boolean isSameRM(XAResource xaresource)
           
 void markReferencedBinaries(BinaryGarbageCollector gc)
           
 Node move(Node source, Node parent, String name)
          Moves a node to a new location with a new name.
 void orderBefore(Node parent, Node source, Node dest)
          Order the given source child node before the destination child node.
 int prepare(Xid xid)
           
 PartialList<Serializable> query(String query, QueryFilter queryFilter, boolean countTotal)
          Makes a NXQL query to the database.
 PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, boolean countTotal)
          Makes a query to the database.
 IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, Object... params)
          Makes a query to the database and returns an iterable (which must be closed when done).
 void rebuildReadAcls()
          Rebuild the read ACLs for the whole repository.
 Xid[] recover(int flag)
           
 Lock removeLock(Serializable id, String owner, boolean force)
          Removes a lock from a document.
 void removeNode(Node node)
          Removes a node from the storage.
 void removePropertyNode(Node node)
          Removes a property node from the storage.
 void requireReadAclsUpdate()
          Read ACLs are optimized ACLs for the read permission, they need to be updated after document creation or ACL change.
 void restore(Node node, Node version)
          Restores a node to a given version.
 void rollback(Xid xid)
           
 void save()
          Saves the modifications to persistent storage.
 Lock setLock(Serializable id, Lock lock)
          Sets a lock on a document.
 void setProxyTarget(Node proxy, Serializable targetId)
          Sets a proxies' target.
 boolean setTransactionTimeout(int seconds)
           
 void start(Xid xid, int flags)
           
 void updateReadAcls()
          Update only the read ACLs that have changed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

public final PersistenceContext context
Constructor Detail

SessionImpl

public SessionImpl(RepositoryImpl repository,
                   Model model,
                   Mapper mapper,
                   Credentials credentials)
            throws StorageException
Throws:
StorageException
Method Detail

getMapper

public Mapper getMapper()
Description copied from interface: Session
Gets the low-level Mapper for this session.

Specified by:
getMapper in interface Session
Returns:
the mapper

getXAResource

public XAResource getXAResource()
Gets the XAResource. Called by the ManagedConnectionImpl, which actually wraps it in a connection-aware implementation.


close

public void close()
           throws ResourceException
Specified by:
close in interface Connection
Throws:
ResourceException

createInteraction

public Interaction createInteraction()
                              throws ResourceException
Specified by:
createInteraction in interface Connection
Throws:
ResourceException

getLocalTransaction

public LocalTransaction getLocalTransaction()
                                     throws ResourceException
Specified by:
getLocalTransaction in interface Connection
Throws:
ResourceException

getMetaData

public ConnectionMetaData getMetaData()
                               throws ResourceException
Specified by:
getMetaData in interface Connection
Throws:
ResourceException

getResultSetInfo

public ResultSetInfo getResultSetInfo()
                               throws ResourceException
Specified by:
getResultSetInfo in interface Connection
Throws:
ResourceException

isLive

public boolean isLive()
Description copied from interface: Session
Checks if the session is live (not closed).

Specified by:
isLive in interface Session
Returns:
true if the session is live

getRepositoryName

public String getRepositoryName()
Description copied from interface: Session
Gets the session repository name.

Specified by:
getRepositoryName in interface Session
Returns:
the repository name

getModel

public Model getModel()
Description copied from interface: Session
Gets the Model associated to this session.

Specified by:
getModel in interface Session
Returns:
the model

getRootNode

public Node getRootNode()
Description copied from interface: Session
Gets the root node of the repository.

Specified by:
getRootNode in interface Session
Returns:
the root node

getBinary

public Binary getBinary(InputStream in)
                 throws StorageException
Description copied from interface: Session
Creates a binary value given an input stream.

Specified by:
getBinary in interface Session
Parameters:
in - the input stream
Returns:
the binary value
Throws:
StorageException

save

public void save()
          throws StorageException
Description copied from interface: Session
Saves the modifications to persistent storage.

Modifications will be actually written only upon transaction commit.

Specified by:
save in interface Session
Throws:
StorageException

getNodeById

public Node getNodeById(Serializable id)
                 throws StorageException
Description copied from interface: Session
Gets a node given its id.

Specified by:
getNodeById in interface Session
Parameters:
id - the id
Returns:
the node, or null if not found
Throws:
StorageException

getNodesByIds

public List<Node> getNodesByIds(List<Serializable> ids,
                                boolean prefetch)
                         throws StorageException
Throws:
StorageException

getNodesByIds

public List<Node> getNodesByIds(List<Serializable> ids)
                         throws StorageException
Description copied from interface: Session
Gets several nodes given their ids.

Specified by:
getNodesByIds in interface Session
Parameters:
ids - the ids
Returns:
the nodes, in the same order as the ids, with elements being null if not found
Throws:
StorageException

getParentNode

public Node getParentNode(Node node)
                   throws StorageException
Description copied from interface: Session
Gets the parent of a node.

The root has a null parent.

Specified by:
getParentNode in interface Session
Parameters:
node - the node
Returns:
the parent node, or null for the root's parent
Throws:
StorageException

getPath

public String getPath(Node node)
               throws StorageException
Description copied from interface: Session
Gets the absolute path of a node.

Specified by:
getPath in interface Session
Parameters:
node - the node
Returns:
the path
Throws:
StorageException

getNodeByPath

public Node getNodeByPath(String path,
                          Node node)
                   throws StorageException
Description copied from interface: Session
Gets a node given its absolute path, or given an existing node and a relative path.

Specified by:
getNodeByPath in interface Session
Parameters:
path - the path
node - the node (ignored for absolute paths)
Returns:
the node, or null if not found
Throws:
StorageException

addChildNode

public Node addChildNode(Node parent,
                         String name,
                         Long pos,
                         String typeName,
                         boolean complexProp)
                  throws StorageException
Description copied from interface: Session
Creates a new child node.

Specified by:
addChildNode in interface Session
Parameters:
parent - the parent to which the child is added
name - the child name
pos - the child position, or null
typeName - the child type
complexProp - whether this is a complex property (true) or a regular child (false)
Returns:
the new node
Throws:
StorageException

addChildNode

public Node addChildNode(Serializable id,
                         Node parent,
                         String name,
                         Long pos,
                         String typeName,
                         boolean complexProp)
                  throws StorageException
Description copied from interface: Session
Creates a new child node with given id (used for import).

Specified by:
addChildNode in interface Session
Parameters:
id - the id
parent - the parent to which the child is added
name - the child name
pos - the child position, or null
typeName - the child type
complexProp - whether this is a complex property (true) or a regular child (false)
Returns:
the new node
Throws:
StorageException

addProxy

public Node addProxy(Serializable targetId,
                     Serializable versionableId,
                     Node parent,
                     String name,
                     Long pos)
              throws StorageException
Description copied from interface: Session
Creates a proxy for a version node.

Specified by:
addProxy in interface Session
Parameters:
targetId - the target id
versionableId - the version series id
parent - the parent to which the proxy is added
name - the proxy name
pos - the proxy position
Returns:
the new proxy node
Throws:
StorageException

setProxyTarget

public void setProxyTarget(Node proxy,
                           Serializable targetId)
                    throws StorageException
Description copied from interface: Session
Sets a proxies' target.

Specified by:
setProxyTarget in interface Session
Parameters:
proxy - the proxy
targetId - the new target id
Throws:
StorageException

hasChildNode

public boolean hasChildNode(Node parent,
                            String name,
                            boolean complexProp)
                     throws StorageException
Description copied from interface: Session
Checks if a child node with the given name exists.

There are two kinds of children, the regular children documents and the complex properties. The boolean allows a choice between those.

Specified by:
hasChildNode in interface Session
Parameters:
parent - the parent node
name - the child name
complexProp - whether to check complex properties or regular children
Returns:
true if a child node with that name exists
Throws:
StorageException

getChildNode

public Node getChildNode(Node parent,
                         String name,
                         boolean complexProp)
                  throws StorageException
Description copied from interface: Session
Gets a child node given its parent and name.

Specified by:
getChildNode in interface Session
Parameters:
parent - the parent node
name - the child name
complexProp - whether to check complex properties or regular children
Returns:
the child node, or null is not found
Throws:
StorageException

hasChildren

public boolean hasChildren(Node parent,
                           boolean complexProp)
                    throws StorageException
Description copied from interface: Session
Checks it a node has children.

Specified by:
hasChildren in interface Session
Parameters:
parent - the parent node
complexProp - whether to check complex properties or regular children
Returns:
true if the parent has children
Throws:
StorageException

getChildren

public List<Node> getChildren(Node parent,
                              String name,
                              boolean complexProp)
                       throws StorageException
Description copied from interface: Session
Gets the children of a node.

Specified by:
getChildren in interface Session
Parameters:
parent - the parent node
name - the children name to get (for lists of complex properties), or null for all
complexProp - whether to check complex properties or regular children
Returns:
the collection of children
Throws:
StorageException

orderBefore

public void orderBefore(Node parent,
                        Node source,
                        Node dest)
                 throws StorageException
Description copied from interface: Session
Order the given source child node before the destination child node. The source node will be placed before the destination one. If destination is null, the source node will be appended at the end of the children list.

Specified by:
orderBefore in interface Session
Parameters:
parent - the parent node
source - the child node to move
dest - the child node before which to place the source node, or null to move at the end
Throws:
StorageException

move

public Node move(Node source,
                 Node parent,
                 String name)
          throws StorageException
Description copied from interface: Session
Moves a node to a new location with a new name.

A Session.save() is automatically done first.

Specified by:
move in interface Session
Parameters:
source - the node to move
parent - the new parent to which the node is moved
name - the new node name
Returns:
the moved node
Throws:
StorageException

copy

public Node copy(Node source,
                 Node parent,
                 String name)
          throws StorageException
Description copied from interface: Session
Copies a node to a new location with a new name.

A Session.save() is automatically done first.

Specified by:
copy in interface Session
Parameters:
source - the node to copy
parent - the new parent to which the node is copied
name - the new node name
Returns:
the copied node
Throws:
StorageException

removeNode

public void removeNode(Node node)
                throws StorageException
Description copied from interface: Session
Removes a node from the storage.

This is much more complex that removing a property node ( Session.removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)).

Specified by:
removeNode in interface Session
Parameters:
node - the node to remove
Throws:
StorageException
See Also:
#removePropertyNode}

removePropertyNode

public void removePropertyNode(Node node)
                        throws StorageException
Description copied from interface: Session
Removes a property node from the storage.

This is much less complex that removing a generic document node ( Session.removeNode(org.nuxeo.ecm.core.storage.sql.Node)).

Specified by:
removePropertyNode in interface Session
Parameters:
node - the property node to remove
Throws:
StorageException
See Also:
#removeNode}

checkIn

public Node checkIn(Node node,
                    String label,
                    String checkinComment)
             throws StorageException
Description copied from interface: Session
Checks in a checked-out node: creates a new version with a copy of its information.

A Session.save() is automatically done first.

Specified by:
checkIn in interface Session
Parameters:
node - the node to check in
label - the label for the version
checkinComment - the description for the version
Returns:
the created version
Throws:
StorageException

checkOut

public void checkOut(Node node)
              throws StorageException
Description copied from interface: Session
Checks out a checked-in node.

Specified by:
checkOut in interface Session
Parameters:
node - the node to check out
Throws:
StorageException

restore

public void restore(Node node,
                    Node version)
             throws StorageException
Description copied from interface: Session
Restores a node to a given version.

The restored node is checked in.

Specified by:
restore in interface Session
Parameters:
node - the node to restore
version - the version to restore from
Throws:
StorageException

getVersionByLabel

public Node getVersionByLabel(Serializable versionSeriesId,
                              String label)
                       throws StorageException
Description copied from interface: Session
Gets a version given its version series id and label.

Specified by:
getVersionByLabel in interface Session
Parameters:
versionSeriesId - the version series id
label - the label
Returns:
the version node, or null if not found
Throws:
StorageException

getLastVersion

public Node getLastVersion(Serializable versionSeriesId)
                    throws StorageException
Description copied from interface: Session
Gets the last version for a given version series id.

A Session.save() is automatically done first.

Specified by:
getLastVersion in interface Session
Parameters:
versionSeriesId - the version series id
Returns:
the last version, or null if no versions exist
Throws:
StorageException

getVersions

public List<Node> getVersions(Serializable versionSeriesId)
                       throws StorageException
Description copied from interface: Session
Gets all the versions for a given version series id.

A Session.save() is automatically done first.

Specified by:
getVersions in interface Session
Parameters:
versionSeriesId - the version series id
Returns:
the list of versions
Throws:
StorageException

getProxies

public List<Node> getProxies(Node document,
                             Node parent)
                      throws StorageException
Description copied from interface: Session
Finds the proxies for a document. If the parent is not null, the search will be limited to its direct children.

If the document is a version, then only proxies to that version will be looked up.

Otherwise all proxies to the same version series than the document are retrieved.

A Session.save() is automatically done first.

Specified by:
getProxies in interface Session
Parameters:
document - the document
parent - the parent, or null
Returns:
the list of proxies
Throws:
StorageException

query

public PartialList<Serializable> query(String query,
                                       QueryFilter queryFilter,
                                       boolean countTotal)
                                throws StorageException
Description copied from interface: Session
Makes a NXQL query to the database.

Specified by:
query in interface Session
Parameters:
query - the query
queryFilter - the query filter
countTotal - if true, also count the total size without offset/limit
Returns:
the resulting list with total size included
Throws:
StorageException

query

public PartialList<Serializable> query(String query,
                                       String queryType,
                                       QueryFilter queryFilter,
                                       boolean countTotal)
                                throws StorageException
Description copied from interface: Session
Makes a query to the database.

Specified by:
query in interface Session
Parameters:
query - the query
queryFilter - the query filter
countTotal - if true, also count the total size without offset/limit
Returns:
the resulting list with total size included
Throws:
StorageException

queryAndFetch

public IterableQueryResult queryAndFetch(String query,
                                         String queryType,
                                         QueryFilter queryFilter,
                                         Object... params)
                                  throws StorageException
Description copied from interface: Session
Makes a query to the database and returns an iterable (which must be closed when done).

Specified by:
queryAndFetch in interface Session
Parameters:
query - the query
queryType - the query type
queryFilter - the query filter
params - optional query-type-dependent parameters
Returns:
an iterable, which must be closed when done
Throws:
StorageException

getLock

public Lock getLock(Serializable id)
             throws StorageException
Description copied from interface: Session
Gets the lock state of a document.

If the document does not exist, null is returned.

Specified by:
getLock in interface Session
Parameters:
id - the document id
Returns:
the existing lock, or null when there is no lock
Throws:
StorageException

setLock

public Lock setLock(Serializable id,
                    Lock lock)
             throws StorageException
Description copied from interface: Session
Sets a lock on a document.

If the document is already locked, returns its existing lock status (there is no re-locking, Session.removeLock(java.io.Serializable, java.lang.String, boolean) must be called first).

Specified by:
setLock in interface Session
Parameters:
id - the document id
lock - the lock object to set
Returns:
null if locking succeeded, or the existing lock if locking failed
Throws:
StorageException

removeLock

public Lock removeLock(Serializable id,
                       String owner,
                       boolean force)
                throws StorageException
Description copied from interface: Session
Removes a lock from a document.

The previous lock is returned.

If owner is null then the lock is unconditionally removed.

If owner is not null, it must match the existing lock owner for the lock to be removed. If it doesn't match, the returned lock will return true for Lock.getFailed().

Specified by:
removeLock in interface Session
Parameters:
id - the document id
force - true to just do the remove and not return the previous lock
Returns:
the previous lock
Throws:
StorageException

requireReadAclsUpdate

public void requireReadAclsUpdate()
Description copied from interface: Session
Read ACLs are optimized ACLs for the read permission, they need to be updated after document creation or ACL change.

This method flag the current session, the read ACLs update will be done automatically at save time.

Specified by:
requireReadAclsUpdate in interface Session

updateReadAcls

public void updateReadAcls()
                    throws StorageException
Description copied from interface: Session
Update only the read ACLs that have changed.

Specified by:
updateReadAcls in interface Session
Throws:
StorageException

rebuildReadAcls

public void rebuildReadAcls()
                     throws StorageException
Description copied from interface: Session
Rebuild the read ACLs for the whole repository.

Specified by:
rebuildReadAcls in interface Session
Throws:
StorageException

checkPermission

public void checkPermission(String absPath,
                            String actions)
                     throws StorageException
Throws:
StorageException

hasPendingChanges

public boolean hasPendingChanges()
                          throws StorageException
Throws:
StorageException

markReferencedBinaries

public void markReferencedBinaries(BinaryGarbageCollector gc)

isSameRM

public boolean isSameRM(XAResource xaresource)
Specified by:
isSameRM in interface XAResource

start

public void start(Xid xid,
                  int flags)
           throws XAException
Specified by:
start in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flags)
         throws XAException
Specified by:
end in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException
Specified by:
prepare in interface XAResource
Throws:
XAException

commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Specified by:
commit in interface XAResource
Throws:
XAException

rollback

public void rollback(Xid xid)
              throws XAException
Specified by:
rollback in interface XAResource
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException
Specified by:
forget in interface XAResource
Throws:
XAException

recover

public Xid[] recover(int flag)
              throws XAException
Specified by:
recover in interface XAResource
Throws:
XAException

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws XAException
Specified by:
setTransactionTimeout in interface XAResource
Throws:
XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.