DDL generate & run is now a plugin

This commit is contained in:
Roland Praml committed 2022-01-03 13:41:59 +01:00
1 parent b7905eb0f6
commit 699f7a8449
9 files changed
+78 -137

No files matched your search

@@ -1,21 +0,0 @@
package io.ebeaninternal.api;
/**
* DDL generate and run for drop all/create all.
*/
public interface SpiDdlGenerator {
/**
* Generate and run the DDL for drop-all and create-all scripts.
* <p>
* Run based on on property settings for ebean.ddl.generate
*/
void generateDdl();
/**
* Runs the created DDL files.
* <p>
* Run based on on property settings for ebean.ddl.run etc.
*/
void runDdl();
}
@@ -1,13 +0,0 @@
package io.ebeaninternal.api;
/**
* Provides the DDL Generator for create-all/drop-all.
*/
public interface SpiDdlGeneratorProvider {
/**
* Provide the DDL generator.
*/
SpiDdlGenerator generator(SpiEbeanServer server);
}
@@ -153,7 +153,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
private final ReadAuditLogger readAuditLogger;
private final CQueryEngine cqueryEngine;
private final List<Plugin> serverPlugins;
private final SpiDdlGenerator ddlGenerator;
private final ScriptRunner scriptRunner;
private final ExpressionFactory expressionFactory;
private final SpiBackgroundExecutor backgroundExecutor;
@@ -215,7 +214,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
this.queryPlanManager = config.initQueryPlanManager(transactionManager);
this.metaInfoManager = new DefaultMetaInfoManager(this);
this.serverPlugins = config.getPlugins();
this.ddlGenerator = config.initDdlGenerator(this);
this.scriptRunner = new DScriptRunner(this);
configureServerPlugins();
@@ -245,9 +243,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Execute all the plugins with an online flag indicating the DB is up or not.
*/
public void executePlugins(boolean online) {
if (!config.isDocStoreOnly()) {
ddlGenerator.generateDdl();
}
for (Plugin plugin : serverPlugins) {
plugin.online(online);
}
@@ -376,8 +371,9 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
migrationRunner.setPlatform(config.getDatabasePlatform().getPlatform().base().name().toLowerCase());
migrationRunner.loadProperties(config.getProperties());
migrationRunner.run(config.getDataSource());
} else if (config.isDdlRun()) {
ddlGenerator.runDdl();
}
for (Plugin plugin : serverPlugins) {
plugin.start();
}
}
@@ -594,31 +594,4 @@ public final class InternalConfiguration {
return new QueryPlanLoggerExplain();
}
}
/**
* Return the DDL generator.
*/
public SpiDdlGenerator initDdlGenerator(SpiEbeanServer server) {
final SpiDdlGeneratorProvider service = service(SpiDdlGeneratorProvider.class);
return service == null ? new NoopDdl(server.config().isDdlRun()) : service.generator(server);
}
private static class NoopDdl implements SpiDdlGenerator {
private final boolean ddlRun;
NoopDdl(boolean ddlRun) {
this.ddlRun = ddlRun;
}
@Override
public void generateDdl() {
// do nothing
}
@Override
public void runDdl() {
if (ddlRun) {
CoreLog.log.error("Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)");
}
}
}
}