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

📄 jahiacontainerdefinitionsdb.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .///** * JahiaContainerDefinitionsDB * @author Eric Vassalli * * Holds all the methods enabling container definitions load, update and delete. * * @todo This is a huge mess... Table names are completely misleading. From what * I can understand jahia_ctn_def_properties is a table used to figure out which * Jahia pages are using which definition, so that we may for example update * or destroy these pages once the definition is changed or deleted. */////  db_load_container_definition( defID )//  db_create_container_definition( theContainerDef )//  db_update_container_definition( theContainerDef )//  db_delete_container_definition( defID )//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 JahiaContainerDefinitionsDB{    private JahiaContainerStructuresDB  c_struct;    /***        * constructor        * EV    26.12.2000        *        */    public JahiaContainerDefinitionsDB()    {        c_struct = new JahiaContainerStructuresDB();    } // end constructor    /***        * load a container definition by its id        *        * @return       a JahiaContainerDefinition object        * @see          org.jahia.data.containers.JahiaContainerDefinition        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        * @exception    throws a warning JahiaException and returns null if container structure not found        *        */    public JahiaContainerDefinition db_load_container_definition( int defID )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        ResultSet rs2 = null;        JahiaContainerDefinition theDef = null;        try {            // creates connexion            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(40);            stmt = dbConn.createStatement();            // prepares sqlQuery            String sqlQuery = "SELECT * FROM jahia_ctn_def ";            sqlQuery += "WHERE id_jahia_ctn_def = " + defID;            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery );            if (rs.next()) {                int     ID              = rs.getInt     ( "id_jahia_ctn_def" );                int     jahiaID         = rs.getInt     ( "jahiaid_jahia_ctn_def" );                String  name            = rs.getString  ( "name_jahia_ctn_def" );                sqlQuery = "SELECT * FROM jahia_ctn_def_properties ";                sqlQuery += "WHERE ctndefid_jahia_ctn_def_prop=" + ID;                rs2 = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );                Hashtable subDefs = new Hashtable();                while (rs2.next()) {                    int     subDefID        = rs2.getInt     ( "id_jahia_ctn_def_properties" );                    int     templateID      = rs2.getInt     ( "pagedefid_jahia_ctn_def_prop" );                    String  title           = rs2.getString  ( "title_jahia_ctn_def_properties" );                    Vector  structure       = c_struct.db_load_container_structure( subDefID );                    subDefs.put( new Integer(templateID),                            new JahiaContainerSubDefinition( subDefID, templateID, title, structure ) );                }                theDef = new JahiaContainerDefinition( ID, jahiaID, name, subDefs );            }        } catch (SQLException se) {            String errorMsg = "Error in db_load_container_definition : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaContainerDefinitionsDB", 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_definition : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return theDef;    } // end db_load_container_definition    /***        * load a container definition by its name and site id        *        * @return       a JahiaContainerDefinition object        * @see          org.jahia.data.containers.JahiaContainerDefinition        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        * @exception    throws a warning JahiaException and returns null if container structure not found        *        */    public JahiaContainerDefinition db_load_container_definition( int siteID, String defName )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        ResultSet rs2 = null;        JahiaContainerDefinition theDef = null;        try {            // creates connexion            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(40);            stmt = dbConn.createStatement();            // prepares sqlQuery            String sqlQuery = "SELECT * FROM jahia_ctn_def ";            sqlQuery += "WHERE jahiaid_jahia_ctn_def = " + siteID + " and name_jahia_ctn_def='" + defName + "'";            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );            if (rs.next()) {                int     ID              = rs.getInt     ( "id_jahia_ctn_def" );                int     jahiaID         = rs.getInt     ( "jahiaid_jahia_ctn_def" );                String  name            = rs.getString  ( "name_jahia_ctn_def" );                sqlQuery = "SELECT * FROM jahia_ctn_def_properties ";                sqlQuery += "WHERE ctndefid_jahia_ctn_def_prop=" + ID;                rs2 = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt, sqlQuery );                Hashtable subDefs = new Hashtable();                while (rs2.next()) {                    int     subDefID        = rs2.getInt     ( "id_jahia_ctn_def_properties" );                    int     templateID      = rs2.getInt     ( "pagedefid_jahia_ctn_def_prop" );                    String  title           = rs2.getString  ( "title_jahia_ctn_def_properties" );                    Vector  structure       = c_struct.db_load_container_structure( subDefID );                    subDefs.put( new Integer(templateID),                            new JahiaContainerSubDefinition( subDefID, templateID, title, structure ) );                }                theDef = new JahiaContainerDefinition( ID, jahiaID, name, subDefs );            }        } catch (SQLException se) {            String errorMsg = "Error in db_load_container_definition : " + se.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "JahiaContainerDefinitionsDB", 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_definition : cannot free resources",                                        JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }        }        return theDef;    } // end db_load_container_definition    /***        * creates a container definition        *        * @param        theDef          the JahiaContainerDefinition object        * @see          org.jahia.data.containers.JahiaContainerDefinition        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        *        */    public void db_create_container_definition( JahiaContainerDefinition theDef )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        try {            // opens connection            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(16);            stmt = dbConn.createStatement();            // gets the field id            int theDefID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService(                                        ).autoIncrement( "jahia_ctn_def" );            theDef.setID( theDefID );            // saves definition base            String sqlQuery = "INSERT INTO jahia_ctn_def (";            sqlQuery += "id_jahia_ctn_def,";            sqlQuery += "jahiaid_jahia_ctn_def,";            sqlQuery += "name_jahia_ctn_def) VALUES(";            sqlQuery += theDef.getID() + ", ";            sqlQuery += theDef.getJahiaID() + ", ";            sqlQuery += "'" + theDef.getName() + "')";            ServicesRegistry.getInstance().getDBPoolService().executeUpdate (stmt,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_definition : cannot free resources",                     JahiaException.DATABASE_ERROR, JahiaException.WARNING );            }            // enters values with update_container_definition            db_update_container_definition (theDef);        }        // catches error if cannot execute insert query        catch (SQLException se)        {            String errorMsg = "Error in db_create_container_definition : " + se.getMessage();            JahiaConsole.println( "JahiaContainerDefinitionsDB", errorMsg + " -> BAILING OUT" );            throw new JahiaException(   "Cannot insert new container definitions in the database",                                        errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL );       }    } // end db_create_container_definition    /***        * updates a container definition        *        * @param        theDef          the JahiaContainerDefinition object        * @see          org.jahia.data.containers.JahiaContainerDefinition        *        * @exception    throws a critical JahiaException if a data access occurs        * @exception    throws a warning JahiaException if cannot free resources        *        */    public void db_update_container_definition( JahiaContainerDefinition theDef )    throws JahiaException    {        Connection dbConn = null;        Statement stmt = null;        String sqlQuery = "";        try {            // creates the connexion            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(17);            stmt = dbConn.createStatement();            // deletes all precedent sub definitions            sqlQuery = "DELETE FROM jahia_ctn_def_properties ";            sqlQuery += "WHERE ctndefid_jahia_ctn_def_prop=" + theDef.getID();            ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery );            // saves all sub definitions            Hashtable subDefs = theDef.getSubDefs();            Enumeration subKeys = subDefs.keys();            while (subKeys.hasMoreElements()) {                int pageDefID = ((Integer)subKeys.nextElement()).intValue();

⌨️ 快捷键说明

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