[jboss-svn-commits] JBL Code SVN: r12399 - in labs/jbossesb/trunk/product/core: listeners/src/org/jboss/soa/esb/listeners/config and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jun 8 00:40:50 EDT 2007
Author: tcunning
Date: 2007-06-08 00:40:50 -0400 (Fri, 08 Jun 2007)
New Revision: 12399
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/HibernateListenerMapper.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateEventBean.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageHibernateMessageContents.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/HibernateCourier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/DefaultHibernateReplyToEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HibernateEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/metadata/MetaDataFilter.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
bug:JBESB-434
Commit Hibernate listener.
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -92,6 +92,9 @@
public static final String FILE_POST_SFX_TAG = "postSuffix";
public static final String FILE_POST_DEL_TAG = "postDelete";
+ /** Hibernate related */
+ public static final String HIBERNATE_OBJECT_DATA_TAG = "hibernateObject";
+
/** SQL related */
public static final String SQL_ROW_DATA_TAG = "sqlRowData";
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -332,6 +332,7 @@
}
} // ________________________________
+
/**
* Find an attribute in the tree (arg 0) or assign default value (arg 2)
*
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -29,12 +29,14 @@
import org.jboss.soa.esb.listeners.config.FtpListenerDocument.FtpListener;
import org.jboss.soa.esb.listeners.config.Generator.XMLBeansModel;
import org.jboss.soa.esb.listeners.config.GroovyListenerDocument.GroovyListener;
+import org.jboss.soa.esb.listeners.config.HibernateListenerDocument.HibernateListener;
import org.jboss.soa.esb.listeners.config.JbrListenerDocument.JbrListener;
import org.jboss.soa.esb.listeners.config.JmsListenerDocument.JmsListener;
import org.jboss.soa.esb.listeners.config.SqlListenerDocument.SqlListener;
import org.jboss.soa.esb.listeners.config.mappers.FsListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.FtpListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.GroovyListenerMapper;
+import org.jboss.soa.esb.listeners.config.mappers.HibernateListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.JbrListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.JcaGatewayMapper;
import org.jboss.soa.esb.listeners.config.mappers.JmsListenerMapper;
@@ -100,8 +102,8 @@
JmsListenerMapper.map(root, (JmsListener)gateway, model);
} else if (gateway instanceof FsListener){
FsListenerMapper.map(root, (FsListener)gateway, model);
- } else if(gateway instanceof JcaGatewayDocument.JcaGateway) {
- JcaGatewayMapper.map(root, (JcaGatewayDocument.JcaGateway)gateway, model);
+ } else if(gateway instanceof JcaGatewayDocument.JcaGateway) {
+ JcaGatewayMapper.map(root, (JcaGatewayDocument.JcaGateway)gateway, model);
} else if (gateway instanceof FtpListener) {
FtpListenerMapper.map(root, (FtpListener)gateway, model);
} else if (gateway instanceof SqlListener) {
@@ -110,6 +112,8 @@
JbrListenerMapper.map(root, (JbrListener)gateway, model);
} else if (gateway instanceof GroovyListener) {
GroovyListenerMapper.map(root, (GroovyListener)gateway, model);
+ } else if (gateway instanceof HibernateListener) {
+ HibernateListenerMapper.map(root, (HibernateListener)gateway, model);
} else {
UntypedListenerMapper.map(root, gateway, model);
}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/HibernateListenerMapper.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/HibernateListenerMapper.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/HibernateListenerMapper.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.config.mappers;
+
+import java.util.List;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
+import org.jboss.soa.esb.dom.YADOMUtil;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.config.Generator.XMLBeansModel;
+import org.jboss.soa.esb.listeners.config.HibernateBusDocument.HibernateBus;
+import org.jboss.soa.esb.listeners.config.HibernateListenerDocument.HibernateListener;
+import org.jboss.soa.esb.listeners.config.HibernateMessageFilterDocument.HibernateMessageFilter;
+import org.jboss.soa.esb.listeners.config.HibernateProviderDocument.HibernateProvider;
+
+import org.jboss.soa.esb.listeners.gateway.HibernateGatewayListener;
+import org.w3c.dom.Element;
+
+/**
+ * Performs the mapping of a <fs-listener> XSD based configuration to the "ConfigTree"
+ * style configuration, adding the "ConfigTree" listener config to the "root" node.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class HibernateListenerMapper {
+
+ /**
+ * Perform the mapping.
+ * @param root The "ConfigTree" configuration root node.
+ * @param listener The Jmslistener to be mapped into the ConfigTree.
+ * @param model The configuration model from which the mapping is being performed.
+ * @return The ConfigTree listener configuration node.
+ * @throws ConfigurationException Invalid listener configuration.
+ */
+ public static Element map(Element root, HibernateListener listener, XMLBeansModel model) throws ConfigurationException {
+ Element listenerNode = YADOMUtil.addElement(root, listener.getName());
+ HibernateBus bus;
+ HibernateProvider provider;
+
+ try {
+ bus = (HibernateBus) model.getBus(listener.getBusidref());
+ } catch (ClassCastException e) {
+ throw new ConfigurationException("Invalid busid reference [" + listener.getBusidref() + "] on listener [" + listener.getName() + "]. A <hibernate-listener> must reference a <hibernate-bus>.");
+ }
+ try {
+ provider = (HibernateProvider) model.getProvider(bus);
+ } catch (ClassCastException e) {
+ throw new ConfigurationException("Invalid bus config [" + listener.getBusidref() + "]. Should be contained within a <hibernate-provider> instance. Unexpected exception - this should have caused a validation error!");
+ }
+
+ List<HibernateMessageFilter> messageFilters = null;
+ messageFilters = listener.getHibernateMessageFilterList();
+
+ if(messageFilters.size() == 0) {
+ messageFilters = bus.getHibernateMessageFilterList();
+ if(messageFilters == null) {
+ throw new ConfigurationException("No <hibernate-message-filter> defined on either <hibernate-listener> [" + listener.getName() + "] or <hibernate-bus> [" + bus.getBusid() + "].");
+ }
+ }
+ listenerNode.setAttribute("pollLatencySeconds", String.valueOf(listener.getPollFrequencySeconds()));
+ // Map the standard listener attributes - common across all listener types...
+ MapperUtil.mapDefaultAttributes(listener, listenerNode, model);
+ // Map the <property> elements targeted at the listener - from the listener itself.
+ MapperUtil.mapProperties(listener.getPropertyList(), listenerNode);
+ if(listener.getIsGateway()) {
+ listenerNode.setAttribute("gatewayClass", HibernateGatewayListener.class.getName());
+ // Map EPR related attributes onto the listener - from the bus and provider and listener.
+ // Note: This will change - the Gateways will also support the EPR element...
+ mapHibernateEprProperties(listenerNode, provider, messageFilters);
+ MapperUtil.mapEPRProperties(listener, listenerNode, model);
+ } else {
+ Element eprNode = YADOMUtil.addElement(listenerNode, ListenerTagNames.EPR_TAG);
+ // Map EPR related attributes onto the EPR - from the bus and provider and listener...
+ mapHibernateEprProperties(eprNode, provider, messageFilters);
+ MapperUtil.mapEPRProperties(listener, eprNode, model);
+ // Remove any empty attributes set on the EPR config...
+ YADOMUtil.removeEmptyAttributes(eprNode);
+ }
+
+ // Remove any empty attributes set on the listener config...
+ YADOMUtil.removeEmptyAttributes(listenerNode);
+
+ return listenerNode;
+ }
+
+ /**
+ * mapHibernateEprProperties creates a ConfigTree with the details we need
+ * from the HibernateProvider and MessageFilters.
+ * @param toElement the element we are passing on
+ * @param provider the provider object
+ * @param messageFilters collection of MessageFilters we need to implement
+ */
+ private static void mapHibernateEprProperties(Element toElement, HibernateProvider provider, List<HibernateMessageFilter> messageFilters) {
+ toElement.setAttribute(HibernateEpr.HIBERNATE_CFG_TAG, provider.getHibernateCfgFile());
+ for (HibernateMessageFilter messageFilter: messageFilters) {
+ Element temp = YADOMUtil.addElement(toElement, "messagefilter");
+ temp.setAttribute(HibernateEpr.CLASS_NAME_TAG, messageFilter.getClassname());
+ temp.setAttribute(HibernateEpr.EVENT_TAG, messageFilter.getEvent());
+ toElement.appendChild(temp);
+ }
+ }
+}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -125,15 +125,11 @@
+ " started on thread " + Thread.currentThread().getName());
}
- do
- {
- File[] fileList;
- try
- {
+ do {
+ File[] fileList;
+ try {
fileList = getFileList();
- }
- catch (GatewayException e)
- {
+ } catch (GatewayException e) {
_logger.error("Can't retrieve file list", e);
continue;
}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateEventBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateEventBean.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateEventBean.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,29 @@
+package org.jboss.soa.esb.listeners.gateway;
+
+public class HibernateEventBean {
+ private String m_event;
+ private String m_className;
+
+ public HibernateEventBean() {
+ }
+
+ public HibernateEventBean(String f_event, String f_className) {
+ m_event = f_event;
+ m_className = f_className;
+ }
+
+ public String getClassname() {
+ return m_className;
+ }
+
+ public void setClassname(String name) {
+ m_className = name;
+ }
+ public String getEvent() {
+ return m_event;
+ }
+
+ public void setEvent(String m_event) {
+ this.m_event = m_event;
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.util.Collection;
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.persist.HibernateSessionFactory;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+
+/**
+ * HibernateGatewayListener is a listener which creates a HibernateInterceptor for
+ * the classname/events that need to be listened to.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ *
+ */
+public class HibernateGatewayListener extends AbstractManagedLifecycle {
+ private static final long serialVersionUID = -8794895112076882394L;
+
+ private String m_cfgFile;
+ private ConfigTree m_config;
+ protected Object _composer;
+ protected Class _composerClass;
+ protected String _composerName;
+ protected String m_targetServiceCategory, m_targetServiceName;
+
+ protected Collection<EPR> m_targetEprs;
+
+ private static final String MESSAGE_FILTER = "messagefilter";
+
+ protected final static Logger m_logger = Logger.getLogger(HibernateGatewayListener.class);
+
+ /**
+ * This constructor takes in a configTree element and grabs the hibernate configuration
+ * file name.
+ *
+ * @param config configtree
+ * @throws ConfigurationException
+ */
+ public HibernateGatewayListener(ConfigTree config) throws ConfigurationException {
+ super(config);
+ m_config = config;
+ m_cfgFile = ListenerUtil.obtainAtt(m_config, HibernateEpr.HIBERNATE_CFG_TAG, null);
+ }
+
+ @Override
+ protected void doDestroy() throws ManagedLifecycleException {
+ }
+
+ @Override
+ protected void doInitialise() throws ManagedLifecycleException {
+ ArrayList<HibernateEventBean> eventList = new ArrayList<HibernateEventBean>();
+
+ Configuration cfg = new Configuration();
+ cfg.configure(m_cfgFile);
+
+ // Need to loop through messagefilters and add them as interceptors
+ for (ConfigTree ct : m_config.getChildren(MESSAGE_FILTER)) {
+ try {
+ String tempEvent = ListenerUtil.obtainAtt(ct, HibernateEpr.EVENT_TAG, null);
+ String[] events = tempEvent.split(",");
+ for (int i = 0; i<events.length; i++) {
+ HibernateEventBean heb = new HibernateEventBean();
+ heb.setEvent(events[i]);
+ heb.setClassname(ListenerUtil.obtainAtt(ct, HibernateEpr.CLASS_NAME_TAG, null));
+ eventList.add(heb);
+ }
+ } catch (ConfigurationException ce) {
+ m_logger.error("Problem parsing Message Filter event/classname");
+ }
+ }
+
+ try {
+ // Grab the session factory and close it - if we have a hot re-deploy,
+ // we need to close the SessionFactory so that the old interceptors don't get
+ // in the way.
+ SessionFactory sf = null;
+ try {
+ sf = HibernateSessionFactory.getInstance(cfg);
+ sf.close();
+ } catch (Exception e) {
+ // Ignore.
+ }
+
+ sf = HibernateSessionFactory.getInstance(cfg);
+ if (eventList.size() != 0) {
+ cfg.setInterceptor(new HibernateInterceptor(m_config, eventList));
+ }
+ } catch (ConfigurationException ce) {
+ throw new ManagedLifecycleException(ce.getMessage());
+ }
+
+
+
+
+ }
+
+ @Override
+ protected void doStart() throws ManagedLifecycleException {
+ }
+
+ @Override
+ protected void doStop() throws ManagedLifecycleException {
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,343 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.hibernate.CallbackException;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.Transaction;
+import org.hibernate.type.Type;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.gateway.HibernateEventListener.HibernateMessageComposer;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.ClassUtil;
+
+/**
+ * HibernateInterceptor intercepts Hibernate events and sends the object they are
+ * being performed upon in a message. The object is sent in the body of the message
+ * with the "hibernateObject" string. The default composer for the HibernateInterceptor
+ * is PackageHibernateMessageContents.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ *
+ */
+public class HibernateInterceptor extends EmptyInterceptor {
+
+ private static final long serialVersionUID = 1L;
+ private ArrayList<HibernateEventBean> m_events;
+ private final static Logger m_logger = Logger.getLogger(HibernateInterceptor.class);
+ private Courier m_courier;
+
+ protected Class m_composerClass;
+ protected Method m_processMethod;
+ protected Object m_composer;
+ protected String m_composerName;
+ protected ConfigTree m_config;
+
+ protected Collection<EPR> m_targetEprs;
+ protected String m_targetServiceCategory, m_targetServiceName;
+
+ // Event Strings
+ private static final String DELETE_EVENT = "onDelete";
+ private static final String SAVE_EVENT = "onSave";
+ private static final String LOAD_EVENT = "onLoad";
+ private static final String FLUSH_DIRTY_EVENT = "onFlushDirty";
+ private static final String COLLECTION_UPDATE_EVENT = "onCollectionUpdate";
+ private static final String COLLECTION_REMOVE_EVENT = "onCollectionRemove";
+
+
+ /**
+ * This constructor takes in a configuration and a list of hibernate events to
+ * monitor.
+ * @param f_config
+ * @param f_list
+ * @throws ManagedLifecycleException
+ */
+ public HibernateInterceptor(ConfigTree f_config, ArrayList<HibernateEventBean> f_list) throws ManagedLifecycleException {
+ m_config = f_config;
+ m_events = f_list;
+ m_composerName = HibernateMessageComposer.class.getName();
+ m_composerClass = HibernateMessageComposer.class;
+ m_composer = new HibernateMessageComposer();
+
+ try {
+ m_targetServiceCategory = ListenerUtil.obtainAtt(m_config,
+ ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+ m_targetServiceName = ListenerUtil.obtainAtt(m_config,
+ ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+ m_targetEprs = RegistryUtil.getEprs(m_targetServiceCategory,m_targetServiceName);
+ if (null == m_targetEprs || m_targetEprs.size() < 1)
+ throw new ManagedLifecycleException("EPR <" + m_targetServiceName + "> not found in registry") ;
+ } catch (final RegistryException re) {
+ throw new ManagedLifecycleException("Unexpected registry exception", re) ;
+ } catch (ConfigurationException e) {
+ throw new ManagedLifecycleException(e.getMessage(), e);
+ }
+
+ try {
+ resolveComposerClass();
+ } catch (ConfigurationException e) {
+ // TODO Auto-generated catch block
+ throw new ManagedLifecycleException("Problem resolving composer class", e);
+ }
+
+ }
+
+ /**
+ * Create message and put messageObject in the body.
+ * @param messageObject hibernate object that goes in the body of the message
+ * @return the message just created
+ */
+ private Message createMessage(Object messageObject) {
+ Object obj = null;
+ try {
+ obj = m_processMethod.invoke(m_composer, new Object[] { messageObject });
+ if (null == obj) {
+ m_logger.error("Action class method <" + m_processMethod
+ .getName() + "> returned a null object");
+ }
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Message message = (Message) obj;
+ return message;
+ }
+
+ /**
+ * Delivers the message.
+ * @param messageObject
+ */
+ private void deliverMessage(Message message) {
+ Throwable thrown = null;
+ String text = null;
+
+ try {
+ boolean bSent = false;
+ for (EPR current : m_targetEprs) {
+ m_courier = CourierFactory.getCourier(current);
+
+ try {
+ if (m_courier.deliver(message)) {
+ bSent = true;
+ break;
+ }
+ } finally {
+ CourierUtil.cleanCourier(m_courier) ;
+ }
+ }
+
+ if (!bSent) {
+ text = "Target service <" + m_targetServiceCategory + "," + m_targetServiceName + "> is not registered";
+ thrown = new Exception(text);
+ }
+ } catch (ClassCastException e) {
+ thrown = e;
+ text = "Action class method <" + m_processMethod.getName() + "> returned a non Message object";
+ } catch (CourierException e) {
+ thrown = e;
+ text = "Courier <" + m_courier.getClass().getName() + ".deliverAsync(Message) FAILED";
+ } catch (MalformedEPRException ex) {
+ thrown = ex;
+ text = "Courier <" + m_courier.getClass().getName() + ".deliverAsync(Message) FAILED with malformed EPR.";
+ } catch (IllegalArgumentException e) {
+ thrown = e;
+ text = "Courier <" + m_courier.getClass().getName() + ".deliverAsync(Message) FAILED with IllegalArgumentException.";
+ }
+ if (null != thrown) {
+ m_logger.error(text);
+ m_logger.debug(text, thrown);
+ //changeStatusToError();
+ }
+ }
+
+
+ /**
+ * This method resolves the composer class. As a default, the HibernateInterceptor
+ * uses
+ * @throws ConfigurationException
+ */
+ protected void resolveComposerClass() throws ConfigurationException {
+ try
+ {
+ String sProcessMethod = null;
+ m_composerName = m_config.getAttribute(ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG);
+ if (null != m_composerName) {
+ m_composerClass = ClassUtil.forName(m_composerName, getClass());
+ Constructor oConst = m_composerClass.getConstructor(new Class[] { ConfigTree.class });
+ m_composer = oConst.newInstance(m_config);
+ sProcessMethod = m_config.getAttribute(ListenerTagNames.GATEWAY_COMPOSER_METHOD_TAG, "process");
+ } else {
+ m_composerName = PackageHibernateMessageContents.class.getName();
+ m_composerClass = PackageHibernateMessageContents.class;
+ m_composer = new PackageHibernateMessageContents();
+ sProcessMethod = "process";
+ m_logger.debug("No <" + ListenerTagNames.ACTION_ELEMENT_TAG + "> element found in configuration" + " - Using default composer class : " + m_composerName);
+ }
+
+ m_processMethod = m_composerClass.getMethod(sProcessMethod, new Class[] { Object.class });
+ } catch (InvocationTargetException ex) {
+ m_logger.debug(ex);
+ throw new ConfigurationException(ex);
+ } catch (IllegalAccessException ex) {
+ m_logger.debug(ex);
+ throw new ConfigurationException(ex);
+ } catch (InstantiationException ex) {
+ m_logger.debug(ex);
+ throw new ConfigurationException(ex);
+ } catch (ClassNotFoundException ex) {
+ m_logger.debug(ex);
+ throw new ConfigurationException(ex);
+ } catch (NoSuchMethodException ex) {
+ m_logger.debug(ex);
+ throw new ConfigurationException(ex);
+ }
+ }
+
+ public void afterTransactionBegin(Transaction arg0) {
+ m_logger.debug("afterTransactionBegin");
+ }
+
+ public void afterTransactionCompletion(Transaction arg0) {
+ m_logger.debug("afterTransactionCompletion");
+ }
+
+ public void beforeTransactionCompletion(Transaction arg0) {
+ m_logger.debug("beforeTransactionCompletion");
+ }
+
+ public void onCollectionRecreate(Object entity, Serializable id) throws CallbackException {
+ m_logger.debug("onCollectionRecreate");
+ }
+
+ public void onCollectionRemove(Object entity, Serializable id) throws CallbackException {
+ System.out.println("onCollectionRemove");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(COLLECTION_REMOVE_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ }
+
+ public void onCollectionUpdate(Object entity, Serializable id) throws CallbackException {
+ System.out.println("onCollectionUpdate");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(COLLECTION_UPDATE_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ }
+
+ public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
+ System.out.println("onDelete");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(DELETE_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ }
+
+ public boolean onFlushDirty(Object entity, Serializable id, Object[] newValues, Object[] oldValues, String[] propertyNames, Type[] types) throws CallbackException {
+ m_logger.debug("onFlushDirty");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(FLUSH_DIRTY_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
+ System.out.println("onLoad");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(LOAD_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean onSave(Object entity, Serializable id, Object[] state,
+ String[] propertyNames, Type[] types) throws CallbackException {
+ System.out.println("onSave");
+ for (HibernateEventBean heb: m_events) {
+ if (heb.getEvent().equals(SAVE_EVENT)) {
+ if (entity.getClass().getName().equals(heb.getClassname())) {
+ Message message = createMessage(entity);
+ deliverMessage(message);
+ }
+ }
+ }
+ return false;
+ }
+
+ public void postFlush(Iterator arg0) throws CallbackException {
+ m_logger.debug("postFlush");
+ }
+
+ public void preFlush(Iterator arg0) throws CallbackException {
+ m_logger.debug("preFlush");
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageHibernateMessageContents.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageHibernateMessageContents.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageHibernateMessageContents.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+* Default packaging for Hibernate Entity messages. <p/>It will just drop the
+* Hibernate entity into a message.
+*
+* @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+* @since Version 4.2
+*
+*/
+public class PackageHibernateMessageContents {
+ public Message process (Object obj) {
+ if (!(obj instanceof Serializable))
+ throw new IllegalArgumentException("Object must be serializable");
+
+ Message message = MessageFactory.getInstance().getMessage();
+
+ message.getBody().add(ListenerTagNames.HIBERNATE_OBJECT_DATA_TAG, obj);
+
+ return message;
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -22,6 +22,7 @@
package org.jboss.soa.esb.listeners.gateway;
+import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -590,7 +591,7 @@
}
/*
- * HSQL does not support FOR UPDATE! All tables appear to
+ * HS QL does not support FOR UPDATE! All tables appear to
* be inherently updatable!
*/
@@ -765,7 +766,7 @@
{
public Message process (Object obj)
{
- if (!(obj instanceof Map))
+ if (!(obj instanceof Serializable))
throw new IllegalArgumentException("Object must be instance of Map");
Message message = MessageFactory.getInstance().getMessage();
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/HibernateCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/HibernateCourier.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/HibernateCourier.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,408 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.couriers;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+import org.jboss.soa.esb.helpers.persist.HibernateConn;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Courier which delivers message.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ *
+ */
+public class HibernateCourier implements PickUpOnlyCourier, DeliverOnlyCourier {
+
+ protected HibernateConn m_conn = null;
+ protected HibernateEpr m_epr = null;
+ protected static Logger m_Logger = Logger.getLogger(HibernateCourier.class);
+
+ protected Query m_prepDelete = null;
+ protected Query m_prepInsert = null;
+ protected Query m_prepUpdate = null;
+ protected Query m_prepSelUpd = null;
+ protected Query m_prepGetList = null;
+
+ private boolean m_isReceiver = false;
+ protected long m_pollLatency = 200;
+
+
+ private HibernateCourier() {
+ }
+
+ /**
+ * package protected constructor - Objects of Courier should only be
+ * instantiated by the Factory
+ *
+ * @param epr
+ */
+ HibernateCourier(HibernateEpr epr) throws CourierException {
+ this(epr, false);
+ }
+
+ public HibernateCourier(HibernateEpr epr, boolean pickUpOnly) {
+ m_isReceiver = pickUpOnly;
+ m_epr = epr;
+ }
+
+ public void cleanup() {
+ if (null != m_conn) {
+ try {
+ m_conn.release();
+ } catch (Exception e) {
+ m_Logger.error("Unable to release connection", e);
+ }
+ }
+ }
+
+ /**
+ * package the ESB message in a java.io.Serializable, and write it
+ *
+ * @param message
+ * Message - the message to deliverAsync
+ * @return boolean - the result of the delivery
+ * @throws CourierException -
+ * if problems were encountered
+ */
+ public boolean deliver(Message message) throws CourierException {
+ if (m_isReceiver)
+ throw new CourierException("This is a read-only Courier");
+
+ if (null == message)
+ return false;
+
+ String msgId = null;
+ Call call = message.getHeader().getCall();
+ if (null==call)
+ message.getHeader().setCall(call=new Call());
+ try {
+ if (null == call.getMessageID())
+ call.setMessageID(new URI(UUID.randomUUID().toString()));
+ msgId = call.getMessageID().toString();
+ } catch (URISyntaxException e) {
+ throw new CourierException("Problems with message header ",e);
+ }
+ /*
+ if (null == m_conn) {
+ try {
+ m_conn = getConn();
+ } catch (Exception e) {
+ throw new CourierException(e);
+ }
+ }
+
+
+ while (m_conn != null) {
+ try {
+ //TODO: Need to get the inserts working
+ int iCol = 1;
+ Query ins = insertStatement();
+ return true;
+ } catch (HibernateException e) {
+ if (null != m_conn) {
+ try {
+ m_conn.rollback();
+ } catch (Exception roll) {
+ m_Logger.error("", roll);
+ }
+ }
+
+ m_Logger.error("Hibernate exception during deliver", e);
+ throw new CourierException(e);
+ } catch (Exception e) {
+ m_Logger.error("", e);
+ }
+ }
+ */
+ return false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.jboss.internal.soa.esb.couriers.PickUpOnlyCourier#pickup(long)
+ */
+
+ public Message pickup(long millis) throws CourierException,
+ CourierTimeoutException {
+ Message result = null;
+ /*
+ long limit = System.currentTimeMillis()
+ + ((millis < 100) ? 100 : millis);
+ do {
+ try {
+ List<String> list = getRowList();
+
+ if (null != list) {
+ for (String messageId : list) {
+ if (null == (result = tryToPickup(messageId)))
+ continue;
+ return result;
+ }
+ }
+ } catch (Exception e) {
+ m_Logger.error("Exception during pickup", e);
+ return null;
+ } finally {
+ if (m_conn != null) {
+ try {
+ m_conn.rollback();
+ } catch (HibernateException e) {} //ignore
+ }
+ }
+
+ try {
+ long lSleep = limit - System.currentTimeMillis();
+ if (m_pollLatency < lSleep)
+ lSleep = m_pollLatency;
+ if (lSleep > 0)
+ Thread.sleep(lSleep);
+ } catch (InterruptedException e) {
+ return null;
+ }
+ } while (System.currentTimeMillis() <= limit);
+ */
+ return null;
+ }
+
+
+ /*
+ private List getRowList() throws CourierException
+ {
+ if (null == m_conn)
+ {
+ try {
+ m_conn = getConn();
+ } catch (Exception e) {
+ throw new CourierException(e);
+ }
+ }
+ while (m_conn != null)
+ {
+ try {
+ Query query = listStatement();
+ return m_conn.execQuery(query);
+ } catch (Exception e) {
+ m_Logger.error("Problem getting row list", e);
+ }
+ }
+ return null;
+ }
+ */
+
+ /*
+ protected Query listStatement()
+ {
+ if (null == m_prepGetList)
+ try {
+ String sb = "select x." + m_epr.getMessageField() + ", "
+ + "x." + m_epr.getTimestampColumn() + " "
+ + "from " + m_epr.getClassName() + " x "
+ + "where x." + m_epr.getStatusField() + " = " + State.Pending.getColumnValue();
+ m_prepGetList = getConn().getSession().createQuery(sb);
+ } catch (Exception e) {
+ m_Logger.debug("Unable to prepare list query", e);
+ return null;
+ }
+ return m_prepGetList;
+ }
+ */
+
+ /*
+ private Query insertStatement() {
+ if (null == m_prepInsert)
+ try
+ {
+ String[] columns =
+ {m_epr.getMessageField(), m_epr.getDataField(),
+ m_epr.getStatusField(), m_epr.getTimestampColumn() };
+
+ StringBuilder sb = new StringBuilder("insert into ").append(
+ m_epr.getClassName()).append("(");
+ int i1 = 0;
+ for (String col : columns)
+ sb.append((i1++ < 1) ? " " : ",").append(col);
+ sb.append(") values (?,?,?,?)");
+ m_prepInsert = getConn().getSession().createQuery(sb.toString());
+ } catch (Exception e) {
+ m_Logger.debug("Problem creating insertion query: ", e);
+ return null;
+ }
+ return m_prepInsert;
+ }
+ */
+
+ /*
+ private Message tryToPickup(String messageId) {
+ int iParm = 1;
+
+ Query updateQuery = selectUpdateStatement();
+ updateQuery.setString("messageid", messageId);
+ updateQuery.setString("statusid", State.Pending.getColumnValue());
+
+ while (m_conn != null) {
+ try {
+ List<String>list = m_conn.execQuery(updateQuery);
+ for (String data : list) {
+ Exception courEx = null;
+ try {
+ Message result = Util.deserialize((Serializable) data);
+ deleteMsg(messageId);
+ changeStatus(messageId, State.Done);
+ return result;
+ } catch (ClassCastException e) {
+ m_Logger.debug("", e);
+ courEx = e;
+ } catch (SAXParseException e) {
+ m_Logger.debug("", e);
+ courEx = e;
+ } catch (Exception e) {
+ throw new CourierException(e);
+ }
+ if (null != courEx) {
+ deleteMsg(messageId);
+ changeStatus(messageId, State.Error);
+ continue;
+ }
+ }
+ return null;
+ } catch (Exception e) {
+ m_Logger.error("", e);
+ }
+ }
+ return null;
+ }
+ */
+
+ /*
+ protected Query selectUpdateStatement() {
+ if (m_prepSelUpd == null) {
+ try {
+ String sb = "select x." + m_epr.getDataField() + " "
+ + "from " + m_epr.getClassName() + " x "
+ + "where x." + m_epr.getMessageField() + " = :messageid "
+ + "and x." + m_epr.getStatusField() + "= :statusid";
+ Query query = getConn().getSession().createQuery(sb);
+ } catch (Exception e) {
+ m_Logger.error("Problem creating select statement", e);
+ return null;
+ }
+ }
+
+ return m_prepSelUpd;
+ }
+ */
+
+ /*
+ private void deleteMsg(String messageId) {
+ Query delQuery = deleteStatement();
+ delQuery.setString("messageid", messageId);
+ m_conn.execQuery(delQuery);
+ m_conn.commit();
+
+ }
+
+ private void changeStatus(String messageId, State to) {
+ Query statusQuery = updateStatement();
+ statusQuery.setString("statusid", messageId);
+ statusQuery.setString("messageid", to.getColumnValue());
+ m_conn.execQuery(statusQuery);
+ m_conn.commit();
+ }
+
+ private Query deleteStatement() {
+ if (null == m_prepDelete) {
+ try
+ {
+ String delStatement = new String("delete " + m_epr.getClassName()
+ + " x where x." + m_epr.getMessageField()
+ + " = :messageid");
+ m_prepDelete = getConn().getSession().createQuery(delStatement);
+ } catch (Exception e) {
+ m_Logger.error("Problem creating deletion query: ", e);
+ return null;
+ }
+ }
+ return m_prepDelete;
+ }
+
+ private Query updateStatement() {
+ if (null == m_prepUpdate) {
+ try {
+ String upStatement = new String("update " + m_epr.getClassName() + " x "
+ + "set " + m_epr.getStatusField() + " = :statusid"
+ + "where x." + m_epr.getStatusField()
+ + " = :messageid");
+ m_prepUpdate = getConn().getSession().createQuery(upStatement);
+ } catch (Exception e) {
+ m_Logger.error("Problem creating update query: ", e);
+ return null;
+ }
+ }
+ return m_prepUpdate;
+ }
+
+ private HibernateConn getConn() throws MalformedEPRException
+ {
+ if (null == m_conn) {
+ try {
+ m_conn = new HibernateConn(m_epr.getHibernateCfgFile());
+ } catch (URISyntaxException ex) {
+ throw new MalformedEPRException(ex);
+ }
+ }
+ return m_conn;
+ }
+
+ public void setPollLatency(Long millis)
+ {
+ if (millis <= 200)
+ m_Logger.error("Poll latency must be >= 200 milliseconds - Keeping old value of "+ m_pollLatency);
+ else
+ m_pollLatency = millis;
+ } // ________________________________
+
+
+ protected enum State {
+ Pending, WorkInProgress, Done, Error;
+ String getColumnValue() {
+ return toString().substring(0, 1);
+ }
+ }
+ */
+}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/metadata/MetaDataFilter.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/metadata/MetaDataFilter.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/metadata/MetaDataFilter.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -30,6 +30,7 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.eprs.FTPEpr;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.common.Environment;
@@ -54,76 +55,81 @@
{
public Message onOutput (Message msg) throws CourierException
{
- final Environment.Transports type ;
- final String name ;
+ final Environment.Transports type ;
+ final String name ;
EPR destination = msg.getHeader().getCall().getTo();
- if (destination != null)
- {
- if (destination instanceof FTPEpr)
+ if (destination != null)
+ {
+ if (destination instanceof FTPEpr)
+ {
+ try
{
- try
- {
- type = Environment.Transports.FTP;
+ type = Environment.Transports.FTP;
- String dir = ModulePropertyManager.getPropertyManager(
- ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
+ String dir = ModulePropertyManager.getPropertyManager(
+ ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
Environment.FTP_LOCALDIR, System.getProperty("java.io.tmpdir"));
- name = dir + File.separator + msg.getHeader().getCall().getMessageID().toString() +
- ((FTPEpr) destination).getPostDirectory();
- }
- catch (URISyntaxException ex)
- {
- throw new CourierException(ex);
- }
+ name = dir + File.separator + msg.getHeader().getCall().getMessageID().toString() +
+ ((FTPEpr) destination).getPostDirectory();
}
- else if (destination instanceof FileEpr)
+ catch (URISyntaxException ex)
{
- try
- {
- type = Environment.Transports.File;
+ throw new CourierException(ex);
+ }
+ }
+ else if (destination instanceof FileEpr)
+ {
+ try
+ {
+ type = Environment.Transports.File;
- name = ((FileEpr) destination).getURL() + File.separator +
- msg.getHeader().getCall().getMessageID().toString() + ((FileEpr) destination).getPostSuffix();
- }
- catch (MalformedURLException ex)
- {
- throw new CourierException(ex);
- }
- catch (URISyntaxException ex)
- {
- throw new CourierException(ex);
- }
- }
- else if (destination instanceof JMSEpr)
+ name = ((FileEpr) destination).getURL() + File.separator +
+ msg.getHeader().getCall().getMessageID().toString() + ((FileEpr) destination).getPostSuffix();
+ }
+ catch (MalformedURLException ex)
{
- type = Environment.Transports.JMS;
-
- name = destination.getAddr().toString();
+ throw new CourierException(ex);
}
- else if (destination instanceof JDBCEpr)
+ catch (URISyntaxException ex)
{
- type = Environment.Transports.SQL;
+ throw new CourierException(ex);
+ }
+ }
+ else if (destination instanceof JMSEpr)
+ {
+ type = Environment.Transports.JMS;
+
+ name = destination.getAddr().toString();
+ }
+ else if (destination instanceof JDBCEpr)
+ {
+ type = Environment.Transports.SQL;
- name = destination.getAddr().toString();
- }
- else
- {
- type = null ;
- name = null ;
- }
- }
- else
- {
- type = null ;
- name = null ;
- }
+ name = destination.getAddr().toString();
+ }
+ else if (destination instanceof HibernateEpr)
+ {
+ type = Environment.Transports.Hibernate;
+ name = destination.getAddr().toString();
+ }
+ else
+ {
+ type = null ;
+ name = null ;
+ }
+ }
+ else
+ {
+ type = null ;
+ name = null ;
+ }
- final Properties props = msg.getProperties() ;
- setProperty(props, Environment.TRANSPORT_TYPE, type) ;
- setProperty(props, Environment.MESSAGE_SOURCE, name);
- props.setProperty(Environment.MESSAGE_ENTRY_TIME, Calendar.getInstance().getTime().toString());
- return msg;
+ final Properties props = msg.getProperties() ;
+ setProperty(props, Environment.TRANSPORT_TYPE, type) ;
+ setProperty(props, Environment.MESSAGE_SOURCE, name);
+ props.setProperty(Environment.MESSAGE_ENTRY_TIME, Calendar.getInstance().getTime().toString());
+ return msg;
}
public Message onInput (Message msg) throws CourierException
@@ -133,15 +139,15 @@
return msg;
}
- private void setProperty(final Properties props, final String name, final Object value)
- {
- if (value == null)
- {
- props.remove(name) ;
- }
- else
- {
- props.setProperty(name, value) ;
- }
- }
+ private void setProperty(final Properties props, final String name, final Object value)
+ {
+ if (value == null)
+ {
+ props.remove(name) ;
+ }
+ else
+ {
+ props.setProperty(name, value) ;
+ }
+ }
}
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/DefaultHibernateReplyToEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/DefaultHibernateReplyToEpr.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/DefaultHibernateReplyToEpr.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.addressing.eprs;
+
+import java.net.URISyntaxException;
+
+public class DefaultHibernateReplyToEpr extends HibernateEpr
+{
+
+ public DefaultHibernateReplyToEpr(HibernateEpr epr) throws URISyntaxException
+ {
+ super(epr);
+ setClassName(replyToClassName(epr));
+ }
+
+ public static String replyToClassName(HibernateEpr epr) throws URISyntaxException
+ {
+ return epr.getClassName()+HibernateEpr.DEFAULT_REPLY_TO_CLASS_SUFFIX;
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HibernateEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HibernateEpr.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HibernateEpr.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,361 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.addressing.eprs;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class HibernateEpr extends EPR {
+
+ public static final String LOAD_LISTENER = "loadListener";
+ public static final String SAVE_LISTENER = "saveListener";
+ public static final String DELETE_LISTENER = "deleteListener";
+
+ public static final String CLASS_NAME_TAG = "classname";
+ public static final String EVENT_TAG = "event";
+ public static final String HIBERNATE_CFG_TAG = "hibernate-cfg-file";
+
+
+
+ public static final String MESSAGE_FIELD_TAG = "message-field";
+ public static final String STATUS_FIELD_TAG = "status-field";
+ public static final String DATA_FIELD_TAG = "data-field";
+ public static final String TIMESTAMP_FIELD_TAG = "insert-timestamp-field";
+ public static final String POST_DEL_TAG = "postDelete";
+ public static final String ERROR_DEL_TAG = "errorDelete";
+
+
+ public static final String DEFAULT_REPLY_TO_CLASS_SUFFIX = "_reply_table";
+
+ private boolean loadListener = true;
+ private boolean saveListener = true;
+ private boolean deleteListener = true;
+ private boolean cfgFileSet = false;
+ private boolean classNameSet = false;
+ private boolean statusSet = false;
+ private boolean messageSet = false;
+ private boolean timestampSet = false;
+ private boolean dataSet = false;
+
+ private static URI m_type;
+
+
+ public HibernateEpr(EPR epr) {
+ copy(epr);
+ }
+
+ public HibernateEpr (EPR epr, Element header)
+ {
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ try
+ {
+ String prefix = nl.item(i).getPrefix();
+ String tag = nl.item(i).getLocalName();
+
+ if (tag != null)
+ {
+ if (tag.equals(HIBERNATE_CFG_TAG)) {
+ getAddr().addExtension(HIBERNATE_CFG_TAG, nl.item(i).getTextContent());
+ } else if (tag.equals(CLASS_NAME_TAG)) {
+ getAddr().addExtension(CLASS_NAME_TAG, nl.item(i).getTextContent());
+ } else if (tag.equals(EVENT_TAG)) {
+ getAddr().addExtension(EVENT_TAG, nl.item(i).getTextContent());
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public PortReference getAddr() {
+ // TODO Auto-generated method stub
+ return super.getAddr();
+ }
+
+ @Override
+ public void setAddr(PortReference uri) {
+ // TODO Auto-generated method stub
+ super.setAddr(uri);
+ }
+
+ /**
+ * @return the driver used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getHibernateCfgFile () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(HIBERNATE_CFG_TAG);
+ }
+
+ /**
+ * Set the tablename that is used by this EPR.
+ *
+ * @param tableName the table name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setHibernateCfgFile(String cfgFile) throws URISyntaxException
+ {
+ if (cfgFile == null)
+ throw new IllegalArgumentException();
+
+ if (cfgFileSet)
+ throw new IllegalStateException("Table name already set.");
+
+ getAddr().addExtension(HIBERNATE_CFG_TAG, cfgFile);
+ cfgFileSet = true;
+ }
+
+ /**
+ * Set the tablename that is used by this EPR.
+ *
+ * @param tableName the table name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setClassName (String className) throws URISyntaxException
+ {
+ if (className == null)
+ throw new IllegalArgumentException();
+
+ if (classNameSet)
+ throw new IllegalStateException("Table name already set.");
+
+ getAddr().addExtension(CLASS_NAME_TAG, className);
+ classNameSet = true;
+ }
+
+ /**
+ * @return the table name used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getClassName () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(CLASS_NAME_TAG);
+ }
+
+
+
+
+ /**
+ * Set the event that is used by this EPR.
+ *
+ * @param tableName the table name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setEvent (String eventName) throws URISyntaxException
+ {
+ if (eventName == null)
+ throw new IllegalArgumentException();
+
+ if (classNameSet)
+ throw new IllegalStateException("Table name already set.");
+
+ getAddr().addExtension(EVENT_TAG, eventName);
+ classNameSet = true;
+ }
+
+ /**
+ * @return the table name used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getEvent () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(EVENT_TAG);
+ }
+
+ /**
+ * Set the status column that is used by this EPR.
+ *
+ * @param statusField the status field.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setStatusField (String statusField) throws URISyntaxException
+ {
+ if (statusField == null)
+ throw new IllegalArgumentException();
+
+ if (statusSet)
+ throw new IllegalStateException("Status column already set.");
+
+ getAddr().addExtension(STATUS_FIELD_TAG, statusField);
+ statusSet = true;
+ }
+
+ /**
+ * @return the status column name used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getStatusField () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(STATUS_FIELD_TAG);
+ }
+
+ /**
+ * Set the message id column name that is used by this EPR.
+ *
+ * @param messageFieldName the column name for the message ID.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setMessageField (String messageFieldName) throws URISyntaxException
+ {
+ if (messageFieldName == null)
+ throw new IllegalArgumentException();
+
+ if (messageSet)
+ throw new IllegalStateException("Message Id column already set.");
+
+ getAddr().addExtension(MESSAGE_FIELD_TAG, messageFieldName);
+ messageSet = true;
+ }
+
+ /**
+ * @return the message id column used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getMessageField () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(MESSAGE_FIELD_TAG);
+ }
+
+
+ /**
+ * Set the column that is used by this EPR to store timestamp when the message was inserted.
+ *
+ * @param timeField the column name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setTimestampField (String timeField) throws URISyntaxException
+ {
+ if (timeField == null)
+ throw new IllegalArgumentException();
+
+ if (timestampSet)
+ throw new IllegalStateException("Timestamp column already set.");
+
+ getAddr().addExtension(TIMESTAMP_FIELD_TAG, timeField);
+ timestampSet = true;
+ }
+
+ /**
+ * @return the timestamp column name used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getTimestampColumn () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(TIMESTAMP_FIELD_TAG);
+ }
+
+ /**
+ * Set the field that is used by this EPR to store message data.
+ *
+ * @param dataField the column name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setDataField (String dataField) throws URISyntaxException
+ {
+ if (dataField == null)
+ throw new IllegalArgumentException();
+
+ if (dataSet)
+ throw new IllegalStateException("Data field already set.");
+
+ getAddr().addExtension(DATA_FIELD_TAG, dataField);
+ dataSet = true;
+ }
+
+ /**
+ * @return the data column name used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getDataField () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(DATA_FIELD_TAG);
+ }
+
+
+ public boolean isDeleteListener() {
+ return deleteListener;
+ }
+
+ public void setDeleteListener(boolean deleteListener) {
+ this.deleteListener = deleteListener;
+ }
+
+ public boolean isLoadListener() {
+ return loadListener;
+ }
+
+ public void setLoadListener(boolean loadListener) {
+ this.loadListener = loadListener;
+ }
+
+ public boolean isSaveListener() {
+ return saveListener;
+ }
+
+ public void setSaveListener(boolean saveListener) {
+ this.saveListener = saveListener;
+ }
+
+ public static final URI type ()
+ {
+ return m_type;
+ }
+
+ static
+ {
+ try
+ {
+ m_type = new URI("urn:jboss/esb/epr/type/hibernate");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ throw new ExceptionInInitializerError(ex.toString());
+ }
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -26,7 +26,7 @@
{
public enum Transports
{
- File, FTP, JMS, SQL;
+ File, FTP, JMS, SQL, Hibernate;
}
public static final String PROPERTIES_FILE = "org.jboss.soa.esb.propertyFile";
@@ -142,4 +142,4 @@
*/
public static final String FILTER_NAME = "org.jboss.soa.esb.courier.filter";
-}
\ No newline at end of file
+}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2007-06-08 04:35:05 UTC (rev 12398)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -46,11 +46,13 @@
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.DefaultFileReplyToEpr;
import org.jboss.soa.esb.addressing.eprs.DefaultFtpReplyToEpr;
+import org.jboss.soa.esb.addressing.eprs.DefaultHibernateReplyToEpr;
import org.jboss.soa.esb.addressing.eprs.DefaultJdbcReplyToEpr;
import org.jboss.soa.esb.addressing.eprs.DefaultJmsReplyToEpr;
import org.jboss.soa.esb.addressing.eprs.DefaultSftpReplyToEpr;
import org.jboss.soa.esb.addressing.eprs.FTPEpr;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
@@ -91,6 +93,8 @@
return new DefaultFileReplyToEpr((FileEpr)toEpr);
if(toEpr instanceof JDBCEpr)
return new DefaultJdbcReplyToEpr((JDBCEpr)toEpr);
+ if(toEpr instanceof HibernateEpr)
+ return new DefaultHibernateReplyToEpr((HibernateEpr)toEpr);
}
catch (MalformedURLException ex)
{
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/HibernateSessionFactory.java 2007-06-08 04:40:50 UTC (rev 12399)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.helpers.persist;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.jboss.soa.esb.ConfigurationException;
+
+/**
+ * HibernateSessionFactory is a singleton for hibernate's SessionFactory object. The Listener
+ * uses JNDI to store the Hibernate SessionFactory.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ * @since Version 4.2
+ *
+ */
+public class HibernateSessionFactory {
+ public static final String HIBERNATE_JNDI = "java:comp/env/hibernate/SessionFactory";
+
+ private static SessionFactory sf = null;
+ private static final Logger m_Logger = Logger.getLogger(HibernateSessionFactory.class);
+
+ private HibernateSessionFactory() {
+ }
+
+ public static SessionFactory getInstance() {
+ if (sf != null) {
+ return sf;
+ } else {
+ return null;
+ }
+ }
+
+ public static SessionFactory getInstance(Configuration f_cfg) throws ConfigurationException {
+ if (sf == null) {
+ init(f_cfg);
+ }
+ return sf;
+ }
+
+ /**
+ * Grab InitialContext out of JNDI.
+ * @param f_cfg hibernate configuration
+ * @throws ConfigurationException
+ */
+ private static synchronized void init(Configuration f_cfg) throws ConfigurationException {
+ String cfgName = f_cfg.getProperty(Environment.SESSION_FACTORY_NAME);
+
+ Context ic = null;
+ // Look up SessionFactory in JNDI
+ if (cfgName != null) {
+ try {
+ ic = new InitialContext();
+ sf = (SessionFactory) ic.lookup(cfgName);
+ m_Logger.debug("Found SessionFactory in JNDI.");
+ } catch (NamingException ne) {
+ m_Logger.debug("Could not find SessionFactory in JNDI.", ne);
+ }
+ } else {
+ f_cfg.setProperty(Environment.SESSION_FACTORY_NAME, HIBERNATE_JNDI);
+ cfgName = HIBERNATE_JNDI;
+ }
+
+ if (sf == null) {
+ if (f_cfg != null) {
+ // Let Hibernate bind it to JNDI
+ m_Logger.debug("Build SessionFactory from Configuration.");
+ f_cfg.buildSessionFactory();
+ } else {
+ throw new ConfigurationException("Hibernate Configuration is null");
+ }
+ }
+ }
+
+ public static void close() {
+ if (sf != null) {
+ sf.close();
+ }
+ sf = null;
+ }
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list