Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.db.jpa;
import org.opencms.configuration.CmsConfigurationManager;
import org.opencms.configuration.CmsParameterConfiguration;
import org.opencms.db.CmsDbConsistencyException;
import org.opencms.db.CmsDbContext;
import org.opencms.db.CmsDbEntryNotFoundException;
import org.opencms.db.CmsDbSqlException;
import org.opencms.db.CmsDriverManager;
import org.opencms.db.CmsResourceState;
import org.opencms.db.I_CmsDriver;
import org.opencms.db.I_CmsHistoryDriver;
import org.opencms.db.I_CmsVfsDriver;
import org.opencms.db.generic.Messages;
import org.opencms.db.jpa.persistence.CmsDAOContents;
import org.opencms.db.jpa.persistence.CmsDAOHistoryPrincipals;
import org.opencms.db.jpa.persistence.CmsDAOHistoryProjectResources;
import org.opencms.db.jpa.persistence.CmsDAOHistoryProjects;
import org.opencms.db.jpa.persistence.CmsDAOHistoryProperties;
import org.opencms.db.jpa.persistence.CmsDAOHistoryPropertyDef;
import org.opencms.db.jpa.persistence.CmsDAOHistoryResources;
import org.opencms.db.jpa.persistence.CmsDAOHistoryStructure;
import org.opencms.file.CmsDataAccessException;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsPropertyDefinition.CmsPropertyType;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.file.CmsVfsResourceNotFoundException;
import org.opencms.file.history.CmsHistoryFile;
import org.opencms.file.history.CmsHistoryFolder;
import org.opencms.file.history.CmsHistoryPrincipal;
import org.opencms.file.history.CmsHistoryProject;
import org.opencms.file.history.I_CmsHistoryResource;
import org.opencms.main.CmsLog;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.util.CmsDataTypeUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.apache.commons.logging.Log;
/**
* JPA database server implementation of the history driver methods.
*
* @since 8.0.0
*/
public class CmsHistoryDriver implements I_CmsDriver, I_CmsHistoryDriver {
/** Query key. */
private static final String C_CONTENT_HISTORY_DELETE = "C_CONTENT_HISTORY_DELETE";
/** Query key. */
private static final String C_CONTENT_PUBLISH_MAXTAG = "C_CONTENT_PUBLISH_MAXTAG";
/** Query key. */
private static final String C_FILES_READ_HISTORY_BYID = "C_FILES_READ_HISTORY_BYID";
/** Query key. */
private static final String C_HISTORY_EXISTS_RESOURCE = "C_HISTORY_EXISTS_RESOURCE";
/** Query key. */
private static final String C_HISTORY_PRINCIPAL_READ = "C_HISTORY_PRINCIPAL_READ";
/** Query key. */
private static final String C_HISTORY_READ_CONTENT = "C_HISTORY_READ_CONTENT";
/** Query key. */
private static final String C_HISTORY_READ_MAXTAG_FOR_VERSION = "C_HISTORY_READ_MAXTAG_FOR_VERSION";
/** Query key. */
private static final String C_HISTORY_READ_MIN_USED_TAG = "C_HISTORY_READ_MIN_USED_TAG";
/** Query key. */
private static final String C_PROJECTRESOURCES_HISTORY_READ = "C_PROJECTRESOURCES_HISTORY_READ";
/** Query key. */
private static final String C_PROJECTS_HISTORY_MAXTAG = "C_PROJECTS_HISTORY_MAXTAG";
/** Query key. */
private static final String C_PROJECTS_HISTORY_READ = "C_PROJECTS_HISTORY_READ";
/** Query key. */
private static final String C_PROJECTS_HISTORY_READ_ALL = "C_PROJECTS_HISTORY_READ_ALL";
/** Query key. */
private static final String C_PROJECTS_HISTORY_READ_BYID = "C_PROJECTS_HISTORY_READ_BYID";
/** Query key. */
private static final String C_PROJECTS_HISTORY_READ_TAG_FOR_DATE = "C_PROJECTS_HISTORY_READ_TAG_FOR_DATE";
/** Query key. */
private static final String C_PROPERTIES_HISTORY_DELETE = "C_PROPERTIES_HISTORY_DELETE";
/** Query key. */
private static final String C_PROPERTIES_HISTORY_READ_PUBTAG = "C_PROPERTIES_HISTORY_READ_PUBTAG";
/** Query key. */
private static final String C_PROPERTIES_HISTORY_READALL_RES = "C_PROPERTIES_HISTORY_READALL_RES";
/** Query key. */
private static final String C_PROPERTIES_HISTORY_READALL_STR = "C_PROPERTIES_HISTORY_READALL_STR";
/** Query key. */
private static final String C_PROPERTIES_READALL_COUNT = "C_PROPERTIES_READALL_COUNT";
/** Query key. */
private static final String C_PROPERTYDEF_DELETE_HISTORY = "C_PROPERTYDEF_DELETE_HISTORY";
/** Query key. */
private static final String C_PROPERTYDEF_READ_HISTORY = "C_PROPERTYDEF_READ_HISTORY";
/** Query key. */
private static final String C_RESOURCES_HISTORY_DELETE = "C_RESOURCES_HISTORY_DELETE";
/** Query key. */
private static final String C_RESOURCES_HISTORY_MAXTAG = "C_RESOURCES_HISTORY_MAXTAG";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_ALL_VERSIONS = "C_RESOURCES_HISTORY_READ_ALL_VERSIONS";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_BTW_VERSIONS = "C_RESOURCES_HISTORY_READ_BTW_VERSIONS";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_DELETED = "C_RESOURCES_HISTORY_READ_DELETED";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_DELETED_NAME = "C_RESOURCES_HISTORY_READ_DELETED_NAME";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_DELETED_NAME_RESTRICTED = "C_RESOURCES_HISTORY_READ_DELETED_NAME_RESTRICTED";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_DELETED_RESTRICTED = "C_RESOURCES_HISTORY_READ_DELETED_RESTRICTED";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_NEW_VERSIONS = "C_RESOURCES_HISTORY_READ_NEW_VERSIONS";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_OLD_VERSIONS = "C_RESOURCES_HISTORY_READ_OLD_VERSIONS";
/** Query key. */
private static final String C_RESOURCES_HISTORY_READ_VERSION = "C_RESOURCES_HISTORY_READ_VERSION";
/** Query key. */
private static final String C_RESOURCES_READ_MAX_PUBLISH_TAG = "C_RESOURCES_READ_MAX_PUBLISH_TAG";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_DELETE = "C_STRUCTURE_HISTORY_DELETE";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_MAXVER = "C_STRUCTURE_HISTORY_MAXVER";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_MAXVER_BYTIME = "C_STRUCTURE_HISTORY_MAXVER_BYTIME";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_READ_DELETED = "C_STRUCTURE_HISTORY_READ_DELETED";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_READ_NOTDELETED = "C_STRUCTURE_HISTORY_READ_NOTDELETED";
/** Query key. */
private static final String C_STRUCTURE_HISTORY_READ_SUBRESOURCES = "C_STRUCTURE_HISTORY_READ_SUBRESOURCES";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(org.opencms.db.jpa.CmsHistoryDriver.class);
/** The driver manager instance. */
protected CmsDriverManager m_driverManager;
/** The SQL manager instance. */
protected CmsSqlManager m_sqlManager;
/**
* @see org.opencms.db.I_CmsHistoryDriver#createPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsPropertyDefinition.CmsPropertyType)
*/
public CmsPropertyDefinition createPropertyDefinition(CmsDbContext dbc, String name, CmsPropertyType type)
throws CmsDataAccessException {
try {
CmsDAOHistoryPropertyDef chpd = new CmsDAOHistoryPropertyDef();
chpd.setPropertyDefId(new CmsUUID().toString());
chpd.setPropertyDefName(name);
chpd.setPropertyDefType(type.getMode());
m_sqlManager.persist(dbc, chpd);
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1), e);
}
return readPropertyDefinition(dbc, name);
}
/**
* @see org.opencms.db.I_CmsHistoryDriver#deleteEntries(org.opencms.db.CmsDbContext, org.opencms.file.history.I_CmsHistoryResource, int, long)
*/
public int deleteEntries(CmsDbContext dbc, I_CmsHistoryResource resource, int versionsToKeep, long time)
throws CmsDataAccessException {
try {
int maxVersion = -1;
// get the maximal version number for this resource
Query q = m_sqlManager.createQuery(dbc, C_STRUCTURE_HISTORY_MAXVER);
q.setParameter(1, resource.getStructureId().toString());
try {
maxVersion = CmsDataTypeUtil.numberToInt((Number)q.getSingleResult());
} catch (NoResultException e) {
// nothing to delete
internalCleanup(dbc, resource);
return 0;
}
if (time >= 0) {
int maxVersionByTime = -1;
// get the maximal version to keep for this resource based on the time parameter
q = m_sqlManager.createQuery(dbc, C_STRUCTURE_HISTORY_MAXVER_BYTIME);
q.setParameter(1, resource.getStructureId().toString());
q.setParameter(2, Long.valueOf(time));
try {
maxVersionByTime = CmsDataTypeUtil.numberToInt((Number)q.getSingleResult());
} catch (NoResultException e) {
// do nothing
}
if (maxVersionByTime > 0) {
if (versionsToKeep < 0) {
versionsToKeep = (maxVersion - maxVersionByTime);
} else {
versionsToKeep = Math.min(versionsToKeep, (maxVersion - maxVersionByTime));
}
}
}
if ((maxVersion - versionsToKeep) <= 0) {
// nothing to delete
internalCleanup(dbc, resource);
return 0;
}
// get the minimal structure publish tag to keep for this sibling
int minStrPublishTagToKeep = -1;
q = m_sqlManager.createQuery(dbc, C_HISTORY_READ_MAXTAG_FOR_VERSION);
q.setParameter(1, resource.getStructureId().toString());
q.setParameter(2, Integer.valueOf((1 + maxVersion) - versionsToKeep));
try {
minStrPublishTagToKeep = CmsDataTypeUtil.numberToInt((Number)q.getSingleResult());
} catch (NoResultException e) {
// nothing to delete
internalCleanup(dbc, resource);
return 0;
}
if (minStrPublishTagToKeep < 1) {
// nothing to delete
internalCleanup(dbc, resource);
return 0;
}
minStrPublishTagToKeep++;
// delete the properties
q = m_sqlManager.createQuery(dbc, C_PROPERTIES_HISTORY_DELETE);
q.setParameter(1, resource.getStructureId().toString());
q.setParameter(2, Integer.valueOf(minStrPublishTagToKeep));
@SuppressWarnings("unchecked")
List hisProps = q.getResultList();
for (CmsDAOHistoryProperties hp : hisProps) {
m_sqlManager.remove(dbc, hp);
}
// delete the structure entries
q = m_sqlManager.createQuery(dbc, C_STRUCTURE_HISTORY_DELETE);
q.setParameter(1, resource.getStructureId().toString());
q.setParameter(2, Integer.valueOf(minStrPublishTagToKeep));
@SuppressWarnings("unchecked")
List structureEntries = q.getResultList();
int structureVersions = 0;
for (CmsDAOHistoryStructure hs : structureEntries) {
m_sqlManager.remove(dbc, hs);
structureVersions++;
}
// get the minimal resource publish tag to keep,
// all entries with publish tag less than this will be deleted
int minResPublishTagToKeep = -1;
q = m_sqlManager.createQuery(dbc, C_HISTORY_READ_MIN_USED_TAG);
q.setParameter(1, resource.getResourceId().toString());
try {
Object numObj = q.getSingleResult();
if (numObj == null) {
minResPublishTagToKeep = Integer.MAX_VALUE;
} else {
minResPublishTagToKeep = CmsDataTypeUtil.numberToInt((Number)numObj);
}
} catch (NoResultException e) {
internalCleanup(dbc, resource);
return structureVersions;
}
// delete the resource entries
q = m_sqlManager.createQuery(dbc, C_RESOURCES_HISTORY_DELETE);
q.setParameter(1, resource.getResourceId().toString());
q.setParameter(2, Integer.valueOf(minResPublishTagToKeep));
int resourceVersions = 0;
@SuppressWarnings("unchecked")
List resourceEntries = q.getResultList();
for (CmsDAOHistoryResources hr : resourceEntries) {
m_sqlManager.remove(dbc, hr);
resourceVersions++;
}
// delete the content entries
q = m_sqlManager.createQuery(dbc, C_CONTENT_HISTORY_DELETE);
q.setParameter(1, resource.getResourceId().toString());
q.setParameter(2, Integer.valueOf(minResPublishTagToKeep));
@SuppressWarnings("unchecked")
List contentEntries = q.getResultList();
for (CmsDAOContents c : contentEntries) {
m_sqlManager.remove(dbc, c);
}
internalCleanup(dbc, resource);
return Math.max(structureVersions, resourceVersions);
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1), e);
}
}
/**
* @see org.opencms.db.I_CmsHistoryDriver#deletePropertyDefinition(org.opencms.db.CmsDbContext, org.opencms.file.CmsPropertyDefinition)
*/
public void deletePropertyDefinition(CmsDbContext dbc, CmsPropertyDefinition metadef)
throws CmsDataAccessException {
try {
if ((internalCountProperties(dbc, metadef, CmsProject.ONLINE_PROJECT_ID) != 0)
|| (internalCountProperties(dbc, metadef, CmsUUID.getOpenCmsUUID()) != 0)) { // HACK: to get an offline project
throw new CmsDbConsistencyException(
Messages.get().container(Messages.ERR_ERROR_DELETING_PROPERTYDEF_1, metadef.getName()));
}
// delete the historical property definition
Query q = m_sqlManager.createQuery(dbc, C_PROPERTYDEF_DELETE_HISTORY);
q.setParameter(1, metadef.getId().toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (CmsDAOHistoryPropertyDef hpd : res) {
m_sqlManager.remove(dbc, hpd);
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(
Messages.get().container(Messages.ERR_GENERIC_SQL_1, Messages.ERR_JPA_PERSITENCE_1),
e);
}
}
/**
* @see org.opencms.db.I_CmsHistoryDriver#destroy()
*/
public void destroy() throws Throwable {
m_sqlManager = null;
m_driverManager = null;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_DRIVER_1, getClass().getName()));
}
}
/**
* @see org.opencms.db.I_CmsHistoryDriver#getAllDeletedEntries(org.opencms.db.CmsDbContext)
*/
public List getAllDeletedEntries(CmsDbContext dbc) throws CmsDataAccessException {
Query q = null;
List entries = new ArrayList();
try {
// get all not-deleted historical entries that may come in question
q = m_sqlManager.createQuery(dbc, C_STRUCTURE_HISTORY_READ_DELETED);
@SuppressWarnings("unchecked")
List