diff --git a/ebean-api/src/main/java/io/ebean/Database.java b/ebean-api/src/main/java/io/ebean/Database.java index 6bd7ebe2b2..1ad4c19a51 100644 --- a/ebean-api/src/main/java/io/ebean/Database.java +++ b/ebean-api/src/main/java/io/ebean/Database.java @@ -1520,4 +1520,8 @@ static DatabaseBuilder builder() { */ 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 0c5a8b45f3..c14251c778 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 @@ -2285,4 +2285,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 c6b6717417..56c65ea5cd 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 9fb81acf1e..a4e8233ea4 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 ff34185508..b0097f76be 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 @@ -632,4 +632,9 @@ public void loadBeanL2(EntityBeanIntercept ebi) { public void loadBean(EntityBeanIntercept ebi) { } + + @Override + public void runDdl() { + + } }