[jboss-svn-commits] JBL Code SVN: r23402 - labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 9 13:18:50 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-10-09 13:18:50 -0400 (Thu, 09 Oct 2008)
New Revision: 23402

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java
Log:
Add support for start/stop to hibernate: JBESB-2046

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java	2008-10-09 16:31:19 UTC (rev 23401)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateGatewayListener.java	2008-10-09 17:18:50 UTC (rev 23402)
@@ -54,6 +54,8 @@
 	protected String _composerName;
 	protected String m_targetServiceCategory, m_targetServiceName;
 	
+	private HibernateInterceptor interceptor ;
+	
 	protected Collection<EPR> m_targetEprs;
 	
 	private static final String MESSAGE_FILTER = "messagefilter";
@@ -119,7 +121,8 @@
 			// we need to close the SessionFactory so that the old interceptors don't get
 			// in the way.
 			if (eventList.size() != 0) {
-				cfg.setInterceptor(new HibernateInterceptor(m_config, eventList));
+				interceptor = new HibernateInterceptor(m_config, eventList) ;
+				cfg.setInterceptor(interceptor);
 			}		
 
 			// We're suppressing warnings here - we need to initialize the
@@ -137,9 +140,15 @@
 
 	@Override
 	protected void doStart() throws ManagedLifecycleException {
+		if (interceptor != null) {
+			interceptor.enable() ;
+		}
 	}
 
 	@Override
 	protected void doStop() throws ManagedLifecycleException {
+		if (interceptor != null) {
+			interceptor.disable() ;
+		}
 	}
 }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java	2008-10-09 16:31:19 UTC (rev 23401)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HibernateInterceptor.java	2008-10-09 17:18:50 UTC (rev 23402)
@@ -36,12 +36,7 @@
 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.client.ServiceInvoker;
-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;
@@ -74,6 +69,8 @@
 	protected Object m_composer;
 	protected String m_composerName;
 	protected ConfigTree m_config;
+	
+	private boolean enabled ;
 
 	protected ServiceInvoker m_serviceInvoker;
 	protected String m_targetServiceCategory, m_targetServiceName;
@@ -267,68 +264,84 @@
 	}
 	
 	public void afterTransactionBegin(Transaction arg0) {
-		m_logger.debug("afterTransactionBegin");
+		if (isEnabled()) {
+			m_logger.debug("afterTransactionBegin");
+		}
 	}
 
 	public void afterTransactionCompletion(Transaction arg0) {
-		m_logger.debug("afterTransactionCompletion");
+		if (isEnabled()) {
+			m_logger.debug("afterTransactionCompletion");
+		}
 	}
 
 	public void beforeTransactionCompletion(Transaction arg0) {
-		m_logger.debug("beforeTransactionCompletion");
+		if (isEnabled()) {
+			m_logger.debug("beforeTransactionCompletion");
+		}
 	}
 
 	public void onCollectionRecreate(Object entity, Serializable id) throws CallbackException {
-		m_logger.debug("onCollectionRecreate");
+		if (isEnabled()) {
+			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);
-					message.getProperties().setProperty(ListenerTagNames.HIBERNATE_INTERCEPTOR_ID, id);
-					deliverMessage(message);
+		if (isEnabled()) {
+			m_logger.debug("onCollectionRemove");
+			for (HibernateEventBean heb: m_events) {
+				if (heb.getEvent().equals(COLLECTION_REMOVE_EVENT)) {
+					if (entity.getClass().getName().equals(heb.getClassname())) {
+						Message message = createMessage(entity);
+						message.getProperties().setProperty(ListenerTagNames.HIBERNATE_INTERCEPTOR_ID, id);
+						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);
-					message.getProperties().setProperty(ListenerTagNames.HIBERNATE_INTERCEPTOR_ID, id);
-					deliverMessage(message);		
+		if (isEnabled()) {
+			m_logger.debug("onCollectionUpdate");
+			for (HibernateEventBean heb: m_events) {
+				if (heb.getEvent().equals(COLLECTION_UPDATE_EVENT)) {
+					if (entity.getClass().getName().equals(heb.getClassname())) {
+						Message message = createMessage(entity);
+						message.getProperties().setProperty(ListenerTagNames.HIBERNATE_INTERCEPTOR_ID, id);
+						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);
-					addMessageInfo(message, id, state, propertyNames, types);
-					deliverMessage(message);
+		if (isEnabled()) {
+			m_logger.debug("onDelete");
+			for (HibernateEventBean heb: m_events) {
+				if (heb.getEvent().equals(DELETE_EVENT)) {
+					if (entity.getClass().getName().equals(heb.getClassname())) {
+						Message message = createMessage(entity);
+						addMessageInfo(message, id, state, propertyNames, types);
+						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);
-					addMessageInfo(message, id, newValues, oldValues, propertyNames, types);
-					deliverMessage(message);
+		if (isEnabled()) {
+			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);
+						addMessageInfo(message, id, newValues, oldValues, propertyNames, types);
+						deliverMessage(message);
+					}
 				}
 			}
 		}
@@ -336,13 +349,15 @@
 	}
 
 	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);
-					addMessageInfo(message, id, state, propertyNames, types);
-					deliverMessage(message);
+		if (isEnabled()) {
+			m_logger.debug("onLoad");
+			for (HibernateEventBean heb: m_events) {
+				if (heb.getEvent().equals(LOAD_EVENT)) {
+					if (entity.getClass().getName().equals(heb.getClassname())) {
+						Message message = createMessage(entity);
+						addMessageInfo(message, id, state, propertyNames, types);
+						deliverMessage(message);
+					}
 				}
 			}
 		}
@@ -351,13 +366,15 @@
 
 	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);
-					addMessageInfo(message, id, state, propertyNames, types);
-					deliverMessage(message);
+		if (isEnabled()) {
+			m_logger.debug("onSave");
+			for (HibernateEventBean heb: m_events) {
+				if (heb.getEvent().equals(SAVE_EVENT)) {
+					if (entity.getClass().getName().equals(heb.getClassname())) {
+						Message message = createMessage(entity);
+						addMessageInfo(message, id, state, propertyNames, types);
+						deliverMessage(message);
+					}
 				}
 			}
 		}
@@ -365,10 +382,26 @@
 	}
 
 	public void postFlush(Iterator arg0) throws CallbackException {
-		m_logger.debug("postFlush");
+		if (isEnabled()) {
+			m_logger.debug("postFlush");
+		}
 	}
 
 	public void preFlush(Iterator arg0) throws CallbackException {
-		m_logger.debug("preFlush");
-	}	
+		if (isEnabled()) {
+			m_logger.debug("preFlush");
+		}
+	}
+	
+	public synchronized boolean isEnabled() {
+		return enabled ;
+	}
+	
+	public synchronized void enable() {
+		enabled = true ;
+	}
+	
+	public synchronized void disable() {
+		enabled = false ;
+	}
 }




More information about the jboss-svn-commits mailing list