📄 cmsvfsdriver.java
字号:
stmt = m_sqlManager.getPreparedStatement(conn, onlineProject, "C_RESOURCES_UPDATE_RESOURCES");
stmt.setInt(1, offlineResource.getTypeId());
stmt.setInt(2, offlineResource.getFlags());
stmt.setLong(3, offlineResource.getDateLastModified());
stmt.setString(4, offlineResource.getUserLastModified().toString());
stmt.setInt(5, CmsResource.STATE_UNCHANGED);
stmt.setInt(6, resourceSize);
stmt.setInt(7, offlineResource.getProjectLastModified());
stmt.setInt(8, this.internalCountSiblings(dbc, onlineProject.getId(), onlineResource.getResourceId()));
stmt.setString(9, offlineResource.getResourceId().toString());
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
// read the parent id
String parentId = internalReadParentId(dbc, onlineProject.getId(), resourcePath);
// update the online structure record
stmt = m_sqlManager.getPreparedStatement(conn, onlineProject, "C_RESOURCES_UPDATE_STRUCTURE");
stmt.setString(1, offlineResource.getResourceId().toString());
stmt.setString(2, resourcePath);
stmt.setInt(3, CmsResource.STATE_UNCHANGED);
stmt.setLong(4, offlineResource.getDateReleased());
stmt.setLong(5, offlineResource.getDateExpired());
stmt.setString(6, parentId);
stmt.setString(7, offlineResource.getStructureId().toString());
stmt.executeUpdate();
} else {
// the resource record does NOT exist online yet
if (writeFileContent && offlineResource.isFile()) {
// create the file content online
resourceSize = offlineResource.getLength();
createContent(
dbc,
onlineProject,
offlineResource.getResourceId(),
((CmsFile)offlineResource).getContents(),
0);
}
// create the resource record online
stmt = m_sqlManager.getPreparedStatement(conn, onlineProject, "C_RESOURCES_WRITE");
stmt.setString(1, offlineResource.getResourceId().toString());
stmt.setInt(2, offlineResource.getTypeId());
stmt.setInt(3, offlineResource.getFlags());
stmt.setLong(4, offlineResource.getDateCreated());
stmt.setString(5, offlineResource.getUserCreated().toString());
stmt.setLong(6, offlineResource.getDateLastModified());
stmt.setString(7, offlineResource.getUserLastModified().toString());
stmt.setInt(8, CmsResource.STATE_UNCHANGED);
stmt.setInt(9, resourceSize);
stmt.setInt(10, offlineResource.getProjectLastModified());
stmt.setInt(11, 1);
stmt.executeUpdate();
m_sqlManager.closeAll(dbc, null, stmt, null);
// read the parent id
String parentId = internalReadParentId(dbc, onlineProject.getId(), resourcePath);
// create the structure record online
stmt = m_sqlManager.getPreparedStatement(conn, onlineProject, "C_STRUCTURE_WRITE");
stmt.setString(1, offlineResource.getStructureId().toString());
stmt.setString(2, offlineResource.getResourceId().toString());
stmt.setString(3, resourcePath);
stmt.setInt(4, CmsResource.STATE_UNCHANGED);
stmt.setLong(5, offlineResource.getDateReleased());
stmt.setLong(6, offlineResource.getDateExpired());
stmt.setString(7, parentId);
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#readChildResources(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.file.CmsResource, boolean, boolean)
*/
public List readChildResources(
CmsDbContext dbc,
CmsProject currentProject,
CmsResource resource,
boolean getFolders,
boolean getFiles) throws CmsDataAccessException {
List result = new ArrayList();
int projectId = currentProject.getId();
String resourceTypeClause;
if (getFolders && getFiles) {
resourceTypeClause = null;
} else if (getFolders) {
resourceTypeClause = m_sqlManager.readQuery(projectId, "C_RESOURCES_GET_SUBRESOURCES_GET_FOLDERS");
} else {
resourceTypeClause = m_sqlManager.readQuery(projectId, "C_RESOURCES_GET_SUBRESOURCES_GET_FILES");
}
StringBuffer query = new StringBuffer();
query.append(m_sqlManager.readQuery(projectId, "C_RESOURCES_GET_SUBRESOURCES"));
if (resourceTypeClause != null) {
query.append(' ');
query.append(resourceTypeClause);
}
String typeColumn = m_sqlManager.readQuery("C_RESOURCES_RESOURCE_TYPE");
Connection conn = null;
PreparedStatement stmt = null;
ResultSet res = null;
try {
conn = m_sqlManager.getConnection(dbc, currentProject.getId());
stmt = m_sqlManager.getPreparedStatementForSql(conn, query.toString());
stmt.setString(1, resource.getStructureId().toString());
res = stmt.executeQuery();
while (res.next()) {
int type = res.getInt(typeColumn);
if (CmsFolder.isFolderType(type)) {
result.add(createFolder(res, projectId, false));
} else {
result.add(createFile(res, projectId, false));
}
}
} 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);
}
// sort result in memory, this is to avoid DB dependencies in the result order
Collections.sort(result, CmsResource.COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST);
return result;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readFile(org.opencms.db.CmsDbContext, int, boolean, org.opencms.util.CmsUUID)
*/
public CmsFile readFile(CmsDbContext dbc, int projectId, boolean includeDeleted, CmsUUID structureId)
throws CmsDataAccessException {
CmsFile file = null;
PreparedStatement stmt = null;
ResultSet res = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc, projectId);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_FILES_READ");
stmt.setString(1, structureId.toString());
res = stmt.executeQuery();
if (res.next()) {
file = createFile(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_FILE_WITH_STRUCTURE_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 (file != null && file.getState() == org.opencms.file.CmsResource.STATE_DELETED && !includeDeleted) {
throw new CmsVfsException(Messages.get().container(
Messages.ERR_READ_DELETED_FILE_1,
dbc.removeSiteRoot(file.getRootPath())));
}
return file;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readFolder(org.opencms.db.CmsDbContext, int, org.opencms.util.CmsUUID)
*/
public CmsFolder readFolder(CmsDbContext dbc, int projectId, CmsUUID folderId) throws CmsDataAccessException {
CmsFolder folder = 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, folderId.toString());
res = stmt.executeQuery();
if (res.next()) {
folder = createFolder(res, projectId, true);
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_FOLDER_WITH_ID_1,
folderId));
}
} 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 folder;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readFolder(org.opencms.db.CmsDbContext, int, java.lang.String)
*/
public CmsFolder readFolder(CmsDbContext dbc, int projectId, String folderPath) throws CmsDataAccessException {
CmsFolder folder = null;
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
folderPath = removeTrailingSeparator(folderPath);
try {
conn = m_sqlManager.getConnection(dbc, projectId);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_READ");
stmt.setString(1, folderPath);
res = stmt.executeQuery();
if (res.next()) {
folder = createFolder(res, projectId, true);
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_FOLDER_1,
dbc.removeSiteRoot(folderPath)));
}
} 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 folder;
}
/**
* @see org.opencms.db.I_CmsVfsDriver#readPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String, int)
*/
public CmsPropertyDefinition readPropertyDefinition(CmsDbContext dbc, String name, int projectId)
throws CmsDataAccessException {
CmsPropertyDefinition propDef = null;
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc, projectId);
stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_PROPERTYDEF_READ");
stmt.setString(1, name);
res = stmt.executeQuery();
// if resultset exists - return it
if (res.next()) {
propDef = new CmsPropertyDefinition(
new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_ID"))),
res.getString(m_sqlManager.readQuery("C_PROPERTYDEF_NAME")));
} else {
throw new CmsDbEntryNotFoundException(Messages.get().container(
Messages.ERR_NO_PROPERTYDEF_WITH_NAME_1,
name));
}
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -