📄 jahiaapplicationspersistancebaseservice.java
字号:
dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(8); stmt = dbConn.createStatement(); // executes the query stmt.execute( sqlQuery ); try { ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); if ( stmt != null ) stmt.close(); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "add_application : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } // enters values with update_jahia_field update_application( theApp ); } // catches error if cannot auto-increment id, or if cannot update values catch (SQLException se) { String errorMsg = "Error in add_application : " + se.getMessage(); JahiaConsole.println( "ApplicationsDBManager", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot insert new application 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", "update_application : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end add_application public void update_application( ApplicationBean theApp ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { //System.out.println("update_application started"); // composes the query String sqlQuery = "UPDATE jahia_app_def SET "; sqlQuery += "jahiaid_jahia_app_def = " + theApp.getJahiaID() + ","; sqlQuery += "name_jahia_app_def = '" + JahiaTools.quote(theApp.getName()) + "',"; sqlQuery += "context_jahia_app_def = '" + JahiaTools.quote(theApp.getContext()) + "',"; sqlQuery += "visible_jahia_app_def = " + theApp.getVisibleStatus() + ","; if ( theApp.isShared() ){ sqlQuery += "shared_jahia_app_def = 1 ,"; } else { sqlQuery += "shared_jahia_app_def = 0 ,"; } sqlQuery += "rights_jahia_app_def = " + theApp.getRights() + " ,"; sqlQuery += "filename_jahia_app_def = '" + JahiaTools.quote(theApp.getFilename()) + "', "; sqlQuery += "desc_jahia_app_def = '" + JahiaTools.quote(theApp.getdesc()) + "' "; sqlQuery += "WHERE id_jahia_app_def=" + theApp.getID(); dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(9); stmt = dbConn.createStatement(); //System.out.println(sqlQuery); // executes the query ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery ); } catch (SQLException se) { String errorMsg = "Error in update_jahia_app_def : " + se.getMessage(); JahiaConsole.println( "JahiaApplicationsDBBaseService", errorMsg + " -> BAILING OUT"); throw new JahiaException( "Cannot update application definitions 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", "update_application : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end update_application public void setName(String name){ this.serviceName = name; } public void removeApplication ( ApplicationBean theApp ) throws JahiaException { removeApplication(theApp.getID()); } public void removeApplication ( int appID ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_app_def WHERE "; sqlQuery += "id_jahia_app_def = " + Integer.toString(appID); dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(10); stmt = dbConn.createStatement(); stmt.execute( sqlQuery ); // delete application role groups Vector vec = GroupsTools.getGroups(true); JahiaGroupManagerService gms = ServicesRegistry.getInstance() .getJahiaGroupManagerService(); int size = vec.size(); JahiaGroup grp = null; String appIDStr = null; for ( int i=0 ; i<size ; i++ ){ grp = (JahiaGroup)vec.get(i); appIDStr = GroupsTools.getAppIDPart(grp.getGroupname()); if ( appIDStr != null && (Integer.parseInt(appIDStr) == appID) ){ gms.deleteGroup(grp); } } } catch (SQLException se) { String errorMsg = "Error in removeApplication : " + se.getMessage(); JahiaConsole.println( "JahiaApplicationsPersistanceBaseService", errorMsg + " -> BAILING OUT"); throw new JahiaException( "Cannot remove application definitions 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", "removeApplication : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } //-------------------------------------------------------------------------- /** * return a DOM document of applications definitions * * @param int the site id * * @return JahiaDOMObject a DOM representation of this object * * @author NK */ public JahiaDOMObject getApplicationDefsAsDOM( int siteID ) throws JahiaException{ Connection dbConn = null; Statement statement = null; String output = null; JahiaDBDOMObject dom = null; try { String sqlQuery = "SELECT * FROM jahia_app_def" +" WHERE jahiaid_jahia_app_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_app_def",rs); return dom; } } } catch (SQLException se) { String errorMsg = "Error in getApplicationDefsAsDOM(int siteID) : " + se.getMessage(); JahiaConsole.println( "JahiaApplicationsPersistanceBaseService", errorMsg ); throw new JahiaException( "Cannot load data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return dom; } //------------------------------------------------------------------------- private Connection getDBConnection () { Connection dbConn = null; try { dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (); } catch (NullPointerException ex) { JahiaConsole.println ("JahiaSiteUserManagerDBService", "Null Pointer Exception, DB Pool Service instance might be null!"); } catch (SQLException ex) { JahiaConsole.println ("JahiaSiteUserManagerDBService", "SQL Exception: cannot get a connection."); } return dbConn; } //------------------------------------------------------------------------- private Connection getDBConnection (int debugInfo) { Connection dbConn = null; try { dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (debugInfo); } catch (NullPointerException ex) { JahiaConsole.println ("JahiaSiteUserManagerDBService", "Null Pointer Exception, DB Pool Service instance might be null!"); } catch (SQLException ex) { JahiaConsole.println ("JahiaSiteUserManagerDBService", "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 ("JahiaSiteUserManagerDBService", "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); } } /////////////////////////////////////////////////////////////////////////////////////////////// // FIXME -Fulco- // // The purpose of the method is only to add the creator of an application // (application adding on a page) into the groups "manager" and "administrator". // // REMOVE THIS METHOD AS SOON AS POSSIBLE !!!!!! // /////////////////////////////////////////////////////////////////////////////////////////////// public void fake_create_application_groups ( ApplicationBean theApp, int fieldID, JahiaUser user) throws JahiaException { String groupname; JahiaGroup group; // Add the user to the "Administrator" group groupname = Integer.toString (theApp.getID()) + "_" + Integer.toString (fieldID) + "_administrator"; group = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup (groupname); if (group != null) { group.addMember (user); } // Add the user to the "manager" group groupname = Integer.toString (theApp.getID()) + "_" + Integer.toString (fieldID) + "_manager"; group = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup (groupname); if (group != null) { group.addMember (user); } } ///////////////////////////////////////////////////////////////////////////////////////////////} // end JahiaApplicationsPersistanceBaseService
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -