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

📄 cmsdbaccess.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    statement.close();
                } catch (SQLException e){
                }
            }
            if (con != null){
                try{
                    con.close();
                } catch (SQLException e){
                }
            }
        }
    }

    /**
     * Add a new group to the Cms.<BR/>
     *
     * Only the admin can do this.<P/>
     *
     * @param name The name of the new group.
     * @param description The description for the new group.
     * @int flags The flags for the new group.
     * @param name The name of the parent group (or null).
     *
     * @return Group
     *
     * @exception CmsException Throws CmsException if operation was not succesfull.
     */
     public CmsGroup createGroup(String name, String description, int flags,String parent)
         throws CmsException {

         int parentId=C_UNKNOWN_ID;
         CmsGroup group=null;

        Connection con = null;
       PreparedStatement statement = null;

         try{

            // get the id of the parent group if nescessary
            if ((parent != null) && (!"".equals(parent))) {
                parentId=readGroup(parent).getId();
            }

            con = DriverManager.getConnection(m_poolName);
            // create statement
            statement=con.prepareStatement(m_cq.get("C_GROUPS_CREATEGROUP"));

            // write new group to the database
            statement.setInt(1,nextId(C_TABLE_GROUPS));
            statement.setInt(2,parentId);
            statement.setString(3,name);
            statement.setString(4,checkNull(description));
            statement.setInt(5,flags);
            statement.executeUpdate();

            // create the user group by reading it from the database.
            // this is nescessary to get the group id which is generated in the
            // database.
            group=readGroup(name);
         } catch (SQLException e){
              throw new CmsException("[" + this.getClass().getName() + "] "+e.getMessage(),CmsException.C_SQL_ERROR, e);
        } finally {
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
         }
         return group;
     }

     /**
     * Creates a project.
     *
     * @param owner The owner of this project.
     * @param group The group for this project.
     * @param managergroup The managergroup for this project.
     * @param task The task.
     * @param name The name of the project to create.
     * @param description The description for the new project.
     * @param flags The flags for the project (e.g. archive).
     * @param type the type for the project (e.g. normal).
     *
     * @exception CmsException Throws CmsException if something goes wrong.
     */
    public CmsProject createProject(CmsUser owner, CmsGroup group, CmsGroup managergroup,
                                    CmsTask task, String name, String description,
                                    int flags, int type)
        throws CmsException {


        if ((description==null) || (description.length()<1)) {
            description=" ";
        }

        Timestamp createTime = new Timestamp(new java.util.Date().getTime());
        Connection con = null;
        PreparedStatement statement = null;

        int id = nextId(C_TABLE_PROJECTS);

        try {
            con = DriverManager.getConnection(m_poolName);

            // write data to database
            statement = con.prepareStatement(m_cq.get("C_PROJECTS_CREATE"));

            statement.setInt(1,id);
            statement.setInt(2,owner.getId());
            statement.setInt(3,group.getId());
            statement.setInt(4,managergroup.getId());
            statement.setInt(5,task.getId());
            statement.setString(6,name);
            statement.setString(7,description);
            statement.setInt(8,flags);
            statement.setTimestamp(9,createTime);
            // no publish data
            //statement.setNull(10,Types.TIMESTAMP);
            //statement.setInt(11,C_UNKNOWN_ID);
            statement.setInt(10,type);
            statement.executeUpdate();
         }
        catch (SQLException e){
            throw new CmsException("["+this.getClass().getName()+"]"+e.getMessage(),CmsException.C_SQL_ERROR, e);
        } finally {
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
        }
        return readProject(id);
    }

    /**
     * Creates the propertydefinitions for the resource type.<BR/>
     *
     * Only the admin can do this.
     *
     * @param name The name of the propertydefinitions to overwrite.
     * @param resourcetype The resource-type for the propertydefinitions.
     * @param type The type of the propertydefinitions (normal|optional)
     *
     * @exception CmsException Throws CmsException if something goes wrong.
     */
    public CmsPropertydefinition createPropertydefinition(String name,
                                                     I_CmsResourceType resourcetype)
        throws CmsException {
        Connection con = null;
        PreparedStatement statement = null;

        try {
            // create the propertydefinition in the offline db
            con = DriverManager.getConnection(m_poolName);
            statement = con.prepareStatement(m_cq.get("C_PROPERTYDEF_CREATE"));
            statement.setInt(1,nextId(m_cq.get("C_TABLE_PROPERTYDEF")));
            statement.setString(2,name);
            statement.setInt(3,resourcetype.getResourceType());
            statement.executeUpdate();
            statement.close();
            con.close();
            // create the propertydefinition in the online db
            con = DriverManager.getConnection(m_poolNameOnline);
            statement = con.prepareStatement(m_cq.get("C_PROPERTYDEF_CREATE_ONLINE"));
            statement.setInt(1,nextId(m_cq.get("C_TABLE_PROPERTYDEF_ONLINE")));
            statement.setString(2,name);
            statement.setInt(3,resourcetype.getResourceType());
            statement.executeUpdate();
            statement.close();
            con.close();
            // create the propertydefinition in the backup db
            con = DriverManager.getConnection(m_poolNameBackup);
            statement = con.prepareStatement(m_cq.get("C_PROPERTYDEF_CREATE_BACKUP"));
            statement.setInt(1,nextId(m_cq.get("C_TABLE_PROPERTYDEF_BACKUP")));
            statement.setString(2,name);
            statement.setInt(3,resourcetype.getResourceType());
            statement.executeUpdate();
            statement.close();
            con.close();
         } catch( SQLException exc ) {
             throw new CmsException("[" + this.getClass().getName() + "] " + exc.getMessage(),
                CmsException.C_SQL_ERROR, exc);
         }finally {
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
          }
         return(readPropertydefinition(name, resourcetype));
    }

   /**
    * Helper method to serialize the hashtable.
    * This method is used by updateSession() and createSession()
    */
    private byte[] serializeSession(Hashtable data) throws IOException {
        // serialize the hashtable
        byte[] value;
        Hashtable sessionData = (Hashtable) data.remove(C_SESSION_DATA);
        StringBuffer notSerializable = new StringBuffer();
        ByteArrayOutputStream bout= new ByteArrayOutputStream();
        ObjectOutputStream oout=new ObjectOutputStream(bout);

        // first write the user data
        oout.writeObject(data);
        if(sessionData != null) {
            Enumeration keys = sessionData.keys();
            while(keys.hasMoreElements()) {
                Object key = keys.nextElement();
                Object sessionValue = sessionData.get(key);
                if( sessionValue instanceof Serializable ) {
                    // this value is serializeable -> write it to the outputstream
                    oout.writeObject(key);
                    oout.writeObject(sessionValue);
                } else {
                    // this object is not serializeable -> remark for warning
                    notSerializable.append(key);
                    notSerializable.append("; ");
                }
            }
        }
        oout.close();
        value=bout.toByteArray();
        if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && (notSerializable.length()>0)) {
            A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsDbAccess] warning, following entrys are not serializeable in the session: " + notSerializable.toString() + ".");
        }
        return value;
    }

    /**
     * This method creates a new session in the database. It is used
     * for sessionfailover.
     *
     * @param sessionId the id of the session.
     * @return data the sessionData.
     */
    public void createSession(String sessionId, Hashtable data)
        throws CmsException {
        byte[] value=null;

        Connection con = null;
        PreparedStatement statement = null;

        try {
                  value = serializeSession(data);

            con = DriverManager.getConnection(m_poolName);

            // write data to database
            statement = con.prepareStatement(m_cq.get("C_SESSION_CREATE"));

            statement.setString(1,sessionId);
            statement.setTimestamp(2,new java.sql.Timestamp(System.currentTimeMillis()));
            statement.setBytes(3,value);
            statement.executeUpdate();
        }
        catch (SQLException e){
            throw new CmsException("["+this.getClass().getName()+"]"+e.getMessage(),CmsException.C_SQL_ERROR, e);
        }
        catch (IOException e){
            throw new CmsException("["+this.getClass().getName()+"]:"+CmsException.C_SERIALIZATION, e);
        } finally {
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
        }
    }

    /**
     * Creates a new task.
     * rootId Id of the root task project
     * parentId Id of the parent task
     * tasktype Type of the task
     * ownerId Id of the owner
     * agentId Id of the agent
     * roleId Id of the role
     * taskname Name of the Task
     * wakeuptime Time when the task will be wake up
     * timeout Time when the task times out
     * priority priority of the task
     *
     * @return The Taskobject  of the generated Task
     *
     * @exception CmsException Throws CmsException if something goes wrong.
     */
    public CmsTask createTask(int rootId, int parentId, int tasktype,
                               int ownerId, int agentId,int  roleId, String taskname,
                               java.sql.Timestamp wakeuptime, java.sql.Timestamp timeout,
                               int priority)
        throws CmsException {
        int newId = C_UNKNOWN_ID;
        CmsTask task = null;
        Connection con = null;
        PreparedStatement statement =

⌨️ 快捷键说明

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