#904 - ENH: Add @PreSoftDelete @PostSoftDelete ... such that methods on beans can be used for these callbacks

This commit is contained in:
Rob Bygrave
2016-11-28 22:24:17 +13:00
parent a585447dc9
commit c46b235eff
3 changed files with 62 additions and 3 deletions
@@ -87,8 +87,15 @@ public class TestLifecycleAnnotatedBean extends BaseTestCase {
Ebean.save(bean);
Ebean.delete(bean);
assertThat(bean.getBuffer()).contains("preSoftDelete");
assertThat(bean.getBuffer()).contains("postSoftDelete");
Ebean.deletePermanent(bean);
assertThat(bean.getBuffer()).contains("preRemove1");
assertThat(bean.getBuffer()).contains("preRemove2");
assertThat(bean.getBuffer()).contains("postRemove1");
assertThat(bean.getBuffer()).contains("postRemove2");
}
@Test
@@ -98,7 +105,7 @@ public class TestLifecycleAnnotatedBean extends BaseTestCase {
bean.setName("Persisted");
Ebean.save(bean);
Ebean.delete(bean);
Ebean.deletePermanent(bean);
assertThat(bean.getBuffer()).contains("postRemove1");
assertThat(bean.getBuffer()).contains("postRemove2");
@@ -1,5 +1,9 @@
package com.avaje.tests.model.basic;
import com.avaje.ebean.annotation.PostSoftDelete;
import com.avaje.ebean.annotation.PreSoftDelete;
import com.avaje.ebean.annotation.SoftDelete;
import javax.annotation.PostConstruct;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -22,6 +26,9 @@ public class EBasicWithLifecycle {
String name;
@SoftDelete
boolean deleted;
@Version
Long version;
@@ -87,6 +94,16 @@ public class EBasicWithLifecycle {
buffer.append("postRemove2");
}
@PostSoftDelete
public void postSoftDelete() {
buffer.append("postSoftDelete");
}
@PreSoftDelete
public void preSoftDelete() {
buffer.append("preSoftDelete");
}
@PostLoad
public void postLoad1() {
buffer.append("postLoad1");
@@ -123,6 +140,14 @@ public class EBasicWithLifecycle {
this.name = name;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public Long getVersion() {
return version;
}