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.CmsAlias;
import org.opencms.db.CmsAliasFilter;
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.CmsRewriteAlias;
import org.opencms.db.CmsRewriteAliasFilter;
import org.opencms.db.CmsVfsOnlineResourceAlreadyExistsException;
import org.opencms.db.I_CmsDriver;
import org.opencms.db.I_CmsProjectDriver;
import org.opencms.db.I_CmsVfsDriver;
import org.opencms.db.generic.Messages;
import org.opencms.db.jpa.persistence.CmsDAOAlias;
import org.opencms.db.jpa.persistence.CmsDAOContents;
import org.opencms.db.jpa.persistence.CmsDAOCounters;
import org.opencms.db.jpa.persistence.CmsDAOOfflineContents;
import org.opencms.db.jpa.persistence.CmsDAOOfflineProperties;
import org.opencms.db.jpa.persistence.CmsDAOOfflinePropertyDef;
import org.opencms.db.jpa.persistence.CmsDAOOfflineResourceRelations;
import org.opencms.db.jpa.persistence.CmsDAOOfflineResources;
import org.opencms.db.jpa.persistence.CmsDAOOfflineStructure;
import org.opencms.db.jpa.persistence.CmsDAOOfflineUrlNameMappings;
import org.opencms.db.jpa.persistence.CmsDAOOnlineProperties;
import org.opencms.db.jpa.persistence.CmsDAOOnlinePropertyDef;
import org.opencms.db.jpa.persistence.CmsDAOOnlineResourceRelations;
import org.opencms.db.jpa.persistence.CmsDAOOnlineResources;
import org.opencms.db.jpa.persistence.CmsDAOOnlineStructure;
import org.opencms.db.jpa.persistence.CmsDAOOnlineUrlNameMappings;
import org.opencms.db.jpa.persistence.CmsDAORewriteAlias;
import org.opencms.db.jpa.persistence.I_CmsDAOProperties;
import org.opencms.db.jpa.persistence.I_CmsDAOPropertyDef;
import org.opencms.db.jpa.persistence.I_CmsDAOResourceRelations;
import org.opencms.db.jpa.persistence.I_CmsDAOResources;
import org.opencms.db.jpa.persistence.I_CmsDAOStructure;
import org.opencms.db.jpa.persistence.I_CmsDAOUrlNameMappings;
import org.opencms.db.jpa.utils.CmsQueryIntParameter;
import org.opencms.db.jpa.utils.CmsQueryStringParameter;
import org.opencms.db.jpa.utils.I_CmsQueryParameter;
import org.opencms.db.urlname.CmsUrlNameMappingEntry;
import org.opencms.db.urlname.CmsUrlNameMappingFilter;
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.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsVfsException;
import org.opencms.file.CmsVfsResourceAlreadyExistsException;
import org.opencms.file.CmsVfsResourceNotFoundException;
import org.opencms.file.I_CmsResource;
import org.opencms.file.history.I_CmsHistoryResource;
import org.opencms.file.types.CmsResourceTypeJsp;
import org.opencms.gwt.shared.alias.CmsAliasMode;
import org.opencms.main.CmsEvent;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.I_CmsEventListener;
import org.opencms.main.OpenCms;
import org.opencms.relations.CmsRelation;
import org.opencms.relations.CmsRelationFilter;
import org.opencms.relations.CmsRelationType;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.security.CmsPermissionSet;
import org.opencms.util.CmsDataTypeUtil;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsPair;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
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 vfs driver methods.
*
* @since 8.0.0
*/
public class CmsVfsDriver implements I_CmsDriver, I_CmsVfsDriver {
/** Internal presentation of empty binary content. */
public static final byte[] EMPTY_BLOB = new byte[0];
/** Query key. */
private static final String C_DELETE_RELATIONS = "C_DELETE_RELATIONS";
/** Query key. */
private static final String C_DELETE_URLNAME_MAPPINGS = "C_DELETE_URLNAME_MAPPINGS";
/** Query key. */
private static final String C_HISTORY_CONTENTS_UPDATE = "C_HISTORY_CONTENTS_UPDATE";
/** Query key. */
private static final String C_MOVE_RELATIONS_SOURCE = "C_MOVE_RELATIONS_SOURCE";
/** Query key. */
private static final String C_MOVE_RELATIONS_TARGET = "C_MOVE_RELATIONS_TARGET";
/** Query key. */
private static final String C_OFFLINE_CONTENTS_UPDATE = "C_OFFLINE_CONTENTS_UPDATE";
/** Query key. */
private static final String C_OFFLINE_FILE_CONTENT_DELETE = "C_OFFLINE_FILE_CONTENT_DELETE";
/** Query key. */
private static final String C_ONLINE_CONTENTS_DELETE = "C_ONLINE_CONTENTS_DELETE";
/** Query key. */
private static final String C_ONLINE_CONTENTS_HISTORY = "C_ONLINE_CONTENTS_HISTORY";
/** Query key. */
private static final String C_ONLINE_FILES_CONTENT = "C_ONLINE_FILES_CONTENT";
/** Query key. */
private static final String C_PROPERTIES_DELETE = "C_PROPERTIES_DELETE";
/** Query key. */
private static final String C_PROPERTIES_DELETE_ALL_STRUCTURE_AND_RESOURCE_VALUES = "C_PROPERTIES_DELETE_ALL_STRUCTURE_AND_RESOURCE_VALUES";
/** Query key. */
private static final String C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE = "C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE";
/** Query key. */
private static final String C_PROPERTIES_READ = "C_PROPERTIES_READ";
/** Query key. */
private static final String C_PROPERTIES_READALL = "C_PROPERTIES_READALL";
/** Query key. */
private static final String C_PROPERTIES_READALL_COUNT = "C_PROPERTIES_READALL_COUNT";
/** Query key. */
private static final String C_PROPERTIES_UPDATE = "C_PROPERTIES_UPDATE";
/** Query key. */
private static final String C_PROPERTYDEF_DELETE = "C_PROPERTYDEF_DELETE";
/** Query key. */
private static final String C_PROPERTYDEF_READ = "C_PROPERTYDEF_READ";
/** Query key. */
private static final String C_PROPERTYDEF_READALL = "C_PROPERTYDEF_READALL";
/** Query key. */
private static final String C_READ_RELATIONS = "C_READ_RELATIONS";
/** Query key. */
private static final String C_READ_RESOURCE_OUS = "C_READ_RESOURCE_OUS";
/** Query key. */
private static final String C_READ_RESOURCE_STATE = "C_READ_RESOURCE_STATE";
/** Query key. */
private static final String C_READ_STRUCTURE_STATE = "C_READ_STRUCTURE_STATE";
/** Query key. */
private static final String C_READ_URLNAME_MAPPINGS = "C_READ_URLNAME_MAPPINGS";
/** Query key. */
private static final String C_RELATION_FILTER_SOURCE_ID = "C_RELATION_FILTER_SOURCE_ID";
/** Query key. */
private static final String C_RELATION_FILTER_SOURCE_PATH = "C_RELATION_FILTER_SOURCE_PATH";
/** Query key. */
private static final String C_RELATION_FILTER_TARGET_ID = "C_RELATION_FILTER_TARGET_ID";
/** Query key. */
private static final String C_RELATION_FILTER_TARGET_PATH = "C_RELATION_FILTER_TARGET_PATH";
/** Query key. */
private static final String C_RELATION_FILTER_TYPE = "C_RELATION_FILTER_TYPE";
/** Query key. */
private static final String C_RELATIONS_REPAIR_BROKEN = "C_RELATIONS_REPAIR_BROKEN";
/** Query key. */
private static final String C_RELATIONS_UPDATE_BROKEN = "C_RELATIONS_UPDATE_BROKEN";
/** Query key. */
private static final String C_RESOURCE_REPLACE = "C_RESOURCE_REPLACE";
/** Query key. */
private static final String C_RESOURCES_COUNT_SIBLINGS = "C_RESOURCES_COUNT_SIBLINGS";
/** Query key. */
private static final String C_RESOURCES_DELETE_BY_RESOURCEID = "C_RESOURCES_DELETE_BY_RESOURCEID";
/** Query key. */
private static final String C_RESOURCES_GET_RESOURCE_IN_PROJECT_IGNORE_STATE = "C_RESOURCES_GET_RESOURCE_IN_PROJECT_IGNORE_STATE";
/** Query key. */
private static final String C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITH_STATE = "C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITH_STATE";
/** Query key. */
private static final String C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITHOUT_STATE = "C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITHOUT_STATE";
/** Query key. */
private static final String C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF = "C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF";
/** Query key. */
private static final String C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF_VALUE = "C_RESOURCES_GET_RESOURCE_WITH_PROPERTYDEF_VALUE";
/** Query key. */
private static final String C_RESOURCES_GET_SUBRESOURCES = "C_RESOURCES_GET_SUBRESOURCES";
/** Query key. */
private static final String C_RESOURCES_GET_SUBRESOURCES_GET_FILES = "C_RESOURCES_GET_SUBRESOURCES_GET_FILES";
/** Query key. */
private static final String C_RESOURCES_GET_SUBRESOURCES_GET_FOLDERS = "C_RESOURCES_GET_SUBRESOURCES_GET_FOLDERS";
/** Query key. */
private static final String C_RESOURCES_MOVE = "C_RESOURCES_MOVE";
/** Query key. */
private static final String C_RESOURCES_ORDER_BY_PATH = "C_RESOURCES_ORDER_BY_PATH";
/** Query key. */
private static final String C_RESOURCES_READ = "C_RESOURCES_READ";
/** Query key. */
private static final String C_RESOURCES_READ_PARENT_BY_ID = "C_RESOURCES_READ_PARENT_BY_ID";
/** Query key. */
private static final String C_RESOURCES_READ_PARENT_STRUCTURE_ID = "C_RESOURCES_READ_PARENT_STRUCTURE_ID";
/** Query key. */
private static final String C_RESOURCES_READ_RESOURCE_STATE = "C_RESOURCES_READ_RESOURCE_STATE";
/** Query key. */
private static final String C_RESOURCES_READ_TREE = "C_RESOURCES_READ_TREE";
/** Query key. */
private static final String C_RESOURCES_READ_VERSION_RES = "C_RESOURCES_READ_VERSION_RES";
/** Query key. */
private static final String C_RESOURCES_READ_VERSION_STR = "C_RESOURCES_READ_VERSION_STR";
/** Query key. */
private static final String C_RESOURCES_READ_WITH_ACE_1 = "C_RESOURCES_READ_WITH_ACE_1";
/** Query key. */
private static final String C_RESOURCES_READBYID = "C_RESOURCES_READBYID";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_AFTER = "C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_AFTER";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_BEFORE = "C_RESOURCES_SELECT_BY_DATE_LASTMODIFIED_BEFORE";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_PARENT_UUID = "C_RESOURCES_SELECT_BY_PARENT_UUID";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_PATH_PREFIX = "C_RESOURCES_SELECT_BY_PATH_PREFIX";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_PROJECT_LASTMODIFIED = "C_RESOURCES_SELECT_BY_PROJECT_LASTMODIFIED";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_RESOURCE_STATE = "C_RESOURCES_SELECT_BY_RESOURCE_STATE";
/** Query key. */
private static final String C_RESOURCES_SELECT_BY_RESOURCE_TYPE = "C_RESOURCES_SELECT_BY_RESOURCE_TYPE";
/** Query key. */
private static final String C_RESOURCES_SELECT_ONLY_FILES = "C_RESOURCES_SELECT_ONLY_FILES";
/** Query key. */
private static final String C_RESOURCES_SELECT_ONLY_FOLDERS = "C_RESOURCES_SELECT_ONLY_FOLDERS";
/** Query key. */
private static final String C_RESOURCES_SELECT_STRUCTURE_ID = "C_RESOURCES_SELECT_STRUCTURE_ID";
/** Query key. */
private static final String C_RESOURCES_TRANSFER_RESOURCE = "C_RESOURCES_TRANSFER_RESOURCE";
/** Query key. */
private static final String C_RESOURCES_UPDATE_FLAGS = "C_RESOURCES_UPDATE_FLAGS";
/** Query key. */
private static final String C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED = "C_RESOURCES_UPDATE_PROJECT_LASTMODIFIED";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RELEASE_EXPIRED = "C_RESOURCES_UPDATE_RELEASE_EXPIRED";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCE_PROJECT = "C_RESOURCES_UPDATE_RESOURCE_PROJECT";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCE_STATE = "C_RESOURCES_UPDATE_RESOURCE_STATE";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCE_STATELASTMODIFIED = "C_RESOURCES_UPDATE_RESOURCE_STATELASTMODIFIED";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCE_VERSION = "C_RESOURCES_UPDATE_RESOURCE_VERSION";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCES = "C_RESOURCES_UPDATE_RESOURCES";
/** Query key. */
private static final String C_RESOURCES_UPDATE_RESOURCES_WITHOUT_STATE = "C_RESOURCES_UPDATE_RESOURCES_WITHOUT_STATE";
/** Query key. */
private static final String C_RESOURCES_UPDATE_SIBLING_COUNT = "C_RESOURCES_UPDATE_SIBLING_COUNT";
/** Query key. */
private static final String C_RESOURCES_UPDATE_STRUCTURE = "C_RESOURCES_UPDATE_STRUCTURE";
/** Query key. */
private static final String C_RESOURCES_UPDATE_STRUCTURE_STATE = "C_RESOURCES_UPDATE_STRUCTURE_STATE";
/** Query key. */
private static final String C_RESOURCES_UPDATE_STRUCTURE_VERSION = "C_RESOURCES_UPDATE_STRUCTURE_VERSION";
/** Query key. */
private static final String C_SELECT_NONDELETED_VFS_SIBLINGS = "C_SELECT_NONDELETED_VFS_SIBLINGS";
/** Query key. */
private static final String C_SELECT_RESOURCES_FOR_PRINCIPAL_ACE = "C_SELECT_RESOURCES_FOR_PRINCIPAL_ACE";
/** Query key. */
private static final String C_SELECT_RESOURCES_FOR_PRINCIPAL_ATTR1 = "C_SELECT_RESOURCES_FOR_PRINCIPAL_ATTR1";
/** Query key. */
private static final String C_SELECT_RESOURCES_FOR_PRINCIPAL_ATTR2 = "C_SELECT_RESOURCES_FOR_PRINCIPAL_ATTR2";
/** Query key. */
private static final String C_SELECT_VFS_SIBLINGS = "C_SELECT_VFS_SIBLINGS";
/** Query key. */
private static final String C_STRUCTURE_DELETE_BY_STRUCTUREID = "C_STRUCTURE_DELETE_BY_STRUCTUREID";
/** Query key. */
private static final String C_STRUCTURE_SELECT_BY_DATE_EXPIRED_AFTER = "C_STRUCTURE_SELECT_BY_DATE_EXPIRED_AFTER";
/** Query key. */
private static final String C_STRUCTURE_SELECT_BY_DATE_EXPIRED_BEFORE = "C_STRUCTURE_SELECT_BY_DATE_EXPIRED_BEFORE";
/** Query key. */
private static final String C_STRUCTURE_SELECT_BY_DATE_RELEASED_AFTER = "C_STRUCTURE_SELECT_BY_DATE_RELEASED_AFTER";
/** Query key. */
private static final String C_STRUCTURE_SELECT_BY_DATE_RELEASED_BEFORE = "C_STRUCTURE_SELECT_BY_DATE_RELEASED_BEFORE";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(org.opencms.db.jpa.CmsVfsDriver.class);
/** The driver manager. */
protected CmsDriverManager m_driverManager;
/**
* This field is temporarily used to compute the versions during publishing.
*
* @see #publishVersions(CmsDbContext, CmsResource, boolean)
*/
protected List m_resOp = new ArrayList();
/** The sql manager. */
protected CmsSqlManager m_sqlManager;
/**
* Escapes the database wildcards within the resource path.
*
* This method is required to ensure chars in the resource path that have a special
* meaning in SQL (for example "_", which is the "any char" operator) are escaped.
*
* It will escape the following chars:
*
*
"_" to "|_"
*
*
* @param path the resource path
* @return the escaped resource path
*/
public static String escapeDbWildcard(String path) {
return CmsStringUtil.substitute(path, "_", "|_");
}
/**
* This method prepares the JPQL conditions for mapping entries for a given URL name mapping filter.
*
* @param filter the filter from which the JPQL conditions should be generated
*
* @return a pair consisting of an JPQL string and a list of the query parameters for the JPQL
*/
public static CmsPair> prepareUrlNameMappingConditions(
CmsUrlNameMappingFilter filter) {
List sqlConditions = new ArrayList();
List parameters = new ArrayList();
if (filter.getName() != null) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_name = ?");
parameters.add(new CmsQueryStringParameter(filter.getName()));
}
if (filter.getStructureId() != null) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_structureId = ?");
parameters.add(new CmsQueryStringParameter(filter.getStructureId().toString()));
}
if (filter.getNamePattern() != null) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_name LIKE ? ");
parameters.add(new CmsQueryStringParameter(filter.getNamePattern()));
}
if ((filter.getStates() != null) && (filter.getStates().length > 0)) {
List stateConditions = new ArrayList();
stateConditions.add("1 = 0");
for (int i = 0; i < filter.getStates().length; i++) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_state = ?");
parameters.add(new CmsQueryIntParameter(filter.getStates()[i]));
}
sqlConditions.add("( " + CmsStringUtil.listAsString(stateConditions, " OR ") + ")");
}
if (filter.getRejectStructureId() != null) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_structureId <> ? ");
parameters.add(new CmsQueryStringParameter(filter.getRejectStructureId().toString()));
}
if (filter.getLocale() != null) {
sqlConditions.add("T_CmsDAO%(PROJECT)UrlNameMappings.m_locale = ? ");
parameters.add(new CmsQueryStringParameter(filter.getLocale()));
}
String conditionString = CmsStringUtil.listAsString(sqlConditions, " AND ");
return CmsPair.create(conditionString, parameters);
}
/**
* @see org.opencms.db.I_CmsVfsDriver#addUrlNameMappingEntry(org.opencms.db.CmsDbContext, boolean, org.opencms.db.urlname.CmsUrlNameMappingEntry)
*/
public void addUrlNameMappingEntry(CmsDbContext dbc, boolean online, CmsUrlNameMappingEntry entry) {
I_CmsDAOUrlNameMappings m = online ? new CmsDAOOnlineUrlNameMappings() : new CmsDAOOfflineUrlNameMappings();
m.setName(entry.getName());
m.setStructureId(entry.getStructureId().toString());
m.setState(entry.getState());
m.setDateChanged(entry.getDateChanged());
m.setLocale(entry.getLocale());
m_sqlManager.persist(dbc, m);
}
/**
* Counts the number of siblings of a resource.
*
* @param dbc the current database context
* @param projectId the current project id
* @param resourceId the resource id to count the number of siblings from
*
* @return number of siblings
* @throws CmsDataAccessException if something goes wrong
*/
public int countSiblings(CmsDbContext dbc, CmsUUID projectId, CmsUUID resourceId) throws CmsDataAccessException {
int count = 0;
try {
Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_COUNT_SIBLINGS);
q.setParameter(1, resourceId.toString());
try {
count = CmsDataTypeUtil.numberToInt((Number)q.getSingleResult());
} catch (NoResultException e) {
// do nothing
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
return count;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createContent(CmsDbContext, CmsUUID, CmsUUID, byte[])
*/
public void createContent(CmsDbContext dbc, CmsUUID projectId, CmsUUID resourceId, byte[] content)
throws CmsDataAccessException {
try {
CmsDAOOfflineContents oc = new CmsDAOOfflineContents();
oc.setResourceId(resourceId.toString());
oc.setFileContent(content);
m_sqlManager.persist(dbc, oc);
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* Creates a {@link CmsFile} instance from a jpa ResultSet.
*
* @param o the jpa ResultSet
* @param projectId the project id
* @param hasFileContentInResultSet flag to include the file content
*
* @return the created file
*/
public CmsFile createFile(Object[] o, CmsUUID projectId, boolean hasFileContentInResultSet) {
I_CmsDAOResources r = (I_CmsDAOResources)o[0];
I_CmsDAOStructure s = (I_CmsDAOStructure)o[1];
String lockedInProjectParameter = (String)o[2];
byte[] content = null;
CmsUUID resProjectId = null;
CmsUUID structureId = new CmsUUID(s.getStructureId());
CmsUUID resourceId = new CmsUUID(r.getResourceId());
String resourcePath = s.getResourcePath();
int resourceType = r.getResourceType();
int resourceFlags = r.getResourceFlags();
int resourceState = r.getResourceState();
int structureState = s.getStructureState();
long dateCreated = r.getDateCreated();
long dateLastModified = r.getDateLastModified();
long dateReleased = s.getDateReleased();
long dateExpired = s.getDateExpired();
int resourceSize = r.getResourceSize();
CmsUUID userCreated = new CmsUUID(r.getUserCreated());
CmsUUID userLastModified = new CmsUUID(r.getUserLastModified());
CmsUUID lockedInProject = new CmsUUID(lockedInProjectParameter);
int siblingCount = r.getSiblingCount();
long dateContent = r.getDateContent();
int resourceVersion = r.getResourceVersion();
int structureVersion = s.getStructureVersion();
// in case of folder type ensure, that the root path has a trailing slash
if (CmsFolder.isFolderType(resourceType)) {
resourcePath = CmsFileUtil.addTrailingSeparator(resourcePath);
}
if (hasFileContentInResultSet) {
//content = m_sqlManager.getBytes(res, m_sqlManager.readQuery("C_RESOURCES_FILE_CONTENT"));
throw new RuntimeException(
"CCmsVfsDriver: public CmsFile createFile(Object[] o, CmsUUID projectId, boolean hasFileContentInResultSet) throws SQLException ");
}
resProjectId = lockedInProject;
int newState = (structureState > resourceState) ? structureState : resourceState;
return new CmsFile(
structureId,
resourceId,
resourcePath,
resourceType,
resourceFlags,
resProjectId,
CmsResourceState.valueOf(newState),
dateCreated,
userCreated,
dateLastModified,
userLastModified,
dateReleased,
dateExpired,
siblingCount,
resourceSize,
dateContent,
resourceVersion + structureVersion,
content);
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createFile(java.sql.ResultSet, org.opencms.util.CmsUUID)
*/
public CmsFile createFile(ResultSet res, CmsUUID projectId) {
LOG.error("This method is not implemented!");
return null;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createFile(java.sql.ResultSet, org.opencms.util.CmsUUID, boolean)
*/
public CmsFile createFile(ResultSet res, CmsUUID projectId, boolean hasFileContentInResultSet) {
LOG.error("This method is not implemented!");
return null;
}
/**
* Creates a {@link CmsFolder} instance from a jpa ResultSet.
*
* @param o the JDBC ResultSet
* @param projectId the ID of the current project
* @param hasProjectIdInResultSet true if the SQL select query includes the PROJECT_ID table attribute
*
* @return the created folder
*/
public CmsFolder createFolder(Object[] o, CmsUUID projectId, boolean hasProjectIdInResultSet) {
I_CmsDAOResources r = (I_CmsDAOResources)o[0];
I_CmsDAOStructure s = (I_CmsDAOStructure)o[1];
String lockedInProjectParameter = (String)o[2];
CmsUUID structureId = new CmsUUID(s.getStructureId());
CmsUUID resourceId = new CmsUUID(r.getResourceId());
String resourcePath = s.getResourcePath();
int resourceType = r.getResourceType();
int resourceFlags = r.getResourceFlags();
int resourceState = r.getResourceState();
int structureState = s.getStructureState();
long dateCreated = r.getDateCreated();
long dateLastModified = r.getDateLastModified();
long dateReleased = s.getDateReleased();
long dateExpired = s.getDateExpired();
CmsUUID userCreated = new CmsUUID(r.getUserCreated());
CmsUUID userLastModified = new CmsUUID(r.getUserLastModified());
CmsUUID resProjectId = new CmsUUID(lockedInProjectParameter);
int resourceVersion = r.getResourceVersion();
int structureVersion = s.getStructureVersion();
int resourceSize = r.getResourceSize();
// in case of folder type ensure, that the root path has a trailing slash
if (CmsFolder.isFolderSize(resourceSize)) {
resourcePath = CmsFileUtil.addTrailingSeparator(resourcePath);
}
int newState = (structureState > resourceState) ? structureState : resourceState;
return new CmsFolder(
structureId,
resourceId,
resourcePath,
resourceType,
resourceFlags,
resProjectId,
CmsResourceState.valueOf(newState),
dateCreated,
userCreated,
dateLastModified,
userLastModified,
dateReleased,
dateExpired,
resourceVersion + structureVersion);
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createFolder(java.sql.ResultSet, org.opencms.util.CmsUUID, boolean)
*/
public CmsFolder createFolder(ResultSet res, CmsUUID projectId, boolean hasProjectIdInResultSet) {
LOG.error("This method is not implemented!");
return null;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createOnlineContent(org.opencms.db.CmsDbContext, org.opencms.util.CmsUUID, byte[], int, boolean, boolean)
*/
public void createOnlineContent(
CmsDbContext dbc,
CmsUUID resourceId,
byte[] contents,
int publishTag,
boolean keepOnline,
boolean needToUpdateContent) throws CmsDataAccessException {
try {
boolean dbcHasProjectId = (dbc.getProjectId() != null) && !dbc.getProjectId().isNullUUID();
if (needToUpdateContent || dbcHasProjectId) {
if (dbcHasProjectId || !OpenCms.getSystemInfo().isHistoryEnabled()) {
// remove the online content for this resource id
Query q = m_sqlManager.createQuery(dbc, "C_ONLINE_CONTENTS_DELETE");
q.setParameter(1, resourceId.toString());
q.executeUpdate();
} else {
// put the online content in the history, only if explicit requested
Query q = m_sqlManager.createQuery(dbc, "C_ONLINE_CONTENTS_HISTORY");
q.setParameter(1, resourceId.toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (CmsDAOContents c : res) {
c.setOnlineFlag(0);
}
}
// create new online content
CmsDAOContents c = new CmsDAOContents();
c.setResourceId(resourceId.toString());
c.setFileContent(contents);
c.setPublishTagFrom(publishTag);
c.setPublishTagTo(publishTag);
c.setOnlineFlag(keepOnline ? 1 : 0);
m_sqlManager.persist(dbc, c);
} else {
// update old content entry
Query q = m_sqlManager.createQuery(dbc, C_HISTORY_CONTENTS_UPDATE);
q.setParameter(1, resourceId.toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (CmsDAOContents c : res) {
c.setPublishTagTo(publishTag);
}
if (!keepOnline) {
// put the online content in the history
q = m_sqlManager.createQuery(dbc, C_ONLINE_CONTENTS_HISTORY);
q.setParameter(1, resourceId.toString());
@SuppressWarnings("unchecked")
List res1 = q.getResultList();
for (CmsDAOContents c : res1) {
c.setOnlineFlag(0);
}
}
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createPropertyDefinition(org.opencms.db.CmsDbContext, org.opencms.util.CmsUUID, java.lang.String, org.opencms.file.CmsPropertyDefinition.CmsPropertyType)
*/
public CmsPropertyDefinition createPropertyDefinition(
CmsDbContext dbc,
CmsUUID projectId,
String name,
CmsPropertyDefinition.CmsPropertyType type) throws CmsDataAccessException {
try {
I_CmsDAOPropertyDef pd = CmsProject.isOnlineProject(projectId)
? new CmsDAOOnlinePropertyDef()
: new CmsDAOOfflinePropertyDef();
pd.setPropertyDefId(new CmsUUID().toString());
pd.setPropertyDefName(name);
pd.setPropertyDefType(type.getMode());
m_sqlManager.persist(dbc, pd);
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
return readPropertyDefinition(dbc, name, projectId);
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createRelation(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.relations.CmsRelation)
*/
public void createRelation(CmsDbContext dbc, CmsUUID projectId, CmsRelation relation)
throws CmsDataAccessException {
try {
I_CmsDAOResourceRelations rr = CmsProject.isOnlineProject(projectId)
? new CmsDAOOnlineResourceRelations()
: new CmsDAOOfflineResourceRelations();
rr.setRelationSourceId(relation.getSourceId().toString());
rr.setRelationSourcePath(relation.getSourcePath());
rr.setRelationTargetId(relation.getTargetId().toString());
rr.setRelationTargetPath(relation.getTargetPath());
rr.setRelationType(relation.getType().getId());
m_sqlManager.persist(dbc, rr);
if (LOG.isDebugEnabled()) {
LOG.debug(
Messages.get().getBundle().key(
Messages.LOG_CREATE_RELATION_2,
String.valueOf(projectId),
relation));
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createResource(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.file.CmsResource, byte[])
*/
public CmsResource createResource(CmsDbContext dbc, CmsUUID projectId, CmsResource resource, byte[] content)
throws CmsDataAccessException {
CmsUUID newStructureId = null;
// check the resource path
String resourcePath = CmsFileUtil.removeTrailingSeparator(resource.getRootPath());
if (resourcePath.length() > CmsDriverManager.MAX_VFS_RESOURCE_PATH_LENGTH) {
throw new CmsDataAccessException(
Messages.get().container(
Messages.ERR_RESOURCENAME_TOO_LONG_2,
resourcePath,
new Integer(CmsDriverManager.MAX_VFS_RESOURCE_PATH_LENGTH)));
}
// check if the parent folder of the resource exists and if is not deleted
if (!resource.getRootPath().equals("/")) {
String parentFolderName = CmsResource.getParentFolder(resource.getRootPath());
CmsFolder parentFolder = m_driverManager.getVfsDriver(dbc).readFolder(dbc, projectId, parentFolderName);
if (parentFolder.getState().isDeleted()) {
throw new CmsDbEntryNotFoundException(
Messages.get().container(Messages.ERR_PARENT_FOLDER_DELETED_1, resource.getRootPath()));
}
}
// validate the resource length
internalValidateResourceLength(resource);
// set the resource state and modification dates
CmsResourceState newState;
long dateModified;
long dateCreated;
long dateContent = System.currentTimeMillis();
if (projectId.equals(CmsProject.ONLINE_PROJECT_ID)) {
newState = CmsResource.STATE_UNCHANGED;
dateCreated = resource.getDateCreated();
dateModified = resource.getDateLastModified();
} else {
newState = CmsResource.STATE_NEW;
if (resource.isTouched()) {
dateCreated = resource.getDateCreated();
dateModified = resource.getDateLastModified();
} else {
dateCreated = System.currentTimeMillis();
dateModified = dateCreated;
}
}
// check if the resource already exists
newStructureId = resource.getStructureId();
try {
CmsResource existingResource = m_driverManager.getVfsDriver().readResource(
dbc,
dbc.getProjectId().isNullUUID() ? projectId : dbc.getProjectId(),
resourcePath,
true);
if (existingResource.getState().isDeleted()) {
// if an existing resource is deleted, it will be finally removed now.
// but we have to reuse its id in order to avoid orphans in the online project
newStructureId = existingResource.getStructureId();
newState = CmsResource.STATE_CHANGED;
// remove the existing file and it's properties
List modifiedResources = m_driverManager.getVfsDriver(dbc).readSiblings(
dbc,
projectId,
existingResource,
false);
int propertyDeleteOption = (existingResource.getSiblingCount() > 1)
? CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES
: CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES;
deletePropertyObjects(dbc, projectId, existingResource, propertyDeleteOption);
removeFile(dbc, projectId, existingResource);
OpenCms.fireCmsEvent(new CmsEvent(
I_CmsEventListener.EVENT_RESOURCES_MODIFIED,
Collections. singletonMap(I_CmsEventListener.KEY_RESOURCES, modifiedResources)));
OpenCms.fireCmsEvent(
new CmsEvent(
I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED,
Collections. singletonMap(I_CmsEventListener.KEY_RESOURCE, existingResource)));
} else {
// we have a collision: there exists already a resource with the same path/name which cannot be removed
throw new CmsVfsResourceAlreadyExistsException(
Messages.get().container(
Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
} catch (CmsVfsResourceNotFoundException e) {
// that's what we want in the best case- anything else should be thrown
}
try {
// read the parent id
String parentId = internalReadParentId(dbc, projectId, resourcePath);
// use consistent version numbers if the file is being restored
int lastVersion = m_driverManager.getHistoryDriver(dbc).readLastVersion(dbc, newStructureId);
int newStrVersion = 0;
int newResVersion = 0;
if (lastVersion > 0) {
I_CmsHistoryResource histRes = m_driverManager.getHistoryDriver(dbc).readResource(
dbc,
newStructureId,
lastVersion);
newStrVersion = histRes.getStructureVersion();
newResVersion = histRes.getResourceVersion();
}
// write the structure
I_CmsDAOStructure s = CmsProject.isOnlineProject(projectId)
? new CmsDAOOnlineStructure()
: new CmsDAOOfflineStructure();
s.setStructureId(newStructureId.toString());
s.setResourceId(resource.getResourceId().toString());
s.setResourcePath(resourcePath);
s.setStructureState(newState.getState());
s.setDateReleased(resource.getDateReleased());
s.setDateExpired(resource.getDateExpired());
s.setParentId(parentId);
s.setStructureVersion(newStrVersion);
m_sqlManager.persist(dbc, s);
if (!validateResourceIdExists(dbc, projectId, resource.getResourceId())) {
// create the resource record
I_CmsDAOResources r = CmsProject.isOnlineProject(projectId)
? new CmsDAOOnlineResources()
: new CmsDAOOfflineResources();
r.setResourceId(resource.getResourceId().toString());
r.setResourceType(resource.getTypeId());
r.setResourceFlags(resource.getFlags());
r.setDateCreated(dateCreated);
r.setUserCreated(resource.getUserCreated().toString());
r.setDateLastModified(dateModified);
r.setUserLastModified(resource.getUserLastModified().toString());
r.setResourceState(newState.getState());
r.setResourceSize(resource.getLength());
r.setDateContent(dateContent);
r.setProjectLastModified(projectId.toString());
r.setSiblingCount(1);
r.setResourceVersion(newResVersion);
m_sqlManager.persist(dbc, r);
if (resource.isFile() && (content != null)) {
// create the file content
createContent(dbc, projectId, resource.getResourceId(), content);
}
} else {
if ((content != null) || !resource.getState().isKeep()) {
CmsUUID projLastMod = projectId;
CmsResourceState state = CmsResource.STATE_CHANGED;
if (projectId.equals(CmsProject.ONLINE_PROJECT_ID)) {
// in case a sibling is being published
projLastMod = resource.getProjectLastModified();
state = CmsResource.STATE_UNCHANGED;
}
// update the resource record only if state has changed or new content is provided
Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_UPDATE_RESOURCES);
q.setParameter(1, resource.getResourceId().toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (I_CmsDAOResources r : res) {
r.setResourceType(resource.getTypeId());
r.setResourceFlags(resource.getFlags());
r.setDateLastModified(dateModified);
r.setUserLastModified(resource.getUserLastModified().toString());
r.setResourceState(state.getState());
r.setResourceSize(resource.getLength());
r.setDateContent(resource.getDateContent());
r.setProjectLastModified(projLastMod.toString());
r.setSiblingCount(countSiblings(dbc, projectId, resource.getResourceId()));
}
}
if (resource.isFile()) {
if (content != null) {
// update the file content
writeContent(dbc, resource.getResourceId(), content);
} else if (resource.getState().isKeep()) {
// special case sibling creation - update the link Count
Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_UPDATE_SIBLING_COUNT);
q.setParameter(1, resource.getResourceId().toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (I_CmsDAOResources r : res) {
r.setSiblingCount(countSiblings(dbc, projectId, resource.getResourceId()));
}
// update the resource flags
q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_UPDATE_FLAGS);
q.setParameter(1, resource.getResourceId().toString());
@SuppressWarnings("unchecked")
List resf = q.getResultList();
for (I_CmsDAOResources r : resf) {
r.setResourceFlags(resource.getFlags());
}
}
}
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
repairBrokenRelations(dbc, projectId, resource.getStructureId(), resource.getRootPath());
return readResource(dbc, projectId, newStructureId, false);
}
/**
* Creates a CmsResource instance from a jpa ResultSet.
*
* @param o the jpa ResultSet
* @param projectId the ID of the current project to adjust the modification date in case the resource is a VFS link
*
* @return the created resource
*/
public CmsResource createResource(Object[] o, CmsUUID projectId) {
I_CmsDAOResources r = (I_CmsDAOResources)o[0];
I_CmsDAOStructure s = (I_CmsDAOStructure)o[1];
CmsUUID structureId = new CmsUUID(s.getStructureId());
CmsUUID resourceId = new CmsUUID(r.getResourceId());
String resourcePath = s.getResourcePath();
int resourceType = r.getResourceType();
int resourceFlags = r.getResourceFlags();
CmsUUID resourceProjectLastModified = new CmsUUID(r.getProjectLastModified());
int resourceState = r.getResourceState();
int structureState = s.getStructureState();
long dateCreated = r.getDateCreated();
long dateLastModified = r.getDateLastModified();
long dateReleased = s.getDateReleased();
long dateExpired = s.getDateExpired();
int resourceSize = r.getResourceSize();
boolean isFolder = CmsFolder.isFolderSize(resourceSize);
if (isFolder) {
// in case of folder type ensure, that the root path has a trailing slash
resourcePath = CmsFileUtil.addTrailingSeparator(resourcePath);
}
long dateContent = isFolder ? -1 : r.getDateContent();
CmsUUID userCreated = new CmsUUID(r.getUserCreated());
CmsUUID userLastModified = new CmsUUID(r.getUserLastModified());
int siblingCount = r.getSiblingCount();
int resourceVersion = r.getResourceVersion();
int structureVersion = s.getStructureVersion();
int newState = (structureState > resourceState) ? structureState : resourceState;
// if there is a change increase the version number
int newVersion = resourceVersion + structureVersion + (newState > 0 ? 1 : 0);
CmsResource newResource = new CmsResource(
structureId,
resourceId,
resourcePath,
resourceType,
isFolder,
resourceFlags,
resourceProjectLastModified,
CmsResourceState.valueOf(newState),
dateCreated,
userCreated,
dateLastModified,
userLastModified,
dateReleased,
dateExpired,
siblingCount,
resourceSize,
dateContent,
newVersion);
return newResource;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createResource(java.sql.ResultSet, org.opencms.util.CmsUUID)
*/
public CmsResource createResource(ResultSet res, CmsUUID projectId) {
LOG.error("This method is not implemented!");
return null;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#createSibling(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.file.CmsResource)
*/
public void createSibling(CmsDbContext dbc, CmsProject project, CmsResource resource)
throws CmsDataAccessException {
if (!project.getUuid().equals(CmsProject.ONLINE_PROJECT_ID)) {
// this method is only intended to be used during publishing
return;
}
// check if the resource already exists
CmsResource existingSibling = null;
CmsUUID newStructureId = resource.getStructureId();
try {
existingSibling = readResource(dbc, project.getUuid(), resource.getRootPath(), true);
if (existingSibling.getState().isDeleted()) {
// if an existing resource is deleted, it will be finally removed now.
// but we have to reuse its id in order to avoid orphans in the online project.
newStructureId = existingSibling.getStructureId();
// remove the existing file and it's properties
List modifiedResources = readSiblings(dbc, project.getUuid(), existingSibling, false);
int propertyDeleteOption = (existingSibling.getSiblingCount() > 1)
? CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES
: CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES;
deletePropertyObjects(dbc, project.getUuid(), existingSibling, propertyDeleteOption);
removeFile(dbc, project.getUuid(), existingSibling);
OpenCms.fireCmsEvent(
new CmsEvent(
I_CmsEventListener.EVENT_RESOURCES_MODIFIED,
Collections. singletonMap(
I_CmsEventListener.KEY_RESOURCES,
modifiedResources)));
OpenCms.fireCmsEvent(
new CmsEvent(
I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED,
Collections. singletonMap(I_CmsEventListener.KEY_RESOURCE, existingSibling)));
} else {
// we have a collision: there exists already a resource with the same path/name which could not be removed
throw new CmsVfsResourceAlreadyExistsException(
Messages.get().container(
Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
} catch (CmsVfsResourceNotFoundException e) {
// that's what we want in the best case- anything else should be thrown
}
// check if a resource with the specified ID already exists
if (!validateResourceIdExists(dbc, project.getUuid(), resource.getResourceId())) {
throw new CmsVfsResourceNotFoundException(
Messages.get().container(
Messages.ERR_CREATE_SIBLING_FILE_NOT_FOUND_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
// write a new structure referring to the resource
try {
// use consistent version numbers if the file is being restored
int lastVersion = m_driverManager.getHistoryDriver(dbc).readLastVersion(dbc, newStructureId);
int newStrVersion = 0;
if (lastVersion > 0) {
I_CmsHistoryResource histRes = m_driverManager.getHistoryDriver(dbc).readResource(
dbc,
newStructureId,
lastVersion);
newStrVersion = histRes.getStructureVersion();
}
// read the parent id
String parentId = internalReadParentId(dbc, project.getUuid(), resource.getRootPath());
// write the structure
I_CmsDAOStructure s = CmsProject.isOnlineProject(project.getUuid())
? new CmsDAOOnlineStructure()
: new CmsDAOOfflineStructure();
s.setStructureId(newStructureId.toString());
s.setResourceId(resource.getResourceId().toString());
s.setResourcePath(resource.getRootPath());
s.setStructureState(CmsResource.STATE_UNCHANGED.getState());
s.setDateReleased(resource.getDateReleased());
s.setDateExpired(resource.getDateExpired());
s.setParentId(parentId);
s.setStructureVersion(newStrVersion);
m_sqlManager.persist(dbc, s);
// update the link Count
Query q = m_sqlManager.createQuery(dbc, project, C_RESOURCES_UPDATE_SIBLING_COUNT);
q.setParameter(1, resource.getResourceId().toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (I_CmsDAOResources r : res) {
r.setSiblingCount(countSiblings(dbc, project.getUuid(), resource.getResourceId()));
}
// update the project last modified and flags
q = m_sqlManager.createQuery(dbc, project, C_RESOURCES_UPDATE_RESOURCE_PROJECT);
q.setParameter(1, resource.getResourceId().toString());
@SuppressWarnings("unchecked")
List resr = q.getResultList();
for (I_CmsDAOResources r : resr) {
r.setResourceFlags(resource.getFlags());
r.setProjectLastModified(resource.getProjectLastModified().toString());
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
repairBrokenRelations(dbc, project.getUuid(), resource.getStructureId(), resource.getRootPath());
}
/**
* @see org.opencms.db.I_CmsVfsDriver#deleteAliases(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.db.CmsAliasFilter)
*/
public void deleteAliases(CmsDbContext dbc, CmsProject project, CmsAliasFilter filter)
throws CmsDataAccessException {
String baseQuery = "DELETE FROM CmsDAOAlias alias ";
try {
Query query = getAliasQueryForFilter(dbc, baseQuery, filter);
query.executeUpdate();
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#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 CmsDataAccessException(
Messages.get().container(Messages.ERR_DELETE_USED_PROPERTY_1, metadef.getName()));
}
Query q;
for (int i = 0; i < 2; i++) {
if (i == 0) {
// delete the offline property definition
q = m_sqlManager.createQuery(dbc, CmsUUID.getOpenCmsUUID(), C_PROPERTYDEF_DELETE); // HACK: to get an offline project
} else {
// delete the online property definition
q = m_sqlManager.createQuery(dbc, CmsProject.ONLINE_PROJECT_ID, C_PROPERTYDEF_DELETE);
}
q.setParameter(1, metadef.getId().toString());
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (I_CmsDAOPropertyDef pd : res) {
m_sqlManager.remove(dbc, pd);
}
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#deletePropertyObjects(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.file.CmsResource, int)
*/
public void deletePropertyObjects(CmsDbContext dbc, CmsUUID projectId, CmsResource resource, int deleteOption)
throws CmsDataAccessException {
try {
Query q;
if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES) {
// delete both the structure and resource property values mapped to the specified resource
q = m_sqlManager.createQuery(dbc, projectId, C_PROPERTIES_DELETE_ALL_STRUCTURE_AND_RESOURCE_VALUES);
q.setParameter(1, resource.getResourceId().toString());
q.setParameter(2, Integer.valueOf(CmsProperty.RESOURCE_RECORD_MAPPING));
q.setParameter(3, String.valueOf(resource.getStructureId()));
q.setParameter(4, Integer.valueOf(CmsProperty.STRUCTURE_RECORD_MAPPING));
} else if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES) {
// delete the structure values mapped to the specified resource
q = m_sqlManager.createQuery(dbc, projectId, C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE);
q.setParameter(1, resource.getStructureId().toString());
q.setParameter(2, Integer.valueOf(CmsProperty.STRUCTURE_RECORD_MAPPING));
} else if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_RESOURCE_VALUES) {
// delete the resource property values mapped to the specified resource
q = m_sqlManager.createQuery(dbc, projectId, C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE);
q.setParameter(1, resource.getResourceId().toString());
q.setParameter(2, Integer.valueOf(CmsProperty.RESOURCE_RECORD_MAPPING));
} else {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_INVALID_DELETE_OPTION_1));
}
@SuppressWarnings("unchecked")
List res = q.getResultList();
for (I_CmsDAOProperties p : res) {
m_sqlManager.remove(dbc, p);
}
} catch (PersistenceException e) {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#deleteRelations(org.opencms.db.CmsDbContext, CmsUUID, CmsResource, org.opencms.relations.CmsRelationFilter)
*/
public void deleteRelations(CmsDbContext dbc, CmsUUID projectId, CmsResource resource, CmsRelationFilter filter)
throws CmsDataAccessException {
try {
if (filter.isSource()) {
List