001: /*
002: * Copyright 2004,2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.wso2.esb.persistence;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.wso2.esb.ServiceBusConstants;
021: import org.wso2.esb.persistence.dao.RegistryEntryDAO;
022: import org.wso2.esb.persistence.dao.StatisticsDAO;
023: import org.wso2.esb.persistence.dataobject.RegistryEntryDO;
024: import org.wso2.esb.persistence.dataobject.StatisticsDO;
025: import org.wso2.esb.util.HibernateConfig;
026: import org.wso2.esb.util.HibernateConfigCache;
027:
028: import java.util.List;
029:
030: /**
031: *
032: */
033: public class PersistenceManager {
034:
035: private static Log log = LogFactory
036: .getLog(PersistenceManager.class);
037:
038: /** The HibernateConfiguration */
039: private HibernateConfig hbConfig;
040:
041: public PersistenceManager() {
042: this .hbConfig = HibernateConfigCache
043: .getHibernateConfig(
044: org.wso2.esb.ServiceBusConstants.WSO2ESB_HB_CONFIG_KEY,
045: System
046: .getProperty(ServiceBusConstants.ESB_HIBERNATE_CFG_XML));
047: }
048:
049: public PersistenceManager(HibernateConfig hbConfig) {
050: this .hbConfig = hbConfig;
051: }
052:
053: /**
054: * add a Statistics Record to the database
055: *
056: * @param statisticsDO
057: */
058: public void addStatisticsRecord(StatisticsDO statisticsDO) {
059: new StatisticsDAO(hbConfig).create(statisticsDO);
060: }
061:
062: /**
063: * delete a Statistics Record
064: *
065: * @param statisticsDO
066: */
067: public void deleteStatisticsRecord(StatisticsDO statisticsDO) {
068: new StatisticsDAO(hbConfig).delete(statisticsDO);
069: }
070:
071: /**
072: * update a Satistics Record
073: *
074: * @param statisticsDO
075: */
076: public void updateStatisticsRecord(StatisticsDO statisticsDO) {
077: new StatisticsDAO(hbConfig).update(statisticsDO);
078: }
079:
080: /**
081: * Retrieves Statistics Records
082: *
083: * @param hqlQuery
084: * @return The Statistics Records
085: */
086: public StatisticsDO[] selectStatisticsRecords(String hqlQuery) {
087: return new StatisticsDAO(hbConfig)
088: .selectStatisticsRecords(hqlQuery);
089: }
090:
091: /**
092: * Retrieves Statistics Records using custom SQL query passed in
093: *
094: * @param sqlQuery
095: * @param aClass
096: * @return The Statistics Records
097: */
098: public StatisticsDO[] selectStatisticsRecordsBySQL(String sqlQuery,
099: Class aClass) {
100: return new StatisticsDAO(hbConfig)
101: .selectStatisticsRecordsBySQL(sqlQuery, aClass);
102: }
103:
104: /**
105: * To create a new object based on Statistics Records
106: *
107: * @param hqlQuery
108: * @return new result object
109: */
110: public Object createAnewObjectFromStatistics(String hqlQuery) {
111: return new StatisticsDAO(hbConfig).createAnewObject(hqlQuery);
112: }
113:
114: public List selectCustomObjectList(String hqlQuery) {
115: return new StatisticsDAO(hbConfig)
116: .selectCustomObjectList(hqlQuery);
117: }
118:
119: public int clearAll(String hglQuery) {
120: return new StatisticsDAO(hbConfig).execute(hglQuery);
121: }
122:
123: /* Data access methods for ESB registry */
124: public void addRegistryEntry(RegistryEntryDO registryEntryDO) {
125: new RegistryEntryDAO(hbConfig)
126: .addRegistryEntry(registryEntryDO);
127: }
128:
129: public void updateRegistryEntry(RegistryEntryDO registryEntryDO) {
130: new RegistryEntryDAO(hbConfig)
131: .updateRegistryEntry(registryEntryDO);
132: }
133:
134: public void saveOrUpdateRegistryEntry(
135: RegistryEntryDO registryEntryDO) {
136: new RegistryEntryDAO(hbConfig)
137: .saveOrUpdateRegistryEntry(registryEntryDO);
138: }
139:
140: public RegistryEntryDO getRegistryEntry(String key) {
141: return new RegistryEntryDAO(hbConfig).getRegistryEntry(key);
142: }
143:
144: public void deleteRegistryEntry(String key) {
145: new RegistryEntryDAO(hbConfig).deleteRegistryEntry(key);
146: }
147: }
|