details:   https://code.openbravo.com/erp/devel/pi/rev/c58405dd0b91
changeset: 15090:c58405dd0b91
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Jan 10 14:17:24 2012 +0100
summary:   Fixes issue 19447: Add transaction events to business event system

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/PersistenceEventOBInterceptor.java
 |  23 ++++-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionBeginEvent.java
         |  49 ++++++++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionCompletedEvent.java
     |  49 ++++++++++
 3 files changed, 120 insertions(+), 1 deletions(-)

diffs (158 lines):

diff -r 007d845c17a4 -r c58405dd0b91 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/PersistenceEventOBInterceptor.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/PersistenceEventOBInterceptor.java
      Tue Jan 10 14:07:21 2012 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/PersistenceEventOBInterceptor.java
      Tue Jan 10 14:17:24 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All portions are Copyright (C) 2011-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -25,6 +25,7 @@
 import javax.inject.Inject;
 
 import org.hibernate.EmptyInterceptor;
+import org.hibernate.Transaction;
 import org.hibernate.type.Type;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.structure.Traceable;
@@ -48,6 +49,12 @@
   @Inject
   private Event<EntityDeleteEvent> entityDeleteEventProducer;
 
+  @Inject
+  private Event<TransactionBeginEvent> transactionBeginEventProducer;
+
+  @Inject
+  private Event<TransactionCompletedEvent> transactionCompletedEventProducer;
+
   public void onDelete(Object entity, Serializable id, Object[] state, 
String[] propertyNames,
       Type[] types) {
     final EntityDeleteEvent entityEvent = new EntityDeleteEvent();
@@ -105,4 +112,18 @@
     return t.getCreatedBy() == null;
   }
 
+  @Override
+  public void afterTransactionBegin(Transaction tx) {
+    final TransactionBeginEvent event = new TransactionBeginEvent();
+    event.setTransaction(tx);
+    transactionBeginEventProducer.fire(event);
+  }
+
+  @Override
+  public void afterTransactionCompletion(Transaction tx) {
+    final TransactionCompletedEvent event = new TransactionCompletedEvent();
+    event.setTransaction(tx);
+    transactionCompletedEventProducer.fire(event);
+  }
+
 }
diff -r 007d845c17a4 -r c58405dd0b91 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionBeginEvent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionBeginEvent.java
      Tue Jan 10 14:17:24 2012 +0100
@@ -0,0 +1,49 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2012 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.kernel.event;
+
+import org.hibernate.Transaction;
+import org.openbravo.dal.core.OBInterceptor;
+
+/**
+ * The event object send out when a transaction is started.
+ * 
+ * To receive this event, create a class with a method which has this 
signature:
+ * 
+ * public void onTransactionBegin(@Observes TransactionBeginEvent event) {
+ * 
+ * Note, the method name is unimportant, the @Observes EntityNewEvent 
specifies that this method
+ * will be called before persisting a new instance.
+ * 
+ * @see OBInterceptor#afterTransactionBegin(Transaction)
+ * 
+ * @author mtaal
+ */
+public class TransactionBeginEvent {
+  private Transaction transaction;
+
+  public Transaction getTransaction() {
+    return transaction;
+  }
+
+  public void setTransaction(Transaction transaction) {
+    this.transaction = transaction;
+  }
+
+}
diff -r 007d845c17a4 -r c58405dd0b91 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionCompletedEvent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/TransactionCompletedEvent.java
  Tue Jan 10 14:17:24 2012 +0100
@@ -0,0 +1,49 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2012 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.kernel.event;
+
+import org.hibernate.Transaction;
+import org.openbravo.dal.core.OBInterceptor;
+
+/**
+ * The event object send out when a transaction has been completed.
+ * 
+ * To receive this event, create a class with a method which has this 
signature:
+ * 
+ * public void onTransactionComplete(@Observes TransactionCompletedEvent 
event) {
+ * 
+ * Note, the method name is unimportant, the @Observes EntityNewEvent 
specifies that this method
+ * will be called before persisting a new instance.
+ * 
+ * @see OBInterceptor#afterTransactionCompletion(Transaction)
+ * 
+ * @author mtaal
+ */
+public class TransactionCompletedEvent {
+  private Transaction transaction;
+
+  public Transaction getTransaction() {
+    return transaction;
+  }
+
+  public void setTransaction(Transaction transaction) {
+    this.transaction = transaction;
+  }
+
+}

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to