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

📄 acldbutils.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                dom.addTable("jahia_acl_entries",null);                return dom;            }            AclFilter filter = new AclFilter(ids);            dom = new JahiaDBDOMObject();            int low = 0;            int high = 0;            while ( high <= aclIDMax ){                low = high;                high += 5000;                StringBuffer buff = new StringBuffer("SELECT DISTINCT id_jahia_acl,type_jahia_acl_entries,target_jahia_acl_entries,entry_state_jahia_acl_entries,entry_trist_jahia_acl_entries FROM jahia_acl_entries WHERE id_jahia_acl");                buff.append(" > ");                buff.append(low);                buff.append(" AND id_jahia_acl <= ");                buff.append(high);                try {                    dbConn = getDBConnection();                    statement = dbConn.createStatement();                    if (statement != null) {                        ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,buff.toString());                        if (rs != null) {                            dom.addTable("jahia_acl_entries",rs,(DBRowDataFilter)filter);                        }                    }                } catch (SQLException se) {                    String errorMsg = "Error in getAclEntriesAsDOM(vector ids) : " + se.getMessage();                    JahiaConsole.println( "AclDBUtils", errorMsg );                    throw new JahiaException(   "Cannot load acl entry from the database",                                                errorMsg, JahiaException.DATABASE_ERROR,                                                JahiaException.CRITICAL );                } finally {                    closeDBConnection (dbConn);                    closeStatement (statement);                }            }        } catch (SQLException se) {            String errorMsg = "Error in getAclsAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "AclDBUtils", errorMsg );            throw new JahiaException(   "Cannot load acl from the database",                                        errorMsg, JahiaException.DATABASE_ERROR,                                        JahiaException.CRITICAL );        }        return dom;    }    /**     * FH   4 Apr. 2001     * Execues and INSERT, UPDATE or DELETE SQL operation. This method should not     * be used with and SELECT operation. This method lock the object on database     * write access.     *     * @param query the SQL operation in qestion.     *     * @return     *      Return <code>true</code> on success.     *     * @exception   JahiaDatabaseException     *      Throws this exception on any database failure.     */    public boolean makeQuery (String query)        throws  JahiaDatabaseException    {        // Get a database connection        Connection  dbConn = getDBConnection ();        if (dbConn == null) {            throw new JahiaDatabaseException (                    "ACL SQL query execution process could not get a database connection.",                    JahiaDatabaseException.CRITICAL);        }        boolean     result = false;        Statement   statement = null;        try {            statement = dbConn.createStatement();            if (statement != null) {                synchronized (this) {                    statement.executeUpdate (query);                    result = true;                }            }        }        catch (SQLException ex) {            throw new JahiaDatabaseException (                    "An SQL exception occrued while executing an SQL query in the ACL DB Utilities.",                    query, ex, JahiaDatabaseException.ERROR);        }        finally {            closeDBConnection (dbConn);            closeStatement (statement);        }        return result;    }    //-------------------------------------------------------------------------    /** Return the biggest acl id number.     *     * @return int , the biggest acl id number or -1 on error     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    public synchronized int getBiggestAclID ()        throws JahiaDatabaseException    {        final String MAX_ID = "MaxID";        int val = -1;        Connection connection = getDBConnection ();        if (connection != null) {            Statement statement = null;            StringBuffer query = new StringBuffer ();            try {                query.append ("SELECT MAX(");                query.append (FIELD_ACL_ID);                query.append (") as ");                query.append (MAX_ID);                query.append (" FROM ");                query.append (JAHIA_ACL);                statement = connection.createStatement();                if (statement != null) {                    ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement, query.toString ());                    if (rs != null) {                        if (rs.next()) {                            // get the highest used acl ID                            val = rs.getInt (MAX_ID);                        }                    }                }            }            catch (SQLException ex) {                throw new JahiaDatabaseException (                        "Could not get the max acl ID",                        query.toString(), ex, JahiaDatabaseException.ERROR);            }            finally{                closeDBConnection (connection);                closeStatement (statement);            }        } else {            throw new JahiaDatabaseException ("Could not get a database connection while getting the max acl ID",                    JahiaDatabaseException.CRITICAL);        }        return val;    }    //-------------------------------------------------------------------------    /** Return the biggest acl entry id number.     *     * @return int , the biggest acl entry id number or -1 on error     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    public synchronized int getBiggestAclEntryID ()        throws JahiaDatabaseException    {        final String MAX_ID = "MaxID";        int val = -1;        Connection connection = getDBConnection ();        if (connection != null) {            Statement statement = null;            StringBuffer query = new StringBuffer ();            try {                query.append ("SELECT MAX(");                query.append (FIELD_ACL_ID);                query.append (") as ");                query.append (MAX_ID);                query.append (" FROM ");                query.append (JAHIA_ACL_ENTRIES);                statement = connection.createStatement();                if (statement != null) {                    ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement, query.toString ());                    if (rs != null) {                        if (rs.next()) {                            // get the highest used acl ID                            val = rs.getInt (MAX_ID);                        }                    }                }            }            catch (SQLException ex) {                throw new JahiaDatabaseException (                        "Could not get the max acl entry ID",                        query.toString(), ex, JahiaDatabaseException.ERROR);            }            finally{                closeDBConnection (connection);                closeStatement (statement);            }        } else {            throw new JahiaDatabaseException ("Could not get a database connection while getting the max acl entry ID",                    JahiaDatabaseException.CRITICAL);        }        return val;    }    //-------------------------------------------------------------------------    // FH   4 Apr. 2001    /** Return the next available page info ID.     *     * @return     *      Return the next available ACL ID.     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    public synchronized int getNextID ()        throws JahiaDatabaseException    {        final String MAX_ID = "MaxID";        int counter = -1;        Connection connection = getDBConnection ();        if (connection != null) {            Statement statement = null;            StringBuffer query = new StringBuffer ();            try {                query.append ("SELECT MAX(");                query.append (FIELD_ACL_ID);                query.append (") as ");                query.append (MAX_ID);                query.append (" FROM ");                query.append (JAHIA_ACL);                statement = connection.createStatement();                if (statement != null) {                    ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement, query.toString ());                    if (rs != null) {                        if (rs.next()) {                            // get the highest used page ID                            counter = rs.getInt (MAX_ID);                            // increment by one to get the next counter                            counter++;                        }                    }                }            }            catch (SQLException ex) {                throw new JahiaDatabaseException (                        "Could not get the next ID in the account table",                        query.toString(), ex, JahiaDatabaseException.ERROR);            }            finally{                closeDBConnection (connection);                closeStatement (statement);            }        } else {            throw new JahiaDatabaseException ("Could not get a database connection while getting the next available account ID",                    JahiaDatabaseException.CRITICAL);        }        return counter;    }    //-------------------------------------------------------------------------    // FH   4 Apr. 2001    /**     * This method try to get a database connection from the DB Pool Connection     * service. If not connection could be taken, or if any database error     * occured, null will be returned. Otherwise the reference on a valid     * connection is returned.     *     * @return     *      Return a reference of the database connection.     *      Return <code>null</code> if no connection could be obtained from     *      the database connection pool.     */    private Connection getDBConnection ()    {        Connection dbConn = null;        try {            dbConn = ServicesRegistry.getInstance().getDBPoolService().                    getConnection (0);        }        catch (NullPointerException ex) {            JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!");        }        catch (SQLException ex) {            JahiaConsole.println ("JahiaPagesDB",                    "SQL Exception: cannot get a connection.");        }        return dbConn;    }    //-------------------------------------------------------------------------    // FH   4 Apr. 2001    /**     * Release the specified database connection     *     * @param   connection     *      Reference to the database connection to be closed.     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    private void closeDBConnection (Connection connection)        throws JahiaDatabaseException    {        if (connection != null) {            try {                ServicesRegistry.getInstance().getDBPoolService().                        freeConnection (connection);            }            catch (SQLException sqlEx) {                // just create an exception without raising it, just to notify                // it in the logs.                JahiaDatabaseException ex = new JahiaDatabaseException (                        "Cannot free resources", sqlEx,                        JahiaDatabaseException.WARNING);            }            catch (NullPointerException ex) {                JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!");            }        }    }    //-------------------------------------------------------------------------    // FH   4 Apr. 2001    /**     * Close he specified SQL statement.     *     * @param   statement     *      Reference to the statement to close.     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    private void closeStatement (Statement statement)        throws JahiaDatabaseException    {        // Close the opened statement        try {            if (statement!=null) {                statement.close();            }        }        catch (SQLException sqlEx) {            // just create an exception without raising it, just to notify it            // in the logs.            JahiaDatabaseException ex = new JahiaDatabaseException (                    "Cannot close a statement", sqlEx,                    JahiaDatabaseException.WARNING);        }    }    class AclFilter implements DBRowDataFilter {        private Vector acls;        public AclFilter(Vector acls){            this.acls = acls;        }        public boolean inValue(Hashtable vals){            if ( vals == null ){                return false;            }            if ( acls == null ){                return true;            }            String val = null;            try {                val = (String)vals.get("id_jahia_acl");                Integer aclID = new Integer(val);                return ( acls.contains(aclID) );            } catch ( Throwable t ){                JahiaConsole.println("JahiaFieldsDB","Error parsing " + val);                //t.printStackTrace();            }            return false;        }    }}

⌨️ 快捷键说明

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