From 1c162b9b1856243bb5f1f453df8d10a6611c2d02 Mon Sep 17 00:00:00 2001
From: Robin Bygrave
Date: Mon, 23 May 2016 10:31:24 +1200
Subject: [PATCH] #723 - Breaking API - Change BeanPersistListener to return
void rather than boolean for inserted(), updated() and deleted()
---
.../event/AbstractBeanPersistListener.java | 9 ++--
.../ebean/event/BeanPersistListener.java | 43 ++++++++-----------
.../deploy/ChainedBeanPersistListener.java | 24 +++--------
.../model/basic/MyEBasicConfigStartup.java | 9 ++--
4 files changed, 30 insertions(+), 55 deletions(-)
diff --git a/src/main/java/com/avaje/ebean/event/AbstractBeanPersistListener.java b/src/main/java/com/avaje/ebean/event/AbstractBeanPersistListener.java
index 4fc999d34..20af32c96 100644
--- a/src/main/java/com/avaje/ebean/event/AbstractBeanPersistListener.java
+++ b/src/main/java/com/avaje/ebean/event/AbstractBeanPersistListener.java
@@ -19,8 +19,7 @@ public abstract class AbstractBeanPersistListener implements BeanPersistListener
* @param bean The bean that was inserted.
*/
@Override
- public boolean inserted(Object bean) {
- return false;
+ public void inserted(Object bean) {
}
/**
@@ -31,8 +30,7 @@ public abstract class AbstractBeanPersistListener implements BeanPersistListener
* @param updatedProperties The properties that were modified by this update.
*/
@Override
- public boolean updated(Object bean, Set updatedProperties) {
- return false;
+ public void updated(Object bean, Set updatedProperties) {
}
/**
@@ -42,8 +40,7 @@ public abstract class AbstractBeanPersistListener implements BeanPersistListener
* @param bean The bean that was deleted.
*/
@Override
- public boolean deleted(Object bean) {
- return false;
+ public void deleted(Object bean) {
}
}
diff --git a/src/main/java/com/avaje/ebean/event/BeanPersistListener.java b/src/main/java/com/avaje/ebean/event/BeanPersistListener.java
index a4004a0dc..45389c83f 100644
--- a/src/main/java/com/avaje/ebean/event/BeanPersistListener.java
+++ b/src/main/java/com/avaje/ebean/event/BeanPersistListener.java
@@ -1,9 +1,9 @@
package com.avaje.ebean.event;
-import java.util.Set;
-
import com.avaje.ebean.config.ServerConfig;
+import java.util.Set;
+
/**
* Listens for committed bean events.
*
@@ -13,22 +13,18 @@ import com.avaje.ebean.config.ServerConfig;
* the listener is notified of the event.
*
*
- * For a cluster these events may need to be broadcast. Each of the inserted(),
- * updated() and deleted() methods return true if you want those events to be
- * broadcast to the other members of a cluster (the id values are broadcast). If
- * these methods return false then the events are not broadcast.
- *
- *
- * It is worth noting that BeanPersistListener is different in three main ways
+ * It is worth noting that BeanPersistListener is different in two main ways
* from BeanPersistController postXXX methods.
*
- * - BeanPersistListener only sees successfully committed events.
- * BeanPersistController pre and post methods occur before the commit or a
- * rollback and will see events that are later rolled back
- * - BeanPersistListener runs in a background thread and will not effect the
- * response time of the actual persist where as BeanPersistController code will
- * - BeanPersistListener can be notified of events from other servers in a
- * cluster.
+ * -
+ * BeanPersistListener only sees successfully committed events.
+ * BeanPersistController pre and post methods occur before the commit or a
+ * rollback and will see events that are later rolled back
+ *
+ * -
+ * BeanPersistListener runs in a background thread and will not effect the
+ * response time of the actual persist where as BeanPersistController code will
+ *
*
*
*
@@ -46,32 +42,29 @@ public interface BeanPersistListener {
boolean isRegisterFor(Class> cls);
/**
- * Notified that a bean has been inserted locally. Return true if you want the
- * cluster to be notified of the event.
+ * Notified that a bean has been inserted.
*
* @param bean
* The bean that was inserted.
*/
- boolean inserted(Object bean);
+ void inserted(Object bean);
/**
- * Notified that a bean has been updated locally. Return true if you want the
- * cluster to be notified of the event.
+ * Notified that a bean has been updated.
*
* @param bean
* The bean that was updated.
* @param updatedProperties
* The properties that were modified by this update.
*/
- boolean updated(Object bean, Set updatedProperties);
+ void updated(Object bean, Set updatedProperties);
/**
- * Notified that a bean has been deleted locally. Return true if you want the
- * cluster to be notified of the event.
+ * Notified that a bean has been deleted.
*
* @param bean
* The bean that was deleted.
*/
- boolean deleted(Object bean);
+ void deleted(Object bean);
}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/ChainedBeanPersistListener.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/ChainedBeanPersistListener.java
index c7d111c09..1ad5b2a82 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/deploy/ChainedBeanPersistListener.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/ChainedBeanPersistListener.java
@@ -83,33 +83,21 @@ public class ChainedBeanPersistListener implements BeanPersistListener {
}
}
- public boolean deleted(Object bean) {
- boolean notifyCluster = false;
+ public void deleted(Object bean) {
for (int i = 0; i < chain.length; i++) {
- if (chain[i].deleted(bean)) {
- notifyCluster = true;
- }
+ chain[i].deleted(bean);
}
- return notifyCluster;
}
- public boolean inserted(Object bean) {
- boolean notifyCluster = false;
+ public void inserted(Object bean) {
for (int i = 0; i < chain.length; i++) {
- if (chain[i].inserted(bean)) {
- notifyCluster = true;
- }
+ chain[i].inserted(bean);
}
- return notifyCluster;
}
- public boolean updated(Object bean, Set updatedProperties) {
- boolean notifyCluster = false;
+ public void updated(Object bean, Set updatedProperties) {
for (int i = 0; i < chain.length; i++) {
- if (chain[i].updated(bean, updatedProperties)) {
- notifyCluster = true;
- }
+ chain[i].updated(bean, updatedProperties);
}
- return notifyCluster;
}
}
diff --git a/src/test/java/com/avaje/tests/model/basic/MyEBasicConfigStartup.java b/src/test/java/com/avaje/tests/model/basic/MyEBasicConfigStartup.java
index 2740c230f..4570e2ff7 100644
--- a/src/test/java/com/avaje/tests/model/basic/MyEBasicConfigStartup.java
+++ b/src/test/java/com/avaje/tests/model/basic/MyEBasicConfigStartup.java
@@ -53,22 +53,19 @@ public class MyEBasicConfigStartup implements ServerConfigStartup {
return EBasic.class.isAssignableFrom(cls);
}
- public boolean inserted(Object bean) {
+ public void inserted(Object bean) {
insertCount.incrementAndGet();
System.out.println("-- EBasic inserted " + ((EBasic) bean).getId());
- return false;
}
- public boolean updated(Object bean, Set updatedProperties) {
+ public void updated(Object bean, Set updatedProperties) {
updateCount.incrementAndGet();
System.out.println("-- EBasic updated " + ((EBasic) bean).getId() + " updatedProperties: " + updatedProperties);
- return false;
}
- public boolean deleted(Object bean) {
+ public void deleted(Object bean) {
deleteCount.incrementAndGet();
System.out.println("-- EBasic deleted " + ((EBasic) bean).getId());
- return false;
}
}