diff --git a/ebean-api/src/main/java/io/ebean/Database.java b/ebean-api/src/main/java/io/ebean/Database.java index 5df0e22ee8..c61c60a7ef 100644 --- a/ebean-api/src/main/java/io/ebean/Database.java +++ b/ebean-api/src/main/java/io/ebean/Database.java @@ -1518,4 +1518,8 @@ default Set checkUniqueness(Object bean, Transaction transaction) { */ void truncate(Class... beanTypes); + /** + * RunDdl manually. This can be used if 'db.ddl.run=false' is set and you plan to run DDL manually. + */ + void runDdl(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java b/ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java index b3c4858139..d821e75b84 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java @@ -12,4 +12,9 @@ public interface SpiDdlGenerator { */ void execute(boolean online); + /** + * Run DDL manually. This can be used to initialize multi tenant environments or if you plan not to run + * DDL on startup + */ + void runDdl(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java index 5f2a6aac1a..65c916243e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java @@ -2291,4 +2291,9 @@ List queryPlanInit(QueryPlanInit initRequest) { List queryPlanCollectNow(QueryPlanRequest request) { return queryPlanManager.collect(request); } + + @Override + public void runDdl() { + ddlGenerator.runDdl(); + } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index b5c994c993..35a8ee0410 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -619,6 +619,11 @@ private static class NoopDdl implements SpiDdlGenerator { this.ddlRun = ddlRun; } + @Override + public void runDdl() { + CoreLog.log.log(ERROR, "Manual DDL run not possible"); + } + @Override public void execute(boolean online) { if (online && ddlRun) { diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java index 4f935f28df..c0c56abddf 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java @@ -63,11 +63,10 @@ public DdlGenerator(SpiEbeanServer server) { if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) { log.log(WARNING, "DDL can''t be run on startup with TenantMode " + config.getTenantMode()); this.runDdl = false; - this.useMigrationStoredProcedures = false; } else { this.runDdl = config.isDdlRun(); - this.useMigrationStoredProcedures = config.getDatabasePlatform().useMigrationStoredProcedures(); } + this.useMigrationStoredProcedures = config.getDatabasePlatform() != null && config.getDatabasePlatform().useMigrationStoredProcedures(); this.scriptTransform = createScriptTransform(config); this.baseDir = initBaseDir(); } @@ -85,7 +84,7 @@ private File initBaseDir() { @Override public void execute(boolean online) { generateDdl(); - if (online) { + if (online && runDdl) { runDdl(); } } @@ -105,16 +104,15 @@ protected void generateDdl() { /** * Run the DDL drop and DDL create scripts if properties have been set. */ - protected void runDdl() { - if (runDdl) { - Connection connection = null; - try { - connection = obtainConnection(); - runDdlWith(connection); - } finally { - JdbcClose.rollback(connection); - JdbcClose.close(connection); - } + @Override + public void runDdl() { + Connection connection = null; + try { + connection = obtainConnection(); + runDdlWith(connection); + } finally { + JdbcClose.rollback(connection); + JdbcClose.close(connection); } } diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java index 1aecd3d5c4..4799a631a6 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java @@ -622,4 +622,9 @@ public void loadBeanL2(EntityBeanIntercept ebi) { public void loadBean(EntityBeanIntercept ebi) { } + + @Override + public void runDdl() { + + } }