📄 cmsvfsdriver.java
字号:
}
/**
* @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 {
Connection conn = null;
PreparedStatement stmt = null;
int newState = 0;
// force some attribs when creating or publishing a file
if (project.getId() == CmsProject.ONLINE_PROJECT_ID) {
newState = CmsResource.STATE_UNCHANGED;
} else {
newState = CmsResource.STATE_NEW;
}
// check if the resource already exists
CmsResource existingSibling = null;
CmsUUID newStructureId = resource.getStructureId();
try {
existingSibling = readResource(dbc, project.getId(), resource.getRootPath(), true);
if (existingSibling.getState() == CmsResource.STATE_DELETED) {
// if an existing resource is deleted, it will be finally removed now.
// but we have to reuse its id in order to avoid orphanes in the online project.
newStructureId = existingSibling.getStructureId();
newState = CmsResource.STATE_CHANGED;
// remove the existing file and it's properties
List modifiedResources = readSiblings(dbc, project, existingSibling, false);
int propertyDeleteOption = (existingSibling.getSiblingCount() > 1) ? CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES
: CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES;
deletePropertyObjects(dbc, project.getId(), existingSibling, propertyDeleteOption);
removeFile(dbc, project, existingSibling, true);
OpenCms.fireCmsEvent(new CmsEvent(
I_CmsEventListener.EVENT_RESOURCES_MODIFIED,
Collections.singletonMap("resources", modifiedResources)));
OpenCms.fireCmsEvent(new CmsEvent(
I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED,
Collections.singletonMap("resource", existingSibling)));
}
} catch (CmsVfsResourceNotFoundException e) {
// that's what we want in the best case- anything else should be thrown
}
if (existingSibling != null && existingSibling.getState() != CmsResource.STATE_DELETED) {
// 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())));
}
// check if a resource with the specified ID already exists
if (!validateResourceIdExists(dbc, project.getId(), 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 {
conn = m_sqlManager.getConnection(dbc, project.getId());
// read the parent id
String parentId = internalReadParentId(dbc, project.getId(), resource.getRootPath());
// write the structure
stmt = m_sqlManager.getPreparedStatement(conn, project, "C_STRUCTURE_WRITE");
stmt.setString(1, newStructureId.toString());
stmt.setString(2, resource.getResourceId().toString());
stmt.setString(3, resource.getRootPath());
stmt.setInt(4, newState);
stmt.setLong(5, resource.getDateReleased());
stmt.setLong(6, resource.getDateExpired());
stmt.setString(7, parentId);
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
// update the link Count
stmt = m_sqlManager.getPreparedStatement(conn, project, "C_RESOURCES_UPDATE_SIBLING_COUNT");
stmt.setInt(1, this.internalCountSiblings(dbc, project.getId(), resource.getResourceId()));
stmt.setString(2, resource.getResourceId().toString());
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
// update the resource flags
stmt = m_sqlManager.getPreparedStatement(conn, project, "C_RESOURCES_UPDATE_FLAGS");
stmt.setInt(1, resource.getFlags());
stmt.setString(2, resource.getResourceId().toString());
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#deletePropertyDefinition(org.opencms.db.CmsDbContext, org.opencms.file.CmsPropertyDefinition)
*/
public void deletePropertyDefinition(CmsDbContext dbc, CmsPropertyDefinition metadef) throws CmsDataAccessException {
Connection conn = null;
PreparedStatement stmt = null;
try {
if (internalCountProperties(dbc, metadef, CmsProject.ONLINE_PROJECT_ID) != 0
|| internalCountProperties(dbc, metadef, Integer.MAX_VALUE) != 0) {
throw new CmsDataAccessException(Messages.get().container(
Messages.ERR_DELETE_USED_PROPERTY_1,
metadef.getName()));
}
conn = m_sqlManager.getConnection(dbc);
for (int i = 0; i < 2; i++) {
if (i == 0) {
// delete the offline propertydef
stmt = m_sqlManager.getPreparedStatement(conn, Integer.MAX_VALUE, "C_PROPERTYDEF_DELETE");
} else if (i == 1) {
// delete the online propertydef
stmt = m_sqlManager.getPreparedStatement(conn, CmsProject.ONLINE_PROJECT_ID, "C_PROPERTYDEF_DELETE");
}
stmt.setString(1, metadef.getId().toString());
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
}
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#deletePropertyObjects(org.opencms.db.CmsDbContext, int, org.opencms.file.CmsResource, int)
*/
public void deletePropertyObjects(CmsDbContext dbc, int projectId, CmsResource resource, int deleteOption)
throws CmsDataAccessException {
Connection conn = null;
PreparedStatement stmt = null;
String resourceName = resource.getRootPath();
// add folder separator to folder name if it is not present
if (resource.isFolder() && !resourceName.endsWith("/")) {
resourceName += "/";
}
try {
conn = m_sqlManager.getConnection(dbc, projectId);
if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES) {
// delete both the structure and resource property values mapped to the specified resource
stmt = m_sqlManager.getPreparedStatement(
conn,
projectId,
"C_PROPERTIES_DELETE_ALL_STRUCTURE_AND_RESOURCE_VALUES");
stmt.setString(1, resource.getResourceId().toString());
stmt.setInt(2, CmsProperty.RESOURCE_RECORD_MAPPING);
stmt.setString(3, resource.getStructureId().toString());
stmt.setInt(4, CmsProperty.STRUCTURE_RECORD_MAPPING);
} else if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES) {
// delete the structure values mapped to the specified resource
stmt = m_sqlManager.getPreparedStatement(
conn,
projectId,
"C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE");
stmt.setString(1, resource.getStructureId().toString());
stmt.setInt(2, CmsProperty.STRUCTURE_RECORD_MAPPING);
} else if (deleteOption == CmsProperty.DELETE_OPTION_DELETE_RESOURCE_VALUES) {
// delete the resource property values mapped to the specified resource
stmt = m_sqlManager.getPreparedStatement(
conn,
projectId,
"C_PROPERTIES_DELETE_ALL_VALUES_FOR_MAPPING_TYPE");
stmt.setString(1, resource.getResourceId().toString());
stmt.setInt(2, CmsProperty.RESOURCE_RECORD_MAPPING);
}
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#destroy()
*/
public void destroy() throws Throwable {
finalize();
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_DRIVER_1, getClass().getName()));
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#getSqlManager()
*/
public CmsSqlManager getSqlManager() {
return m_sqlManager;
}
/**
* @see org.opencms.db.I_CmsDriver#init(org.opencms.db.CmsDbContext, org.opencms.configuration.CmsConfigurationManager, java.util.List, org.opencms.db.CmsDriverManager)
*/
public void init(
CmsDbContext dbc,
CmsConfigurationManager configurationManager,
List successiveDrivers,
CmsDriverManager driverManager) {
Map configuration = configurationManager.getConfiguration();
String poolUrl = (String)configuration.get("db.vfs.pool");
String classname = (String)configuration.get("db.vfs.sqlmanager");
m_sqlManager = this.initSqlManager(classname);
m_sqlManager.init(I_CmsVfsDriver.DRIVER_TYPE_ID, poolUrl);
m_driverManager = driverManager;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ASSIGNED_POOL_1, poolUrl));
}
if (successiveDrivers != null && !successiveDrivers.isEmpty()) {
if (LOG.isWarnEnabled()) {
LOG.warn(Messages.get().getBundle().key(
Messages.LOG_SUCCESSIVE_DRIVERS_UNSUPPORTED_1,
getClass().getName()));
}
}
}
/**
* @see org.opencms.db.I_CmsVfsDriver#initSqlManager(String)
*/
public org.opencms.db.generic.CmsSqlManager initSqlManager(String classname) {
return CmsSqlManager.getInstance(classname);
}
/**
* @see org.opencms.db.I_CmsVfsDriver#publishResource(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.file.CmsResource, org.opencms.file.CmsResource, boolean)
*/
public void publishResource(
CmsDbContext dbc,
CmsProject onlineProject,
CmsResource onlineResource,
CmsResource offlineResource,
boolean writeFileContent) throws CmsDataAccessException {
Connection conn = null;
PreparedStatement stmt = null;
// validate the resource length
internalValidateResourceLength(offlineResource);
int resourceSize = offlineResource.getLength();
String resourcePath = removeTrailingSeparator(offlineResource.getRootPath());
try {
conn = m_sqlManager.getConnection(dbc, onlineProject.getId());
if (validateResourceIdExists(dbc, onlineProject.getId(), offlineResource.getResourceId())) {
// the resource record exists online already
if (writeFileContent && offlineResource.isFile()) {
// update the online file content
writeContent(
dbc,
onlineProject,
offlineResource.getResourceId(),
((CmsFile)offlineResource).getContents());
}
// update the online resource record
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -