org.opencms.db.generic
Class CmsBackupDriver

java.lang.Object
  extended byorg.opencms.db.generic.CmsBackupDriver
All Implemented Interfaces:
I_CmsBackupDriver, I_CmsDriver
Direct Known Subclasses:
CmsBackupDriver, CmsBackupDriver, CmsBackupDriver, CmsBackupDriver, CmsBackupDriver

public class CmsBackupDriver
extends java.lang.Object
implements I_CmsDriver, I_CmsBackupDriver

Generic (ANSI-SQL) database server implementation of the backup driver methods.

Since:
6.0.0
Version:
$Revision: 1.141 $
Author:
Thomas Weckert, Michael Emmerich, Carsten Weinholz

Field Summary
protected  CmsDriverManager m_driverManager
          The driver manager instance.
protected  CmsSqlManager m_sqlManager
          The SQL manager instance.
 
Fields inherited from interface org.opencms.db.I_CmsBackupDriver
DRIVER_TYPE_ID
 
Constructor Summary
CmsBackupDriver()
           
 
Method Summary
 CmsPropertyDefinition createBackupPropertyDefinition(CmsDbContext dbc, java.lang.String name)
          Creates a new property defintion in the database.
 CmsBackupResource createBackupResource(java.sql.ResultSet res, boolean hasContent)
          Creates a valid CmsBackupResource instance from a JDBC ResultSet.
 void deleteBackup(CmsDbContext dbc, CmsBackupResource resource, int tag, int versions)
          Deletes all backup versions of a backup resource that are older than a given project tag and where the version id is lower than a given value.
 void deleteBackupPropertyDefinition(CmsDbContext dbc, CmsPropertyDefinition metadef)
          Deletes a property defintion.
 void deleteBackups(CmsDbContext dbc, java.util.List existingBackups, int maxVersions)
          Deletes backup versions of a resource.
 void destroy()
          Destroys this driver.
protected  void finalize()
          Releases any allocated resources during garbage collection.
 CmsSqlManager getSqlManager()
          Returns the SqlManager of this driver.
 void init(CmsDbContext dbc, CmsConfigurationManager configurationManager, java.util.List successiveDrivers, CmsDriverManager driverManager)
          Initializes the driver.
 CmsSqlManager initSqlManager(java.lang.String classname)
          Initializes the SQL manager for this driver.
protected  int internalCountProperties(CmsDbContext dbc, CmsPropertyDefinition metadef, int projectId)
          Returns the amount of properties for a propertydefinition.
protected  void internalWriteBackupFileContent(CmsDbContext dbc, CmsUUID backupId, CmsResource resource, int tagId, int versionId)
          Internal method to write the backup content.
 CmsBackupResource readBackupFile(CmsDbContext dbc, int tagId, java.lang.String resourcePath)
          Reads a backup file including the file content.
 java.util.List readBackupFileHeaders(CmsDbContext dbc)
          Reads all backup file headers excluding the file content.
 java.util.List readBackupFileHeaders(CmsDbContext dbc, java.lang.String resourcePath, CmsUUID id)
          Reads all file headers of a file.
 int readBackupMaxVersion(CmsDbContext dbc, CmsUUID resourceId)
          Returns the max. current backup version of a resource.
 CmsBackupProject readBackupProject(CmsDbContext dbc, int tagId)
          Reads a backup project.
 java.util.List readBackupProjectResources(CmsDbContext dbc, int tagId)
          Reads all resources that belong to a given backup version ID.
 java.util.List readBackupProjects(CmsDbContext dbc)
          Returns all projects from the history.
 int readBackupProjectTag(CmsDbContext dbc, long maxdate)
          Gets the TagId of the first backup project after a given date.
 java.util.List readBackupProperties(CmsDbContext dbc, CmsBackupResource resource)
          Returns a list of all properties of a backup file or folder.
 CmsPropertyDefinition readBackupPropertyDefinition(CmsDbContext dbc, java.lang.String name)
          Reads a property definition for the specified mapping type.
 int readMaxTagId(CmsDbContext dbc, CmsResource resource)
          Reads the max. backup tag ID for a specified resource.
 int readNextBackupTagId(CmsDbContext dbc)
          Returns the next available backup version ID for a resource.
 void writeBackupProject(CmsDbContext dbc, int tagId, long publishDate)
          Creates a backup of the current project.
 void writeBackupProperties(CmsDbContext dbc, CmsResource resource, java.util.List properties, CmsUUID backupId, int tagId, int versionId)
          Writes the properties of a resource to the backup.
 void writeBackupResource(CmsDbContext dbc, CmsResource resource, java.util.List properties, int tagId, long publishDate, int maxVersions)
          Writes a resource to the backup.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opencms.db.I_CmsDriver
toString
 

Field Detail

m_driverManager

protected CmsDriverManager m_driverManager
The driver manager instance.


m_sqlManager

protected CmsSqlManager m_sqlManager
The SQL manager instance.

Constructor Detail

CmsBackupDriver

public CmsBackupDriver()
Method Detail

createBackupPropertyDefinition

public CmsPropertyDefinition createBackupPropertyDefinition(CmsDbContext dbc,
                                                            java.lang.String name)
                                                     throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Creates a new property defintion in the database.

Specified by:
createBackupPropertyDefinition in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
name - the name of the propertydefinitions to overwrite
Returns:
the new propertydefinition
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.createBackupPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String)

createBackupResource

public CmsBackupResource createBackupResource(java.sql.ResultSet res,
                                              boolean hasContent)
                                       throws java.sql.SQLException
Description copied from interface: I_CmsBackupDriver
Creates a valid CmsBackupResource instance from a JDBC ResultSet.

Specified by:
createBackupResource in interface I_CmsBackupDriver
Parameters:
res - the JDBC result set
hasContent - true if the file content is part of the result set
Returns:
CmsBackupResource the new resource/file instance
Throws:
java.sql.SQLException - if a requested attribute was not found in the result set
See Also:
I_CmsBackupDriver.createBackupResource(java.sql.ResultSet, boolean)

deleteBackup

public void deleteBackup(CmsDbContext dbc,
                         CmsBackupResource resource,
                         int tag,
                         int versions)
                  throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Deletes all backup versions of a backup resource that are older than a given project tag and where the version id is lower than a given value.

Specified by:
deleteBackup in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resource - the backup resource
tag - the project tag date
versions - the deletion version
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.deleteBackup(org.opencms.db.CmsDbContext, org.opencms.file.CmsBackupResource, int, int)

deleteBackupPropertyDefinition

public void deleteBackupPropertyDefinition(CmsDbContext dbc,
                                           CmsPropertyDefinition metadef)
                                    throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Deletes a property defintion.

Specified by:
deleteBackupPropertyDefinition in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
metadef - the propertydefinitions to be deleted
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.deleteBackupPropertyDefinition(org.opencms.db.CmsDbContext, org.opencms.file.CmsPropertyDefinition)

deleteBackups

public void deleteBackups(CmsDbContext dbc,
                          java.util.List existingBackups,
                          int maxVersions)
                   throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Deletes backup versions of a resource.

Deletes the m-n oldest backup versions, if m is the number of backup versions, and n the number of max. allowed backup versions.

Specified by:
deleteBackups in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
existingBackups - a list of backup resources ordered by their ascending creation date
maxVersions - maximum number of versions per resource
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.deleteBackups(org.opencms.db.CmsDbContext, java.util.List, int)

destroy

public void destroy()
             throws java.lang.Throwable
Description copied from interface: I_CmsBackupDriver
Destroys this driver.

Specified by:
destroy in interface I_CmsBackupDriver
Throws:
java.lang.Throwable - if something goes wrong
See Also:
I_CmsBackupDriver.destroy()

getSqlManager

public CmsSqlManager getSqlManager()
Description copied from interface: I_CmsBackupDriver
Returns the SqlManager of this driver.

Specified by:
getSqlManager in interface I_CmsBackupDriver
Returns:
the SqlManager of this driver
See Also:
I_CmsBackupDriver.getSqlManager()

init

public void init(CmsDbContext dbc,
                 CmsConfigurationManager configurationManager,
                 java.util.List successiveDrivers,
                 CmsDriverManager driverManager)
Description copied from interface: I_CmsDriver
Initializes the driver.

Specified by:
init in interface I_CmsDriver
Parameters:
dbc - the current database context
configurationManager - the configuration manager
successiveDrivers - a list of successive drivers to be initialized
driverManager - the initialized OpenCms driver manager
See Also:
I_CmsDriver.init(org.opencms.db.CmsDbContext, org.opencms.configuration.CmsConfigurationManager, java.util.List, org.opencms.db.CmsDriverManager)

initSqlManager

public CmsSqlManager initSqlManager(java.lang.String classname)
Description copied from interface: I_CmsBackupDriver
Initializes the SQL manager for this driver.

Specified by:
initSqlManager in interface I_CmsBackupDriver
Parameters:
classname - the classname of the SQL manager
Returns:
the SQL manager for this driver
See Also:
I_CmsBackupDriver.initSqlManager(String)

readBackupFile

public CmsBackupResource readBackupFile(CmsDbContext dbc,
                                        int tagId,
                                        java.lang.String resourcePath)
                                 throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads a backup file including the file content.

Specified by:
readBackupFile in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
tagId - the desired tag ID of the file
resourcePath - the path of the file to read
Returns:
the backup file
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupFile(CmsDbContext, int, String)

readBackupFileHeaders

public java.util.List readBackupFileHeaders(CmsDbContext dbc)
                                     throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads all backup file headers excluding the file content.

.

Specified by:
readBackupFileHeaders in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
Returns:
List with all backup file headers
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupFileHeaders(org.opencms.db.CmsDbContext)

readBackupFileHeaders

public java.util.List readBackupFileHeaders(CmsDbContext dbc,
                                            java.lang.String resourcePath,
                                            CmsUUID id)
                                     throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads all file headers of a file.
This method returns a list with the history of all file headers, i.e. the file headers of a file, independent of the project they were attached to.
The reading excludes the file content.

The filter is (path OR id).

Specified by:
readBackupFileHeaders in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resourcePath - the path of the file to read
id - the resource id (usefull for siblings)
Returns:
a list of file headers, as CmsBackupResource objects, read from the Cms
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupFileHeaders(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.util.CmsUUID)

readBackupMaxVersion

public int readBackupMaxVersion(CmsDbContext dbc,
                                CmsUUID resourceId)
                         throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Returns the max. current backup version of a resource.

Specified by:
readBackupMaxVersion in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resourceId - the resource ID of the resource
Returns:
Returns the max. current backup version of a resource
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupMaxVersion(org.opencms.db.CmsDbContext, org.opencms.util.CmsUUID)

readBackupProject

public CmsBackupProject readBackupProject(CmsDbContext dbc,
                                          int tagId)
                                   throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads a backup project.

Specified by:
readBackupProject in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
tagId - the versionId of the project
Returns:
the requested backup project
Throws:
CmsDataAccessException - is something goes wrong
See Also:
I_CmsBackupDriver.readBackupProject(org.opencms.db.CmsDbContext, int)

readBackupProjectResources

public java.util.List readBackupProjectResources(CmsDbContext dbc,
                                                 int tagId)
                                          throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads all resources that belong to a given backup version ID.

Specified by:
readBackupProjectResources in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
tagId - the version ID of the backup
Returns:
all resources that belong to the given backup version ID
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupProjectResources(org.opencms.db.CmsDbContext, int)

readBackupProjects

public java.util.List readBackupProjects(CmsDbContext dbc)
                                  throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Returns all projects from the history.

Specified by:
readBackupProjects in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
Returns:
list of CmsBackupProject objects with all projects from history.
Throws:
CmsDataAccessException - if an error occurs
See Also:
I_CmsBackupDriver.readBackupProjects(org.opencms.db.CmsDbContext)

readBackupProjectTag

public int readBackupProjectTag(CmsDbContext dbc,
                                long maxdate)
                         throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Gets the TagId of the first backup project after a given date.

This method is used during the deletion process of older backup data.

Specified by:
readBackupProjectTag in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
maxdate - the date to compare the backup projects with
Returns:
tag id of the first backup project after maxdate
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupProjectTag(org.opencms.db.CmsDbContext, long)

readBackupProperties

public java.util.List readBackupProperties(CmsDbContext dbc,
                                           CmsBackupResource resource)
                                    throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Returns a list of all properties of a backup file or folder.

Specified by:
readBackupProperties in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resource - the resource to read the properties from
Returns:
a Map of Strings representing the properties of the resource
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupProperties(org.opencms.db.CmsDbContext, org.opencms.file.CmsBackupResource)

readBackupPropertyDefinition

public CmsPropertyDefinition readBackupPropertyDefinition(CmsDbContext dbc,
                                                          java.lang.String name)
                                                   throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads a property definition for the specified mapping type.

Specified by:
readBackupPropertyDefinition in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
name - the name of the propertydefinition to read
Returns:
the propertydefinition that corresponds to the overgiven arguments - or null if there is no valid propertydefinition
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readBackupPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String)

readMaxTagId

public int readMaxTagId(CmsDbContext dbc,
                        CmsResource resource)
                 throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Reads the max. backup tag ID for a specified resource.

Specified by:
readMaxTagId in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resource - the Cms resource
Returns:
the max. backup tag ID
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.readMaxTagId(org.opencms.db.CmsDbContext, org.opencms.file.CmsResource)

readNextBackupTagId

public int readNextBackupTagId(CmsDbContext dbc)
Description copied from interface: I_CmsBackupDriver
Returns the next available backup version ID for a resource.

Specified by:
readNextBackupTagId in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
Returns:
the next available backup version ID
See Also:
I_CmsBackupDriver.readNextBackupTagId(org.opencms.db.CmsDbContext)

writeBackupProject

public void writeBackupProject(CmsDbContext dbc,
                               int tagId,
                               long publishDate)
                        throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Creates a backup of the current project.

Specified by:
writeBackupProject in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
tagId - the version ID of the backup
publishDate - long timestamp when the current project was published.
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.writeBackupProject(org.opencms.db.CmsDbContext, int, long)

writeBackupProperties

public void writeBackupProperties(CmsDbContext dbc,
                                  CmsResource resource,
                                  java.util.List properties,
                                  CmsUUID backupId,
                                  int tagId,
                                  int versionId)
                           throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Writes the properties of a resource to the backup.

Specified by:
writeBackupProperties in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resource - the resource of the properties
properties - the properties to write
backupId - the id backup
tagId - the tag ID of the backup
versionId - the version ID of the backup
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.writeBackupProperties(org.opencms.db.CmsDbContext, org.opencms.file.CmsResource, java.util.List, org.opencms.util.CmsUUID, int, int)

writeBackupResource

public void writeBackupResource(CmsDbContext dbc,
                                CmsResource resource,
                                java.util.List properties,
                                int tagId,
                                long publishDate,
                                int maxVersions)
                         throws CmsDataAccessException
Description copied from interface: I_CmsBackupDriver
Writes a resource to the backup.

Specified by:
writeBackupResource in interface I_CmsBackupDriver
Parameters:
dbc - the current database context
resource - the resource that is written to the backup
properties - the properties of the resource
tagId - the version ID of the backup
publishDate - long timestamp when the resource was published
maxVersions - maximum number of backup versions
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsBackupDriver.writeBackupResource(org.opencms.db.CmsDbContext, org.opencms.file.CmsResource, java.util.List, int, long, int)

finalize

protected void finalize()
                 throws java.lang.Throwable
Releases any allocated resources during garbage collection.

Throws:
java.lang.Throwable
See Also:
Object.finalize()

internalCountProperties

protected int internalCountProperties(CmsDbContext dbc,
                                      CmsPropertyDefinition metadef,
                                      int projectId)
                               throws CmsDataAccessException
Returns the amount of properties for a propertydefinition.

Parameters:
dbc - the current database context
metadef - the propertydefinition to test
projectId - the ID of the current project
Returns:
the amount of properties for a propertydefinition
Throws:
CmsDataAccessException - if something goes wrong

internalWriteBackupFileContent

protected void internalWriteBackupFileContent(CmsDbContext dbc,
                                              CmsUUID backupId,
                                              CmsResource resource,
                                              int tagId,
                                              int versionId)
                                       throws CmsDataAccessException
Internal method to write the backup content.

Parameters:
dbc - the current database context
backupId - the backup id
resource - the resource to backup
tagId - the tag revision
versionId - the version revision
Throws:
CmsDataAccessException - if something goes wrong