Class SessionDelegate
- java.lang.Object
-
- org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate
-
public class SessionDelegate extends Object
TODO document
-
-
Constructor Summary
Constructors Constructor Description SessionDelegate(@NotNull ContentSession contentSession, @NotNull SecurityProvider securityProvider, @NotNull RefreshStrategy refreshStrategy, @NotNull ThreadLocal<Long> threadSaveCount, @NotNull StatisticManager statisticManager, @NotNull Clock clock)
Create a new session delegate for aContentSession
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAlive()
Check that this session is alive.void
checkProtectedNode(String path)
void
commit()
Commits the changes currently in the transient space.void
commit(Root root)
Commits the changes applied to the given root.@NotNull AuthInfo
getAuthInfo()
@NotNull ContentSession
getContentSession()
@NotNull IdentifierManager
getIdManager()
@Nullable ItemDelegate
getItem(String path)
Returns the node or property delegate at the given path.SessionNamespaces
getNamespaces()
@Nullable NodeDelegate
getNode(String path)
NodeDelegate
at the given path@Nullable NodeDelegate
getNodeByIdentifier(String id)
@NotNull PermissionProvider
getPermissionProvider()
@Nullable PropertyDelegate
getProperty(String path)
PropertyDelegate
at the given path@NotNull QueryEngine
getQueryEngine()
@NotNull Root
getRoot()
The currentRoot
instance this session delegate instance operates on.@Nullable NodeDelegate
getRootNode()
@NotNull SessionStats
getSessionStats()
long
getUpdateCount()
@NotNull String
getWorkspaceName()
boolean
hasPendingChanges()
boolean
isAlive()
Determine whether this session is alive and has not been logged out or become stale by other means.void
logout()
void
move(String srcPath, String destPath, boolean transientOp)
Move a node<T> T
perform(@NotNull SessionOperation<T> sessionOperation)
Performs the passedSessionOperation
in a safe execution context.<T> T
performNullable(@NotNull SessionOperation<T> sessionOperation)
Same asperform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
but with the option to returnnull
; thus callingSessionOperation.performNullable()
void
performVoid(SessionOperation<Void> sessionOperation)
Same asperform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
for calls that don't expect any return value; thus callingSessionOperation.performVoid()
.void
refresh(boolean keepChanges)
void
refreshAtNextAccess()
<T> T
safePerform(SessionOperation<T> sessionOperation)
Same asperform(SessionOperation)
unless this method expectsSessionOperation.perform()
not to throw aRepositoryException
.<T> T
safePerformNullable(SessionOperation<T> sessionOperation)
Same asperformNullable(SessionOperation)
unless this method expectsSessionOperation.performNullable()
not to throw aRepositoryException
.void
save(String path)
Save the subtree rooted at the givenpath
, or the entire transient space if given the root path ornull
.void
setUserData(String userData)
<T> Iterator<T>
sync(Iterator<T> iterator)
Wrap the passediterator
in an iterator that synchronizes all access to the underlying session.String
toString()
protected void
treeLookedUpByIdentifier(@NotNull Tree tree)
-
-
-
Constructor Detail
-
SessionDelegate
public SessionDelegate(@NotNull @NotNull ContentSession contentSession, @NotNull @NotNull SecurityProvider securityProvider, @NotNull @NotNull RefreshStrategy refreshStrategy, @NotNull @NotNull ThreadLocal<Long> threadSaveCount, @NotNull @NotNull StatisticManager statisticManager, @NotNull @NotNull Clock clock)
Create a new session delegate for aContentSession
. The refresh behaviour of the session is governed by the value of therefreshInterval
argument: if the session has been idle longer than that value, an implicit refresh will take place. In addition a refresh can always be scheduled from the next access by an explicit call torefreshAtNextAccess()
. This is typically done from within the observation event dispatcher in order.- Parameters:
contentSession
- the content sessionsecurityProvider
- the security providerrefreshStrategy
- the refresh strategy used for auto refreshing this sessionstatisticManager
- the statistics manager for tracking session operations
-
-
Method Detail
-
getSessionStats
@NotNull public @NotNull SessionStats getSessionStats()
-
refreshAtNextAccess
public void refreshAtNextAccess()
-
sync
public <T> Iterator<T> sync(Iterator<T> iterator)
Wrap the passediterator
in an iterator that synchronizes all access to the underlying session.- Type Parameters:
T
-- Parameters:
iterator
- iterator to synchronized- Returns:
- synchronized iterator
-
perform
@NotNull public <T> T perform(@NotNull @NotNull SessionOperation<T> sessionOperation) throws RepositoryException
Performs the passedSessionOperation
in a safe execution context. This context ensures that the session is refreshed if necessary and that refreshing occurs before the session operation is performed and the refreshing is done only once.- Type Parameters:
T
- return type ofsessionOperation
- Parameters:
sessionOperation
- theSessionOperation
to perform- Returns:
- the result of
sessionOperation.perform()
- Throws:
RepositoryException
- See Also:
getRoot()
-
performNullable
@Nullable public <T> T performNullable(@NotNull @NotNull SessionOperation<T> sessionOperation) throws RepositoryException
Same asperform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
but with the option to returnnull
; thus callingSessionOperation.performNullable()
- Type Parameters:
T
- return type ofsessionOperation
- Parameters:
sessionOperation
- theSessionOperation
to perform- Returns:
- the result of
sessionOperation.performNullable()
, which might also benull
. - Throws:
RepositoryException
- See Also:
perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
-
performVoid
public void performVoid(SessionOperation<Void> sessionOperation) throws RepositoryException
Same asperform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
for calls that don't expect any return value; thus callingSessionOperation.performVoid()
.- Parameters:
sessionOperation
- theSessionOperation
to perform.- Throws:
RepositoryException
- See Also:
perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
-
safePerform
@NotNull public <T> T safePerform(SessionOperation<T> sessionOperation)
Same asperform(SessionOperation)
unless this method expectsSessionOperation.perform()
not to throw aRepositoryException
. Such exceptions will be wrapped into aRuntimeException
and rethrown as they are considered an internal error.- Type Parameters:
T
- return type ofsessionOperation
- Parameters:
sessionOperation
- theSessionOperation
to perform- Returns:
- the result of
sessionOperation.perform()
- See Also:
getRoot()
-
safePerformNullable
@Nullable public <T> T safePerformNullable(SessionOperation<T> sessionOperation)
Same asperformNullable(SessionOperation)
unless this method expectsSessionOperation.performNullable()
not to throw aRepositoryException
. Such exceptions will be wrapped into aRuntimeException
and rethrown as they are considered an internal error.- Type Parameters:
T
- return type ofsessionOperation
- Parameters:
sessionOperation
- theSessionOperation
to perform- Returns:
- the result of
sessionOperation.performNullable()
-
getContentSession
@NotNull public @NotNull ContentSession getContentSession()
-
isAlive
public boolean isAlive()
Determine whether this session is alive and has not been logged out or become stale by other means.- Returns:
true
if this session is alive,false
otherwise.
-
checkAlive
public void checkAlive() throws RepositoryException
Check that this session is alive.- Throws:
RepositoryException
- if this session is not alive- See Also:
isAlive()
-
getUpdateCount
public long getUpdateCount()
- Returns:
- session update counter
-
setUserData
public void setUserData(String userData)
-
commit
public void commit() throws CommitFailedException
Commits the changes currently in the transient space. TODO: Consolidate with save().- Throws:
CommitFailedException
- if the commit failed
-
commit
public void commit(Root root) throws CommitFailedException
Commits the changes applied to the given root. The user data (if any) currently attached to this session is passed as the commit message. Used both for normal save() calls and for the various direct-to-workspace operations.- Throws:
CommitFailedException
- if the commit failed
-
checkProtectedNode
public void checkProtectedNode(String path) throws RepositoryException
- Throws:
RepositoryException
-
getAuthInfo
@NotNull public @NotNull AuthInfo getAuthInfo()
-
logout
public void logout()
-
getIdManager
@NotNull public @NotNull IdentifierManager getIdManager()
-
getRootNode
@Nullable public @Nullable NodeDelegate getRootNode()
-
getNode
@Nullable public @Nullable NodeDelegate getNode(String path)
NodeDelegate
at the given path- Parameters:
path
- Oak path- Returns:
- The
NodeDelegate
atpath
ornull
if none exists or not accessible.
-
getItem
@Nullable public @Nullable ItemDelegate getItem(String path)
Returns the node or property delegate at the given path.- Parameters:
path
- Oak path- Returns:
- node or property delegate, or
null
if none exists
-
getNodeByIdentifier
@Nullable public @Nullable NodeDelegate getNodeByIdentifier(String id)
-
treeLookedUpByIdentifier
protected void treeLookedUpByIdentifier(@NotNull @NotNull Tree tree)
-
getProperty
@Nullable public @Nullable PropertyDelegate getProperty(String path)
PropertyDelegate
at the given path- Parameters:
path
- Oak path- Returns:
- The
PropertyDelegate
atpath
ornull
if none exists or not accessible.
-
hasPendingChanges
public boolean hasPendingChanges()
-
save
public void save(String path) throws RepositoryException
Save the subtree rooted at the givenpath
, or the entire transient space if given the root path ornull
.This implementation only performs the save if the subtree rooted at
path
contains all transient changes and will throw anUnsupportedRepositoryOperationException
otherwise.- Parameters:
path
-- Throws:
RepositoryException
-
refresh
public void refresh(boolean keepChanges)
-
getWorkspaceName
@NotNull public @NotNull String getWorkspaceName()
-
move
public void move(String srcPath, String destPath, boolean transientOp) throws RepositoryException
Move a node- Parameters:
srcPath
- oak path to the source node to copydestPath
- oak path to the destinationtransientOp
- whether or not to perform the move in transient space- Throws:
RepositoryException
-
getQueryEngine
@NotNull public @NotNull QueryEngine getQueryEngine()
-
getPermissionProvider
@NotNull public @NotNull PermissionProvider getPermissionProvider()
-
getRoot
@NotNull public @NotNull Root getRoot()
The currentRoot
instance this session delegate instance operates on. To ensure the returned root reflects the correct repository revision access should only be done from within aSessionOperation
closure throughperform(SessionOperation)
.- Returns:
- current root
-
getNamespaces
public SessionNamespaces getNamespaces()
-
-