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

📄 jahiacontainerlistsdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .///** * Holds all the methods enabling container lists load, create, update and * delete. * * @author Eric Vassalli * */////  db_load_container_list( containerListID )//  db_create_container_list( theContainerList )//  db_update_container_list( theContainerList )//  db_delete_container_list( theContainerList )//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 JahiaContainerListsDB {    /***        * constructor        *        */    public JahiaContainerListsDB()    {    } // end constructor    /***        * loads a container list from its list ID        *        * @param        listID          the list ID        * @return       returns a JahiaContainerList object        * @see          org.jahia.data.containers.JahiaContainerList        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        *        */    public JahiaContainerList db_load_container_list( int listID )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        JahiaContainerList theList = null;        try {            String sqlQuery = "SELECT * FROM jahia_ctn_lists";            sqlQuery += " WHERE id_jahia_ctn_lists=" + listID;            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(19);            stmt = dbConn.createStatement();            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            if (rs.next()) {                int id                          = rs.getInt( "id_jahia_ctn_lists" );                int parentid                    = rs.getInt( "parententryid_jahia_ctn_lists" );                int pageid                      = rs.getInt( "pageid_jahia_ctn_lists" );                int defid                       = rs.getInt( "ctndefid_jahia_ctn_lists" );                int rights                      = rs.getInt( "rights_jahia_ctn_lists" );                theList = new JahiaContainerList( id, parentid, pageid, defid, rights );            }        } catch (SQLException se) {            String errorMsg = "Error in db_load_container_list : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaContainerListsDB", errorMsg );            throw new JahiaException(   "Cannot load containers 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_list : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return theList;    } // end db_load_container_list    /***        * creates a new containerlist, and assignes it a new ID        *        * @param        theContainerList    the JahiaContainerList object to save        * @see          org.jahia.data.containers.JahiaContainerList        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        *        */    public void db_create_container_list( JahiaContainerList theContainerList )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        try {            // opens connection            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(20);            stmt = dbConn.createStatement();            // gets the field id            int theListID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_ctn_lists" );            theContainerList.setID( theListID );            // creates empty line            String sqlQuery = "INSERT INTO jahia_ctn_lists(id_jahia_ctn_lists) VALUES(" + theContainerList.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_containerlist : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );             }            // enters values with db_update_container_list            db_update_container_list( theContainerList );        } catch (SQLException se) {            String errorMsg = "Error in db_create_container_list : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaContainerListsDB", 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_list : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }    } // end db_create_container_list    /***        * creates a new containerlist with the new ID already set.        *        * @param        theContainerList    the JahiaContainerList object to save        * @see          org.jahia.data.containers.JahiaContainerList        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        *        */    public void db_create_container_list2( JahiaContainerList theContainerList )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        try {            // opens connection            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(20);            stmt = dbConn.createStatement();            // creates empty line            String sqlQuery = "INSERT INTO jahia_ctn_lists(id_jahia_ctn_lists) VALUES(" + theContainerList.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_containerlist : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );             }            // enters values with db_update_container_list            db_update_container_list( theContainerList );        } catch (SQLException se) {            String errorMsg = "Error in db_create_container_list : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaContainerListsDB", 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();

⌨️ 快捷键说明

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