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

📄 folderdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if ( whereSql==null ){            whereSql="";        }        if ( orderSql== null ){            orderSql="";        }        try {            // get a connection to the db            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            // execute the query            String query = "select * from jahia_filemgr_folders " + whereSql + " " + orderSql;            stmt = dbConn.createStatement();            debugQuery(query);            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query);            while ( rs.next() )            {                int folderID = rs.getInt("id_jahia_fld");                int filemanagerID = rs.getInt("filemanagerid_jahia_fld");                int parentID = rs.getInt("parent_jahia_fld");                String folderName = rs.getString("fldname_jahia_fld");                folder = new Folder(	filemanagerID,                                        parentID,                                        folderName);                folder.setFolderID(folderID);                folders.addElement(folder);            }        }        catch (SQLException ex) {            processSQLException("FolderDB::getFolders( where, order )",ex);        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("FolderDB::getFolders(where, order) freeing connection fails",ex);            }        }        return folders;   }    /**    * Method getFoldersByFilemanager    * Return a Vector of folder for a gived filemanagerID    *    * @param filemanager id    * @return a Vector of folder objects else null    */   public Vector getFoldersByFilemanager(int filemanagerID)   {        Folder folder = null;        Vector  folders = null;        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        try {            // get a connection to the db            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            // execute the query            String query = "select * from jahia_filemgr_folders where filemanagerid_jahia_fld=" + filemanagerID;            stmt = dbConn.createStatement();            debugQuery(query);            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query);            while ( rs.next() )            {                int folderID = rs.getInt("fld_folder_id");                int parentID = rs.getInt("parent_jahia_fld");                String folderName = rs.getString("fldname_jahia_fld");                folder = new Folder(	filemanagerID,                                        parentID,                                        folderName);                folder.setFolderID(folderID);                folders.add(folder);            }        }        catch (SQLException ex) {            processSQLException("FolderDB::getFoldersByFilemanager(id)",ex);        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("FolderDB::getFoldersByFilemanager(filemanagerID) freeing connection fails",ex);            }        }        return folders;   }    /**     * Method getRootFolder<br>     * Return a root folder (parent id = -1) for a gived filemanager     *     * @param fmngID filemanager id     * @return a folder object else null     */   public Folder getRootFolder(int fmngID)   {        Folder  folder = null;        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        try {            // get a connection to the db            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            // execute the query            String query = " select * from jahia_filemgr_folders where parent_jahia_fld=-1 and filemanagerid_jahia_fld=" + fmngID;            stmt = dbConn.createStatement();            debugQuery(query);            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query);            while ( rs.next() )            {                int folderID = rs.getInt("id_jahia_fld");                int filemanagerID = rs.getInt("filemanagerid_jahia_fld");                int parentID = rs.getInt("parent_jahia_fld");                String folderName = rs.getString("fldname_jahia_fld");                folder = new Folder(	filemanagerID,                                        parentID,                                        folderName);                folder.setFolderID(folderID);            }        }        catch (SQLException ex) {            processSQLException("FolderDB::getRootFolder()",ex);        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("FolderDB::getRootFolder() freeing connection fails",ex);            }        }        return folder;   }    //--------------------------------------------------------------------------    /**     * return a DOM document of all filemgr folders of a site     *     * @param int the site id     *     * @return JahiaDOMObject a DOM representation of this object     *     * @author NK     */    public JahiaDOMObject getFileMgrFoldersAsDOM( int siteID )    throws JahiaException{        Connection dbConn = null;        Statement statement = null;        String output = null;        JahiaDBDOMObject dom = null;        try {            Filemanager fmng = FilemanagerDB.getInstance().getFilemanagerByOwner(siteID);            if ( fmng == null ) {                dom = new JahiaDBDOMObject();                dom.addTable("jahia_filemgr_folders",null);                return dom;            }            String sqlQuery = "SELECT * FROM jahia_filemgr_folders where filemanagerid_jahia_fld="+fmng.getFilemanagerID();            dbConn = getDBConnection(0);            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {                    dom = new JahiaDBDOMObject();                    dom.addTable("jahia_filemgr_folders",rs);                    return dom;                }            }        } catch (SQLException se) {            String errorMsg = "Error in getFileMgrFoldersAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "FolderDB", errorMsg + " -> B	AILING OUT" );            throw new JahiaException(   "Cannot load filemanager folders from the database",                                        errorMsg, JahiaException.DATABASE_ERROR,                                        JahiaException.CRITICAL );        } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }        return dom;    }    //-------------------------------------------------------------------------    private Connection getDBConnection (int debugInfo)    {        Connection dbConn = null;        try {            if ( debugInfo != 0 ){                dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (debugInfo);            } else {                dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection ();            }        }        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;    }    //-------------------------------------------------------------------------    private void closeDBConnection (Connection dbConn)    {        if (dbConn != null) {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection (dbConn);            }            catch (SQLException sqlEx) {                // just create an exception without raising it, just to notify it                // in the logs.                JahiaException je = new JahiaException ("Cannot free resources",                        "Cannot free resources", JahiaException.DATABASE_ERROR,                        JahiaException.WARNING);            }            catch (NullPointerException ex) {                JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!");            }        }    }    //-------------------------------------------------------------------------    private void closeStatement (Statement statement)    {        // 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.            JahiaException je = new JahiaException ("Cannot close a statement",                    "Cannot close a statement", JahiaException.DATABASE_ERROR,                    JahiaException.WARNING);        }    }    /**    * Method executeQuery<br>    * Execute any query, doesnt return any resultset    *    * @param sqlQuery    * @return false if error    */   public boolean executeQuery(String query)   {        Connection dbConn = null;        Statement stmt = null;        boolean success = false;        try {            // get a connection to the db            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            stmt = dbConn.createStatement();            debugQuery(query);            ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query);            success = true;        }        catch (SQLException ex) {            processSQLException("FolderDB::executeQuery()",ex);        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("FolderDB::  executeQuery() freeing connection fails",ex);            }            return success;        }   }    /**     * Method filter     * Filter special caracters     *     * @param input String to filter     * @return a filtered string     */   public static String filter(String input) {        StringBuffer filtered = new StringBuffer ( input.length() );        char c;        for ( int i=0 ; i<input.length(); i++ )        {            c = input.charAt(i);            if ( c == '\'' ) {                 filtered.append( "&#39;" );            } else if ( c== '"' ) {                 filtered.append( "&#34;" );            } else {                 filtered.append(c);            }        }        return (filtered.toString());   }    /**     * Method toConsole     * Write a message to the console     *     * @param msg the message to display     */     public void toConsole(String msg){        if (false){            //System.out.println(msg);        }     }    /**     * Method debugQuery     * Outout the query for debug purpose     * @param query     */   public static void debugQuery(String query) {        if ( m_debugQuery ) {            JahiaConsole.println("FolderDB",query);        }   }    /*     * Method processSQLException     * For debug purpose     *     * @param func the name of the calling method     * @param SQLException     */    public void processSQLException (String func, SQLException ex) {        if ( m_debugQuery ) {            while (ex != null) {                JahiaConsole.println("FolderDB","SQL EXCEPTION in function [" + func + "]: SqlState = " + ex.getSQLState() + "   Error code = " + ex.getErrorCode() + "   Error msg = " + ex.toString());                ex = ex.getNextException();            }        }    }}

⌨️ 快捷键说明

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