📄 cmsvfsdriver.java
字号:
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, res);
}
return propDef;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readPropertyDefinitions(org.opencms.db.CmsDbContext, int)
*/
public List readPropertyDefinitions(CmsDbContext dbc, int projectId) throws CmsDataAccessException {
ArrayList propertyDefinitions = new ArrayList();
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_PROPERTYDEF_READALL");
res = stmt.executeQuery();
while (res.next()) {
propertyDefinitions.add(new CmsPropertyDefinition(
new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_ID"))),
res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_NAME"))));
}
} 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, res);
}
return propertyDefinitions;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readPropertyObject(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsProject, org.opencms.file.CmsResource)
*/
public CmsProperty readPropertyObject(CmsDbContext dbc, String key, CmsProject project, CmsResource resource)
throws CmsDataAccessException {
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
String propertyValue = null;
int mappingType = -1;
CmsProperty property = null;
int resultSize = 0;
String resourceName = resource.getRootPath();
if ((resource.isFolder()) && (!resourceName.endsWith("/"))) {
resourceName += "/";
}
try {
conn = m_sqlManager.getConnection(dbc, project.getId());
stmt = m_sqlManager.getPreparedStatement(conn, project.getId(), "C_PROPERTIES_READ");
stmt.setString(1, key);
stmt.setString(2, resource.getStructureId().toString());
stmt.setString(3, resource.getResourceId().toString());
res = stmt.executeQuery();
while (res.next()) {
if (resultSize >= 2) {
throw new CmsDbConsistencyException(Messages.get().container(
Messages.ERR_TOO_MANY_PROPERTIES_3,
key,
resource.getRootPath(),
new Integer(resultSize)));
}
if (property == null) {
property = new CmsProperty();
property.setName(key);
}
propertyValue = res.getString(1);
mappingType = res.getInt(2);
if (mappingType == CmsProperty.STRUCTURE_RECORD_MAPPING) {
property.setStructureValue(propertyValue);
} else if (mappingType == CmsProperty.RESOURCE_RECORD_MAPPING) {
property.setResourceValue(propertyValue);
} else {
throw new CmsDbConsistencyException(Messages.get().container(
Messages.ERR_UNKNOWN_PROPERTY_VALUE_MAPPING_3,
resource.getRootPath(),
new Integer(mappingType),
key));
}
resultSize++;
}
} 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, res);
}
return (property != null) ? property : CmsProperty.getNullProperty();
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readPropertyObjects(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.file.CmsResource)
*/
public List readPropertyObjects(CmsDbContext dbc, CmsProject project, CmsResource resource)
throws CmsDataAccessException {
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
String propertyKey = null;
String propertyValue = null;
int mappingType = -1;
Map propertyMap = new HashMap();
CmsProperty property = null;
String resourceName = resource.getRootPath();
if ((resource.isFolder()) && (!resourceName.endsWith("/"))) {
resourceName += "/";
}
try {
conn = m_sqlManager.getConnection(dbc, project.getId());
stmt = m_sqlManager.getPreparedStatement(conn, project.getId(), "C_PROPERTIES_READALL");
stmt.setString(1, resource.getStructureId().toString());
stmt.setString(2, resource.getResourceId().toString());
res = stmt.executeQuery();
while (res.next()) {
propertyKey = null;
propertyValue = null;
mappingType = -1;
propertyKey = res.getString(1);
propertyValue = res.getString(2);
mappingType = res.getInt(3);
property = (CmsProperty)propertyMap.get(propertyKey);
if (property == null) {
// there doesn't exist a property object for this key yet
property = new CmsProperty();
property.setName(propertyKey);
propertyMap.put(propertyKey, property);
}
if (mappingType == CmsProperty.STRUCTURE_RECORD_MAPPING) {
// this property value is mapped to a structure record
property.setStructureValue(propertyValue);
} else if (mappingType == CmsProperty.RESOURCE_RECORD_MAPPING) {
// this property value is mapped to a resource record
property.setResourceValue(propertyValue);
} else {
throw new CmsDbConsistencyException(Messages.get().container(
Messages.ERR_UNKNOWN_PROPERTY_VALUE_MAPPING_3,
resource.getRootPath(),
new Integer(mappingType),
propertyKey));
}
}
} 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, res);
}
return new ArrayList(propertyMap.values());
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readResource(org.opencms.db.CmsDbContext, int, org.opencms.util.CmsUUID, boolean)
*/
public CmsResource readResource(CmsDbContext dbc, int projectId, CmsUUID structureId, boolean includeDeleted)
throws CmsDataAccessException {
CmsResource resource = null;
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc, projectId);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_READBYID");
stmt.setString(1, structureId.toString());
res = stmt.executeQuery();
if (res.next()) {
resource = createResource(res, projectId);
while (res.next()) {
// do nothing only move through all rows because of mssql odbc driver
}
} else {
throw new CmsVfsResourceNotFoundException(Messages.get().container(
Messages.ERR_READ_RESOURCE_WITH_ID_1,
structureId));
}
} 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, res);
}
// check if this resource is marked as deleted and if we are allowed to return a deleted resource
if (resource != null && resource.getState() == org.opencms.file.CmsResource.STATE_DELETED && !includeDeleted) {
throw new CmsVfsException(Messages.get().container(
Messages.ERR_READ_DELETED_RESOURCE_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
return resource;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readResource(org.opencms.db.CmsDbContext, int, java.lang.String, boolean)
*/
public CmsResource readResource(CmsDbContext dbc, int projectId, String path, boolean includeDeleted)
throws CmsDataAccessException {
CmsResource resource = null;
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
// must remove trailing slash
path = removeTrailingSeparator(path);
try {
conn = m_sqlManager.getConnection(dbc, projectId);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_READ");
stmt.setString(1, path);
res = stmt.executeQuery();
if (res.next()) {
resource = createResource(res, projectId);
while (res.next()) {
// do nothing only move through all rows because of mssql odbc driver
}
} else {
throw new CmsVfsResourceNotFoundException(Messages.get().container(
Messages.ERR_READ_RESOURCE_1,
dbc.removeSiteRoot(path)));
}
} 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, res);
}
// check if this resource is marked as deleted and if we are allowed to return a deleted resource
if (resource != null && resource.getState() == CmsResource.STATE_DELETED && !includeDeleted) {
throw new CmsVfsResourceNotFoundException(Messages.get().container(
Messages.ERR_READ_DELETED_RESOURCE_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
return resource;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readResources(org.opencms.db.CmsDbContext, int, int, int)
*/
public List readResources(CmsDbContext dbc, int projectId, int state, int mode) throws CmsDataAccessException {
List result = new ArrayList();
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc, projectId);
if (mode == CmsDriverManager.READMODE_MATCHSTATE) {
stmt = m_sqlManager.getPreparedStatement(
conn,
projectId,
"C_RESOURCES_GET_RESOURCE_IN_PROJECT_WITH_STATE");
stmt.setInt(1, projectId);
stmt.setInt(2, state);
stmt.setInt(3, state);
stmt.setInt(4, state);
stmt.setInt(5, state);
} else i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -