cmsvfsdriver.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,400 行 · 第 1/5 页
JAVA
1,400 行
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
repairBrokenRelations(dbc, project.getUuid(), resource.getStructureId(), resource.getRootPath());
}
/**
* @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, CmsUUID.getOpenCmsUUID()) != 0)) { // HACK: to get an offline project
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 property definition
stmt = m_sqlManager.getPreparedStatement(conn, CmsUUID.getOpenCmsUUID(), "C_PROPERTYDEF_DELETE"); // HACK: to get an offline project
} else {
// delete the online property definition
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, CmsUUID, org.opencms.file.CmsResource, int)
*/
public void deletePropertyObjects(CmsDbContext dbc, CmsUUID projectId, CmsResource resource, int deleteOption)
throws CmsDataAccessException {
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = m_sqlManager.getConnection(dbc);
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);
} else {
throw new CmsDataAccessException(Messages.get().container(Messages.ERR_INVALID_DELETE_OPTION_1));
}
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#deleteRelations(org.opencms.db.CmsDbContext, CmsUUID, CmsResource, org.opencms.relations.CmsRelationFilter)
*/
public void deleteRelations(CmsDbContext dbc, CmsUUID projectId, CmsResource resource, CmsRelationFilter filter)
throws CmsDataAccessException {
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = m_sqlManager.getConnection(dbc);
if (filter.isSource()) {
List params = new ArrayList(7);
StringBuffer queryBuf = new StringBuffer(256);
queryBuf.append(m_sqlManager.readQuery(projectId, "C_DELETE_RELATIONS"));
queryBuf.append(prepareRelationConditions(projectId, filter, resource, params, true));
stmt = m_sqlManager.getPreparedStatementForSql(conn, queryBuf.toString());
for (int i = 0; i < params.size(); i++) {
stmt.setString(i + 1, (String)params.get(i));
}
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
}
if (filter.isTarget()) {
List params = new ArrayList(7);
StringBuffer queryBuf = new StringBuffer(256);
queryBuf.append(m_sqlManager.readQuery(projectId, "C_DELETE_RELATIONS"));
queryBuf.append(prepareRelationConditions(projectId, filter, resource, params, false));
stmt = m_sqlManager.getPreparedStatementForSql(conn, queryBuf.toString());
for (int i = 0; i < params.size(); i++) {
stmt.setString(i + 1, (String)params.get(i));
}
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);
}
// update broken remaining relations
updateBrokenRelations(dbc, projectId, resource.getRootPath());
}
/**
* @see org.opencms.db.I_CmsVfsDriver#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_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#moveResource(CmsDbContext, CmsUUID, CmsResource, String)
*/
public void moveResource(CmsDbContext dbc, CmsUUID projectId, CmsResource source, String destinationPath)
throws CmsDataAccessException {
// do not allow to move a resource into an as deleted marked folder
CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION;
if (projectId.equals(CmsProject.ONLINE_PROJECT_ID)) {
// does not matter online
filter = CmsResourceFilter.ALL;
}
// determine destination folder
String destinationFoldername = CmsResource.getParentFolder(destinationPath);
// read the destination folder (will also check read permissions)
CmsFolder destinationFolder = m_driverManager.readFolder(dbc, destinationFoldername, filter);
if (!projectId.equals(CmsProject.ONLINE_PROJECT_ID)) {
// check online resource
try {
CmsResource onlineResource = m_driverManager.getVfsDriver().readResource(
dbc,
CmsProject.ONLINE_PROJECT_ID,
destinationPath,
true);
if (!onlineResource.getStructureId().equals(source.getStructureId())) {
// source resource has been moved and it is not the
// same as the resource that is being trying to move back
CmsResource offlineResource = null;
try {
// read new location in offline project
offlineResource = readResource(
dbc,
dbc.getRequestContext().currentProject().getUuid(),
onlineResource.getStructureId(),
true);
} catch (CmsException e) {
// should never happen
if (LOG.isErrorEnabled()) {
LOG.error(e.getMessage(), e);
}
}
throw new CmsVfsOnlineResourceAlreadyExistsException(Messages.get().container(
Messages.ERR_OVERWRITE_MOVED_RESOURCE_3,
dbc.removeSiteRoot(source.getRootPath()),
dbc.removeSiteRoot(destinationPath),
dbc.removeSiteRoot(offlineResource == null ? "__ERROR__" : offlineResource.getRootPath())));
}
} catch (CmsVfsResourceNotFoundException e) {
// ok, no online resource
}
}
Connection conn = null;
PreparedStatement stmt = null;
ResultSet res = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_MOVE");
stmt.setString(1, CmsFileUtil.removeTrailingSeparator(destinationPath)); // must remove trailing slash
stmt.setString(2, destinationFolder.getStructureId().toString());
stmt.setString(3, source.getStructureId().toString());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?