⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsbackupdriver.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    public int readBackupProjectTag(CmsDbContext dbc, long maxdate) throws CmsDataAccessException {

        ResultSet res = null;
        PreparedStatement stmt = null;
        Connection conn = null;
        int maxVersion = 0;

        try {
            conn = m_sqlManager.getConnection(dbc);
            stmt = m_sqlManager.getPreparedStatement(conn, "C_BACKUP_READ_MAXVERSION");
            stmt.setTimestamp(1, new Timestamp(maxdate));
            res = stmt.executeQuery();
            if (res.next()) {
                maxVersion = res.getInt(1);
            }
        } 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 maxVersion;
    }

    /** 
     * @see org.opencms.db.I_CmsBackupDriver#readBackupProperties(org.opencms.db.CmsDbContext, org.opencms.file.CmsBackupResource)
     */
    public List readBackupProperties(CmsDbContext dbc, CmsBackupResource 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;

        try {
            conn = m_sqlManager.getConnection(dbc);
            stmt = m_sqlManager.getPreparedStatement(conn, "C_PROPERTIES_READALL_BACKUP");
            stmt.setString(1, resource.getStructureId().toString());
            stmt.setString(2, resource.getResourceId().toString());
            stmt.setInt(3, resource.getTagId());
            res = stmt.executeQuery();

            while (res.next()) {
                propertyKey = res.getString(1);
                propertyValue = res.getString(2);
                mappingType = res.getInt(3);

                property = (CmsProperty)propertyMap.get(propertyKey);
                if (property != null) {
                    // there exists already a property for this key in the result

                    switch (mappingType) {
                        case CmsProperty.STRUCTURE_RECORD_MAPPING:
                            // this property value is mapped to a structure record
                            property.setStructureValue(propertyValue);
                            break;
                        case CmsProperty.RESOURCE_RECORD_MAPPING:
                            // this property value is mapped to a resource record
                            property.setResourceValue(propertyValue);
                            break;
                        default:
                            throw new CmsDbConsistencyException(Messages.get().container(
                                Messages.ERR_UNKNOWN_PROPERTY_VALUE_MAPPING_3,
                                resource.getRootPath(),
                                new Integer(mappingType),
                                propertyKey));
                    }
                } else {
                    // there doesn't exist a property for this key yet
                    property = new CmsProperty();
                    property.setName(propertyKey);

                    switch (mappingType) {
                        case CmsProperty.STRUCTURE_RECORD_MAPPING:
                            // this property value is mapped to a structure record
                            property.setStructureValue(propertyValue);
                            property.setResourceValue(null);
                            break;
                        case CmsProperty.RESOURCE_RECORD_MAPPING:
                            // this property value is mapped to a resource record
                            property.setStructureValue(null);
                            property.setResourceValue(propertyValue);
                            break;
                        default:
                            throw new CmsDbConsistencyException(Messages.get().container(
                                Messages.ERR_UNKNOWN_PROPERTY_VALUE_MAPPING_3,
                                resource.getRootPath(),
                                new Integer(mappingType),
                                propertyKey));
                    }

                    propertyMap.put(propertyKey, property);
                }
            }
        } 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_CmsBackupDriver#readBackupPropertyDefinition(org.opencms.db.CmsDbContext, java.lang.String)
     */
    public CmsPropertyDefinition readBackupPropertyDefinition(CmsDbContext dbc, String name)
    throws CmsDataAccessException {

        CmsPropertyDefinition propDef = null;
        ResultSet res = null;
        PreparedStatement stmt = null;
        Connection conn = null;

        try {
            conn = m_sqlManager.getConnection(dbc);
            stmt = m_sqlManager.getPreparedStatement(conn, "C_PROPERTYDEF_READ_BACKUP");
            stmt.setString(1, name);
            res = stmt.executeQuery();

            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,
                CmsDbSqlException.getErrorQuery(stmt)), e);
        } finally {
            m_sqlManager.closeAll(dbc, conn, stmt, res);
        }

        return propDef;
    }

    /**
     * @see org.opencms.db.I_CmsBackupDriver#readMaxTagId(org.opencms.db.CmsDbContext, org.opencms.file.CmsResource)
     */
    public int readMaxTagId(CmsDbContext dbc, CmsResource resource) throws CmsDataAccessException {

        PreparedStatement stmt = null;
        Connection conn = null;
        ResultSet res = null;
        int result = 0;

        try {
            conn = m_sqlManager.getConnection(dbc);
            stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_READ_MAX_PUBLISH_TAG");
            stmt.setString(1, resource.getResourceId().toString());
            res = stmt.executeQuery();

            if (res.next()) {
                result = res.getInt(1);
            }
        } 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 result;
    }

    /**
     * @see org.opencms.db.I_CmsBackupDriver#readNextBackupTagId(org.opencms.db.CmsDbContext)
     */
    public int readNextBackupTagId(CmsDbContext dbc) {

        PreparedStatement stmt = null;
        Connection conn = null;
        ResultSet res = null;
        int projectBackupTagId = 1;
        int resourceBackupTagId = 1;

        try {
            // get the max version id
            conn = m_sqlManager.getConnection(dbc);
            stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_BACKUP_MAXTAG");
            res = stmt.executeQuery();

            if (res.next()) {
                projectBackupTagId = res.getInt(1) + 1;
            }

            m_sqlManager.closeAll(dbc, null, stmt, res);

            stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_BACKUP_MAXTAG_RESOURCE");
            res = stmt.executeQuery();

            if (res.next()) {
                resourceBackupTagId = res.getInt(1) + 1;
            }

            if (resourceBackupTagId > projectBackupTagId) {
                projectBackupTagId = resourceBackupTagId;
            }
        } catch (SQLException exc) {
            return 1;
        } finally {
            m_sqlManager.closeAll(dbc, conn, stmt, res);
        }

        return projectBackupTagId;
    }

    /**
     * @see org.opencms.db.I_CmsBackupDriver#writeBackupProject(org.opencms.db.CmsDbContext, int, long)
     */
    public void writeBackupProject(CmsDbContext dbc, int tagId, long publishDate) throws CmsDataAccessException {

        Connection conn = null;
        PreparedStatement stmt = null;
        String group = null;
        String managerGroup = null;

        CmsProject currentProject = dbc.currentProject();
        CmsUser currentUser = dbc.currentUser();

        CmsUser owner = m_driverManager.getUserDriver().readUser(dbc, currentProject.getOwnerId());

        StringBuffer buf = new StringBuffer();
        buf.append(owner.getName()).append(" ").append(owner.getFirstname()).append(" ").append(owner.getLastname());
        String ownerName = buf.toString();

        try {
            group = m_driverManager.getUserDriver().readGroup(dbc, currentProject.getGroupId()).getName();
        } catch (CmsDbEntryNotFoundException e) {
            // the group could not be read
            group = "";
        }

        try {
            managerGroup = m_driverManager.getUserDriver().readGroup(dbc, currentProject.getManagerGroupId()).getName();
        } catch (CmsDbEntryNotFoundException e) {
            // the group could not be read
            managerGroup = "";
        }

        List projectresources = m_driverManager.getProjectDriver().readProjectResources(dbc, currentProject);

        // write backup project to the database
        try {
            conn = m_sqlManager.getConnection(dbc);

            stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_CREATE_BACKUP");
            // first write the project
            stmt.setInt(1, tagId);
            stmt.setInt(2, currentProject.getId());
            stmt.setString(3, currentProject.getName());
            stmt.setTimestamp(4, new Timestamp(publishDate));
            stmt.setString(5, currentUser.getId().toString());
            stmt.setString(6, currentUser.getName()
                + " "
                + currentUser.getFirstname()
                + " "
                + currentUser.getLastname());
            stmt.setString(7, currentProject.getOwnerId().toString());
            stmt.setString(8, ownerName);
            stmt.setString(9, currentProject.getGroupId().toString());
            stmt.setString(10, group);
            stmt.setString(11, currentProject.getManagerGroupId().toString());
            stmt.setString(12, managerGroup);
            stmt.setString(13, currentProject.getDescription());
            stmt.setLong(14, currentProject.getDateCreated());
            stmt.setInt(15, currentProject.getType());
            stmt.setInt(16, currentProject.getTaskId());
            stmt.executeUpdate();

            m_sqlManager.closeAll(dbc, null, stmt, null);

            // now write the projectresources
            stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_CREATE_BACKUP");
            Iterator i = projectresources.iterator();
            while (i.hasNext()) {
                stmt.setInt(1, tagId);
                stmt.setInt(2, currentProject.getId());
                stmt.setString(3, (String)i.next());
                stmt.executeUpdate();
                stmt.clearParameters();
            }
        } 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_CmsBackupDriver#writeBackupProperties(org.opencms.db.CmsDbContext, org.opencms.file.CmsResource, java.util.List, org.opencms.util.CmsUUID, int, int)
     */
    public void writeBackupProperties(
        CmsDbContext dbc,
        CmsResource resource,
        List properties,
        CmsUUID backupId,
        int tagId,
        int versionId) throws CmsDataAccessException {

        Connection conn = null;
        PreparedStatement stmt = null;
        String propDefName = null;
        CmsProperty property = null;
        int mappingType = -1;
        String value = null;
        CmsUUID id = null;
        CmsPropertyDefinition propDef = null;

        try {
            conn = m_sqlManager.getConnection(dbc);

            Iterator dummy = properties.iterator();
            while (dummy.hasNext()) {
                property = (CmsProperty)dummy.next();
                propDefName = property.getName();
                propDef = readBackupPropertyDefinition(dbc, propDefName);

                for (int i = 0; i < 2; i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -