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

📄 jahiafieldsdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            props.db_save_field_properties( theField );        }        // catches error if cannot execute update query        catch (SQLException se)        {            String errorMsg = "Error in db_update_field : " + se.getMessage();            JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> BAILING OUT" );            throw new JahiaException(   "Cannot update fields in the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                        "db_update_field : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }    } // end db_update_field    /***        * deletes a field entry in the database        *        * @param       fieldID              the field id        *        * @exception   throws a critical JahiaException if SQL error        * @exception   throws a warning JahiaException if cannot free resources        *        */    public void db_delete_field( int fieldID )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        try {            String sqlQuery = "DELETE FROM jahia_fields_data WHERE id_jahia_fields_data=" + fieldID;            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(54);            stmt = dbConn.createStatement();            ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery );            // deletes field properties            props.db_delete_field_properties( fieldID );        } catch (SQLException se) {            String errorMsg = "Error in db_delete_field : " + se.getMessage();            JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> BAILING OUT" );            JahiaException je = new JahiaException(   "Cannot delete fields in the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.ERROR );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                        "db_field_value : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }    } // end db_delete_field    //--------------------------------------------------------------------------    /**     * return a DOM document of all fields of a site     *     * @param int the site id     *     * @return JahiaDOMObject a DOM representation of this object     *     * @author NK     */    public JahiaDOMObject getFieldsAsDOM( int siteID )     throws JahiaException {        JahiaFieldUtilsDB f_utils = new JahiaFieldUtilsDB();        JahiaDBDOMObject dom = new JahiaDBDOMObject();        Connection dbConn = null;        Statement statement = null;        ResultSet rs = null;        StringBuffer buff = new StringBuffer("SELECT DISTINCT id_jahia_fields_data,");        buff.append("jahiaid_jahia_fields_data,");        buff.append("pageid_jahia_fields_data,");        buff.append("ctnid_jahia_fields_data,");        buff.append("fielddefid_jahia_fields_data,");        buff.append("type_jahia_fields_data,");        buff.append("connecttype_jahia_fields_data,");        buff.append("value_jahia_fields_data,");        buff.append("rank_jahia_fields_data,");        buff.append("rights_jahia_fields_data FROM jahia_fields_data WHERE id_jahia_fields_data");        int fieldIDMax = getBiggestFieldID();        if ( fieldIDMax == -1 ){			dom = new JahiaDBDOMObject();			try {			    dom.addTable("jahia_fields_data",null);			} catch ( Throwable t ){		        String errorMsg = "Error in getFieldsAsDOM(int siteID) : " + t.getMessage();	            JahiaConsole.println( "JahiaFieldsDB", errorMsg );		        throw new JahiaException(   "Cannot load field from the database",		                                    errorMsg, JahiaException.DATABASE_ERROR,		                                    JahiaException.CRITICAL );			}			return dom;        }                FieldFilter filter = new FieldFilter(siteID);        		dom = new JahiaDBDOMObject();        int low = 0;        int high = 0;        while ( high <= fieldIDMax ){            low = high;            high += 5000;            StringBuffer query = new StringBuffer(buff.toString());			query.append(" > ");			query.append(low);            query.append(" AND id_jahia_fields_data <= ");            query.append(high);	        try {		        dbConn = getDBConnection(11000);	            statement = dbConn.createStatement();	            if (statement != null) {	                rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query.toString());	                //JahiaConsole.println( "JahiaFieldsDB.getFieldsAsDOM", query.toString() );	                if (rs != null) {						dom.addTable("jahia_fields_data",rs,filter);					}				}		    } catch (SQLException se) {		        se.printStackTrace();		        String errorMsg = "Error in getFieldsAsDOM(int siteID) : " + se.getMessage();	            JahiaConsole.println( "JahiaFieldsDB", errorMsg );		        throw new JahiaException(   "Cannot load field from the database",		                                    errorMsg, JahiaException.DATABASE_ERROR,		                                    JahiaException.CRITICAL );		    } catch (JahiaDatabaseException jdbe ) {		        jdbe.printStackTrace();		        String errorMsg = "Error in getFieldsAsDOM(int siteID) : " + jdbe.getMessage();	            JahiaConsole.println( "JahiaFieldsDB", errorMsg );		        throw new JahiaException(   "Cannot load field from the database",		                                    errorMsg, JahiaException.DATABASE_ERROR,		                                    JahiaException.CRITICAL );		    } finally {	            closeDBConnection (dbConn);	            closeStatement (statement);	        }        }        return dom;    }    //-------------------------------------------------------------------------    /** Return the biggest field id number.     *     * @return int , the biggest field id number or -1 on error     *     * @exception   JahiaDatabaseException     *      Thows this exception on any database failure.     */    public synchronized int getBiggestFieldID ()        throws JahiaDatabaseException    {        final String MAX_ID = "MaxID";        int val = -1;        Connection connection = getDBConnection (11000);        if (connection != null) {            Statement statement = null;            StringBuffer query = new StringBuffer ();            try {                query.append ("SELECT MAX(id_jahia_fields_data) as ");                query.append (MAX_ID);                query.append (" FROM jahia_fields_data");                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 field 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 field ID",                    JahiaDatabaseException.CRITICAL);        }        return val;    }    //-------------------------------------------------------------------------    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);        }    }    class FieldFilter implements DBRowDataFilter {                private int siteID;                public FieldFilter(int siteID){            this.siteID = siteID;        }                    public boolean inValue(Hashtable vals){            if ( vals == null ){                return false;            }            String val = null;            try {                val = (String)vals.get("jahiaid_jahia_fields_data");                //JahiaConsole.println("JahiaFieldsDB","field id to parse :" + val);                int jahiaID = Integer.parseInt(val);                return ( this.siteID == jahiaID );            } catch ( Throwable t ){               JahiaConsole.println("JahiaFieldsDB","Error parsing " + val);               // t.printStackTrace();            }                  return false;        }    }} // end JahiaFieldsDB

⌨️ 快捷键说明

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