Package org.opencms.db
Class CmsDbContext
java.lang.Object
org.opencms.db.CmsDbContext
Wraps context information to access the OpenCms database.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionContext attributes.protected CmsFlexRequestContextInfo
The current Flex request context info (if available).protected CmsUUID
The id of the project for the context.protected CmsRequestContext
The wrapped user request context. -
Constructor Summary
ConstructorDescriptionCreates a new, empty database context.CmsDbContext
(CmsRequestContext context) Creates a new database context initialized with the given user request context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears this database context.Returns the current users project.Returns the current user.getAttribute
(String key) Get an attribute from the DB context.Returns the current Flex request context info.getHistoryDriver
(CmsUUID projectId) Gets the history driver associated with this database context.getProjectDriver
(CmsUUID projectId) Gets the project driver associated with this database context.Returns the project id of the context.Returns the request context.getUserDriver
(CmsUUID projectId) Gets the user driver associated with this database context.getVfsDriver
(CmsUUID projectId) Gets the VFS driver associated with this database context.boolean
Checks if the database context uses the default implementation.void
pop()
Processes the current database context.void
removeAttribute
(String key) Removes the given attribute from the DB context.removeSiteRoot
(String resourcename) Removes the current site root prefix from the absolute path in the resource name, that is adjusts the resource name for the current site root.void
report
(I_CmsReport report, CmsMessageContainer message, Throwable throwable) Reports an error to the given report (if available) and to the OpenCms log file.void
rollback()
Rolls back current transaction.void
setAttribute
(String key, Object value) Sets an attribute in the DB context.void
setProjectId
(CmsUUID projectId) Sets the project id of the context.void
throwException
(CmsMessageContainer message, Throwable throwable) Returns an exception of the same type asthrowable
, ifthrowable
is an OpenCms Exception with the message as aCmsMessageContainer
and thethrowable
as a cause.
-
Field Details
-
m_attributes
Context attributes. -
m_flexRequestContextInfo
The current Flex request context info (if available). -
m_projectId
The id of the project for the context. -
m_requestContext
The wrapped user request context.
-
-
Constructor Details
-
CmsDbContext
public CmsDbContext()Creates a new, empty database context. -
CmsDbContext
Creates a new database context initialized with the given user request context.- Parameters:
context
- the current users request context
-
-
Method Details
-
clear
Clears this database context. -
currentProject
Returns the current users project.- Returns:
- the current users project
-
currentUser
Returns the current user.- Returns:
- the current user
-
getAttribute
Get an attribute from the DB context.- Parameters:
key
- the attribute key- Returns:
- the attribute value or null if the attribute does not exist
-
getFlexRequestContextInfo
Returns the current Flex request context info.- Returns:
- the current Flex request context info
-
getHistoryDriver
Gets the history driver associated with this database context.- Parameters:
projectId
- the project id for which the history driver should be retrieved- Returns:
- the history driver
-
getProjectDriver
Gets the project driver associated with this database context.- Parameters:
projectId
- the project id for which the project driver should be retrieved- Returns:
- the project driver
-
getProjectId
Returns the project id of the context.- Returns:
- the project
-
getRequestContext
Returns the request context.- Returns:
- the request context
-
getUserDriver
Gets the user driver associated with this database context.- Parameters:
projectId
- the project id for which the user driver should be retrieved- Returns:
- the user driver
-
getVfsDriver
Gets the VFS driver associated with this database context.- Parameters:
projectId
- the project id for which the VFS driver should be retrieved- Returns:
- the VFS driver
-
isDefaultDbContext
Checks if the database context uses the default implementation.- Returns:
true
if the database context uses the default implementation
-
pop
Processes the current database context.- Throws:
CmsException
- if something goes wrong
-
removeAttribute
Removes the given attribute from the DB context.- Parameters:
key
- the attribute key
-
removeSiteRoot
Removes the current site root prefix from the absolute path in the resource name, that is adjusts the resource name for the current site root.If no user request context is available, the given resource name is returned unchanged.
- Parameters:
resourcename
- the resource name- Returns:
- the resource name adjusted for the current site root
-
report
public void report(I_CmsReport report, CmsMessageContainer message, Throwable throwable) throws CmsVfsException, CmsException Reports an error to the given report (if available) and to the OpenCms log file.- Parameters:
report
- the report to write the error tomessage
- the message to write to the report / logthrowable
- the exception to write to the report / log- Throws:
CmsException
- if thethrowable
parameter is notnull
and aCmsException
CmsVfsException
- if thethrowable
parameter is notnull
and noCmsException
-
rollback
Rolls back current transaction. -
setAttribute
Sets an attribute in the DB context.- Parameters:
key
- the attribute keyvalue
- the attribute value
-
setProjectId
Sets the project id of the context.- Parameters:
projectId
- the id of the project to set
-
throwException
public void throwException(CmsMessageContainer message, Throwable throwable) throws CmsVfsException, CmsException Returns an exception of the same type asthrowable
, ifthrowable
is an OpenCms Exception with the message as aCmsMessageContainer
and thethrowable
as a cause.- Parameters:
message
- the message container for the exception to createthrowable
- the cause of the exception- Throws:
CmsException
- if thethrowable
parameter is notnull
and aCmsException
CmsVfsException
- if thethrowable
parameter is notnull
and noCmsException
-