📄 jahiacontainerlistsdb.java
字号:
} 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_list2 /*** * updates a container list in the database * * @param theContainerList a JahiaContainerList object * * @exception throws a critical JahiaException if SQL error * @exception throws a warning JahiaException if cannot free resources * */ public void db_update_container_list( JahiaContainerList theContainerList ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "UPDATE jahia_ctn_lists SET "; sqlQuery += "parententryid_jahia_ctn_lists = " + theContainerList.getParentEntryID() + ","; sqlQuery += "pageid_jahia_ctn_lists = " + theContainerList.getPageID() + ","; sqlQuery += "ctndefid_jahia_ctn_lists = " + theContainerList.getctndefid() + ","; sqlQuery += "rights_jahia_ctn_lists = " + theContainerList.getAclID() + " "; sqlQuery += "WHERE id_jahia_ctn_lists = " + theContainerList.getID(); // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(21); stmt = dbConn.createStatement(); ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery ); } // catches error if cannot execute update query catch (SQLException se) { String errorMsg = "Error in db_update_container_list : " + se.getMessage(); JahiaConsole.println( "JahiaContainerListsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot update 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_update_container_list : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_update_container_list /*** * deletes a container list in the database * * @param listID the container list id * * @exception throws a critical JahiaException if SQL error * @exception throws a warning JahiaException if cannot free resources * */ public void db_delete_container_list( int listID ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_ctn_lists "; sqlQuery += "WHERE id_jahia_ctn_lists = " + listID; // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(22); stmt = dbConn.createStatement(); ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery ); } // catches error if cannot execute update query catch (SQLException se) { String errorMsg = "Error in db_delete_container_list : " + se.getMessage(); JahiaConsole.println( "JahiaContainerListsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot delete 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_delete_container_list : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_delete_container_list //-------------------------------------------------------------------------- /** * return a DOM document of all container lists of a site * * @param siteID the site id * * @return JahiaDOMObject a DOM representation of this object * * @author NK */ public JahiaDOMObject getContainerListsAsDOM( int siteID ) throws JahiaException{ Connection dbConn = null; Statement statement = null; String output = null; JahiaDBDOMObject dom = null; try { String sqlQuery = "SELECT DISTINCT jahia_ctn_lists.id_jahia_ctn_lists," +"jahia_ctn_lists.parententryid_jahia_ctn_lists,jahia_ctn_lists.pageid_jahia_ctn_lists," +"jahia_ctn_lists.ctndefid_jahia_ctn_lists,jahia_ctn_lists.rights_jahia_ctn_lists" +" FROM jahia_ctn_lists,jahia_ctn_def where jahia_ctn_lists.ctndefid_jahia_ctn_lists=" +"jahia_ctn_def.id_jahia_ctn_def AND jahia_ctn_def.jahiaid_jahia_ctn_def=" +siteID; dbConn = getDBConnection(0); statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement, sqlQuery ); if (rs != null) { dom = new JahiaDBDOMObject(); dom.addTable("jahia_ctn_lists",rs); return dom; } } } catch (SQLException se) { String errorMsg = "Error in getContainerListsAsDOM(int siteID) : " + se.getMessage(); JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load container lists from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return dom; } //------------------------------------------------------------------------- private Connection getDBConnection (int debugInfo) { Connection dbConn = null; try { if ( debugInfo != 0 ){ dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (debugInfo); } else { dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (); } } catch (NullPointerException ex) { JahiaConsole.println ("JahiaPagesDB", "Null Pointer Exception, DB Pool Service instance might be null!"); } catch (SQLException ex) { JahiaConsole.println ("JahiaPagesDB", "SQL Exception: cannot get a connection."); } return dbConn; } //------------------------------------------------------------------------- private void closeDBConnection (Connection dbConn) { if (dbConn != null) { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection (dbConn); } 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 ("JahiaPagesDB", "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(); } } 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); } }} // end JahiaContainerListsDB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -