mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1084 - NPE When DB Migration generation run with @WhoCreated mapping
This commit is contained in:
@@ -12,6 +12,7 @@ import io.ebean.cache.ServerCachePlugin;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.DbEncrypt;
|
||||
import io.ebean.config.dbplatform.DbType;
|
||||
import io.ebean.dbmigration.DbOffline;
|
||||
import io.ebean.dbmigration.MigrationRunner;
|
||||
import io.ebean.event.BeanFindController;
|
||||
import io.ebean.event.BeanPersistController;
|
||||
@@ -1632,6 +1633,16 @@ public class ServerConfig {
|
||||
this.encryptor = encryptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the instance is coming up in offline mode.
|
||||
* <p>
|
||||
* Offline mode is mostly used when generating DB migration.
|
||||
* </p>
|
||||
*/
|
||||
public boolean isOfflineMode() {
|
||||
return dbOffline || DbOffline.isSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the EbeanServer instance should be created in offline mode.
|
||||
*/
|
||||
|
||||
@@ -268,7 +268,7 @@ public class DefaultContainer implements SpiContainer {
|
||||
|
||||
private DataSource getDataSourceFromConfig(ServerConfig config) {
|
||||
|
||||
if (config.isDbOffline() || DbOffline.isSet()) {
|
||||
if (config.isOfflineMode()) {
|
||||
logger.debug("... DbOffline using platform [{}]", DbOffline.getPlatform());
|
||||
return null;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public class DefaultContainer implements SpiContainer {
|
||||
*/
|
||||
private boolean checkDataSource(ServerConfig serverConfig) {
|
||||
|
||||
if (serverConfig.isDbOffline() || DbOffline.isSet()) {
|
||||
if (serverConfig.isOfflineMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -45,6 +45,10 @@ public class GeneratedPropertyFactory {
|
||||
if (currentUserProvider != null) {
|
||||
generatedWhoCreated = new GeneratedWhoCreated(currentUserProvider);
|
||||
generatedWhoModified = new GeneratedWhoModified(currentUserProvider);
|
||||
} else if (serverConfig.isOfflineMode()) {
|
||||
currentUserProvider = new DummyCurrentUser();
|
||||
generatedWhoCreated = new GeneratedWhoCreated(currentUserProvider);
|
||||
generatedWhoModified = new GeneratedWhoModified(currentUserProvider);
|
||||
} else {
|
||||
generatedWhoCreated = null;
|
||||
generatedWhoModified = null;
|
||||
@@ -150,4 +154,11 @@ public class GeneratedPropertyFactory {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
private static class DummyCurrentUser implements CurrentUserProvider {
|
||||
@Override
|
||||
public Object currentUser() {
|
||||
throw new RuntimeException("never called");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user