📄 jahiacontainersdb.java
字号:
} } // end db_create_container /*** * updates a container entry in the database * * @param theContainer a JahiaContainer object * * @exception throws a critical JahiaException if SQL error * @exception throws a warning JahiaException if cannot free resources * */ public void db_update_container( JahiaContainer theContainer ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { String errorMsg = ""; if (theContainer.getDefinition().getName().equals("")) { errorMsg = "Error in db_update_container : container name value is an empty string"; } if (errorMsg != "") { JahiaConsole.println( "JahiaContainersDB", errorMsg ); throw new JahiaException( "Cannot update containers in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } // composes the query String sqlQuery = "UPDATE jahia_ctn_entries SET "; sqlQuery += "jahiaid_jahia_ctn_entries = " + theContainer.getJahiaID() + ","; sqlQuery += "pageid_jahia_ctn_entries = " + theContainer.getPageID() + ","; sqlQuery += "listid_jahia_ctn_entries = " + theContainer.getListID() + ","; sqlQuery += "ctndefid_jahia_ctn_entries = " + theContainer.getctndefid() + ","; sqlQuery += "rank_jahia_ctn_entries = " + theContainer.getRank() + ","; sqlQuery += "rights_jahia_ctn_entries = " + theContainer.getAclID() + " "; sqlQuery += "WHERE id_jahia_ctn_entries = " + theContainer.getID(); // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(25); 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 : " + se.getMessage(); JahiaConsole.println( "JahiaContainersDB", 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 : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_update_container /*** * deletes a container entry in the database * * @param thectnid the JahiaContainer object ID * * @exception throws a critical JahiaException if SQL error * @exception throws a warning JahiaException if cannot free resources * */ public void db_delete_container( int thectnid ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_ctn_entries "; sqlQuery += "WHERE id_jahia_ctn_entries=" + thectnid; // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(26); 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 : " + se.getMessage(); JahiaConsole.println( "JahiaContainersDB", 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 : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_delete_container //-------------------------------------------------------------------------- /** * return a DOM document of all containers of a site * * @param int the site id * * @return JahiaDOMObject a DOM representation of this object * * @author NK */ public JahiaDOMObject getContainersAsDOM( int siteID ) throws JahiaException{ Connection dbConn = null; Statement statement = null; String output = null; JahiaDBDOMObject dom = null; try { String sqlQuery = "SELECT * FROM jahia_ctn_entries where jahiaid_jahia_ctn_entries="+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_entries",rs); return dom; } } } catch (SQLException se) { String errorMsg = "Error in getContainersAsDOM(int siteID) : " + se.getMessage(); JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load containers 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 JahiaContainersDB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -