Merge pull request #13 from rvowles/master

Please consider this for updates to the server.
This commit is contained in:
Rob Bygrave
2013-04-08 03:36:24 -07:00
6 changed files with 77 additions and 13 deletions
+5 -5
View File
@@ -1,11 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.avaje</groupId>
<artifactId>avaje-javaparent</artifactId>
<version>1.1</version>
</parent>
<!--<parent>-->
<!--<groupId>org.avaje</groupId>-->
<!--<artifactId>avaje-javaparent</artifactId>-->
<!--<version>1.1</version>-->
<!--</parent>-->
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm-server</artifactId>
@@ -0,0 +1,22 @@
package com.avaje.ebeaninternal.api;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
/**
* Allows us to have more than one plugin (the ddl generator) active based on flags.
*
* author: Richard Vowles - http://gplus.to/RichardVowles
*/
public interface SpiEbeanPlugin {
/**
* initializes the plugin.
*
* @param server - the ebean server with extensions for all of the Ebean internals
* @param dbPlatform - the database we are using - this is available from the server, but it is provided for convenience
* @param serverConfig - the configured server information. It allows access to pre-collected information (but not the collector PropertySource, yet)
*/
public void setup(SpiEbeanServer server, DatabasePlatform dbPlatform, ServerConfig serverConfig);
public void execute(boolean online);
}
@@ -14,6 +14,7 @@ import java.util.Set;
import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ServiceLoader;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanServer;
@@ -68,6 +69,7 @@ import com.avaje.ebeaninternal.api.LoadManyRequest;
import com.avaje.ebeaninternal.api.ScopeTrans;
import com.avaje.ebeaninternal.api.SpiBackgroundExecutor;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiEbeanPlugin;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.api.SpiQuery.Mode;
import com.avaje.ebeaninternal.api.SpiQuery.Type;
@@ -177,7 +179,8 @@ public final class DefaultServer implements SpiEbeanServer {
private final CQueryEngine cqueryEngine;
private final DdlGenerator ddlGenerator;
@Deprecated
private DdlGenerator ddlGenerator;
private final ExpressionFactory ldapExpressionFactory = new LdapExpressionFactory();
@@ -213,6 +216,12 @@ public final class DefaultServer implements SpiEbeanServer {
*/
private PstmtBatch pstmtBatch;
/**
* holds plugins (e.g. ddl generator) detected by the service loader
*/
private List<SpiEbeanPlugin> ebeanPlugins;
/**
* Create the DefaultServer.
*/
@@ -254,7 +263,6 @@ public final class DefaultServer implements SpiEbeanServer {
this.autoFetchManager = config.createAutoFetchManager(this);
this.adminAutofetch = new MAdminAutofetch(autoFetchManager);
this.ddlGenerator = new DdlGenerator(this, config.getDatabasePlatform(), config.getServerConfig());
this.beanLoader = new DefaultBeanLoader(this, config.getDebugLazyLoad());
this.jsonContext = config.createJsonContext(this);
@@ -265,9 +273,40 @@ public final class DefaultServer implements SpiEbeanServer {
this.ldapQueryEngine = new LdapOrmQueryEngine(ldapConfig.isVanillaMode(), ldapConfig.getContextFactory());
}
loadAndInitializePlugins(config);
ShutdownManager.register(new Shutdown());
}
protected void loadAndInitializePlugins(InternalConfiguration config) {
List<SpiEbeanPlugin> spiPlugins = new ArrayList<SpiEbeanPlugin>();
final Iterator<SpiEbeanPlugin> plugins = ServiceLoader.load(SpiEbeanPlugin.class).iterator();
while (plugins.hasNext()) {
SpiEbeanPlugin plugin = plugins.next();
spiPlugins.add(plugin);
plugin.setup(this, this.getDatabasePlatform(), config.getServerConfig());
if (plugin instanceof DdlGenerator) // backwards compatible
ddlGenerator = (DdlGenerator)plugin;
}
ebeanPlugins = Collections.unmodifiableList(spiPlugins);
}
public List<SpiEbeanPlugin> getSpiEbeanPlugins() {
return ebeanPlugins;
}
public void executePlugins(boolean online) {
for(SpiEbeanPlugin plugin : ebeanPlugins) {
plugin.execute(online);
}
}
public boolean isDefaultDeleteMissingChildren() {
return defaultDeleteMissingChildren;
}
@@ -227,7 +227,8 @@ public class DefaultServerFactory implements BootupEbeanManager {
server.registerMBeans(mbeanServer, uniqueServerId);
// generate and run DDL if required
executeDDL(server, online);
// if there are any other tasks requiring action in their plugins, do them as well
server.executePlugins(online);
// initialise prior to registering with clusterManager
server.initialise();
@@ -22,18 +22,19 @@ import com.avaje.ebean.Transaction;
import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
import com.avaje.ebeaninternal.api.SpiEbeanPlugin;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
/**
* Controls the generation of DDL and potentially runs the resulting scripts.
*/
public class DdlGenerator {
public class DdlGenerator implements SpiEbeanPlugin {
private static final Logger logger = Logger.getLogger(DdlGenerator.class.getName());
private static final Logger logger = Logger.getLogger(DdlGenerator.class.getName());
private final SpiEbeanServer server;
private SpiEbeanServer server;
private final DatabasePlatform dbPlatform;
private DatabasePlatform dbPlatform;
private int summaryLength = 80;
@@ -45,7 +46,7 @@ public class DdlGenerator {
private NamingConvention namingConvention;
public DdlGenerator(SpiEbeanServer server, DatabasePlatform dbPlatform, ServerConfig serverConfig) {
public void setup(SpiEbeanServer server, DatabasePlatform dbPlatform, ServerConfig serverConfig) {
this.server = server;
this.dbPlatform = dbPlatform;
this.generateDdl = serverConfig.isDdlGenerate();
@@ -0,0 +1 @@
com.avaje.ebeaninternal.server.ddl.DdlGenerator