mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge branch 'api-to-run-ddl-manually' into ebean-new
# Conflicts: # ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java
This commit is contained in:
@@ -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.
|
||||
* <p>
|
||||
* Note: runDdl is normally executed at startup automatically, if
|
||||
* <code>ebean.db.ddl.run=true</code> is set. Calling this method, will not check
|
||||
* that flag.
|
||||
* </p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Note: runDdl is normally executed at startup automatically, if
|
||||
* <code>ebean.db.migration.run=true</code> is set. Calling this method, will not check
|
||||
* that flag.
|
||||
* </p>
|
||||
**/
|
||||
void runMigration();
|
||||
void start();
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Annotation> 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.
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() ;
|
||||
|
||||
@@ -644,12 +644,7 @@ public class TDSpiServer implements SpiServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDdl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runMigration() {
|
||||
|
||||
public void start() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user