public class SessionImpl extends Object implements Session, XAResource
Modifier and Type | Class and Description |
---|---|
protected static class |
SessionImpl.FulltextFinder
Finds the fulltext in a document and sends it to a fulltext parser.
|
Session.PathResolver
Modifier and Type | Field and Description |
---|---|
protected boolean |
changeTokenEnabled |
static String |
COMPAT_REPOSITORY_NAME_KEY
Set this system property to false if you don't want repositories to be looked up under the compatibility name
"default" in the "repositories" table.
|
PersistenceContext |
context |
protected FulltextParser |
fulltextParser |
protected com.codahale.metrics.MetricRegistry |
registry |
protected RepositoryImpl |
repository |
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
Constructor and Description |
---|
SessionImpl(RepositoryImpl repository,
Model model,
Mapper mapper) |
Modifier and Type | Method and Description |
---|---|
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).
|
boolean |
addMixinType(Node node,
String mixin)
Adds a mixin to a node.
|
protected Node |
addNode(Serializable id,
Serializable parentId,
String name,
Long pos,
String typeName,
boolean complexProp) |
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.
|
protected void |
checkInvalidationsConflict()
Post transaction check invalidations processing.
|
void |
checkLive() |
void |
checkOut(Node node)
Checks out a checked-in node.
|
void |
checkPermission(String absPath,
String actions) |
protected void |
checkThread() |
protected void |
checkThreadEnd() |
protected void |
checkThreadStart() |
int |
cleanupDeletedDocuments(int max,
Calendar beforeTime) |
protected int |
clearCaches()
Clears all the caches.
|
void |
close() |
protected void |
closeSession() |
void |
commit(Xid xid,
boolean onePhase) |
protected void |
commitDone() |
Node |
copy(Node source,
Node parent,
String name)
Copies a node to a new location with a new name.
|
javax.resource.cci.Interaction |
createInteraction() |
protected void |
doFlush() |
void |
end(Xid xid,
int flags) |
protected void |
findPrefetchedFragments(SimpleFragment hierFragment,
List<RowId> bulkRowIds,
Set<Serializable> proxyIds)
Finds prefetched fragments for a hierarchy fragment, takes note of the ones that are proxies.
|
protected void |
flush() |
void |
forget(Xid xid) |
protected Serializable |
generateNewId(Serializable id)
Generates a new id, or used a pre-generated one (import).
|
Map<String,String> |
getBinaryFulltext(Serializable id)
Gets the fulltext extracted from the binary fields.
|
long |
getCacheMapperSize() |
long |
getCachePristineSize() |
long |
getCacheSelectionSize() |
long |
getCacheSize() |
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.
|
protected Set<String> |
getChildrenNames(String primaryType,
List<String> mixins)
Gets complex children names defined by the primary type and the list of mixins.
|
protected Serializable |
getContainingDocument(Serializable id) |
protected PersistenceContext |
getContext() |
protected void |
getFulltextBinariesWorks(List<Work> works,
Set<Serializable> dirtyBinaries) |
protected void |
getFulltextSimpleWorks(List<Work> works,
Set<Serializable> dirtyStrings) |
protected List<Work> |
getFulltextWorks()
Gets the fulltext updates to do.
|
protected List<Fragment> |
getHierarchyAndAncestors(Collection<Serializable> ids)
Fetches the hierarchy fragment for the given rows and all their ancestors.
|
Node |
getLastVersion(Serializable versionSeriesId)
Gets the last version for a given version series id.
|
javax.resource.cci.LocalTransaction |
getLocalTransaction() |
LockManager |
getLockManager()
Gets the lock manager for this session.
|
Mapper |
getMapper()
Gets the low-level Mapper for this session.
|
javax.resource.cci.ConnectionMetaData |
getMetaData() |
Model |
getModel()
Gets the
Model associated to this session. |
Node |
getNodeById(Serializable id)
Gets a node given its id.
|
protected Node |
getNodeById(Serializable id,
boolean prefetch) |
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.
|
javax.resource.cci.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 |
isChangeTokenEnabled()
Checks if change token management is enabled.
|
protected boolean |
isIdNew(Serializable id) |
boolean |
isLive()
Checks if the session is live (not closed).
|
boolean |
isSameRM(XAResource xaresource) |
void |
markReferencedBinaries() |
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.
|
protected String |
normalize(String path) |
void |
orderBefore(Node parent,
Node source,
Node dest)
Order the given source child node before the destination child node.
|
int |
prepare(Xid xid) |
protected void |
processReceivedInvalidations()
Processes all invalidations accumulated.
|
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,
long countUpTo)
Makes a 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.
|
Xid[] |
recover(int flag) |
boolean |
removeMixinType(Node node,
String mixin)
Removes a mixin from a node.
|
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.
|
protected void |
rollback() |
void |
rollback(Xid xid) |
void |
save()
Saves the modifications to persistent storage.
|
protected void |
scheduleWork(List<Work> works) |
ScrollResult<String> |
scroll(String scrollId)
Get the next batch of results containing id of documents, the
scrollId is part of the previous
ScrollResult 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 the
keepAliveSeconds delay. |
protected void |
sendInvalidationsToOthers()
Post-transaction invalidations notification.
|
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.
|
public static final String COMPAT_REPOSITORY_NAME_KEY
Only do this if you start from an empty database, or if you have migrated the "repositories" table by hand, or if you need to create a new repository in a database already containing a "default" repository (table sharing, not recommended).
protected final RepositoryImpl repository
protected final FulltextParser fulltextParser
public final PersistenceContext context
protected final boolean changeTokenEnabled
protected final com.codahale.metrics.MetricRegistry registry
public SessionImpl(RepositoryImpl repository, Model model, Mapper mapper)
public void checkLive()
public Mapper getMapper()
Session
public XAResource getXAResource()
protected int clearCaches()
protected PersistenceContext getContext()
protected void rollback()
protected void checkThread()
protected void checkThreadStart()
protected void checkThreadEnd()
protected Serializable generateNewId(Serializable id)
protected boolean isIdNew(Serializable id)
public void close() throws javax.resource.ResourceException
close
in interface javax.resource.cci.Connection
javax.resource.ResourceException
protected void closeSession()
public javax.resource.cci.Interaction createInteraction() throws javax.resource.ResourceException
createInteraction
in interface javax.resource.cci.Connection
javax.resource.ResourceException
public javax.resource.cci.LocalTransaction getLocalTransaction() throws javax.resource.ResourceException
getLocalTransaction
in interface javax.resource.cci.Connection
javax.resource.ResourceException
public javax.resource.cci.ConnectionMetaData getMetaData() throws javax.resource.ResourceException
getMetaData
in interface javax.resource.cci.Connection
javax.resource.ResourceException
public javax.resource.cci.ResultSetInfo getResultSetInfo() throws javax.resource.ResourceException
getResultSetInfo
in interface javax.resource.cci.Connection
javax.resource.ResourceException
public boolean isLive()
Session
public String getRepositoryName()
Session
getRepositoryName
in interface Session
public Model getModel()
Session
Model
associated to this session.public Node getRootNode()
Session
getRootNode
in interface Session
public void save()
Session
Modifications will be actually written only upon transaction commit.
protected void flush()
protected void scheduleWork(List<Work> works)
protected void doFlush()
protected Serializable getContainingDocument(Serializable id)
protected List<Work> getFulltextWorks()
Work
instances to schedule post-commit.protected void getFulltextSimpleWorks(List<Work> works, Set<Serializable> dirtyStrings)
protected void getFulltextBinariesWorks(List<Work> works, Set<Serializable> dirtyBinaries)
protected void sendInvalidationsToOthers()
Called post-transaction by session commit/rollback or transactionless save.
protected void processReceivedInvalidations()
Called pre-transaction by start or transactionless save;
protected void checkInvalidationsConflict()
protected Node getNodeById(Serializable id, boolean prefetch)
public Node getNodeById(Serializable id)
Session
getNodeById
in interface Session
id
- the idnull
if not foundpublic List<Node> getNodesByIds(List<Serializable> ids, boolean prefetch)
protected void findPrefetchedFragments(SimpleFragment hierFragment, List<RowId> bulkRowIds, Set<Serializable> proxyIds)
public List<Node> getNodesByIds(List<Serializable> ids)
Session
getNodesByIds
in interface Session
ids
- the idsnull
if not foundpublic Node getParentNode(Node node)
Session
The root has a null
parent.
getParentNode
in interface Session
node
- the nodenull
for the root's parentpublic String getPath(Node node)
Session
public Node getNodeByPath(String path, Node node)
Session
getNodeByPath
in interface Session
path
- the pathnode
- the node (ignored for absolute paths)null
if not foundpublic boolean addMixinType(Node node, String mixin)
Session
Does nothing if the mixin was already present on the node.
addMixinType
in interface Session
node
- the nodemixin
- the mixin nametrue
if the mixin was added, or false
if it is already presentpublic boolean removeMixinType(Node node, String mixin)
Session
It's not possible to remove a mixin coming from the primary type.
removeMixinType
in interface Session
node
- the nodemixin
- the mixintrue
if the mixin was removed, or false
if it isn't present or is present on the type or
does not existpublic ScrollResult<String> scroll(String query, int batchSize, int keepAliveSeconds)
Session
keepAliveSeconds
delay.public ScrollResult<String> scroll(String scrollId)
Session
scrollId
is part of the previous
ScrollResult
response.protected Set<String> getChildrenNames(String primaryType, List<String> mixins)
public Node addChildNode(Node parent, String name, Long pos, String typeName, boolean complexProp)
Session
addChildNode
in interface Session
parent
- the parent to which the child is addedname
- the child namepos
- the child position, or null
typeName
- the child typecomplexProp
- whether this is a complex property (true
) or a regular child (false
)public Node addChildNode(Serializable id, Node parent, String name, Long pos, String typeName, boolean complexProp)
Session
addChildNode
in interface Session
id
- the idparent
- the parent to which the child is addedname
- the child namepos
- the child position, or null
typeName
- the child typecomplexProp
- whether this is a complex property (true
) or a regular child (false
)protected Node addNode(Serializable id, Serializable parentId, String name, Long pos, String typeName, boolean complexProp)
public Node addProxy(Serializable targetId, Serializable versionableId, Node parent, String name, Long pos)
Session
public void setProxyTarget(Node proxy, Serializable targetId)
Session
setProxyTarget
in interface Session
proxy
- the proxytargetId
- the new target idpublic boolean hasChildNode(Node parent, String name, boolean complexProp)
Session
There are two kinds of children, the regular children documents and the complex properties. The boolean
allows a choice between those.
hasChildNode
in interface Session
parent
- the parent nodename
- the child namecomplexProp
- whether to check complex properties or regular childrentrue
if a child node with that name existspublic Node getChildNode(Node parent, String name, boolean complexProp)
Session
getChildNode
in interface Session
parent
- the parent nodename
- the child namecomplexProp
- whether to check complex properties or regular childrennull
is not foundpublic boolean hasChildren(Node parent, boolean complexProp)
Session
hasChildren
in interface Session
parent
- the parent nodecomplexProp
- whether to check complex properties or regular childrentrue
if the parent has childrenpublic List<Node> getChildren(Node parent, String name, boolean complexProp)
Session
getChildren
in interface Session
parent
- the parent nodename
- the children name to get (for lists of complex properties), or null
for allcomplexProp
- whether to check complex properties or regular childrenpublic void orderBefore(Node parent, Node source, Node dest)
Session
null
, the source node will be appended at the end of the children
list.orderBefore
in interface Session
parent
- the parent nodesource
- the child node to movedest
- the child node before which to place the source node, or null
to move at the endpublic Node move(Node source, Node parent, String name)
Session
A Session.save()
is automatically done first.
public Node copy(Node source, Node parent, String name)
Session
A Session.save()
is automatically done first.
public void removeNode(Node node)
Session
This is much more complex that removing a property node ( Session.removePropertyNode(org.nuxeo.ecm.core.storage.sql.Node)
).
removeNode
in interface Session
node
- the node to remove#removePropertyNode}
public void removePropertyNode(Node node)
Session
This is much less complex that removing a generic document node ( Session.removeNode(org.nuxeo.ecm.core.storage.sql.Node)
).
removePropertyNode
in interface Session
node
- the property node to remove#removeNode}
public Node checkIn(Node node, String label, String checkinComment)
Session
A Session.save()
is automatically done first.
public void checkOut(Node node)
Session
public void restore(Node node, Node version)
Session
The restored node is checked in.
public Node getVersionByLabel(Serializable versionSeriesId, String label)
Session
getVersionByLabel
in interface Session
versionSeriesId
- the version series idlabel
- the labelnull
if not foundpublic Node getLastVersion(Serializable versionSeriesId)
Session
A Session.save()
is automatically done first.
getLastVersion
in interface Session
versionSeriesId
- the version series idnull
if no versions existpublic List<Node> getVersions(Serializable versionSeriesId)
Session
A Session.save()
is automatically done first.
getVersions
in interface Session
versionSeriesId
- the version series idpublic List<Node> getProxies(Node document, Node parent)
Session
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.
getProxies
in interface Session
document
- the documentparent
- the parent, or null
protected List<Fragment> getHierarchyAndAncestors(Collection<Serializable> ids)
ids
- the fragment idspublic PartialList<Serializable> query(String query, QueryFilter queryFilter, boolean countTotal)
Session
public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo)
Session
query
in interface Session
query
- the queryqueryType
- the query typequeryFilter
- the query filtercountUpTo
- if -1
, also count the total size without offset/limit.0
, don't count the total size.n
, count the total number if there are less than n documents otherwise set the size to
-1
.public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, Object... params)
Session
queryAndFetch
in interface Session
query
- the queryqueryType
- the query typequeryFilter
- the query filterparams
- optional query-type-dependent parameterspublic IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, Object... params)
Session
queryAndFetch
in interface Session
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- if true
then a maximum of one row per document will be returnedparams
- optional query-type-dependent parameterspublic PartialList<Map<String,Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params)
Session
queryProjection
in interface Session
query
- the queryqueryType
- the query typequeryFilter
- the query filterdistinctDocuments
- if true
then a maximum of one row per document will be returnedcountUpTo
- if -1
, also count the total size without offset/limit.0
, don't count the total size.n
, count the total number if there are less than n documents otherwise set the size to
-1
.params
- optional query-type-dependent parameterspublic LockManager getLockManager()
Session
getLockManager
in interface Session
public void requireReadAclsUpdate()
Session
This method flag the current session, the read ACLs update will be done automatically at save time.
requireReadAclsUpdate
in interface Session
public void updateReadAcls()
Session
updateReadAcls
in interface Session
public void rebuildReadAcls()
Session
rebuildReadAcls
in interface Session
public void checkPermission(String absPath, String actions)
public boolean hasPendingChanges()
public void markReferencedBinaries()
public int cleanupDeletedDocuments(int max, Calendar beforeTime)
public boolean isSameRM(XAResource xaresource)
isSameRM
in interface XAResource
public void start(Xid xid, int flags) throws XAException
start
in interface XAResource
XAException
public void end(Xid xid, int flags) throws XAException
end
in interface XAResource
XAException
public int prepare(Xid xid) throws XAException
prepare
in interface XAResource
XAException
public void commit(Xid xid, boolean onePhase) throws XAException
commit
in interface XAResource
XAException
protected void commitDone() throws XAException
XAException
public void rollback(Xid xid) throws XAException
rollback
in interface XAResource
XAException
public void forget(Xid xid) throws XAException
forget
in interface XAResource
XAException
public Xid[] recover(int flag) throws XAException
recover
in interface XAResource
XAException
public boolean setTransactionTimeout(int seconds) throws XAException
setTransactionTimeout
in interface XAResource
XAException
public int getTransactionTimeout() throws XAException
getTransactionTimeout
in interface XAResource
XAException
public long getCacheSize()
public long getCacheMapperSize()
public long getCachePristineSize()
public long getCacheSelectionSize()
public Map<String,String> getBinaryFulltext(Serializable id)
Session
getBinaryFulltext
in interface Session
public boolean isChangeTokenEnabled()
Session
isChangeTokenEnabled
in interface Session
public void markUserChange(Serializable id)
Session
This causes an additional change token increment and check during save.
markUserChange
in interface Session
id
- the document idCopyright © 2018 Nuxeo. All rights reserved.