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

📄 jahiacontainersdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .///***    * JahiaContainersDB    * @author Eric Vassalli    *    * Holds all the methods enabling containers load, update and delete.    *    */////  db_load_container( ctnid )//  db_create_container( theContainer )//  db_update_container( theContainer )//  db_delete_container( thectnid )//package org.jahia.services.containers;import java.sql.*;                      // ResultSetimport java.util.*;                     // Vectorimport org.jahia.params.*;          // ParamBeanimport org.jahia.data.*;            // JahiaDataimport org.jahia.utils.*;           // JahiaConsoleimport org.jahia.data.fields.*;     // JahiaFieldimport org.jahia.data.containers.*; // JahiaContainersimport org.jahia.registries.*;      // ServiceRegistryimport org.jahia.exceptions.JahiaException;import org.jahia.data.JahiaDOMObject;import org.jahia.data.JahiaDBDOMObject;public class JahiaContainersDB{    /***        * constructor        *        */	public JahiaContainersDB()	{	} // end constructor    /***        * loads all the container info from page        *	    * @param        cpageid     the page id	    * @return       returns a vector of JahiaContainer	    *	    * @exception    throws a critical JahiaException if a data access occurs	    * @exception    throws a warning JahiaException if cannot free resources        *        */	public Vector db_load_all_containers_info_from_page(int pageID)	throws JahiaException	{	    Vector result = new Vector();  		Connection dbConn = null;  		Statement stmt = null;  		ResultSet rs = null;        JahiaContainer theContainer = null;	    try {	        String sqlQuery = "SELECT * FROM jahia_ctn_entries ";	        sqlQuery += "WHERE pageid_jahia_ctn_entries=" + pageID;	        dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(231);	        stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery );            while (rs.next()) {    	        // load values from container_entries	            int     ID              = rs.getInt     ( "id_jahia_ctn_entries" );	            int     jahiaID         = rs.getInt     ( "jahiaid_jahia_ctn_entries" );	            int     listID          = rs.getInt     ( "listid_jahia_ctn_entries" );	            int     definitionID    = rs.getInt     ( "ctndefid_jahia_ctn_entries" );	            int     rank            = rs.getInt     ( "rank_jahia_ctn_entries" );	            int     rights          = rs.getInt     ( "rights_jahia_ctn_entries" );	            theContainer = new JahiaContainer( ID, jahiaID, pageID, listID, rank, rights, definitionID );	            result.add(theContainer);            }	    } catch (SQLException se) {	        String errorMsg = "Error in db_load_container : " + se.getMessage() + " -> BAILING OUT";	        JahiaConsole.println( "JahiaContainersDB", errorMsg );	        throw new JahiaException(   "Cannot load fields from 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_load_container : cannot free resources",	                                    JahiaException.DATABASE_ERROR, JahiaException.WARNING );			}        }        return result;	} // end db_load_container    /***        * loads a container from its container id        *        * @param        jParams         the ParamBean	    * @param        ctnid     the entry ID	    * @return       returns a JahiaContainer if ctnid found, null if not	    * @see          org.jahia.data.containers.JahiaContainer	    *	    * @exception    throws a critical JahiaException if a data access occurs	    * @exception    throws a warning JahiaException if cannot free resources        *        */	public JahiaContainer db_load_container( int ctnid )	throws JahiaException	{  		Connection dbConn = null;  		Statement stmt = null;  		ResultSet rs = null;        JahiaContainer theContainer = null;	    try {	        String sqlQuery = "SELECT * FROM jahia_ctn_entries ";	        sqlQuery += "WHERE id_jahia_ctn_entries=" + ctnid;	        dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(23);	        stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery );            if (rs.next()) {    	        // load values from container_entries	            int     ID              = rs.getInt     ( "id_jahia_ctn_entries" );	            int     jahiaID         = rs.getInt     ( "jahiaid_jahia_ctn_entries" );	            int     pageID          = rs.getInt     ( "pageid_jahia_ctn_entries" );	            int     listID          = rs.getInt     ( "listid_jahia_ctn_entries" );	            int     definitionID    = rs.getInt     ( "ctndefid_jahia_ctn_entries" );	            int     rank            = rs.getInt     ( "rank_jahia_ctn_entries" );	            int     rights          = rs.getInt     ( "rights_jahia_ctn_entries" );	            theContainer = new JahiaContainer( ID, jahiaID, pageID, listID, rank, rights, definitionID );            }	    } catch (SQLException se) {	        String errorMsg = "Error in db_load_container : " + se.getMessage() + " -> BAILING OUT";	        JahiaConsole.println( "JahiaContainersDB", errorMsg );	        throw new JahiaException(   "Cannot load fields from 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_load_container : cannot free resources",	                                    JahiaException.DATABASE_ERROR, JahiaException.WARNING );			}        }        return theContainer;	} // end db_load_container    /***        * creates a new container, and assignes it a new ID        *        * @param        theContainer    the JahiaContainer object to save	    * @see          org.jahia.data.containers.JahiaContainer	    *	    * @exception    throws a critical JahiaException if a data access occurs	    * @exception    throws a warning JahiaException if cannot free resources        *        */	public void db_create_container( JahiaContainer theContainer )	throws JahiaException	{  		Connection dbConn = null;  		Statement stmt = null;  		ResultSet rs = null;	    try {	        // opens connection	        dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(24);	        stmt = dbConn.createStatement();	        // creates empty line	        String sqlQuery = "INSERT INTO jahia_ctn_entries(id_jahia_ctn_entries) VALUES(" + theContainer.getID() + ")";	        // executes the query, then closes the connection	        stmt.execute( sqlQuery );			 try {				ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);				if ( stmt != null ) stmt.close();			 } catch ( SQLException ex ) {			   	 JahiaException je = new JahiaException(   "Cannot free resources",	                                    "db_create_container : cannot free resources",	                                    JahiaException.DATABASE_ERROR, JahiaException.WARNING );			 }	        // enters values with db_update_container	        db_update_container( theContainer );	    } catch (SQLException se) {	        String errorMsg = "Error in db_create_container : " + se.getMessage() + " -> BAILING OUT";	        JahiaConsole.println( "JahiaContainersDB", errorMsg );	        throw new JahiaException(   "Cannot create containers 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_create_container : cannot free resources",	                                    JahiaException.DATABASE_ERROR, JahiaException.WARNING );			}

⌨️ 快捷键说明

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