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

📄 jahiapagesdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  JahiaPagesDB//  EV      09.01.2001////  loadPageInfo (pageID)//  createPageInfo (thePage)//  updatePageInfo (thePage)//  deletePageInfo (pageID)//package org.jahia.services.pages;import java.sql.*;import java.util.*;import org.jahia.utils.JahiaConsole;import org.jahia.registries.ServicesRegistry;import org.jahia.exceptions.JahiaException;import org.jahia.services.pages.JahiaPageInfo;import org.jahia.data.FormDataManager;/** * This class contains static methods accessing the database for page * operations. This class is mainly used by the Jahia Page Service. * * @author      Eric Vassalli, Fulco Houkes * @version     1.1 */class JahiaPagesDB{    private static JahiaPagesDB mObject = null;    //-------------------------------------------------------------------------    /**     * Default constructor     */    private JahiaPagesDB () {    }    //-------------------------------------------------------------------------    public static JahiaPagesDB getInstance () {        if (mObject == null) {            mObject = new JahiaPagesDB ();        }        return mObject;    }    //-------------------------------------------------------------------------    /** Loads the page info from the database for the requested page ID.     *  A JahiaPage object is created     *     * @param       pageID      The page unique identification number.     *     * @return  Return a JahiaPage object instance, or null if the page doesn't     *          exist in the database.     *     * @exception   JahiaException     *      Throws a {@link org.jahia.exceptions.JahiaException JahiaException}     *      on any database error.     */    public JahiaPageInfo loadPageInfo (int pageID)        throws JahiaException    {        // get the DB connection        Connection dbConn = getDBConnection (70);        if (dbConn == null) {            return null;        }        JahiaPageInfo pageInfo = null;        Statement statement = null;        try {            String sqlQuery = "SELECT * FROM jahia_pages_data WHERE id_jahia_pages_data=" + pageID;            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement,sqlQuery);                if (rs != null) {                    if (rs.next()) {                        pageInfo = readPageInfoFromResultSet (pageID, rs);                    }                }            }        } catch (SQLException se) {            String errorMsg = "Error in loadPageInfo : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaPagesDB", errorMsg );            throw new JahiaException(   "Cannot load the page values from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        }        finally {            closeDBConnection (dbConn);            closeStatement (statement);        }        return pageInfo;    }    //-------------------------------------------------------------------------    /** Create a new page entry in the database.     *     * @param   thePage The JahiaPage object reference to save. Must be a     *          non-null object reference.     *     * @return  Return true if the page info could be inserted into the     *          database or false on any error.     *     * @exception   JahiaException     *      Throws a {@link org.jahia.exceptions.JahiaException JahiaException}     *      on any database error.     */    public synchronized boolean insertPageInfo (JahiaPageInfo pageInfo)        throws JahiaException    {        // Get the database connection.        Connection dbConn = getDBConnection (71);        if (dbConn == null) {            throw new JahiaException (                    "Page creation error on database access",                    "Cannot create a new page in the database, could not obtain a DB connection.",                    JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        }        boolean result = false;        Statement statement = null;        try {            // opens connection            statement = dbConn.createStatement();            if (statement != null) {                // create the SQL query                String sqlQuery2 = "INSERT INTO jahia_pages_data (id_jahia_pages_data) VALUES ("+pageInfo.getID()+")";                // executes the query                statement.execute (sqlQuery2);                                // composes the query                StringBuffer sqlQuery = new StringBuffer ("UPDATE jahia_pages_data SET ");                sqlQuery.append ("jahiaid_jahia_pages_data = " + pageInfo.getJahiaID() + ",");                sqlQuery.append ("parentid_jahia_pages_data = " + pageInfo.getParentID() + ",");                sqlQuery.append ("pagetype_jahia_pages_data = " + pageInfo.getPageType() + ",");                sqlQuery.append ("title_jahia_pages_data = '" + FormDataManager.getInstance().encode (pageInfo.getTitle()) + "',");                sqlQuery.append ("pagedefid_jahia_pages_data = " + pageInfo.getPageTemplateID() + ",");                sqlQuery.append ("remoteurl_jahia_pages_data = '" + FormDataManager.getInstance().encode (pageInfo.getRemoteURL()) + "',");                sqlQuery.append ("pagelinkid_jahia_pages_data = " + pageInfo.getPageLinkID() + ",");                sqlQuery.append ("creator_jahia_pages_data = '" + pageInfo.getCreator() + "',");                sqlQuery.append ("doc_jahia_pages_data = '" + pageInfo.getDoc() + "',");                sqlQuery.append ("counter_jahia_pages_data = " + pageInfo.getCounter() + ",");                sqlQuery.append ("rights_jahia_pages_data = " + pageInfo.getAclID() + " ");                sqlQuery.append ("WHERE id_jahia_pages_data = " + pageInfo.getID());                // executes the query                statement.execute (sqlQuery.toString());                result = true;                                closeDBConnection (dbConn);                closeStatement (statement);                                // enters values with db_update_page_info                //result = updatePageInfo (pageInfo);            }        } // catches an exception in the query        catch (SQLException se) {            String errorMsg = "Error in createPageInfo : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaPagesDB", errorMsg );            throw new JahiaException(   "Cannot create a new page in the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        }        finally {            closeDBConnection (dbConn);            closeStatement (statement);        }        return result;    }    //-------------------------------------------------------------------------    /** Update the page info in the database.     *     * @param   pageInfo    The Jahiapage object reference to update.     *     * @return  Return true if the page info could be updated in the database,     *          return false on any error.     *     * @exception   JahiaException     *      Throws a {@link org.jahia.exceptions.JahiaException JahiaException}     *      on any database error.     */    public boolean updatePageInfo (JahiaPageInfo pageInfo)        throws JahiaException    {                // Get the database connection.        Connection dbConn = getDBConnection (72);        if (dbConn == null) {            throw new JahiaException (                    "Page update error on database access",                    "Cannot update the requested page in the database, could not obtain a DB connection.",                    JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        }        boolean result = false;        Statement statement = null;        try {            // composes the query            StringBuffer sqlQuery = new StringBuffer ("UPDATE jahia_pages_data SET ");            sqlQuery.append ("jahiaid_jahia_pages_data = " + pageInfo.getJahiaID() + ",");            sqlQuery.append ("parentid_jahia_pages_data = " + pageInfo.getParentID() + ",");            sqlQuery.append ("pagetype_jahia_pages_data = " + pageInfo.getPageType() + ",");            sqlQuery.append ("title_jahia_pages_data = '" + FormDataManager.getInstance().encode (pageInfo.getTitle()) + "',");            sqlQuery.append ("pagedefid_jahia_pages_data = " + pageInfo.getPageTemplateID() + ",");            sqlQuery.append ("remoteurl_jahia_pages_data = '" + FormDataManager.getInstance().encode (pageInfo.getRemoteURL()) + "',");            sqlQuery.append ("pagelinkid_jahia_pages_data = " + pageInfo.getPageLinkID() + ",");            sqlQuery.append ("creator_jahia_pages_data = '" + pageInfo.getCreator() + "',");            sqlQuery.append ("doc_jahia_pages_data = '" + pageInfo.getDoc() + "',");            sqlQuery.append ("counter_jahia_pages_data = " + pageInfo.getCounter() + ",");            sqlQuery.append ("rights_jahia_pages_data = " + pageInfo.getAclID() + " ");            sqlQuery.append ("WHERE id_jahia_pages_data = " + pageInfo.getID());            // executes the query            statement = dbConn.createStatement();            if (statement != null) {                statement.execute (sqlQuery.toString());                result = true;            }

⌨️ 快捷键说明

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