org.apache.jackrabbit.oak.jcr.delegate
Class SessionDelegate

java.lang.Object
  extended by org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate

public class SessionDelegate
extends Object

TODO document


Constructor Summary
SessionDelegate(org.apache.jackrabbit.oak.api.ContentSession contentSession, org.apache.jackrabbit.oak.spi.security.SecurityProvider securityProvider, RefreshStrategy refreshStrategy, ThreadLocal<Long> threadSaveCount, org.apache.jackrabbit.oak.stats.StatisticManager statisticManager, org.apache.jackrabbit.oak.stats.Clock clock)
          Create a new session delegate for a ContentSession.
 
Method Summary
 void checkAlive()
          Check that this session is alive.
 void checkProtectedNode(String path)
           
 void commit()
          Commits the changes currently in the transient space.
 void commit(org.apache.jackrabbit.oak.api.Root root)
          Commits the changes applied to the given root.
 org.apache.jackrabbit.oak.api.AuthInfo getAuthInfo()
           
 org.apache.jackrabbit.oak.api.ContentSession getContentSession()
           
 org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager getIdManager()
           
 ItemDelegate getItem(String path)
          Returns the node or property delegate at the given path.
 Date getLoginTime()
           
 NodeDelegate getNode(String path)
          NodeDelegate at the given path
 NodeDelegate getNodeByIdentifier(String id)
           
 org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider getPermissionProvider()
           
 PropertyDelegate getProperty(String path)
          PropertyDelegate at the given path
 org.apache.jackrabbit.oak.api.QueryEngine getQueryEngine()
           
 long getReadCount()
           
 Date getReadTime()
           
 long getRefreshCount()
           
 Date getRefreshTime()
           
 org.apache.jackrabbit.oak.api.Root getRoot()
          The current Root instance this session delegate instance operates on.
 NodeDelegate getRootNode()
           
 long getSaveCount()
           
 Date getSaveTime()
           
 long getSecondsSinceLogin()
           
 SessionStats getSessionStats()
           
 long getUpdateCount()
           
 String getWorkspaceName()
           
 long getWriteCount()
           
 Date getWriteTime()
           
 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(SessionOperation<T> sessionOperation)
          Performs the passed SessionOperation in a safe execution context.
 void refresh(boolean keepChanges)
           
 void refreshAtNextAccess()
           
<T> T
safePerform(SessionOperation<T> sessionOperation)
          Same as perform(SessionOperation) unless this method expects SessionOperation.perform() not to throw a RepositoryException.
 void save(String path)
          Save the subtree rooted at the given path, or the entire transient space if given the root path or null.
 void setUserData(String userData)
           
<T> Iterator<T>
sync(Iterator<T> iterator)
          Wrap the passed iterator in an iterator that synchronizes all access to the underlying session.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SessionDelegate

public SessionDelegate(@Nonnull
                       org.apache.jackrabbit.oak.api.ContentSession contentSession,
                       @Nonnull
                       org.apache.jackrabbit.oak.spi.security.SecurityProvider securityProvider,
                       @Nonnull
                       RefreshStrategy refreshStrategy,
                       @Nonnull
                       ThreadLocal<Long> threadSaveCount,
                       @Nonnull
                       org.apache.jackrabbit.oak.stats.StatisticManager statisticManager,
                       @Nonnull
                       org.apache.jackrabbit.oak.stats.Clock clock)
Create a new session delegate for a ContentSession. The refresh behaviour of the session is governed by the value of the refreshInterval 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 to refreshAtNextAccess(). This is typically done from within the observation event dispatcher in order.

Parameters:
contentSession - the content session
securityProvider - the security provider
refreshStrategy - the refresh strategy used for auto refreshing this session
statisticManager - the statistics manager for tracking session operations
Method Detail

getSessionStats

@Nonnull
public SessionStats getSessionStats()

getSecondsSinceLogin

public long getSecondsSinceLogin()

getLoginTime

public Date getLoginTime()

getReadTime

public Date getReadTime()

getWriteTime

public Date getWriteTime()

getRefreshTime

public Date getRefreshTime()

getSaveTime

public Date getSaveTime()

getReadCount

public long getReadCount()

getWriteCount

public long getWriteCount()

getRefreshCount

public long getRefreshCount()

getSaveCount

public long getSaveCount()

refreshAtNextAccess

public void refreshAtNextAccess()

sync

public <T> Iterator<T> sync(Iterator<T> iterator)
Wrap the passed iterator in an iterator that synchronizes all access to the underlying session.

Type Parameters:
T -
Parameters:
iterator - iterator to synchronized
Returns:
synchronized iterator

perform

public <T> T perform(SessionOperation<T> sessionOperation)
          throws javax.jcr.RepositoryException
Performs the passed SessionOperation 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 of sessionOperation
Parameters:
sessionOperation - the SessionOperation to perform
Returns:
the result of sessionOperation.perform()
Throws:
javax.jcr.RepositoryException
See Also:
getRoot()

safePerform

public <T> T safePerform(SessionOperation<T> sessionOperation)
Same as perform(SessionOperation) unless this method expects SessionOperation.perform() not to throw a RepositoryException. Such exceptions will be wrapped into a RuntimeException and rethrown as they are considered an internal error.

Type Parameters:
T - return type of sessionOperation
Parameters:
sessionOperation - the SessionOperation to perform
Returns:
the result of sessionOperation.perform()
See Also:
getRoot()

getContentSession

@Nonnull
public org.apache.jackrabbit.oak.api.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 javax.jcr.RepositoryException
Check that this session is alive.

Throws:
javax.jcr.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 org.apache.jackrabbit.oak.api.CommitFailedException
Commits the changes currently in the transient space. TODO: Consolidate with save().

Throws:
org.apache.jackrabbit.oak.api.CommitFailedException - if the commit failed

commit

public void commit(org.apache.jackrabbit.oak.api.Root root)
            throws org.apache.jackrabbit.oak.api.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:
org.apache.jackrabbit.oak.api.CommitFailedException - if the commit failed

checkProtectedNode

public void checkProtectedNode(String path)
                        throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getAuthInfo

@Nonnull
public org.apache.jackrabbit.oak.api.AuthInfo getAuthInfo()

logout

public void logout()

getIdManager

@Nonnull
public org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager getIdManager()

getRootNode

@CheckForNull
public NodeDelegate getRootNode()

getNode

@CheckForNull
public NodeDelegate getNode(String path)
NodeDelegate at the given path

Parameters:
path - Oak path
Returns:
The NodeDelegate at path or null if none exists or not accessible.

getItem

@CheckForNull
public 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

@CheckForNull
public NodeDelegate getNodeByIdentifier(String id)

getProperty

@CheckForNull
public PropertyDelegate getProperty(String path)
PropertyDelegate at the given path

Parameters:
path - Oak path
Returns:
The PropertyDelegate at path or null if none exists or not accessible.

hasPendingChanges

public boolean hasPendingChanges()

save

public void save(String path)
          throws javax.jcr.RepositoryException
Save the subtree rooted at the given path, or the entire transient space if given the root path or null.

This implementation only performs the save if the subtree rooted at path contains all transient changes and will throw an UnsupportedRepositoryOperationException otherwise.

Parameters:
path -
Throws:
javax.jcr.RepositoryException

refresh

public void refresh(boolean keepChanges)

getWorkspaceName

@Nonnull
public String getWorkspaceName()

move

public void move(String srcPath,
                 String destPath,
                 boolean transientOp)
          throws javax.jcr.RepositoryException
Move a node

Parameters:
srcPath - oak path to the source node to copy
destPath - oak path to the destination
transientOp - whether or not to perform the move in transient space
Throws:
javax.jcr.RepositoryException

getQueryEngine

@Nonnull
public org.apache.jackrabbit.oak.api.QueryEngine getQueryEngine()

getPermissionProvider

@Nonnull
public org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider getPermissionProvider()

getRoot

@Nonnull
public org.apache.jackrabbit.oak.api.Root getRoot()
The current Root instance this session delegate instance operates on. To ensure the returned root reflects the correct repository revision access should only be done from within a SessionOperation closure through perform(SessionOperation).

Returns:
current root

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012-2014 The Apache Software Foundation. All Rights Reserved.