📄 jahiasitespersistance.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// JahiaSitesPersistance//// NK 12.03.2001//package org.jahia.services.sites;import java.sql.*;import java.util.Vector;import java.util.Enumeration;import org.jahia.services.acl.JahiaBaseACL;import org.jahia.services.acl.JahiaACLException;import org.jahia.settings.JahiaPrivateSettings;import org.jahia.registries.ServicesRegistry;import org.jahia.utils.JahiaTools;import org.jahia.utils.JahiaConsole;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.database.JahiaDatabaseException;import org.jahia.exceptions.JahiaInitializationException;import org.jahia.services.sites.SitesDBInterface;import org.jahia.data.JahiaDOMObject;import org.jahia.data.JahiaDBDOMObject;/** * persistance storage of jahia sites informations * * @author Khue ng */class JahiaSitesPersistance implements SitesDBInterface{ private static final String CLASS_NAME = JahiaSitesPersistance.class.getName(); /** unique instance */ private static JahiaSitesPersistance m_Instance = null; public static final int ORDER_BY_SERVER_NAME = 1; public static final int ORDER_BY_TITLE = 2; /** * constructor * */ protected JahiaSitesPersistance(){ } //-------------------------------------------------------------------------- /** * return the singleton instance of this class * */ public static synchronized JahiaSitesPersistance getInstance(){ if ( m_Instance == null ){ m_Instance = new JahiaSitesPersistance(); } return m_Instance; } //-------------------------------------------------------------------------- /** * return the list of all sites * * @param int the Order attribute * @return a Vector of JahiaSite bean * */ public Vector dbGetSites() throws JahiaException{ //return dbGetSites(ORDER_BY_TITLE); return dbGetSites(ORDER_BY_SERVER_NAME); } //-------------------------------------------------------------------------- /** * return the list of all sites * * @param int the Order attribute * @return Vector of JahiaSite bean */ public Vector dbGetSites( int orderType ) throws JahiaException{ Connection dbConn = null; Statement statement = null; Vector sites = new Vector(); JahiaSite site = null; try { String sqlQuery = "SELECT * FROM jahia_sites" + getOrderCond(orderType); dbConn = getDBConnection(); statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery ); if (rs != null) { while (rs.next()) { site = getJahiaSiteFromResultSet(rs); sites.add(site); } } } } catch (SQLException se) { String errorMsg = "Error in dbGetSites : " + se.getMessage(); JahiaConsole.println( "JahiaSitesPersistance", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load sites from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return sites; } //-------------------------------------------------------------------------- /** * return the JahiaSite bean looking at it id * * @param int the JahiaSite id * @return JahiaSite the JahiaSite bean */ public JahiaSite dbGetSite( int id ) throws JahiaException{ Connection dbConn = null; Statement statement = null; JahiaSite site = null; try { String sqlQuery = "SELECT * FROM jahia_sites where id_jahia_sites=" + id; dbConn = getDBConnection(); statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery ); if (rs != null) { if ( rs.next() ){ site = getJahiaSiteFromResultSet(rs); } } } } catch (SQLException se) { String errorMsg = "Error in dbGetSite(int id) : " + se.getMessage(); JahiaConsole.println( "JahiaSitesPersistance", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load site from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return site; } //-------------------------------------------------------------------------- /** * return the JahiaSite bean looking at it key * * @param String the JahiaSite key * @return JahiaSite the JahiaSite bean */ public JahiaSite dbGetSiteByKey( String siteKey ) throws JahiaException{ Connection dbConn = null; Statement statement = null; JahiaSite site = null; try { StringBuffer sqlQuery = new StringBuffer("SELECT * FROM jahia_sites where key_jahia_sites='"); sqlQuery.append(siteKey); sqlQuery.append("'"); dbConn = getDBConnection(); statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery.toString() ); if (rs != null) { if ( rs.next() ){ site = getJahiaSiteFromResultSet(rs); } } } } catch (SQLException se) { String errorMsg = "Error in dbGetSite(int id) : " + se.getMessage(); JahiaConsole.println( "JahiaSitesPersistance", errorMsg + " -> B AILING OUT" ); throw new JahiaException( "Cannot load site from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return site; } //-------------------------------------------------------------------------- /** * return a site looking at it's server name ( www.jahia.org ) * * @param String server name ( www.jahia.org ) * @return JahiaSite the JahiaSite bean or null */ public JahiaSite dbGetSite( String name ) throws JahiaException{ Connection dbConn = null; Statement statement = null; JahiaSite site = null; try { StringBuffer sqlQuery = new StringBuffer("SELECT * FROM jahia_sites WHERE servername_jahia_sites='"); sqlQuery.append(JahiaTools.quote(name)); sqlQuery.append("'"); dbConn = getDBConnection(); statement = dbConn.createStatement(); if (statement != null) { ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery.toString() ); if (rs != null) { if ( rs.next() ){ site = getJahiaSiteFromResultSet(rs); } } } } catch (SQLException se) { String errorMsg = "Error in dbGetSite(String name) : " + se.getMessage(); JahiaConsole.println( "JahiaSitesPersistance", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load site from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return site; } //-------------------------------------------------------------------------- /** * add a new site * * @param JahiaSite the JahiaSite bean */ public void dbAddSite( JahiaSite site ) throws JahiaException{ try { int id = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sites"); StringBuffer sqlQuery = new StringBuffer("INSERT INTO jahia_sites VALUES("); sqlQuery.append(id); sqlQuery.append(",'"); sqlQuery.append(JahiaTools.quote(site.getTitle())); sqlQuery.append("','"); sqlQuery.append(JahiaTools.quote(site.getServerName())); sqlQuery.append("','"); sqlQuery.append(JahiaTools.quote(site.getSiteKey())); sqlQuery.append("',"); if ( site.isActive() ){ sqlQuery.append(1); } else { sqlQuery.append(0); } sqlQuery.append(","); sqlQuery.append(site.getHomePageID()); sqlQuery.append(","); sqlQuery.append(site.getDefaultTemplateID()); sqlQuery.append(","); if ( site.getTemplatesAutoDeployMode() ){ sqlQuery.append(1); } else { sqlQuery.append(0); } sqlQuery.append(","); if ( site.getWebAppsAutoDeployMode() ){ sqlQuery.append(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -