📄 jahiapagesdb.java
字号:
} // catches an exception in the query catch (SQLException se) { String errorMsg = "Error in updatePageInfo : " + se.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "JahiaPagesDB", errorMsg ); throw new JahiaException( "Cannot create a new page in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return result; } //------------------------------------------------------------------------- /** Remove only the page info from the database. * * @param pageID The page id to delete. * * @return Return true if the page info could be removed from the database, * or false on any error. * * @exception JahiaException * Throws a {@link org.jahia.exceptions.JahiaException JahiaException} * on any database error. */ public boolean deletePageInfo (int pageID) throws JahiaException { // Get the database connection. Connection dbConn = getDBConnection (73); if (dbConn == null) { throw new JahiaException ( "Page deletion error on database access", "Cannot delete the requested page in the database, could not obtain a DB connection.", JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } boolean result = false; Statement statement = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_pages_data WHERE id_jahia_pages_data = " + pageID; // executes the query statement = dbConn.createStatement(); if (statement != null) { statement.execute (sqlQuery); result = true; } } // catches an exception in the query catch (SQLException se) { String errorMsg = "Error in db_delete_page_info : " + se.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "JahiaPagesDB", errorMsg ); throw new JahiaException( "Cannot delete a page in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return result; } //------------------------------------------------------------------------- /** Return the next available page info ID. * * @return Return the next available page info ID. */ public synchronized int getNextID () { int counter = -1; Connection dbConn = getDBConnection (74); if (dbConn != null) { Statement statement = null; try { String query = "SELECT MAX(id_jahia_pages_data) as MaxID FROM jahia_pages_data"; statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement,query); if (rs != null) { if (rs.next()) { // get the highest used page ID counter = rs.getInt ("MaxID"); // increment by one to get the next counter counter++; } } } } catch (SQLException ex) { // .............. } finally{ closeDBConnection (dbConn); closeStatement (statement); } } return counter; } //------------------------------------------------------------------------- /** * public Vector loadAllPageInfos () throws JahiaException { Vector result = new Vector (); // get the DB connection Connection dbConn = getDBConnection (76); if (dbConn == null) { return null; } Statement statement = null; try { String sqlQuery = "SELECT * FROM jahia_pages_data"; statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = statement.executeQuery (sqlQuery); if (rs != null) { while (rs.next()) { JahiaPage page = readPageInfoFromResultSet (rs); if (page != null) { result.add (page); } } } } } catch (SQLException se) { String errorMsg = "Error in loadAllPageInfo : " + se.getMessage() + " -> BAILING OUT"; JahiaConsole.println( "JahiaPagesDB", errorMsg ); throw new JahiaException( "Cannot load the page values from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return result; }*/ //------------------------------------------------------------------------- // This method try to get a database connection from the DB Pool Connection // service. If not connection could be taken, or if any database error // occured, null will be returned. Otherwise the reference on a valid // connection is returned. private Connection getDBConnection (int debugInfo) { Connection dbConn = null; try { dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (debugInfo); } 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; } //------------------------------------------------------------------------- // Release the specified database connection 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!"); } } } //------------------------------------------------------------------------- // Close the specified SQL statement. 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); } } //------------------------------------------------------------------------- private JahiaPageInfo readPageInfoFromResultSet (int pageID, ResultSet rs) throws SQLException { // Extract all the page info from the ResultSet int jahiaID = rs.getInt ( "jahiaid_jahia_pages_data" ); int parentID = rs.getInt ( "parentid_jahia_pages_data" ); int pageType = rs.getInt ( "pagetype_jahia_pages_data" ); String pageTitle = FormDataManager.getInstance().decode(rs.getString ( "title_jahia_pages_data" )); int pageTemplateID = rs.getInt ( "pagedefid_jahia_pages_data" ); String remoteUrl = FormDataManager.getInstance().decode(rs.getString ( "remoteurl_jahia_pages_data" )); int pageLinkID = rs.getInt ( "pagelinkid_jahia_pages_data" ) + 0; String creator = rs.getString ( "creator_jahia_pages_data" ) + ""; String doc = rs.getString ( "doc_jahia_pages_data" ) + ""; int counter = rs.getInt ( "counter_jahia_pages_data" ) + 0; int rights = rs.getInt ( "rights_jahia_pages_data" ) + 0; if (remoteUrl.equals("<no url>")) { remoteUrl = null; } // create the page return new JahiaPageInfo (pageID, jahiaID, parentID, pageType, pageTitle, pageTemplateID, remoteUrl, pageLinkID, creator, doc, counter, rights); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -