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

📄 cmsdbaccess.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            statement.setTimestamp(9, new Timestamp(lastlogin));
            statement.setTimestamp(10, new Timestamp(lastused));
            statement.setInt(11, flags);
            //statement.setBytes(12,value);
            statement.setInt(12, defaultGroup.getId());
            statement.setString(13, checkNull(address));
            statement.setString(14, checkNull(section));
            statement.setInt(15, type);
            statement.executeUpdate();
            statement.close();
            // now update user_info of the new user
            statement2 = con.prepareStatement(cq.get("C_PLSQL_USERSFORUPDATE"));
            statement2.setInt(1, id);
            con.setAutoCommit(false);
            res = statement2.executeQuery();
            while (res.next()) {
                oracle.sql.BLOB blob = ((OracleResultSet) res).getBLOB("USER_INFO");
                ByteArrayInputStream instream = new ByteArrayInputStream(value);
                OutputStream outstream = blob.getBinaryOutputStream();
                byte[] chunk = new byte[blob.getChunkSize()];
                int i = -1;
                while ((i = instream.read(chunk)) != -1) {
                    outstream.write(chunk, 0, i);
                }
                instream.close();
                outstream.close();
            }
            statement2.close();
            res.close();
            // for the oracle-driver commit or rollback must be executed manually
            // because setAutoCommit = false in CmsDbPool.CmsDbPool
            nextStatement = con.prepareStatement(cq.get("C_COMMIT"));
            nextStatement.execute();
            nextStatement.close();
            con.setAutoCommit(true);
        } catch (SQLException e) {
            throw new CmsException("[" + this.getClass().getName() + "]" + e.getMessage(), CmsException.C_SQL_ERROR, e);
        } catch (IOException e) {
            throw new CmsException("[CmsAccessUserInfoMySql/addUserInformation(id,object)]:" + CmsException.C_SERIALIZATION, e);
        } finally {
            if (res != null) {
                try {
                    res.close();
                } catch (SQLException se) {
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException exc){
                }
            }
            if (statement2 != null) {
                try {
                    statement2.close();
                } catch (SQLException exc){
                }
                try {
                    nextStatement = con.prepareStatement(cq.get("C_ROLLBACK"));
                    nextStatement.execute();
                } catch (SQLException se) {
                }
            }
            if (nextStatement != null) {
                try {
                    nextStatement.close();
                } catch (SQLException exc){
                }
            }
            if (con != null) {
                try {
                    con.setAutoCommit(true);
                } catch (SQLException se) {
                }
                try {
                    con.close();
                } catch (SQLException e) {
                }
            }
        }
        return readUser(id);
    }

    /**
     * Copies the file.
     *
     * @param project The project in which the resource will be used.
     * @param onlineProject The online project of the OpenCms.
     * @param userId The id of the user who wants to copy the file.
     * @param source The complete path of the sourcefile.
     * @param parentId The parentId of the resource.
     * @param destination The complete path of the destinationfile.
     *
     * @exception CmsException Throws CmsException if operation was not succesful.
     */
    public void copyFile(CmsProject project, int userId, String source, String destination) throws CmsException {
        //System.out.println("PL/SQL: copyFile");
        if (destination.length() > C_MAX_LENGTH_RESOURCE_NAME){
            throw new CmsException("["+this.getClass().getName()+"] "+"Resourcename too long(>"+C_MAX_LENGTH_RESOURCE_NAME+") ",CmsException.C_BAD_NAME);
        }

        com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
        CallableStatement statement = null;
        Connection con = null;
        try {
            // create the statement
            con = DriverManager.getConnection(m_poolName);
            statement = con.prepareCall(cq.get("C_PLSQL_RESOURCES_COPYFILE"));
            statement.setInt(1, project.getId());
            statement.setInt(2, userId);
            statement.setString(3, source);
            statement.setString(4, destination);
            statement.execute();
        } catch (SQLException sqlexc) {
            CmsException cmsException = getCmsException("[" + this.getClass().getName() + "] ", sqlexc);
            throw cmsException;
        } catch (Exception e) {
            throw new CmsException("[" + this.getClass().getName() + "]", e);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException exc) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                }
            }
        }
    }
    // methods working with resources

/**
 * Creates a new file with the given content and resourcetype.
 *
 * @param user The user who wants to create the file.
 * @param project The project in which the resource will be used.
 * @param onlineProject The online project of the OpenCms.
 * @param filename The complete name of the new file (including pathinformation).
 * @param flags The flags of this resource.
 * @param parentId The parentId of the resource.
 * @param contents The contents of the new file.
 * @param resourceType The resourceType of the new file.
 *
 * @return file The created file.
 *
 * @exception CmsException Throws CmsException if operation was not succesful
 */
public CmsFile createFile(CmsUser user, CmsProject project, CmsProject onlineProject, String filename, int flags, int parentId, byte[] contents, I_CmsResourceType resourceType) throws CmsException {
    //System.out.println("PL/SQL: createFile");
    if (filename.length() > C_MAX_LENGTH_RESOURCE_NAME){
        throw new CmsException("["+this.getClass().getName()+"] "+"Resourcename too long(>"+C_MAX_LENGTH_RESOURCE_NAME+") ",CmsException.C_BAD_NAME);
    }

    com.opencms.file.oracleplsql.CmsQueries cq = (com.opencms.file.oracleplsql.CmsQueries) m_cq;
    // it is not allowed, that there is no content in the file
    // TODO: check if this can be done in another way:
    if (contents.length == 0) {
        contents = " ".getBytes();
    }
    int state = C_STATE_NEW;
    // Test if the file is already there and marked as deleted.
    // If so, delete it
    try {
        CmsResource resource = readFileHeader(project.getId(), filename);
        throw new CmsException("["+this.getClass().getName()+"] ",CmsException.C_FILE_EXISTS);
    } catch (CmsException e) {
        // if the file is maked as deleted remove it!
        if (e.getType()==CmsException.C_RESOURCE_DELETED) {
           removeFile(project.getId(),filename);
           state=C_STATE_CHANGED;
           //throw new CmsException("["+this.getClass().getName()+"] ",CmsException.C_FILE_EXISTS);
        }
        if (e.getType()==CmsException.C_FILE_EXISTS) {
           throw e;
        }
    }
    int resourceId = nextId(m_cq.get("C_TABLE_RESOURCES"));
    int fileId = nextId(m_cq.get("C_TABLE_FILES"));

    PreparedStatement statement = null;
    PreparedStatement statementFileIns = null;
    PreparedStatement statementFileUpd = null;
    PreparedStatement nextStatement = null;
    Connection con = null;
    ResultSet res = null;
    String usedPool;
    String usedStatement;
    if (project.getId() == onlineProject.getId()){
        usedPool = m_poolNameOnline;
        usedStatement = "_ONLINE";
    } else {
        usedPool = m_poolName;
        usedStatement = "";
    }
    try {
        con = DriverManager.getConnection(usedPool);
        statement = con.prepareStatement(m_cq.get("C_RESOURCES_WRITE"+usedStatement));
        // write new resource to the database
        statement.setInt(1, resourceId);
        statement.setInt(2, parentId);
        statement.setString(3, filename);
        statement.setInt(4, resourceType.getResourceType());
        statement.setInt(5, flags);
        statement.setInt(6, user.getId());
        statement.setInt(7, user.getDefaultGroupId());
        statement.setInt(8, project.getId());
        statement.setInt(9, fileId);
        statement.setInt(10, C_ACCESS_DEFAULT_FLAGS);
        statement.setInt(11, state);
        statement.setInt(12, C_UNKNOWN_ID);
        statement.setInt(13, resourceType.getLauncherType());
        statement.setString(14, resourceType.getLauncherClass());
        statement.setTimestamp(15, new Timestamp(System.currentTimeMillis()));
        statement.setTimestamp(16, new Timestamp(System.currentTimeMillis()));
        statement.setInt(17, contents.length);
        statement.setInt(18, user.getId());
        statement.executeUpdate();
        statement.close();
        // first insert new file without file_content, then update the file_content
        // these two steps are necessary because of using BLOBs in the Oracle DB
        statementFileIns = con.prepareStatement(cq.get("C_PLSQL_FILESFORINSERT"+usedStatement));
        statementFileIns.setInt(1, fileId);
        statementFileIns.executeUpdate();
        statementFileIns.close();
        // update the file content in the FILES database.
        statementFileUpd = con.prepareStatement(cq.get("C_PLSQL_FILESFORUPDATE"+usedStatement));
        statementFileUpd.setInt(1, fileId);
        con.setAutoCommit(false);
        res = statementFileUpd.executeQuery();
        try {
            while (res.next()) {
                oracle.sql.BLOB blobnew = ((OracleResultSet) res).getBLOB("FILE_CONTENT");
                ByteArrayInputStream instream = new ByteArrayInputStream(contents);
                OutputStream outstream = blobnew.getBinaryOutputStream();
                byte[] chunk = new byte[blobnew.getChunkSize()];
                int i = -1;
                while ((i = instream.read(chunk)) != -1) {
                    outstream.write(chunk, 0, i);
                }
                instream.close();
                outstream.close();
            }
            // for the oracle-driver commit or rollback must be executed manually
            // because setAutoCommit = false
            nextStatement = con.prepareStatement(cq.get("C_COMMIT"));
            nextStatement.execute();
            nextStatement.close();
            con.setAutoCommit(true);
        } catch (IOException e) {
            throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage(), e);
        }
        statementFileUpd.close();
        res.close();
    } catch (SQLException e) {
        throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage(), CmsException.C_SQL_ERROR, e);
    } finally {
        if (res != null) {
            try {
                res.close();
            } catch (SQLException se) {
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException exc){
            }
        }
        if (statementFileIns != null) {
            try {
                statementFileIns.close();
            } catch (SQLException exc) {
            }
        }
        if (statementFileUpd != null) {
            try {
                statementFileUpd.close();
            } catch (SQLException exc) {
            }
            try {
                nextStatement = con.prepareStatement(cq.get("C_ROLLBACK"));
                nextStatement.execute();
            } catch (SQLException se) {
            }
        }
        if (nextStatement != null) {
            try {
                nextStatement.close();
            } catch (SQLException exc) {
            }
        }
        if (con != null) {
            try {
                con.setAutoCommit(true);
            } catch (SQLException se) {
            }
            try {
                con.close();
            } catch (SQLException e){
            }
        }
    }
    return readFile(project.getId(), onlineProject.getId(), filename);
}

⌨️ 快捷键说明

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