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 |
|---|---|
static short |
READ_ONLY
option flags
|
| Constructor and Description |
|---|
Context()
Construct a new context object with default options.
|
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 |
cache(Object o,
int id)
Store an object in the object cache.
|
void |
clearCache()
Remove all the objects from the object cache
|
void |
commit()
Commit any transaction that is currently in progress, but do not close
the context.
|
void |
complete()
Close the context object after all of the operations performed in the
context have completed successfully.
|
protected void |
finalize() |
Object |
fromCache(Class<?> objectClass,
int id)
Store an object in the object cache.
|
int |
getCacheSize()
Get the count of cached objects, which you can use to instrument an
application to track whether it is "leaking" heap space by letting cached
objects build up.
|
Locale |
getCurrentLocale()
Gets the current Locale
|
EPerson |
getCurrentUser()
Get the current (authenticated) user
|
Connection |
getDBConnection()
Get the database connection associated with the context
|
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.
|
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(int groupID)
test if member of special group
|
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 & removes it from the list of events once retrieved
|
void |
removeCached(Object o,
int id)
Remove an object from the object 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(int groupID)
set membership in a special group
|
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
public Context()
throws SQLException
SQLException - if there was an error obtaining a database connectionpublic Context(short options)
throws SQLException
options - context operation flagsSQLException - if there was an error obtaining a database connectionpublic Connection getDBConnection()
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
SQLException - if there was an error completing the database transaction
or closing the connectionpublic void commit()
throws SQLException
SQLException - if there was an error completing the database transaction
or closing the connectionpublic void setDispatcher(String dispatcher)
null selects the defaultpublic void addEvent(Event event)
event - public LinkedList<Event> getEvents()
public boolean hasEvents()
public Event pollEvent()
null if the list is emptypublic void abort()
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 Object fromCache(Class<?> objectClass, int id)
objectClass - Java Class of object to check for in cacheid - ID of object in cachenull if it's not
cached.public void cache(Object o, int id)
o - the object to storeid - the object's IDpublic void removeCached(Object o, int id)
o - the object to removeid - the object's IDpublic void clearCache()
public int getCacheSize()
public void setSpecialGroup(int groupID)
groupID - special group's IDpublic boolean inSpecialGroup(int groupID)
groupID - ID of special group to testpublic Group[] getSpecialGroups() throws SQLException
SQLExceptionCopyright © 2013 DuraSpace. All Rights Reserved.