mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#366 - ServerConfigStart when registered via instance rather than class not fired
This commit is contained in:
@@ -27,27 +27,27 @@ public class BootupClasses implements ClassPathSearchMatcher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BootupClasses.class);
|
||||
|
||||
private final ArrayList<Class<?>> embeddableList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> embeddableList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> entityList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> entityList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> scalarTypeList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> scalarTypeList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> scalarConverterList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> scalarConverterList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> compoundTypeList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> compoundTypeList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> beanControllerList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> beanControllerList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> transactionEventListenerList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> transactionEventListenerList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> beanFindControllerList = new ArrayList<Class<?>>();
|
||||
private final ArrayList<Class<?>> beanQueryAdapterList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> beanFindControllerList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> beanQueryAdapterList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> beanListenerList = new ArrayList<Class<?>>();
|
||||
private final List<Class<?>> beanListenerList = new ArrayList<Class<?>>();
|
||||
|
||||
private final ArrayList<Class<?>> serverConfigStartupList = new ArrayList<Class<?>>();
|
||||
private final ArrayList<ServerConfigStartup> serverConfigStartupInstances = new ArrayList<ServerConfigStartup>();
|
||||
private final List<Class<?>> serverConfigStartupList = new ArrayList<Class<?>>();
|
||||
private final List<ServerConfigStartup> serverConfigStartupInstances = new ArrayList<ServerConfigStartup>();
|
||||
|
||||
private final List<BeanFindController> findControllerInstances = new ArrayList<BeanFindController>();
|
||||
private final List<BeanPersistController> persistControllerInstances = new ArrayList<BeanPersistController>();
|
||||
@@ -75,10 +75,17 @@ public class BootupClasses implements ClassPathSearchMatcher {
|
||||
try {
|
||||
ServerConfigStartup newInstance = (ServerConfigStartup) cls.newInstance();
|
||||
newInstance.onStart(serverConfig);
|
||||
|
||||
} catch (Exception e) {
|
||||
String msg = "Error creating BeanQueryAdapter " + cls;
|
||||
logger.error(msg, e);
|
||||
// assume that the desired behavior is to fail - add your own try catch if needed
|
||||
throw new IllegalStateException("Error running ServerConfigStartup " + cls, e);
|
||||
}
|
||||
}
|
||||
for (ServerConfigStartup startup : serverConfigStartupInstances) {
|
||||
try {
|
||||
startup.onStart(serverConfig);
|
||||
} catch (Exception e) {
|
||||
// assume that the desired behavior is to fail - add your own try catch if needed
|
||||
throw new IllegalStateException("Error running ServerConfigStartup " + startup.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.avaje.ebean;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.event.ServerConfigStartup;
|
||||
import com.avaje.tests.model.basic.UTDetail;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EbeanServerFactory_ServerConfigStart_Test {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
config.setName("h2");
|
||||
config.loadFromProperties();
|
||||
config.setName("h2other");
|
||||
config.setDdlGenerate(false);
|
||||
config.setDdlRun(false);
|
||||
config.setDefaultServer(false);
|
||||
config.setRegister(false);
|
||||
|
||||
config.addClass(UTDetail.class);
|
||||
config.addClass(OnStartupViaClass.class);
|
||||
|
||||
// act - register an instance
|
||||
OnStartup onStartup = new OnStartup();
|
||||
config.addServerConfigStartup(onStartup);
|
||||
|
||||
EbeanServer ebeanServer = EbeanServerFactory.create(config);
|
||||
|
||||
assertThat(onStartup.calledWithConfig).isSameAs(config);
|
||||
assertThat(OnStartupViaClass.calledWithConfig).isSameAs(config);
|
||||
|
||||
assertThat(ebeanServer).isNotNull();
|
||||
}
|
||||
|
||||
public static class OnStartup implements ServerConfigStartup {
|
||||
|
||||
ServerConfig calledWithConfig;
|
||||
|
||||
@Override
|
||||
public void onStart(ServerConfig serverConfig) {
|
||||
calledWithConfig = serverConfig;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class OnStartupViaClass implements ServerConfigStartup {
|
||||
|
||||
static ServerConfig calledWithConfig;
|
||||
|
||||
@Override
|
||||
public void onStart(ServerConfig serverConfig) {
|
||||
calledWithConfig = serverConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user