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 | Field and Description |
|---|---|
protected EventService |
eventService |
static short |
READ_ONLY
option flags
|
| Modifier | Constructor and Description |
|---|---|
|
Context()
Construct a new context object with default options.
|
protected |
Context(EventService eventService,
DBConnection dbConnection) |
|
Context(short options)
Construct a new context object with passed options.
|
| 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 |
clearCache()
Clear the cache of all object that have been read from the database so far.
|
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)
Enable or disable "batch processing mode" for this context.
|
protected void |
finalize() |
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
|
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()
Check if "batch processing mode" is enabled for this context.
|
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 |
setIgnoreAuthorization(boolean b)
Deprecated.
use turnOffAuthorisationSystem() for make the change and
restoreAuthSystemState() when change are not more required
|
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.
|
public static final short READ_ONLY
protected EventService eventService
protected Context(EventService eventService, DBConnection dbConnection)
public Context()
SQLException - if there was an error obtaining a database connectionpublic Context(short options)
options - context operation flagspublic 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 setIgnoreAuthorization(boolean b)
b - if true, authorisation should be ignored for this
session.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 void clearCache()
throws SQLException
reloadEntity(ReloadableEntity)).
This method will take care of reloading the current user.SQLException - When clearing the entity cache failspublic long getCacheSize()
throws SQLException
clearCache).SQLException - When connecting to the active cache fails.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.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.Copyright © 2016 DuraSpace. All rights reserved.