mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for #201: Change BeanPersistListener to use isRegisterFor() method rather than generics type (just like BeanPersistController)
This commit is contained in:
@@ -2,6 +2,7 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.tests.model.basic.MyEBasicConfigStartup;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,10 +11,16 @@ import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.tests.model.basic.EBasic;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestExplicitInsert extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws InterruptedException {
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
MyEBasicConfigStartup.resetCounters();
|
||||
|
||||
EBasic b = new EBasic();
|
||||
b.setName("exp insert");
|
||||
@@ -34,9 +41,22 @@ public class TestExplicitInsert extends BaseTestCase {
|
||||
Assert.assertNotNull(b2.getId());
|
||||
Assert.assertTrue(!b.getId().equals(b2.getId()));
|
||||
|
||||
List<EBasic> list = server.find(EBasic.class).where().in("id",b.getId(), b2.getId()).findList();
|
||||
List<EBasic> list = server.find(EBasic.class).where().in("id", b.getId(), b2.getId()).findList();
|
||||
|
||||
Assert.assertEquals(2, list.size());
|
||||
assertEquals(2, list.size());
|
||||
|
||||
b2.setName("do an update");
|
||||
server.save(b2);
|
||||
|
||||
server.delete(b);
|
||||
server.delete(b2);
|
||||
|
||||
// just sleep a little to allow the background thread to fire
|
||||
Thread.sleep(100);
|
||||
|
||||
assertEquals(2, MyEBasicConfigStartup.insertCount.get());
|
||||
assertEquals(1, MyEBasicConfigStartup.updateCount.get());
|
||||
assertEquals(2, MyEBasicConfigStartup.deleteCount.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,23 @@ package com.avaje.tests.model.basic;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
import com.avaje.ebean.event.BulkTableEvent;
|
||||
import com.avaje.ebean.event.BulkTableEventListener;
|
||||
import com.avaje.ebean.event.ServerConfigStartup;
|
||||
import com.avaje.ebean.event.*;
|
||||
|
||||
public class MyEBasicConfigStartup implements ServerConfigStartup {
|
||||
|
||||
public static AtomicLong insertCount = new AtomicLong();
|
||||
public static AtomicLong updateCount = new AtomicLong();
|
||||
public static AtomicLong deleteCount = new AtomicLong();
|
||||
|
||||
public static void resetCounters() {
|
||||
insertCount.set(0);
|
||||
updateCount.set(0);
|
||||
deleteCount.set(0);
|
||||
}
|
||||
|
||||
public void onStart(ServerConfig serverConfig) {
|
||||
|
||||
serverConfig.add(new EbasicPersistList());
|
||||
@@ -35,32 +43,31 @@ public class MyEBasicConfigStartup implements ServerConfigStartup {
|
||||
|
||||
}
|
||||
|
||||
public static class EbasicPersistList implements BeanPersistListener<EBasic> {
|
||||
public static class EbasicPersistList extends AbstractBeanPersistListener {
|
||||
|
||||
public boolean inserted(EBasic bean) {
|
||||
System.out.println("-- EBasic inserted " + bean.getId());
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasic.class.isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
public boolean inserted(Object bean) {
|
||||
insertCount.incrementAndGet();
|
||||
System.out.println("-- EBasic inserted " + ((EBasic)bean).getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updated(EBasic bean, Set<String> updatedProperties) {
|
||||
System.out.println("-- EBasic updated " + bean.getId()+" updatedProperties: "+updatedProperties);
|
||||
public boolean updated(Object bean, Set<String> updatedProperties) {
|
||||
updateCount.incrementAndGet();
|
||||
System.out.println("-- EBasic updated " + ((EBasic)bean).getId()+" updatedProperties: "+updatedProperties);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean deleted(EBasic bean) {
|
||||
System.out.println("-- EBasic deleted " + bean.getId());
|
||||
public boolean deleted(Object bean) {
|
||||
deleteCount.incrementAndGet();
|
||||
System.out.println("-- EBasic deleted " + ((EBasic)bean).getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
public void remoteInsert(Object id) {
|
||||
}
|
||||
|
||||
public void remoteUpdate(Object id) {
|
||||
}
|
||||
|
||||
public void remoteDelete(Object id) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user