Package org.opencms.db.generic
Class CmsHistoryDriver
java.lang.Object
org.opencms.db.generic.CmsHistoryDriver
- All Implemented Interfaces:
I_CmsDriver
,I_CmsHistoryDriver
- Direct Known Subclasses:
CmsHistoryDriver
,CmsHistoryDriver
,CmsHistoryDriver
,CmsHistoryDriver
,CmsHistoryDriver
,CmsHistoryDriver
,CmsHistoryDriver
Generic (ANSI-SQL) database server implementation of the history driver methods.
- Since:
- 6.9.1
-
Field Summary
Modifier and TypeFieldDescriptionprotected CmsDriverManager
The driver manager instance.protected CmsSqlManager
The SQL manager instance.Fields inherited from interface org.opencms.db.I_CmsDriver
AND_CONDITION, BEGIN_CONDITION, BEGIN_EXCLUDE_CONDITION, BEGIN_INCLUDE_CONDITION, END_CONDITION, OR_CONDITION
Fields inherited from interface org.opencms.db.I_CmsHistoryDriver
DRIVER_TYPE_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreatePropertyDefinition
(CmsDbContext dbc, String name, CmsPropertyDefinition.CmsPropertyType type) Creates a new property defintion in the database.int
deleteEntries
(CmsDbContext dbc, I_CmsHistoryResource resource, int versionsToKeep, long time) Deletes all historical versions of a resource keeping maximalversionsToKeep
versions.void
deletePropertyDefinition
(CmsDbContext dbc, CmsPropertyDefinition metadef) Deletes a property definition.void
destroy()
Destroys this driver.Returns all historical resources (of deleted resources).Returns all historical resources (of not deleted resources).Returns the SqlManager of this driver.void
init
(CmsDbContext dbc, CmsConfigurationManager configurationManager, List<String> successiveDrivers, CmsDriverManager driverManager) Initializes the driver.initSqlManager
(String classname) Initializes the SQL manager for this driver.protected void
internalAddToPropMap
(Map<String, CmsProperty> propertyMap, I_CmsHistoryResource resource, String propertyKey, String propertyValue, int mappingType) Updates the property map for the given resource with the given property data.protected void
internalCleanup
(CmsDbContext dbc, I_CmsHistoryResource resource) Deletes all historical entries of subresources of a folder without any historical netry left.protected int
internalCountProperties
(CmsDbContext dbc, CmsPropertyDefinition metadef, CmsUUID projectId) Returns the amount of properties for a propertydefinition.protected CmsHistoryProject
internalCreateProject
(ResultSet res, List<String> resources) Creates a historical project from the given result set and resources.protected I_CmsHistoryResource
Creates a validI_CmsHistoryResource
instance from a JDBC ResultSet.protected I_CmsHistoryResource
internalMergeResource
(I_CmsHistoryResource histRes, ResultSet res, int versionOffset) Merges an historical entry for a sibling, based on the structure data from the given historical resource and result set for the resource entry.protected boolean
internalValidateResource
(CmsDbContext dbc, CmsResource resource, int publishTag) Tests if a history resource does exist.readAllAvailableVersions
(CmsDbContext dbc, CmsUUID structureId) Reads all file headers of the resource with the given structure id.byte[]
readContent
(CmsDbContext dbc, CmsUUID resourceId, int publishTag) Reads the content of the historical version of the resource identified by its structure id.readDeletedResources
(CmsDbContext dbc, CmsUUID structureId, CmsUUID userId) Reads all deleted (historical) resources below the given path, that the given user deleted by itself.int
readLastVersion
(CmsDbContext dbc, CmsUUID structureId) Returns the last historical version of a resource.int
readMaxPublishTag
(CmsDbContext dbc, CmsUUID resourceId) Reads the maximal publish tag for a specified resource id.int
Returns the next available history publish tag.readPrincipal
(CmsDbContext dbc, CmsUUID principalId) Reads an historical principal entry.readProject
(CmsDbContext dbc, int publishTag) Reads an historical project version.readProject
(CmsDbContext dbc, CmsUUID projectId) Reads the latest historical project version with the given id.readProjectResources
(CmsDbContext dbc, int publishTag) Reads all resources that belong to the historical project identified by the given publish tag.readProjects
(CmsDbContext dbc) Returns all projects from the history.readProperties
(CmsDbContext dbc, I_CmsHistoryResource resource) Returns a list of all properties of a historical file or folder.readPropertyDefinition
(CmsDbContext dbc, String name) Reads a property definition with the given name.int
readPublishTag
(CmsDbContext dbc, long maxdate) Gets the publish tag of the first historical project after a given date.readResource
(CmsDbContext dbc, CmsUUID structureId, int version) Reads a historical resource version without including the file content.void
setDriverManager
(CmsDriverManager driverManager) Sets the driver manager for this driver if possible.void
setSqlManager
(CmsSqlManager sqlManager) Sets the SQL manager for this driver if possible.void
writePrincipal
(CmsDbContext dbc, I_CmsPrincipal principal) Writes an historical entry for the given principal.void
writeProject
(CmsDbContext dbc, int publishTag, long publishDate) Creates an historical entry for the current project.void
writeProperties
(CmsDbContext dbc, CmsResource resource, List<CmsProperty> properties, int publishTag) Writes the properties of a resource to the history.void
writeResource
(CmsDbContext dbc, CmsResource resource, List<CmsProperty> properties, int publishTag) Writes a resource to the history.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opencms.db.I_CmsDriver
toString
-
Field Details
-
m_driverManager
The driver manager instance. -
m_sqlManager
The SQL manager instance.
-
-
Constructor Details
-
CmsHistoryDriver
public CmsHistoryDriver()
-
-
Method Details
-
createPropertyDefinition
public CmsPropertyDefinition createPropertyDefinition(CmsDbContext dbc, String name, CmsPropertyDefinition.CmsPropertyType type) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Creates a new property defintion in the database.- Specified by:
createPropertyDefinition
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextname
- the name of the property definitiontype
- the type of the property definition- Returns:
- the new property definition object
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
deleteEntries
public int deleteEntries(CmsDbContext dbc, I_CmsHistoryResource resource, int versionsToKeep, long time) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Deletes all historical versions of a resource keeping maximalversionsToKeep
versions.- Specified by:
deleteEntries
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresource
- the historical resource to delete versions forversionsToKeep
- the number of versions to keeptime
- deleted resources older than this will also be deleted, is ignored if negative- Returns:
- the number of versions that were deleted
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
deletePropertyDefinition
public void deletePropertyDefinition(CmsDbContext dbc, CmsPropertyDefinition metadef) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Deletes a property definition.- Specified by:
deletePropertyDefinition
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextmetadef
- the property definition to be deleted- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
destroy
Description copied from interface:I_CmsHistoryDriver
Destroys this driver.- Specified by:
destroy
in interfaceI_CmsHistoryDriver
- Throws:
Throwable
- if something goes wrong- See Also:
-
getAllDeletedEntries
public List<I_CmsHistoryResource> getAllDeletedEntries(CmsDbContext dbc) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Returns all historical resources (of deleted resources).- Specified by:
getAllDeletedEntries
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database context- Returns:
- a list of
I_CmsHistoryResource
objects - Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
getAllNotDeletedEntries
public List<I_CmsHistoryResource> getAllNotDeletedEntries(CmsDbContext dbc) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Returns all historical resources (of not deleted resources).- Specified by:
getAllNotDeletedEntries
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database context- Returns:
- a list of
I_CmsHistoryResource
objects - Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
getSqlManager
Description copied from interface:I_CmsHistoryDriver
Returns the SqlManager of this driver.- Specified by:
getSqlManager
in interfaceI_CmsHistoryDriver
- Returns:
- the SqlManager of this driver
- See Also:
-
init
public void init(CmsDbContext dbc, CmsConfigurationManager configurationManager, List<String> successiveDrivers, CmsDriverManager driverManager) Description copied from interface:I_CmsDriver
Initializes the driver.- Specified by:
init
in interfaceI_CmsDriver
- Parameters:
dbc
- the current database contextconfigurationManager
- the configuration managersuccessiveDrivers
- a list of successive drivers to be initializeddriverManager
- the initialized OpenCms driver manager- See Also:
-
initSqlManager
Description copied from interface:I_CmsHistoryDriver
Initializes the SQL manager for this driver.- Specified by:
initSqlManager
in interfaceI_CmsHistoryDriver
- Parameters:
classname
- the classname of the SQL manager- Returns:
- the SQL manager for this driver
- See Also:
-
readAllAvailableVersions
public List<I_CmsHistoryResource> readAllAvailableVersions(CmsDbContext dbc, CmsUUID structureId) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads all file headers of the resource with the given structure id.This method returns a list with the history of the resource, i.e. the historical resources, independent of the project they were attached to.
The reading excludes the file content.- Specified by:
readAllAvailableVersions
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextstructureId
- the structure id- Returns:
- a list of historical resources, as
objectsI_CmsHistoryResource
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readContent
public byte[] readContent(CmsDbContext dbc, CmsUUID resourceId, int publishTag) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads the content of the historical version of the resource identified by its structure id.- Specified by:
readContent
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresourceId
- the resource id of the resource to read the content forpublishTag
- the publish tag of the version- Returns:
- the content if found
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readDeletedResources
public List<I_CmsHistoryResource> readDeletedResources(CmsDbContext dbc, CmsUUID structureId, CmsUUID userId) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads all deleted (historical) resources below the given path, that the given user deleted by itself.- Specified by:
readDeletedResources
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current db contextstructureId
- the structure id of the parent resource to read the deleted resources fromuserId
- the id of the user that deleted the resources, ornull
to retrieve them all- Returns:
- a list of
objectsI_CmsHistoryResource
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readLastVersion
Description copied from interface:I_CmsHistoryDriver
Returns the last historical version of a resource.- Specified by:
readLastVersion
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextstructureId
- the structure ID of the resource- Returns:
- the last historical version of a resource
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readMaxPublishTag
Description copied from interface:I_CmsHistoryDriver
Reads the maximal publish tag for a specified resource id.- Specified by:
readMaxPublishTag
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresourceId
- the id of the resource the get the publish tag for- Returns:
- the maximal publish tag for the given resource
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readNextPublishTag
Description copied from interface:I_CmsHistoryDriver
Returns the next available history publish tag.- Specified by:
readNextPublishTag
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database context- Returns:
- the next available history publish tag
- See Also:
-
readPrincipal
public CmsHistoryPrincipal readPrincipal(CmsDbContext dbc, CmsUUID principalId) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads an historical principal entry.- Specified by:
readPrincipal
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextprincipalId
- the id of the principal to retrieve- Returns:
- the historical principal entry
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readProject
public CmsHistoryProject readProject(CmsDbContext dbc, CmsUUID projectId) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads the latest historical project version with the given id.- Specified by:
readProject
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextprojectId
- the project id- Returns:
- the requested historical project
- Throws:
CmsDataAccessException
- is something goes wrong- See Also:
-
readProject
public CmsHistoryProject readProject(CmsDbContext dbc, int publishTag) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads an historical project version.- Specified by:
readProject
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextpublishTag
- the publish tag- Returns:
- the requested historical project
- Throws:
CmsDataAccessException
- is something goes wrong- See Also:
-
readProjectResources
public List<String> readProjectResources(CmsDbContext dbc, int publishTag) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads all resources that belong to the historical project identified by the given publish tag.- Specified by:
readProjectResources
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextpublishTag
- the publish tag- Returns:
- all resources that belong to the historical project identified by the given publish tag
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readProjects
Description copied from interface:I_CmsHistoryDriver
Returns all projects from the history.- Specified by:
readProjects
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database context- Returns:
- list of
objects with all projects from history.CmsHistoryProject
- Throws:
CmsDataAccessException
- if an error occurs- See Also:
-
readProperties
public List<CmsProperty> readProperties(CmsDbContext dbc, I_CmsHistoryResource resource) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Returns a list of all properties of a historical file or folder.- Specified by:
readProperties
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresource
- the resource to read the properties from- Returns:
- a list of
CmsProperty
objects - Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readPropertyDefinition
public CmsPropertyDefinition readPropertyDefinition(CmsDbContext dbc, String name) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads a property definition with the given name.- Specified by:
readPropertyDefinition
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextname
- the name of the property definition to read- Returns:
- the property definition that corresponds to the given arguments - or
null
if not found - Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readPublishTag
Description copied from interface:I_CmsHistoryDriver
Gets the publish tag of the first historical project after a given date.This method is used during the deletion process of older historical data.
- Specified by:
readPublishTag
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextmaxdate
- the date to compare the historical projects with- Returns:
- publish tag of the first historical project after maxdate
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
readResource
public I_CmsHistoryResource readResource(CmsDbContext dbc, CmsUUID structureId, int version) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Reads a historical resource version without including the file content.- Specified by:
readResource
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextstructureId
- the structure id of the resource to readversion
- the desired version number- Returns:
- the historical resource version
- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
setDriverManager
Description copied from interface:I_CmsHistoryDriver
Sets the driver manager for this driver if possible.- Specified by:
setDriverManager
in interfaceI_CmsHistoryDriver
- Parameters:
driverManager
- the new driver manager- See Also:
-
setSqlManager
Description copied from interface:I_CmsHistoryDriver
Sets the SQL manager for this driver if possible.- Specified by:
setSqlManager
in interfaceI_CmsHistoryDriver
- Parameters:
sqlManager
- the new SQL manager- See Also:
-
writePrincipal
public void writePrincipal(CmsDbContext dbc, I_CmsPrincipal principal) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Writes an historical entry for the given principal.- Specified by:
writePrincipal
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextprincipal
- the principal to write- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
writeProject
public void writeProject(CmsDbContext dbc, int publishTag, long publishDate) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Creates an historical entry for the current project.- Specified by:
writeProject
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextpublishTag
- the publish tagpublishDate
- long timestamp when the current project was published- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
writeProperties
public void writeProperties(CmsDbContext dbc, CmsResource resource, List<CmsProperty> properties, int publishTag) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Writes the properties of a resource to the history.- Specified by:
writeProperties
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresource
- the resource of the propertiesproperties
- the properties to writepublishTag
- the publish tag- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
writeResource
public void writeResource(CmsDbContext dbc, CmsResource resource, List<CmsProperty> properties, int publishTag) throws CmsDataAccessException Description copied from interface:I_CmsHistoryDriver
Writes a resource to the history.- Specified by:
writeResource
in interfaceI_CmsHistoryDriver
- Parameters:
dbc
- the current database contextresource
- the resource that is written to the historyproperties
- the properties of the resourcepublishTag
- the publish tag- Throws:
CmsDataAccessException
- if something goes wrong- See Also:
-
internalAddToPropMap
protected void internalAddToPropMap(Map<String, CmsProperty> propertyMap, I_CmsHistoryResource resource, String propertyKey, String propertyValue, int mappingType) throws CmsDbConsistencyExceptionUpdates the property map for the given resource with the given property data.- Parameters:
propertyMap
- the map to updateresource
- the resource the properties belong topropertyKey
- the property keypropertyValue
- the property valuemappingType
- the mapping type- Throws:
CmsDbConsistencyException
- if the mapping type is wrong
-
internalCleanup
protected void internalCleanup(CmsDbContext dbc, I_CmsHistoryResource resource) throws CmsDataAccessException Deletes all historical entries of subresources of a folder without any historical netry left.- Parameters:
dbc
- the current database contextresource
- the resource to check- Throws:
CmsDataAccessException
- if something goes wrong
-
internalCountProperties
protected int internalCountProperties(CmsDbContext dbc, CmsPropertyDefinition metadef, CmsUUID projectId) throws CmsDataAccessException Returns the amount of properties for a propertydefinition.- Parameters:
dbc
- the current database contextmetadef
- the propertydefinition to testprojectId
- the ID of the current project- Returns:
- the amount of properties for a propertydefinition
- Throws:
CmsDataAccessException
- if something goes wrong
-
internalCreateProject
protected CmsHistoryProject internalCreateProject(ResultSet res, List<String> resources) throws SQLException Creates a historical project from the given result set and resources.- Parameters:
res
- the resource setresources
- the historical resources- Returns:
- the historical project
- Throws:
SQLException
- if something goes wrong
-
internalCreateResource
Creates a validI_CmsHistoryResource
instance from a JDBC ResultSet.- Parameters:
res
- the JDBC result set- Returns:
- the new historical resource instance
- Throws:
SQLException
- if a requested attribute was not found in the result set
-
internalMergeResource
protected I_CmsHistoryResource internalMergeResource(I_CmsHistoryResource histRes, ResultSet res, int versionOffset) throws SQLException Merges an historical entry for a sibling, based on the structure data from the given historical resource and result set for the resource entry.- Parameters:
histRes
- the original historical entryres
- the result set of the resource entryversionOffset
- the offset for the structure version- Returns:
- a merged historical entry for the sibling
- Throws:
SQLException
- if something goes wrong
-
internalValidateResource
protected boolean internalValidateResource(CmsDbContext dbc, CmsResource resource, int publishTag) throws CmsDataAccessException Tests if a history resource does exist.- Parameters:
dbc
- the current database contextresource
- the resource to testpublishTag
- the publish tag of the resource to test- Returns:
true
if the resource already exists,false
otherwise- Throws:
CmsDataAccessException
- if something goes wrong
-