Interface Session
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
SessionImpl
public interface Session extends AutoCloseable
The session is the main high level access point to data from the underlying database.- Author:
- Florent Guillaume
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Session.PathResolver
Interface for a class that knows how to resolve a node path into a node id.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description 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
addChildNode(Node parent, String name, Long pos, String typeName, boolean complexProp)
Creates a new child node.boolean
addMixinType(Node node, String mixin)
Adds a mixin to a node.Node
addProxy(Serializable targetId, Serializable versionSeriesId, 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
close()
default Node
copy(Node source, Node parent, String name)
Copies a node to a new location with a new name.Node
copy(Node source, Node parent, String name, Consumer<Node> afterRecordCopy)
Copies a node to a new location with a new name.default Map<String,String>
getBinaryFulltext(Serializable id)
Deprecated.since 11.1, usegetBinaryFulltext(Serializable, Document)
insteadMap<String,String>
getBinaryFulltext(Serializable id, Document doc)
Gets the fulltext extracted from the binary fields.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.LockManager
getLockManager()
Gets the lock manager for this session.Mapper
getMapper()
Gets the low-level Mapper for this session.Model
getModel()
Gets theModel
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(Collection<Serializable> ids)
Gets several nodes given their ids.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)
Finds the proxies for a document.List<Node>
getProxies(Node document, Node parent)
Finds the proxies for a document.String
getRepositoryName()
Gets the session repository name.Node
getRootNode()
Gets the root node of the repository.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.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
isChangeTokenEnabled()
Checks if change token management is enabled.boolean
isFulltextStoredInBlob()
Checks if fulltext extracted from the binary fields is internally stored as a blob.void
markUserChange(Serializable id)
Marks the document as being modified by a user change.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.PartialList<Serializable>
query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Makes a query to the database.PartialList<Serializable>
query(String query, QueryFilter queryFilter, boolean countTotal)
Makes a NXQL query to the database.IterableQueryResult
queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
Makes a query to the database and returns an iterable (which must be closed when done).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).PartialList<Map<String,Serializable>>
queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object[] params)
Makes a query to the database.void
rebuildReadAcls()
Rebuild the read ACLs for the whole repository.boolean
removeMixinType(Node node, String mixin)
Removes a mixin from a node.default void
removeNode(Node node)
Removes a node from the storage.void
removeNode(Node node, Consumer<Node> beforeRecordRemove)
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
save()
Saves the modifications to persistent storage.ScrollResult<String>
scroll(String scrollId)
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.ScrollResult<String>
scroll(String query, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.ScrollResult<String>
scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.void
setProxyTarget(Node proxy, Serializable targetId)
Sets a proxies' target.void
updateReadAcls()
Update only the read ACLs that have changed.
-
-
-
Method Detail
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
-
getMapper
Mapper getMapper()
Gets the low-level Mapper for this session.- Returns:
- the mapper
-
getRepositoryName
String getRepositoryName()
Gets the session repository name.- Returns:
- the repository name
-
save
void save()
Saves the modifications to persistent storage.Modifications will be actually written only upon transaction commit.
-
getRootNode
Node getRootNode()
Gets the root node of the repository.- Returns:
- the root node
-
getNodeById
Node getNodeById(Serializable id)
Gets a node given its id.- Parameters:
id
- the id- Returns:
- the node, or
null
if not found
-
getNodesByIds
List<Node> getNodesByIds(Collection<Serializable> ids)
Gets several nodes given their ids.- Parameters:
ids
- the ids- Returns:
- the nodes, in the same order as the ids, with elements being
null
if not found
-
getNodeByPath
Node getNodeByPath(String path, Node node)
Gets a node given its absolute path, or given an existing node and a relative path.- Parameters:
path
- the pathnode
- the node (ignored for absolute paths)- Returns:
- the node, or
null
if not found
-
addMixinType
boolean addMixinType(Node node, String mixin)
Adds a mixin to a node.Does nothing if the mixin was already present on the node.
- Parameters:
node
- the nodemixin
- the mixin name- Returns:
true
if the mixin was added, orfalse
if it is already present- Since:
- 5.8
-
removeMixinType
boolean removeMixinType(Node node, String mixin)
Removes a mixin from a node.It's not possible to remove a mixin coming from the primary type.
- Parameters:
node
- the nodemixin
- the mixin- Returns:
true
if the mixin was removed, orfalse
if it isn't present or is present on the type or does not exist- Since:
- 5.8
-
scroll
ScrollResult<String> scroll(String query, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.- Since:
- 8.4
-
scroll
ScrollResult<String> scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.- Since:
- 10.3
-
scroll
ScrollResult<String> scroll(String scrollId)
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.- Since:
- 8.4
-
getParentNode
Node getParentNode(Node node)
Gets the parent of a node.The root has a
null
parent.- Parameters:
node
- the node- Returns:
- the parent node, or
null
for the root's parent
-
getPath
String getPath(Node node)
Gets the absolute path of a node.- Parameters:
node
- the node- Returns:
- the path
-
hasChildNode
boolean hasChildNode(Node parent, String name, boolean complexProp)
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
complexProp
allows a choice between those.- Parameters:
parent
- the parent nodename
- the child namecomplexProp
- whether to check complex properties or regular children- Returns:
true
if a child node with that name exists
-
getChildNode
Node getChildNode(Node parent, String name, boolean complexProp)
Gets a child node given its parent and name.- Parameters:
parent
- the parent nodename
- the child namecomplexProp
- whether to check complex properties or regular children- Returns:
- the child node, or
null
is not found
-
hasChildren
boolean hasChildren(Node parent, boolean complexProp)
Checks it a node has children.- Parameters:
parent
- the parent nodecomplexProp
- whether to check complex properties or regular children- Returns:
true
if the parent has children
-
getChildren
List<Node> getChildren(Node parent, String name, boolean complexProp)
Gets the children of a node.- Parameters:
parent
- the parent nodename
- the children name to get (for lists of complex properties), ornull
for allcomplexProp
- whether to check complex properties or regular children- Returns:
- the collection of children
-
addChildNode
Node addChildNode(Node parent, String name, Long pos, String typeName, boolean complexProp)
Creates a new child node.- Parameters:
parent
- the parent to which the child is addedname
- the child namepos
- the child position, ornull
typeName
- the child typecomplexProp
- whether this is a complex property (true
) or a regular child (false
)- Returns:
- the new node
-
addChildNode
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).- Parameters:
id
- the idparent
- the parent to which the child is addedname
- the child namepos
- the child position, ornull
typeName
- the child typecomplexProp
- whether this is a complex property (true
) or a regular child (false
)- Returns:
- the new node
-
addProxy
Node addProxy(Serializable targetId, Serializable versionSeriesId, Node parent, String name, Long pos)
Creates a proxy for a version node.- Parameters:
targetId
- the target idversionSeriesId
- the version series idparent
- the parent to which the proxy is addedname
- the proxy namepos
- the proxy position- Returns:
- the new proxy node
-
setProxyTarget
void setProxyTarget(Node proxy, Serializable targetId)
Sets a proxies' target.- Parameters:
proxy
- the proxytargetId
- the new target id- Since:
- 5.5
-
removeNode
default void removeNode(Node node)
Removes a node from the storage.This is much more complex that removing a property node (
removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)
).- Parameters:
node
- the node to remove- See Also:
removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)
-
removeNode
void removeNode(Node node, Consumer<Node> beforeRecordRemove)
Removes a node from the storage.This is much more complex than removing a property node (
removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)
).- Parameters:
node
- the node to removebeforeRecordRemove
- a consumer called on nodes of records before they are removed- Since:
- 11.1
- See Also:
removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)
-
removePropertyNode
void removePropertyNode(Node node)
Removes a property node from the storage.This is much less complex that removing a generic document node (
removeNode(org.nuxeo.ecm.core.storage.sql.Node)
).- Parameters:
node
- the property node to remove- See Also:
removeNode(org.nuxeo.ecm.core.storage.sql.Node)
-
orderBefore
void orderBefore(Node parent, Node source, Node dest)
Order the given source child node before the destination child node. The source node will be placed before the destination one. If destination isnull
, the source node will be appended at the end of the children list.- Parameters:
parent
- the parent nodesource
- the child node to movedest
- the child node before which to place the source node, ornull
to move at the end
-
move
Node move(Node source, Node parent, String name)
Moves a node to a new location with a new name.A
save()
is automatically done first.- Parameters:
source
- the node to moveparent
- the new parent to which the node is movedname
- the new node name- Returns:
- the moved node
-
copy
default Node copy(Node source, Node parent, String name)
Copies a node to a new location with a new name.A
save()
is automatically done first.- Parameters:
source
- the node to copyparent
- the new parent to which the node is copiedname
- the new node name- Returns:
- the copied node
-
copy
Node copy(Node source, Node parent, String name, Consumer<Node> afterRecordCopy)
Copies a node to a new location with a new name.A
save()
is automatically done first.- Parameters:
source
- the node to copyparent
- the new parent to which the node is copiedname
- the new node nameafterRecordCopy
- a consumer called on nodes that were records before copy- Returns:
- the copied node
- Since:
- 11.1
-
checkIn
Node checkIn(Node node, String label, String checkinComment)
Checks in a checked-out node: creates a new version with a copy of its information.A
save()
is automatically done first.- Parameters:
node
- the node to check inlabel
- the label for the versioncheckinComment
- the description for the version- Returns:
- the created version
-
checkOut
void checkOut(Node node)
Checks out a checked-in node.- Parameters:
node
- the node to check out
-
restore
void restore(Node node, Node version)
Restores a node to a given version.The restored node is checked in.
- Parameters:
node
- the node to restoreversion
- the version to restore from
-
getVersionByLabel
Node getVersionByLabel(Serializable versionSeriesId, String label)
Gets a version given its version series id and label.- Parameters:
versionSeriesId
- the version series idlabel
- the label- Returns:
- the version node, or
null
if not found
-
getVersions
List<Node> getVersions(Serializable versionSeriesId)
Gets all the versions for a given version series id.A
save()
is automatically done first.- Parameters:
versionSeriesId
- the version series id- Returns:
- the list of versions
-
getLastVersion
Node getLastVersion(Serializable versionSeriesId)
Gets the last version for a given version series id.A
save()
is automatically done first.- Parameters:
versionSeriesId
- the version series id- Returns:
- the last version, or
null
if no versions exist
-
getProxies
List<Node> getProxies(Node document, Node parent)
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
save()
is automatically done first.- Parameters:
document
- the documentparent
- the parent, ornull
- Returns:
- the list of proxies
-
getProxies
List<Node> getProxies(Node document)
Finds the proxies for a document. (The document may be a version or a live document)- Parameters:
document
- the document- Returns:
- the list of proxies, or an empty list
- Since:
- 10.2
-
query
PartialList<Serializable> query(String query, QueryFilter queryFilter, boolean countTotal)
Makes a NXQL query to the database.- Parameters:
query
- the queryqueryFilter
- the query filtercountTotal
- iftrue
, also count the total size without offset/limit- Returns:
- the resulting list with total size included
-
query
PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Makes a query to the database.- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filtercountUpTo
- if-1
, also count the total size without offset/limit.
If0
, don't count the total size.
Ifn
, count the total number if there are less than n documents otherwise set the size to-1
.- Returns:
- the resulting list with total size included
- Since:
- 5.6
-
queryAndFetch
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).- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filterparams
- optional query-type-dependent parameters- Returns:
- an iterable, which must be closed when done
-
queryAndFetch
IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
Makes a query to the database and returns an iterable (which must be closed when done).- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- iftrue
then a maximum of one row per document will be returnedparams
- optional query-type-dependent parameters- Returns:
- an iterable, which must be closed when done
- Since:
- 7.10-HF04, 8.2
-
queryProjection
PartialList<Map<String,Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object[] params)
Makes a query to the database.- Parameters:
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- iftrue
then a maximum of one row per document will be returnedcountUpTo
- if-1
, also count the total size without offset/limit.
If0
, don't count the total size.
Ifn
, count the total number if there are less than n documents otherwise set the size to-1
.params
- optional query-type-dependent parameters- Returns:
- a projection
- Since:
- 7.10-HF-25, 8.10-HF06, 9.2
-
getLockManager
LockManager getLockManager()
Gets the lock manager for this session.- Returns:
- the lock manager
- Since:
- 7.4
-
requireReadAclsUpdate
void requireReadAclsUpdate()
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.
-
updateReadAcls
void updateReadAcls()
Update only the read ACLs that have changed.
-
rebuildReadAcls
void rebuildReadAcls()
Rebuild the read ACLs for the whole repository.
-
isFulltextStoredInBlob
boolean isFulltextStoredInBlob()
Checks if fulltext extracted from the binary fields is internally stored as a blob.- Returns:
true
if fulltext from binaries is store as a blob- Since:
- 11.1
-
getBinaryFulltext
Map<String,String> getBinaryFulltext(Serializable id, Document doc)
Gets the fulltext extracted from the binary fields.- Since:
- 11.1
-
getBinaryFulltext
@Deprecated default Map<String,String> getBinaryFulltext(Serializable id)
Deprecated.since 11.1, usegetBinaryFulltext(Serializable, Document)
insteadGets the fulltext extracted from the binary fields.- Since:
- 5.9.3
-
isChangeTokenEnabled
boolean isChangeTokenEnabled()
Checks if change token management is enabled.- Since:
- 9.1
-
markUserChange
void markUserChange(Serializable id)
Marks the document as being modified by a user change.This causes an additional change token increment and check during save.
- Parameters:
id
- the document id- Since:
- 9.2
-
-