Skip to content

Commit 8c501f8

Browse files
committed
NEW: DDL generation can be invoked separately
Fix for css
1 parent 83e87b0 commit 8c501f8

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

ebean-api/src/main/java/io/ebean/Database.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,4 +1509,8 @@ public interface Database {
15091509
*/
15101510
void truncate(Class<?>... beanTypes);
15111511

1512+
/**
1513+
* RunDdl manually. This can be used if 'db.ddl.run=false' is set and you plan to run DDL manually.
1514+
*/
1515+
void runDdl();
15121516
}

ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public interface SpiDdlGenerator {
1212
*/
1313
void execute(boolean online);
1414

15+
/**
16+
* Run DDL manually. This can be used to initialize multi tenant environments or if you plan not to run
17+
* DDL on startup
18+
*/
19+
void runDdl();
1520
}

ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,4 +2255,9 @@ List<MetaQueryPlan> queryPlanInit(QueryPlanInit initRequest) {
22552255
List<MetaQueryPlan> queryPlanCollectNow(QueryPlanRequest request) {
22562256
return queryPlanManager.collect(request);
22572257
}
2258+
2259+
@Override
2260+
public void runDdl() {
2261+
ddlGenerator.runDdl();
2262+
}
22582263
}

ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ private static class NoopDdl implements SpiDdlGenerator {
616616
this.ddlRun = ddlRun;
617617
}
618618

619+
@Override
620+
public void runDdl() {
621+
CoreLog.log.log(ERROR, "Manual DDL run not possible");
622+
}
623+
619624
@Override
620625
public void execute(boolean online) {
621626
if (online && ddlRun) {

ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public DdlGenerator(SpiEbeanServer server) {
6363
if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) {
6464
log.log(WARNING, "DDL can''t be run on startup with TenantMode " + config.getTenantMode());
6565
this.runDdl = false;
66-
this.useMigrationStoredProcedures = false;
6766
} else {
6867
this.runDdl = config.isDdlRun();
69-
this.useMigrationStoredProcedures = config.getDatabasePlatform().useMigrationStoredProcedures();
7068
}
69+
this.useMigrationStoredProcedures = config.getDatabasePlatform() != null && config.getDatabasePlatform().useMigrationStoredProcedures();
7170
this.scriptTransform = createScriptTransform(config);
7271
this.baseDir = initBaseDir();
7372
}
@@ -85,7 +84,7 @@ private File initBaseDir() {
8584
@Override
8685
public void execute(boolean online) {
8786
generateDdl();
88-
if (online) {
87+
if (online && runDdl) {
8988
runDdl();
9089
}
9190
}
@@ -105,16 +104,15 @@ protected void generateDdl() {
105104
/**
106105
* Run the DDL drop and DDL create scripts if properties have been set.
107106
*/
108-
protected void runDdl() {
109-
if (runDdl) {
110-
Connection connection = null;
111-
try {
112-
connection = obtainConnection();
113-
runDdlWith(connection);
114-
} finally {
115-
JdbcClose.rollback(connection);
116-
JdbcClose.close(connection);
117-
}
107+
@Override
108+
public void runDdl() {
109+
Connection connection = null;
110+
try {
111+
connection = obtainConnection();
112+
runDdlWith(connection);
113+
} finally {
114+
JdbcClose.rollback(connection);
115+
JdbcClose.close(connection);
118116
}
119117
}
120118

ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,9 @@ public void loadBeanL2(EntityBeanIntercept ebi) {
627627
public void loadBean(EntityBeanIntercept ebi) {
628628

629629
}
630+
631+
@Override
632+
public void runDdl() {
633+
634+
}
630635
}

0 commit comments

Comments
 (0)