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

📄 jahiaapplicationspersistancebaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.jahia.services.applications;import java.sql.*;                      // ResultSetimport java.util.*;                     // Vectorimport org.jahia.utils.*;           // JahiaConsole, JahiaToolsimport org.jahia.data.*;            // JahiaDataimport org.jahia.data.fields.JahiaField;import org.jahia.services.usermanager.JahiaGroup;import org.jahia.services.usermanager.JahiaUser;import org.jahia.services.usermanager.*;import org.jahia.data.applications.*;import org.jahia.registries.*;      // ServicesRegistryimport org.jahia.exceptions.JahiaException;import org.jahia.data.JahiaDOMObject;import org.jahia.data.JahiaDBDOMObject;/** * Handles all the storage and retrieval of application data from the persistant * storage area, in this implementation from a JDBC database. * You should not directly access this service, but rather through the JahiaApplicationManagerService ! * * @author Eric Vassali, Serge Huber * @version 1.0 */public class JahiaApplicationsPersistanceBaseService extends JahiaApplicationsPersistanceService {    private String serviceName;    private static  JahiaApplicationsPersistanceBaseService theObject = null;    /**     * Constructor is protected because of Singleton pattern     */    protected JahiaApplicationsPersistanceBaseService() {        JahiaConsole.println( "JahiaApplicationsDBBaseService", "***** Starting *****" );    } // end constructor    /**     * Retrieves the single instance of the service. If the instance does not     * exist it creates it.     * @returns Singleton instance of the service     */    public static synchronized JahiaApplicationsPersistanceBaseService getInstance() {        if (theObject == null) {            theObject = new JahiaApplicationsPersistanceBaseService();        }        return theObject;    } // end getInstance    /**     * Retrieves the number of distinct jahia website     * exist it creates it.     * @returns Singleton instance of the service     */    public Vector getWebSites() throws JahiaException {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        Vector webSites = new Vector();        try {            String sqlQuery = "SELECT distinct(jahiaid_jahia_app_def) FROM jahia_app_def order by jahiaid_jahia_app_def";            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(6);            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            int jahiaID = -1;            int newID = 0;            while (rs.next()) {                newID = rs.getInt("jahiaid_jahia_app_def");                if ( jahiaID != newID ){                    webSites.add(new Integer(newID));                    jahiaID = newID;                }            }        } catch (SQLException se) {            String errorMsg = "Error in getWebSites : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot retrieve the number of jahia websites ",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( rs != null ) rs = null;                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                "getWebSites : cannot free resources",                                JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return webSites;    } // end getWebSites    /**     * return the list of applications     *     * @param visibleOnly if true return only applications with visible status = 1     */    public Vector get_applications_list( boolean visibleOnly ) throws JahiaException {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        Vector appList = new Vector();        try {            String sqlQuery = "SELECT * FROM jahia_app_def ";            if ( visibleOnly ){                sqlQuery += " where visible_jahia_app_def=1 ";            }            sqlQuery +=" order by name_jahia_app_def";            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(6);            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            while (rs.next()) {                ApplicationBean appBean = get_application_from_resultset( rs );                appList.add( appBean );            }        } catch (SQLException se) {            String errorMsg = "Error in get_applications_list : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot load external application info from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( rs != null ) rs = null;                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                "get_applications_list : cannot free resources",                                JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }		Vector newList = new Vector();        int size = appList.size();        for ( int i=0 ; i<size ; i++ ){        	ApplicationBean app = (ApplicationBean) appList.get(i);        	newList.add(app);        }        return newList;    } // end get_applications_list    /**     * return the list of applications for a gived site     *     * @param visibleOnly if true return only applications with visible status = 1     */    public Vector get_applications_list( int jahiaID , boolean visibleOnly) throws JahiaException {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        Vector appList = new Vector();        try {            String sqlQuery = "SELECT * FROM jahia_app_def ";            sqlQuery += "WHERE (jahiaid_jahia_app_def=" + jahiaID + " or shared_jahia_app_def=1)" ;            if ( visibleOnly ){                sqlQuery += " and visible_jahia_app_def=1 ";            }            sqlQuery += " order by name_jahia_app_def";            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(6);            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            while (rs.next()) {                ApplicationBean appBean = get_application_from_resultset( rs );                appList.add( appBean );            }        } catch (SQLException se) {            String errorMsg = "Error in get_applications_list : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot load external application info from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( rs != null ) rs = null;                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                "get_applications_list : cannot free resources",                                JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }		Vector newList = new Vector();        int size = appList.size();        for ( int i=0 ; i<size ; i++ ){        	ApplicationBean app = (ApplicationBean) appList.get(i);        	newList.add(app);        }        return newList;    } // end get_applications_list    public ApplicationBean get_application_definition( int appID )    throws JahiaException {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        ApplicationBean appBean = null;        try {            String sqlQuery = "SELECT * FROM jahia_app_def ";            sqlQuery += "WHERE id_jahia_app_def=" + appID;            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(7);            stmt = dbConn.createStatement();                      rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            if (rs.next()) {                appBean = get_application_from_resultset( rs );            }        } catch (SQLException se) {            String errorMsg = "Error in get_application_definition : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot load external application info from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                    ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                    if ( stmt != null ) stmt.close();                    //if ( rs != null ) rs.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                "get_application_definition : cannot free resources",                                JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return appBean;    } // end get_application_definition	/**	 * return an Application Definition , looking at the context property	 *	 */    public ApplicationBean get_application_definition( String context )    throws JahiaException {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        ApplicationBean appBean = null;        try {            String sqlQuery = "SELECT * FROM jahia_app_def ";            sqlQuery += "WHERE context_jahia_app_def='" + JahiaTools.quote(context) + "' ";            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(7);            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            if (rs.next()) {                appBean = get_application_from_resultset( rs );            }        } catch (SQLException se) {            String errorMsg = "Error in get_application_definition : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot load external application info from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        } finally {            try {                    ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                    if ( stmt != null ) stmt.close();                    //if ( rs != null ) rs.close();            } catch ( SQLException ex ) {                JahiaException je = new JahiaException(   "Cannot free resources",                                "get_application_definition : cannot free resources",                                JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return appBean;    } // end get_application_definition    private ApplicationBean get_application_from_resultset( ResultSet rs )    throws JahiaException {        try {            return new ApplicationBean(  rs.getInt   ( "id_jahia_app_def" ),                                         rs.getInt   ( "jahiaid_jahia_app_def" ),                                         rs.getString( "name_jahia_app_def" ),                                         rs.getString( "context_jahia_app_def" ),                                         rs.getInt   ( "visible_jahia_app_def" ),                                         (rs.getInt   ( "shared_jahia_app_def" )==1),                                         rs.getInt   ( "rights_jahia_app_def" ),                                         rs.getString( "filename_jahia_app_def" ),                                         rs.getString( "desc_jahia_app_def" ) );        }        catch (SQLException se) {            String errorMsg = "Error in get_application_from_resultset : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "ApplicationsDBManager", errorMsg );            throw new JahiaException(   "Cannot load external application info from the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );        }    } // end get_application_from_resultset    public void add_application( ApplicationBean theApp )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        try {            // gets the field id            int theAppID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_app_def" );            theApp.setID( theAppID );            // creates empty line            String sqlQuery = "INSERT INTO jahia_app_def(id_jahia_app_def) ";            sqlQuery += "VALUES(" + theApp.getID() + ")";

⌨️ 快捷键说明

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