Fix for #175 - Change to use System.getProperty("ebean.serverfactory")

rather than GlobalProperties
This commit is contained in:
rbygrave
2014-07-21 22:31:01 +12:00
parent f7ece0f13c
commit e50656871d
3 changed files with 47 additions and 79 deletions
@@ -6,8 +6,6 @@ import com.avaje.ebean.common.BootupEbeanManager;
import com.avaje.ebean.config.GlobalProperties;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.util.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Creates EbeanServer instances.
@@ -26,14 +24,9 @@ import org.slf4j.LoggerFactory;
* methods on the Ebean singleton such as {@link Ebean#find(Class)} are just a
* convenient way of using the 'default/primary' EbeanServer.
* </p>
*
* @author Rob Bygrave
*
*/
public class EbeanServerFactory {
private static final Logger logger = LoggerFactory.getLogger(EbeanServerFactory.class);
private static BootupEbeanManager serverFactory = createServerFactory();
/**
@@ -69,27 +62,10 @@ public class EbeanServerFactory {
private static BootupEbeanManager createServerFactory() {
// String d___ =
// com.avaje.ebean.server.core.DefaultServerFactory.class.getName();
String dflt = "com.avaje.ebeaninternal.server.core.DefaultServerFactory";
String implClassName = GlobalProperties.get("ebean.serverfactory", dflt);
String implClassName = System.getProperty("ebean.serverfactory", dflt);
int delaySecs = GlobalProperties.getInt("ebean.start.delay", 0);
if (delaySecs > 0) {
try {
// perhaps useful to delay the startup to give time to
// attach a debugger when running in a server like tomcat.
String m = "Ebean sleeping " + delaySecs + " seconds due to ebean.start.delay";
logger.info(m);
Thread.sleep(delaySecs * 1000);
} catch (InterruptedException e) {
String m = "Interrupting debug.start.delay of " + delaySecs;
logger.error(m, e);
}
}
try {
// use a client side implementation?
return (BootupEbeanManager) ClassUtil.newInstance(implClassName);
} catch (Exception ex) {
throw new RuntimeException(ex);
@@ -1,22 +1,3 @@
/**
* Copyright (C) 2006 Robin Bygrave
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.ebeaninternal.server.core;
import java.sql.Connection;
@@ -1,9 +1,11 @@
package com.avaje.tests.unitinternal;
import java.io.File;
import org.avaje.agentloader.AgentLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.DataSourceConfig;
@@ -12,42 +14,51 @@ import com.avaje.tests.model.basic.TOne;
public class HelloMain {
public static void main(String[] args) {
// ### Configuration Objects ###
ServerConfig serverConfig = new ServerConfig();
DataSourceConfig dataSourceConfig = new DataSourceConfig();
protected static Logger logger = LoggerFactory.getLogger(HelloMain.class);
// ### Configuration Settings ###
// -> data source
dataSourceConfig.setDriver("org.h2.Driver");
dataSourceConfig.setUsername("howtouser");
dataSourceConfig.setPassword("");
dataSourceConfig.setUrl("jdbc:h2:db/howto1");
static {
logger.debug("... preStart");
if (!AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1;packages=com.avaje.tests.**")) {
logger.info("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
}
}
// -> server
serverConfig.setName("default");
serverConfig.setDataSourceConfig(dataSourceConfig);
public static void main(String[] args) {
// ### Configuration Objects ###
ServerConfig serverConfig = new ServerConfig();
DataSourceConfig dataSourceConfig = new DataSourceConfig();
// auto create db if it does not exist
if(!(new File("db/howto1.data.db")).exists() ){
serverConfig.setDdlGenerate(true);
serverConfig.setDdlRun(true);
serverConfig.addClass(TOne.class);
}
// ### Configuration Settings ###
// -> data source
dataSourceConfig.setDriver("org.h2.Driver");
dataSourceConfig.setUsername("howtouser");
dataSourceConfig.setPassword("");
dataSourceConfig.setUrl("jdbc:h2:db/howto1");
EbeanServer eServer = EbeanServerFactory.create(serverConfig);
// -> server
serverConfig.setName("default");
serverConfig.setDataSourceConfig(dataSourceConfig);
// auto create db if it does not exist
if (!(new File("db/howto1.data.db")).exists()) {
serverConfig.setDdlGenerate(true);
serverConfig.setDdlRun(true);
serverConfig.addClass(TOne.class);
}
EbeanServer eServer = EbeanServerFactory.create(serverConfig);
long id = 1;
TOne data = eServer.find(TOne.class, id);
if (data == null) {
System.out.println("This is the first run, saving data..");
TOne tone = new TOne();
tone.setName("banan");
eServer.save(tone);// new TOne()id, "Hello World!"));
} else {
System.out.println(String.format("############\n%s############", data.getName()));
}
// ShutdownManager.shutdown();
}
long id = 1;
TOne data = eServer.find(TOne.class, id);
if (data == null) {
System.out.println("This is the first run, saving data..");
TOne tone = new TOne();
tone.setName("banan");
eServer.save(tone);//new TOne()id, "Hello World!"));
} else {
System.out.println(String.format("############\n%s############", data.getName()));
}
//ShutdownManager.shutdown();
}
}