diff --git a/ebean-api/src/main/java/io/ebean/Database.java b/ebean-api/src/main/java/io/ebean/Database.java
index 509fd4764..d2344db52 100644
--- a/ebean-api/src/main/java/io/ebean/Database.java
+++ b/ebean-api/src/main/java/io/ebean/Database.java
@@ -1742,25 +1742,13 @@ public interface Database {
void truncate(Class>... tables);
/**
- * Runs the DDL manually. Can be used, if database is offline or if you use a
- * TenantMode that does not support DDL run on startup.
- *
- * Note: runDdl is normally executed at startup automatically, if
- * ebean.db.ddl.run=true is set. Calling this method, will not check
- * that flag.
- *
+ * Starts the database and runs db-migration or ddl. Normally the server is
+ * started automatically when the teantMode supports ddl-generation and start is
+ * not skipped by server config.
+ *
+ * In a multi tenancy environment, you may have call start multiple times for
+ * each tenant to initialize the database.
*/
- void runDdl();
-
- /**
- * Runs the migration manually. Can be used, if database is offline or if you use a
- * TenantMode that does not support DDL run on startup.
- *
- * Note: runDdl is normally executed at startup automatically, if
- * ebean.db.migration.run=true is set. Calling this method, will not check
- * that flag.
- *
- **/
- void runMigration();
+ void start();
}
diff --git a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
index d6bd7f4a8..6db8b4ca7 100644
--- a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
+++ b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
@@ -302,6 +302,11 @@ public class DatabaseConfig {
private ExternalTransactionManager externalTransactionManager;
private boolean skipDataSourceCheck;
+
+ /**
+ * Skip server start (i.e. run DDL/migration on creation).
+ */
+ private boolean skipStart;
/**
* The data source (if programmatically provided).
@@ -1646,6 +1651,20 @@ public class DatabaseConfig {
public void setSkipDataSourceCheck(boolean skipDataSourceCheck) {
this.skipDataSourceCheck = skipDataSourceCheck;
}
+
+ /**
+ * Return true if the server start should be skipped.
+ */
+ public boolean skipStart() {
+ return skipStart;
+ }
+
+ /**
+ * Set to true to skip the server start.
+ */
+ public void setSkipStart(boolean skipStart) {
+ this.skipStart = skipStart;
+ }
/**
* Return the DataSource.
@@ -2926,6 +2945,7 @@ public class DatabaseConfig {
jsonMutationDetection = p.getEnum(MutationDetection.class, "jsonMutationDetection", jsonMutationDetection);
skipDataSourceCheck = p.getBoolean("skipDataSourceCheck", skipDataSourceCheck);
+ skipStart = p.getBoolean("skipStart", skipStart);
runMigration = p.getBoolean("migration.run", runMigration);
ddlGenerate = p.getBoolean("ddl.generate", ddlGenerate);
ddlRun = p.getBoolean("ddl.run", ddlRun);
diff --git a/ebean-api/src/main/java/io/ebean/util/AnnotationUtil.java b/ebean-api/src/main/java/io/ebean/util/AnnotationUtil.java
index 4006fa512..709019158 100644
--- a/ebean-api/src/main/java/io/ebean/util/AnnotationUtil.java
+++ b/ebean-api/src/main/java/io/ebean/util/AnnotationUtil.java
@@ -71,14 +71,6 @@ public class AnnotationUtil {
return typeGet(clazz, annotation) != null;
}
- public static boolean metaHas(AnnotatedElement element, Class> annotationType) {
- return !metaFindAll(element, annotationType).isEmpty();
- }
-
- public static Set metaFindAll(AnnotatedElement element, Class> annotationType) {
- return metaFindAllFor(element, Collections.singleton(annotationType));
- }
-
/**
* Check if an element is annotated with an annotation of given type searching meta-annotations.
*/
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java
index afff3e2a0..b1626036c 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java
@@ -109,8 +109,12 @@ public final class DefaultContainer implements SpiContainer {
InternalConfiguration c = new InternalConfiguration(online, clusterManager, executor, config, bootupClasses);
DefaultServer server = new DefaultServer(c, c.cacheManager());
// generate and run DDL if required plus other plugins
+
if (!DbOffline.isGenerateMigration()) {
- startServer(online, server);
+ initServer(online, server);
+ if (online && config.getTenantMode().isDdlEnabled() && !config.skipStart()) {
+ server.start();
+ }
}
DbOffline.reset();
log.info("Started database[{}] platform[{}] in {}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start);
@@ -141,7 +145,7 @@ public final class DefaultContainer implements SpiContainer {
}
}
- private void startServer(boolean online, DefaultServer server) {
+ private void initServer(boolean online, DefaultServer server) {
server.executePlugins(online);
// initialise prior to registering with clusterManager
server.initialise();
@@ -150,8 +154,6 @@ public final class DefaultContainer implements SpiContainer {
clusterManager.registerServer(server);
}
}
- // start any services after registering with clusterManager
- server.start();
}
/**
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 9e3aadc86..1f44e01b2 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
@@ -55,7 +55,6 @@ import io.ebean.config.QueryPlanListener;
import io.ebean.config.SlowQueryEvent;
import io.ebean.config.SlowQueryListener;
import io.ebean.config.TempFileProvider;
-import io.ebean.config.TenantMode;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.event.BeanPersistController;
import io.ebean.event.ShutdownManager;
@@ -367,53 +366,29 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
encryptKeyManager.initialise();
}
serverCacheManager.enabledRegions(config.getEnabledL2Regions());
- }
-
-
- /**
- * Start any services after registering with the ClusterManager.
- */
- public void start() {
- // check, if DB is available to run DDL and migration
- boolean dbAvailable = !config.isDocStoreOnly()
- && !config.isDbOffline()
- && config.getDataSource() != null
- && config.getTenantMode().isDdlEnabled();
-
- if (dbAvailable) {
- if (config.isDdlRun()) {
- runDdl();
- }
- if (config.isRunMigration()) {
- runMigration();
- }
- } else if (config.isDdlRun() || config.isRunMigration()) {
- log.warn("There was a request to run DDL or migration, but this is currently not possible, as the database is not available");
- }
startQueryPlanCapture();
}
+
@Override
- public void runDdl() {
- ddlGenerator.runDdl();
- }
+ public void start() {
- @Override
- public void runMigration() {
- final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
- if (migrationRunner == null) {
- throw new IllegalStateException(
- "No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
+ if (config.isRunMigration()) {
+ final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
+ if (migrationRunner == null) {
+ throw new IllegalStateException("No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
+ }
+ final String dbSchema = config.getDbSchema();
+ if (dbSchema != null) {
+ migrationRunner.setDefaultDbSchema(dbSchema);
+ }
+ migrationRunner.setName(config.getName());
+ migrationRunner.setPlatform(config.getDatabasePlatform().getPlatform().base().name().toLowerCase());
+ migrationRunner.loadProperties(config.getProperties());
+ migrationRunner.run(config.getDataSource());
+ } else if (config.isDdlRun()) {
+ ddlGenerator.runDdl();
}
-
- final String dbSchema = config.getDbSchema();
- if (dbSchema != null) {
- migrationRunner.setDefaultDbSchema(dbSchema);
- }
- migrationRunner.setName(config.getName());
- migrationRunner.setPlatform(config.getDatabasePlatform().getPlatform().base().name().toLowerCase());
- migrationRunner.loadProperties(config.getProperties());
- migrationRunner.run(dataSource());
}
private void startQueryPlanCapture() {
diff --git a/ebean-test/src/test/java/io/ebean/config/TestServerOffline.java b/ebean-test/src/test/java/io/ebean/config/TestServerOffline.java
index bed9ab01e..b4ddf274d 100644
--- a/ebean-test/src/test/java/io/ebean/config/TestServerOffline.java
+++ b/ebean-test/src/test/java/io/ebean/config/TestServerOffline.java
@@ -55,8 +55,7 @@ public class TestServerOffline {
public synchronized void initDatabase() {
if (!initialized) {
- server.runDdl();
- server.runMigration();
+ server.start();
initialized = true;
}
}
@@ -78,11 +77,11 @@ public class TestServerOffline {
Properties props = props(url);
- // to bring up ebean without a database, we must disable varous things
+ // to bring up ebean without a database, we must disable various things
// that happen on startup
props.setProperty("datasource.h2_offline.failOnStart", "false");
props.setProperty("ebean.h2_offline.skipDataSourceCheck", "true");
- props.setProperty("ebean.h2_offline.ddl.run", "false");
+ props.setProperty("ebean.h2_offline.skipStart", "true");
DatabaseConfig config = config(props);
LazyDatasourceInitializer alert = new LazyDatasourceInitializer() ;
diff --git a/ebean-test/src/test/java/io/ebeaninternal/api/TDSpiServer.java b/ebean-test/src/test/java/io/ebeaninternal/api/TDSpiServer.java
index ba823c057..f0d91b935 100644
--- a/ebean-test/src/test/java/io/ebeaninternal/api/TDSpiServer.java
+++ b/ebean-test/src/test/java/io/ebeaninternal/api/TDSpiServer.java
@@ -644,12 +644,7 @@ public class TDSpiServer implements SpiServer {
}
@Override
- public void runDdl() {
-
- }
-
- @Override
- public void runMigration() {
-
+ public void start() {
+
}
}