public class Context extends Object
Typical use of the context object will involve constructing one, and setting
the current user if one is authenticated. Several operations may be performed
using the context object. If all goes well, complete is called
to commit the changes and free up any resources used by the context. If
anything has gone wrong, abort is called to roll back any
changes and free up the resources.
The context object is also used as a cache for CM API objects.
| Modifier and Type | Class and Description |
|---|---|
static class |
Context.Mode |
| Modifier and Type | Field and Description |
|---|---|
protected EventService |
eventService |
| Modifier | Constructor and Description |
|---|---|
|
Context()
Construct a new context object with default options.
|
|
Context(Context.Mode mode)
Construct a new context object with the given mode enabled.
|
protected |
Context(EventService eventService,
DBConnection dbConnection) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Close the context, without committing any of the changes performed using
this context.
|
void |
addEvent(Event event)
Add an event to be dispatched when this context is committed.
|
void |
cacheAllMemberGroupsSet(EPerson ePerson,
Set<Group> groups) |
void |
cacheAuthorizedAction(DSpaceObject dspaceObject,
int action,
EPerson eperson,
Boolean result,
ResourcePolicy rp) |
void |
cacheGroupMembership(Group group,
EPerson eperson,
Boolean isMember) |
void |
commit()
Commit the current transaction with the database, persisting any pending changes.
|
void |
complete()
Close the context object after all of the operations performed in the
context have completed successfully.
|
void |
dispatchEvents() |
void |
enableBatchMode(boolean batchModeEnabled)
Deprecated.
|
protected void |
finalize() |
Set<Group> |
getCachedAllMemberGroupsSet(EPerson ePerson) |
Boolean |
getCachedAuthorizationResult(DSpaceObject dspaceObject,
int action,
EPerson eperson) |
Boolean |
getCachedGroupMembership(Group group,
EPerson eperson) |
long |
getCacheSize()
Returns the size of the cache of all object that have been read from the database so far.
|
Locale |
getCurrentLocale()
Gets the current Locale
|
Context.Mode |
getCurrentMode()
The current database mode of this context.
|
EPerson |
getCurrentUser()
Get the current (authenticated) user
|
DatabaseConfigVO |
getDBConfig() |
String |
getDbType() |
LinkedList<Event> |
getEvents()
Get the current event list.
|
String |
getExtraLogInfo()
Get extra information to be logged with message logged in the scope of
this context.
|
List<Group> |
getSpecialGroups()
Get an array of all of the special groups that current user is a member
of.
|
boolean |
hasEvents() |
boolean |
ignoreAuthorization()
Find out if the authorisation system should be ignored for this context.
|
boolean |
inSpecialGroup(UUID groupID)
test if member of special group
|
boolean |
isBatchModeEnabled()
Deprecated.
|
boolean |
isReadOnly()
Reports whether context supports updating DSpaceObjects, or only reading.
|
boolean |
isValid()
Find out if this context is valid.
|
Event |
pollEvent()
Retrieves the first element in the events list and removes it from the list of events once retrieved
|
<E extends ReloadableEntity> |
reloadEntity(E entity)
Reload an entity from the database into the cache.
|
void |
restoreAuthSystemState()
Restore the previous Authorisation System State.
|
void |
setCurrentLocale(Locale locale)
set the current Locale
|
void |
setCurrentUser(EPerson user)
Set the current user.
|
void |
setDispatcher(String dispatcher)
Select an event dispatcher,
null selects the default |
void |
setExtraLogInfo(String info)
Set extra information that should be added to any message logged in the
scope of this context.
|
void |
setMode(Context.Mode newMode)
Change the mode of this current context.
|
void |
setSpecialGroup(UUID groupID) |
void |
shutDownDatabase() |
void |
turnOffAuthorisationSystem()
Turn Off the Authorisation System for this context and store this change
in a history for future use.
|
<E extends ReloadableEntity> |
uncacheEntity(E entity)
Remove an entity from the cache.
|
protected EventService eventService
protected Context(EventService eventService, DBConnection dbConnection)
public Context()
public Context(Context.Mode mode)
mode - The mode to use when opening the context.public DatabaseConfigVO getDBConfig() throws SQLException
SQLExceptionpublic String getDbType()
public void setCurrentUser(EPerson user)
user - the new current user, or null if no user is
authenticatedpublic EPerson getCurrentUser()
null if no user is
authenticatedpublic Locale getCurrentLocale()
public void setCurrentLocale(Locale locale)
locale - the current Localepublic boolean ignoreAuthorization()
true if authorisation should be ignored for this
session.public void turnOffAuthorisationSystem()
public void restoreAuthSystemState()
mycontext.turnOffAuthorisationSystem();
some java code that require no authorisation check
mycontext.restoreAuthSystemState();
If Context debug is enabled, the correct sequence calling will be
checked and a warning will be displayed if not.public void setExtraLogInfo(String info)
setExtraLogInfo("session_id="+request.getSession().getId());
info - the extra information to logpublic String getExtraLogInfo()
nullpublic void complete()
throws SQLException
Calling complete() on a Context which is no longer valid (isValid()==false), is a no-op.
SQLException - if there was an error completing the database transaction
or closing the connectionpublic void commit()
throws SQLException
reloadEntity(ReloadableEntity)).SQLException - When committing the transaction in the database fails.public void dispatchEvents()
public void setDispatcher(String dispatcher)
null selects the defaultdispatcher - dispatcherpublic void addEvent(Event event)
event - public LinkedList<Event> getEvents()
public boolean hasEvents()
public Event pollEvent()
null if the list is emptypublic void abort()
Calling abort() on a Context which is no longer valid (isValid()==false), is a no-op.
public boolean isValid()
false if this
context has been aborted or completed.true if the context is still valid, otherwise
falsepublic boolean isReadOnly()
true if the context is read-only, otherwise
falsepublic void setSpecialGroup(UUID groupID)
public boolean inSpecialGroup(UUID groupID)
groupID - ID of special group to testpublic List<Group> getSpecialGroups() throws SQLException
SQLException - if database errorprotected void finalize()
throws Throwable
public void shutDownDatabase()
throws SQLException
SQLExceptionpublic long getCacheSize()
throws SQLException
uncacheEntity(ReloadableEntity) () uncacheEntity}).SQLException - When connecting to the active cache fails.public void setMode(Context.Mode newMode)
newMode - The mode to put this context inpublic Context.Mode getCurrentMode()
@Deprecated public void enableBatchMode(boolean batchModeEnabled) throws SQLException
batchModeEnabled - When true, batch processing mode will be enabled. If false, it will be disabled.SQLException - When configuring the database connection fails.@Deprecated public boolean isBatchModeEnabled()
public <E extends ReloadableEntity> E reloadEntity(E entity) throws SQLException
E - The class of the enity. The entity must implement the ReloadableEntity interface.entity - The entity to reloadSQLException - When reloading the entity from the database fails.public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException
E - The class of the enity. The entity must implement the ReloadableEntity interface.entity - The entity to reloadSQLException - When reloading the entity from the database fails.public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson)
public void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result, ResourcePolicy rp)
public void cacheGroupMembership(Group group, EPerson eperson, Boolean isMember)
Copyright © 2022 LYRASIS. All rights reserved.