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

📄 jahiahomepagespersistance.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    } catch (SQLException se) {	        String errorMsg = "Error in addProperty(JahiaHomepage hp, String key, String value) : " 	        												+ se.getMessage();            JahiaConsole.println( CLASS_NAME+".addProperty", errorMsg  );	        throw new JahiaException(   "Cannot add a homepage property in the database",	                                    errorMsg, 	                                    JahiaException.DATABASE_ERROR, 	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement ((Statement)pstmt);        }	}    //--------------------------------------------------------------------------	/**	 * delete all properties of a homepage	 *	 * @param JahiaHomepage hp, the homepage bean	 */	void deleteProperties(JahiaHomepage hp) throws JahiaException{				if ( hp == null )			return;	    try {            StringBuffer buff =            new StringBuffer("DELETE FROM jahia_homepages_prop WHERE id_jahia_homepages=");            buff.append(hp.getID());			executeQueryNoResultSet(buff.toString());	    } catch (JahiaException je) {	        String errorMsg = "Error in deleteProperties(JahiaHomepage) : " 	        												+ je.getMessage();            JahiaConsole.println( CLASS_NAME+".deleteProperties(JahiaHomepage)", errorMsg  );	        throw new JahiaException(   "Cannot delete all homepage properties in the database",	                                    errorMsg, 	                                    JahiaException.DATABASE_ERROR, 	                                    JahiaException.CRITICAL );	    }	}    //--------------------------------------------------------------------------	/**	 * remove a property of a home page	 *	 * @param int the home page id	 * @param String the property name	 */	void deleteProperty( int id , String key ) throws JahiaException {				if ( (key == null) || (key.trim().equals("")) )			return;		Connection dbConn = null;        PreparedStatement pstmt = null;				    try {			dbConn = getDBConnection();						pstmt = dbConn.prepareStatement("DELETE FROM jahia_homepages_prop WHERE id_jahia_homepages=? AND name_homepages_prop=? ");   			pstmt.setInt(1, id);   			pstmt.setString(2, key);	    } catch (SQLException se) {	        String errorMsg = "Error in deleteProperty(int id, String key) : " 	        												+ se.getMessage();            JahiaConsole.println( CLASS_NAME+".deleteProperty", errorMsg  );	        throw new JahiaException(   "Cannot delete a homepage property in the database",	                                    errorMsg, 	                                    JahiaException.DATABASE_ERROR, 	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement ((Statement)pstmt);        }	}    //--------------------------------------------------------------------------	/**	 * Build a JahiaHomepage bean from a result set	 *	 * @return JahiaHomepage the bean	 */	protected JahiaHomepage getHomepageFromResultSet(ResultSet rs) 	throws JahiaException {		if ( rs == null )			throw new JahiaException(CLASS_NAME+".getHomepageFromResultSet",										"Resultset is null",										JahiaException.DATABASE_ERROR,										JahiaException.ERROR );				JahiaHomepagesService hps = ServicesRegistry.getInstance()												.getJahiaHomepagesService();		if ( hps == null )			throw new JahiaException(CLASS_NAME+".getHomepageFromResultSet",										"JahiaHomepageService is not available",										JahiaException.SERVICE_ERROR,										JahiaException.ERROR );				int id 					= 0;		String name 			= "";		String descr	 		= "";		String siteKey			= "";		int type		 		= 0;		int aclID				= 0;		try {			id 						= rs.getInt("id_jahia_homepages");       		name 					= rs.getString("name_jahia_homepages");       		descr 					= rs.getString("descr_jahia_homepages");			siteKey					= rs.getString("sitekey_jahia_homepages");			type					= rs.getInt("type_jahia_homepages");       		aclID 					= rs.getInt("rights_jahia_homepages");     	}catch ( SQLException se ){	        String errorMsg = "DB Error : " + se.getMessage();	        JahiaConsole.println( CLASS_NAME+".getHomepageFromResultSet", errorMsg );	 	    throw new JahiaException( CLASS_NAME+".getHomepageFromResultSet",	                                   errorMsg, JahiaException.DATABASE_ERROR, 	                                   JahiaException.CRITICAL );     	}		JahiaHomepage hp = hps.createHomepage(	name,        										descr,        										siteKey,        										type,        										new Hashtable(),												aclID );		hp.setID(id);												return hp;	}    //--------------------------------------------------------------------------	/**	 * return a DOM representation of hompage def of a site	 *	 * @param String the site keys	 *	 * @return JahiaDOMObjet a DOM representation of homepage def of a site	 *	 * @author NK	 */	public JahiaDOMObject getHomepageDefsAsDOM( String siteKey ) throws JahiaException{			Connection dbConn = null;        Statement statement = null;		String output = null;		JahiaDBDOMObject dom = null;			    try {            String sqlQuery = "SELECT * FROM jahia_homepages where sitekey_jahia_homepages='" + siteKey + "'";	        dbConn = getDBConnection();            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {					dom = new JahiaDBDOMObject();					dom.addTable("jahia_homepages",rs);					return dom;				}			}	    } catch (SQLException se) {	        String errorMsg = "Error in getHomepageDefsAsDOM() : " + se.getMessage();            JahiaConsole.println( "JahiaHomepagesPersistance", errorMsg );	        throw new JahiaException(   "Cannot load data from the database",	                                    errorMsg, JahiaException.DATABASE_ERROR,	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }		return dom;	}    //--------------------------------------------------------------------------	/**	 * return a DOM representation of a site's homepage properties	 *	 * @param String siteKey the site key	 *	 * @return JahiaDOMObjet a DOM representation of a site's homepage def props	 *	 * @author NK	 */	public JahiaDOMObject getHomepageDefPropsAsDOM( String siteKey ) throws JahiaException{			Connection dbConn = null;        Statement statement = null;		String output = null;		JahiaDBDOMObject dom = null;			    try {            String sqlQuery = "SELECT * FROM jahia_homepages_prop where sitekey_homepages_prop='" + siteKey + "'";	        dbConn = getDBConnection();            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {					dom = new JahiaDBDOMObject();					dom.addTable("jahia_homepages_prop",rs);					return dom;				}			}	    } catch (SQLException se) {	        String errorMsg = "Error in getHomepageDefPropsAsDOM() : " + se.getMessage();            JahiaConsole.println( CLASS_NAME, errorMsg  );	        throw new JahiaException(   "Cannot load data from the database",	                                    errorMsg, JahiaException.DATABASE_ERROR,	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }		return dom;	}	//--------------------------------------------------------------------------    /**     * gets all home page acl ids for a given site     *     * @return       a Vector of all acl id     *     */    public Vector db_get_all_acl_id(String siteKey)    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        Vector theIDs = new Vector();        try        {            String sqlQuery = "SELECT DISTINCT rights_jahia_homepages FROM jahia_homepages "            +"WHERE sitekey_jahia_homepages='"+siteKey+"'";            dbConn = getDBConnection();            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery );            while (rs.next())            {                theIDs.add( new Integer(rs.getInt( "rights_jahia_homepages" )) );            }        }        catch (SQLException se)        {            String errorMsg = "Error in db_get_all_acl_id : " + se.getMessage();            JahiaConsole.println (CLASS_NAME+".db_get_all_acl_id", errorMsg);            throw new JahiaException ("Cannot load acl id from the database",                                      errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL);	    } finally {            closeDBConnection (dbConn);            closeStatement (stmt);        }        return theIDs;    }    //-------------------------------------------------------------------------    private void executeQueryNoResultSet(String queryStr) throws JahiaException    {		Connection dbConn = null;        Statement statement = null;		try {			dbConn = getDBConnection();            statement = dbConn.createStatement();            if (statement != null) {                ServicesRegistry.getInstance().getDBPoolService().executeUpdate(statement,queryStr);			}	    } catch (SQLException se) {	        String errorMsg = "Error in executeQueryNoResultSet(String queryStr) : " + se.getMessage();            JahiaConsole.println( CLASS_NAME, errorMsg );	        throw new JahiaException(   "Cannot execute query" + queryStr,	                                    errorMsg, 	                                    JahiaException.DATABASE_ERROR, 	                                    JahiaException.CRITICAL );	    } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }    }    //-------------------------------------------------------------------------    private Connection getDBConnection ()    {        return getDBConnection(0);    }    //-------------------------------------------------------------------------    private Connection getDBConnection (int debugInfo)    {        Connection dbConn = null;        try {            dbConn = ServicesRegistry.getInstance()            					.getDBPoolService().getConnection (debugInfo);        }        catch (NullPointerException ex) {            JahiaConsole.println (CLASS_NAME,             "Null Pointer Exception, DB Pool Service instance might be null!");        }        catch (SQLException ex) {            JahiaConsole.println (CLASS_NAME,            						"SQL Exception: cannot get a connection.");        }        return dbConn;    }    //-------------------------------------------------------------------------    private void closeDBConnection (Connection dbConn)    {        if (dbConn != null) {            try {                ServicesRegistry.getInstance()                					.getDBPoolService().freeConnection (dbConn);                dbConn = null;            }            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 (CLASS_NAME,                 "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();                statement = null;            }        }        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);        }    }}

⌨️ 快捷键说明

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