📄 jahiacontainerdefinitionsdb.java
字号:
JahiaContainerSubDefinition theSubDef = (JahiaContainerSubDefinition) subDefs.get( new Integer(pageDefID) ); // sets the subdef id if (theSubDef.getID() == 0) { int theSubDefID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService(). autoIncrement ( "jahia_ctn_def_properties" ); theSubDef.setID( theSubDefID ); } JahiaConsole.println("JahiaContainerDefinitionsDB.db_update_container_definition","Updating container def for " + theSubDef.getTitle() ); if (!theSubDef.getTitle().equals("")) { // composes the query sqlQuery = "INSERT INTO jahia_ctn_def_properties ("; sqlQuery += "id_jahia_ctn_def_properties,"; sqlQuery += "ctndefid_jahia_ctn_def_prop,"; sqlQuery += "pagedefid_jahia_ctn_def_prop,"; sqlQuery += "title_jahia_ctn_def_properties) VALUES("; sqlQuery += theSubDef.getID() + ","; sqlQuery += theDef.getID() + ","; sqlQuery += pageDefID + ","; sqlQuery += "'" + theSubDef.getTitle() + "')"; ServicesRegistry.getInstance().getDBPoolService().executeUpdate( stmt,sqlQuery ); } // creates the container structure c_struct.db_create_container_structure( theSubDef ); } } // catches error if cannot execute update query catch (SQLException se) { String errorMsg = "Error in db_update_container_definition : " + se.getMessage(); JahiaConsole.println( "JahiaContainerDefinitionsDB", errorMsg + " -> BAILING OUT"); throw new JahiaException( "Cannot update container definitions in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { if ( stmt != null ) stmt.close(); ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_update_container_definition : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_update_container_definition /*** * deletes a container definition and all it's subdef * * @param theDefID the container definition id * * @exception throws a critical JahiaException if a data access occurs * @exception throws a warning JahiaException if cannot free resources * */ public void db_delete_container_definition( int theDefID ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_ctn_def "; sqlQuery += "WHERE id_jahia_ctn_def=" + theDefID; // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(18); 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_definition : " + se.getMessage(); JahiaConsole.println( "JahiaContainerDefinitionsDB", errorMsg + " -> BAILING OUT"); throw new JahiaException( "Cannot delete container definitions in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { if ( stmt != null ) stmt.close(); ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_delete_container_definition : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_delete_container_definition /*** * deletes a container sub definitions of a ctn definition ID * * @param thePageDefID the pageDefID * * @exception throws a critical JahiaException if a data access occurs * @exception throws a warning JahiaException if cannot free resources * */ public void db_delete_container_sub_definition( int ctnDefID ) throws JahiaException { Connection dbConn = null; Statement stmt = null; try { // composes the query String sqlQuery = "DELETE FROM jahia_ctn_def_properties "; sqlQuery += "WHERE ctndefid_jahia_ctn_def_prop=" + ctnDefID; // executes the query dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(18); 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_sub_definition : " + se.getMessage(); JahiaConsole.println( "JahiaContainerDefinitionsDB", errorMsg + " -> BAILING OUT"); throw new JahiaException( "Cannot delete container sub definitions in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { if ( stmt != null ) stmt.close(); ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_delete_container_sub_definition : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } } // end db_delete_container_sub_definition //-------------------------------------------------------------------------- /** * return a DOM document of all container def of a site * * @param int the site id * * @return JahiaDOMObject a DOM representation of this object * * @author NK */ public JahiaDOMObject getContainerDefsAsDOM( int siteID ) throws JahiaException{ Connection dbConn = null; Statement statement = null; String output = null; JahiaDBDOMObject dom = null; try { String sqlQuery = "SELECT * FROM jahia_ctn_def where 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_def",rs); return dom; } } } catch (SQLException se) { String errorMsg = "Error in getContainerDefsAsDOM(int siteID) : " + se.getMessage(); JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load container defs from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return dom; } //-------------------------------------------------------------------------- /** * return a DOM document of all container def prop of a site * * @param int the site id * * @return JahiaDOMObject a DOM representation of this object * * @author NK */ public JahiaDOMObject getContainerDefPropsAsDOM( int siteID ) throws JahiaException{ Connection dbConn = null; Statement statement = null; String output = null; JahiaDBDOMObject dom = null; try { String sqlQuery = "SELECT DISTINCT jahia_ctn_def_properties.id_jahia_ctn_def_properties," +"jahia_ctn_def_properties.ctndefid_jahia_ctn_def_prop,jahia_ctn_def_properties.pagedefid_jahia_ctn_def_prop," +"jahia_ctn_def_properties.title_jahia_ctn_def_properties" +" FROM jahia_ctn_def_properties,jahia_ctn_def where jahia_ctn_def_properties.ctndefid_jahia_ctn_def_prop=" +"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_def_properties",rs); return dom; } } } catch (SQLException se) { String errorMsg = "Error in getContainerDefPropsAsDOM(int siteID) : " + se.getMessage(); JahiaConsole.println( "JahiaFieldsDB", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load container defs prop 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 JahiaContainerDefinitionsDB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -