mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2274 Add DatabaseConfig jsonMutationDetection property setting the global default mode
This commit is contained in:
1 parent
a06f7bea41
commit
2043fdf7e1
5 files changed
+42
-7
No files matched your search
@@ -134,7 +134,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
this.postgres = isPostgres(config.getDatabasePlatform());
|
||||
this.objectMapperPresent = config.getClassLoadConfig().isJacksonObjectMapperPresent();
|
||||
this.objectMapper = (objectMapperPresent) ? initObjectMapper(config) : null;
|
||||
this.jsonManager = (objectMapperPresent) ? new TypeJsonManager(postgres, objectMapper) : null;
|
||||
this.jsonManager = (objectMapperPresent) ? new TypeJsonManager(postgres, objectMapper, config.getJsonMutationDetection()) : null;
|
||||
this.extraTypeFactory = new DefaultTypeFactory(config);
|
||||
this.arrayTypeListFactory = arrayTypeListFactory(config.getDatabasePlatform());
|
||||
this.arrayTypeSetFactory = arrayTypeSetFactory(config.getDatabasePlatform());
|
||||
|
||||
+2
-1
@@ -38,7 +38,8 @@ class ScalarTypeJsonObjectMapper {
|
||||
} else if (mode != MutationDetection.DEFAULT) {
|
||||
return new GenericObject(jsonManager, field, dbType, docType);
|
||||
}
|
||||
prop.setMutationDetection(MutationDetection.HASH);
|
||||
// using the global default MutationDetection mode (defaults to HASH)
|
||||
prop.setMutationDetection(jsonManager.mutationDetection());
|
||||
return new GenericObject(jsonManager, field, dbType, docType);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,23 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.ebean.ModifyAwareType;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
|
||||
class TypeJsonManager {
|
||||
|
||||
private final boolean postgres;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final MutationDetection mutationDetection;
|
||||
|
||||
TypeJsonManager(boolean postgres, Object objectMapper) {
|
||||
TypeJsonManager(boolean postgres, Object objectMapper, MutationDetection mutationDetection) {
|
||||
this.postgres = postgres;
|
||||
this.objectMapper = (ObjectMapper) objectMapper;
|
||||
this.mutationDetection = mutationDetection;
|
||||
}
|
||||
|
||||
MutationDetection mutationDetection() {
|
||||
return mutationDetection;
|
||||
}
|
||||
|
||||
ObjectMapper objectMapper() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
@@ -62,7 +63,7 @@ public class ServerConfigTest {
|
||||
props.setProperty("dbOffline", "true");
|
||||
props.setProperty("jsonDateTime", "MILLIS");
|
||||
props.setProperty("jsonDate", "MILLIS");
|
||||
props.setProperty("jsonDirtyByDefault", "false");
|
||||
props.setProperty("jsonMutationDetection", "NONE");
|
||||
props.setProperty("autoReadOnlyDataSource", "true");
|
||||
props.setProperty("disableL2Cache", "true");
|
||||
props.setProperty("notifyL2CacheInForeground", "true");
|
||||
@@ -98,6 +99,9 @@ public class ServerConfigTest {
|
||||
|
||||
assertThat(serverConfig.getNamingConvention()).isInstanceOf(MatchingNamingConvention.class);
|
||||
|
||||
assertEquals(MutationDetection.NONE, serverConfig.getJsonMutationDetection());
|
||||
serverConfig.setJsonMutationDetection(MutationDetection.SOURCE);
|
||||
assertEquals(MutationDetection.SOURCE, serverConfig.getJsonMutationDetection());
|
||||
assertEquals(IdType.SEQUENCE, serverConfig.getIdType());
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatch());
|
||||
assertEquals(PersistBatch.ALL, serverConfig.getPersistBatchOnCascade());
|
||||
@@ -156,6 +160,7 @@ public class ServerConfigTest {
|
||||
assertFalse(serverConfig.isIdGeneratorAutomatic());
|
||||
assertEquals(JsonConfig.DateTime.ISO8601, serverConfig.getJsonDateTime());
|
||||
assertEquals(JsonConfig.Date.ISO8601, serverConfig.getJsonDate());
|
||||
assertEquals(MutationDetection.HASH, serverConfig.getJsonMutationDetection());
|
||||
assertTrue(serverConfig.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertTrue(serverConfig.isAutoLoadModuleInfo());
|
||||
|
||||
|
||||
Reference in new issue
Block a user