mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Refactor extract ebean-json-node module - support for Jackson JsonNode (into separate module)
This commit is contained in:
1 parent
39de9d56db
commit
5c1b478085
27 files changed
+266
-84
No files matched your search
@@ -31,6 +31,12 @@
|
|||||||
<version>13.9.3-SNAPSHOT</version>
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-json-node</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-datasource</artifactId>
|
<artifactId>ebean-datasource</artifactId>
|
||||||
|
|||||||
@@ -116,6 +116,12 @@
|
|||||||
<version>13.9.3-SNAPSHOT</version>
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-json-node</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-ddl-generator</artifactId>
|
<artifactId>ebean-ddl-generator</artifactId>
|
||||||
|
|||||||
@@ -26,6 +26,14 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Provided scope for Postgres JSON/JSONB support -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.4.1</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.avaje</groupId>
|
<groupId>io.avaje</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|||||||
+14
-3
@@ -1,5 +1,7 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.core.type;
|
||||||
|
|
||||||
|
import io.ebean.annotation.Platform;
|
||||||
|
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||||
import org.postgresql.util.PGobject;
|
import org.postgresql.util.PGobject;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -9,12 +11,12 @@ public final class PostgresHelper {
|
|||||||
/**
|
/**
|
||||||
* The Postgres JSON DB type.
|
* The Postgres JSON DB type.
|
||||||
*/
|
*/
|
||||||
static final String JSON_TYPE = "json";
|
public static final String JSON_TYPE = "json";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Postgres JSONB DB type.
|
* The Postgres JSONB DB type.
|
||||||
*/
|
*/
|
||||||
static final String JSONB_TYPE = "jsonb";
|
public static final String JSONB_TYPE = "jsonb";
|
||||||
|
|
||||||
static final String INET_TYPE = "inet";
|
static final String INET_TYPE = "inet";
|
||||||
|
|
||||||
@@ -31,4 +33,13 @@ public final class PostgresHelper {
|
|||||||
pgo.setValue(rawJson);
|
pgo.setValue(rawJson);
|
||||||
return pgo;
|
return pgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the platform is Postgres or compatible like Yugabyte, Cockroach.
|
||||||
|
*/
|
||||||
|
public static boolean isPostgresCompatible(DatabasePlatform databasePlatform) {
|
||||||
|
return databasePlatform.isPlatform(Platform.POSTGRES)
|
||||||
|
|| databasePlatform.isPlatform(Platform.YUGABYTE)
|
||||||
|
|| databasePlatform.isPlatform(Platform.COCKROACH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package io.ebean.core.type;
|
||||||
|
|
||||||
|
import io.avaje.lang.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A ScalarType that has variations based on the mapped JDBC type (like VARCHAR, CLOB, JSON etc).
|
||||||
|
*/
|
||||||
|
public interface ScalarTypeSet<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The property type these scalar types map to.
|
||||||
|
*/
|
||||||
|
Class<?> type();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a default ScalarType to use when no other annotations like {@code @DbJson} are present.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
ScalarType<?> defaultType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the scalarType to use for the given jdbc type.
|
||||||
|
* <p>
|
||||||
|
* For example VARCHAR, CLOB, JSON etc.
|
||||||
|
*/
|
||||||
|
ScalarType<T> forType(int jdbcType);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package io.ebean.core.type;
|
||||||
|
|
||||||
|
import io.avaje.lang.Nullable;
|
||||||
|
import io.ebean.config.DatabaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory to create ScalarTypeSet.
|
||||||
|
*/
|
||||||
|
public interface ScalarTypeSetFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the ScalarTypeSet given the config and optional objectMapper.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
ScalarTypeSet<?> createTypeSet(DatabaseConfig config, @Nullable Object objectMapper);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ module io.ebean.core.type {
|
|||||||
|
|
||||||
requires transitive java.sql;
|
requires transitive java.sql;
|
||||||
requires transitive io.ebean.api;
|
requires transitive io.ebean.api;
|
||||||
|
requires static org.postgresql.jdbc;
|
||||||
|
|
||||||
requires static com.fasterxml.jackson.core;
|
requires static com.fasterxml.jackson.core;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.persist;
|
|||||||
|
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DataReader;
|
import io.ebean.core.type.DataReader;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebean.core.type.ScalarType;
|
import io.ebean.core.type.ScalarType;
|
||||||
import io.ebeaninternal.api.BindParams;
|
import io.ebeaninternal.api.BindParams;
|
||||||
import io.ebeaninternal.api.CoreLog;
|
import io.ebeaninternal.api.CoreLog;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebeaninternal.server.type;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.ebean.annotation.*;
|
import io.ebean.annotation.*;
|
||||||
import io.ebean.config.DatabaseConfig;
|
import io.ebean.config.DatabaseConfig;
|
||||||
@@ -9,9 +8,7 @@ import io.ebean.config.PlatformConfig;
|
|||||||
import io.ebean.config.ScalarTypeConverter;
|
import io.ebean.config.ScalarTypeConverter;
|
||||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DocPropertyType;
|
import io.ebean.core.type.*;
|
||||||
import io.ebean.core.type.ExtraTypeFactory;
|
|
||||||
import io.ebean.core.type.ScalarType;
|
|
||||||
import io.ebean.types.Cidr;
|
import io.ebean.types.Cidr;
|
||||||
import io.ebean.types.Inet;
|
import io.ebean.types.Inet;
|
||||||
import io.ebean.util.AnnotationUtil;
|
import io.ebean.util.AnnotationUtil;
|
||||||
@@ -51,6 +48,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
|
|
||||||
private static final System.Logger log = CoreLog.internal;
|
private static final System.Logger log = CoreLog.internal;
|
||||||
|
|
||||||
|
private final Map<Class<?>, ScalarTypeSet<?>> typeSets = new HashMap<>();
|
||||||
private final ConcurrentHashMap<Class<?>, ScalarType<?>> typeMap;
|
private final ConcurrentHashMap<Class<?>, ScalarType<?>> typeMap;
|
||||||
private final ConcurrentHashMap<Integer, ScalarType<?>> nativeMap;
|
private final ConcurrentHashMap<Integer, ScalarType<?>> nativeMap;
|
||||||
private final ConcurrentHashMap<String, ScalarType<?>> logicalMap;
|
private final ConcurrentHashMap<String, ScalarType<?>> logicalMap;
|
||||||
@@ -71,28 +69,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
private final EnumType defaultEnumType;
|
private final EnumType defaultEnumType;
|
||||||
private final DatabasePlatform databasePlatform;
|
private final DatabasePlatform databasePlatform;
|
||||||
|
|
||||||
// OPTIONAL ScalarTypes registered if Jackson/JsonNode is in the classpath
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Jackson's JsonNode storage to Clob.
|
|
||||||
*/
|
|
||||||
private ScalarType<?> jsonNodeClob;
|
|
||||||
/**
|
|
||||||
* Jackson's JsonNode storage to Blob.
|
|
||||||
*/
|
|
||||||
private ScalarType<?> jsonNodeBlob;
|
|
||||||
/**
|
|
||||||
* Jackson's JsonNode storage to Varchar.
|
|
||||||
*/
|
|
||||||
private ScalarType<?> jsonNodeVarchar;
|
|
||||||
/**
|
|
||||||
* Jackson's JsonNode storage to Postgres JSON or Clob.
|
|
||||||
*/
|
|
||||||
private ScalarType<?> jsonNodeJson;
|
|
||||||
/**
|
|
||||||
* Jackson's JsonNode storage to Postgres JSONB or Clob.
|
|
||||||
*/
|
|
||||||
private ScalarType<?> jsonNodeJsonb;
|
|
||||||
|
|
||||||
private final PlatformArrayTypeFactory arrayTypeListFactory;
|
private final PlatformArrayTypeFactory arrayTypeListFactory;
|
||||||
private final PlatformArrayTypeFactory arrayTypeSetFactory;
|
private final PlatformArrayTypeFactory arrayTypeSetFactory;
|
||||||
@@ -120,7 +97,6 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
|
|
||||||
initialiseStandard(config);
|
initialiseStandard(config);
|
||||||
initialiseJavaTimeTypes(config);
|
initialiseJavaTimeTypes(config);
|
||||||
initialiseJacksonTypes();
|
|
||||||
loadTypesFromProviders(config, objectMapper);
|
loadTypesFromProviders(config, objectMapper);
|
||||||
loadGeoTypeBinder(config);
|
loadGeoTypeBinder(config);
|
||||||
|
|
||||||
@@ -160,16 +136,21 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* Load custom scalar types registered via ExtraTypeFactory and ServiceLoader.
|
* Load custom scalar types registered via ExtraTypeFactory and ServiceLoader.
|
||||||
*/
|
*/
|
||||||
private void loadTypesFromProviders(DatabaseConfig config, Object objectMapper) {
|
private void loadTypesFromProviders(DatabaseConfig config, Object objectMapper) {
|
||||||
ServiceLoader<ExtraTypeFactory> factories = ServiceLoader.load(ExtraTypeFactory.class);
|
for (ExtraTypeFactory plugin : ServiceLoader.load(ExtraTypeFactory.class)) {
|
||||||
Iterator<ExtraTypeFactory> iterator = factories.iterator();
|
for (ScalarType<?> type : plugin.createTypes(config, objectMapper)) {
|
||||||
if (iterator.hasNext()) {
|
|
||||||
// use the cacheFactory (via classpath service loader)
|
|
||||||
ExtraTypeFactory plugin = iterator.next();
|
|
||||||
List<? extends ScalarType<?>> types = plugin.createTypes(config, objectMapper);
|
|
||||||
for (ScalarType<?> type : types) {
|
|
||||||
add(type);
|
add(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (ScalarTypeSetFactory factory : ServiceLoader.load(ScalarTypeSetFactory.class)) {
|
||||||
|
ScalarTypeSet<?> typeSet = factory.createTypeSet(config, objectMapper);
|
||||||
|
if (typeSet != null) {
|
||||||
|
typeSets.put(typeSet.type(), typeSet);
|
||||||
|
ScalarType<?> defaultType = typeSet.defaultType();
|
||||||
|
if (defaultType != null) {
|
||||||
|
typeMap.put(typeSet.type(), defaultType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPostgresCompatible(DatabasePlatform databasePlatform) {
|
private boolean isPostgresCompatible(DatabasePlatform databasePlatform) {
|
||||||
@@ -350,19 +331,9 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (objectMapperPresent && prop.getMutationDetection() == MutationDetection.DEFAULT) {
|
if (objectMapperPresent && prop.getMutationDetection() == MutationDetection.DEFAULT) {
|
||||||
if (type.equals(JsonNode.class)) {
|
ScalarTypeSet<?> typeSet = typeSets.get(type);
|
||||||
switch (dbType) {
|
if (typeSet != null) {
|
||||||
case Types.VARCHAR:
|
return typeSet.forType(dbType);
|
||||||
return jsonNodeVarchar;
|
|
||||||
case Types.BLOB:
|
|
||||||
return jsonNodeBlob;
|
|
||||||
case Types.CLOB:
|
|
||||||
return jsonNodeClob;
|
|
||||||
case DbPlatformType.JSONB:
|
|
||||||
return jsonNodeJsonb;
|
|
||||||
default:
|
|
||||||
return jsonNodeJson;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createJsonObjectMapperType(prop, dbType, DocPropertyType.OBJECT);
|
return createJsonObjectMapperType(prop, dbType, DocPropertyType.OBJECT);
|
||||||
@@ -709,25 +680,6 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add support for Jackson's JsonNode mapping to Clob, Blob, Varchar, JSON and JSONB.
|
|
||||||
*/
|
|
||||||
private void initialiseJacksonTypes() {
|
|
||||||
if (objectMapper != null) {
|
|
||||||
ObjectMapper mapper = (ObjectMapper) objectMapper;
|
|
||||||
jsonNodeClob = new ScalarTypeJsonNode.Clob(mapper);
|
|
||||||
jsonNodeBlob = new ScalarTypeJsonNode.Blob(mapper);
|
|
||||||
jsonNodeVarchar = new ScalarTypeJsonNode.Varchar(mapper);
|
|
||||||
jsonNodeJson = jsonNodeClob; // Default for non-Postgres databases
|
|
||||||
jsonNodeJsonb = jsonNodeClob; // Default for non-Postgres databases
|
|
||||||
if (postgres) {
|
|
||||||
jsonNodeJson = new ScalarTypeJsonNodePostgres.JSON(mapper);
|
|
||||||
jsonNodeJsonb = new ScalarTypeJsonNodePostgres.JSONB(mapper);
|
|
||||||
}
|
|
||||||
// add as default mapping for JsonNode (when not annotated with @DbJson etc)
|
|
||||||
typeMap.put(JsonNode.class, jsonNodeJson);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialiseJavaTimeTypes(DatabaseConfig config) {
|
private void initialiseJavaTimeTypes(DatabaseConfig config) {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.type;
|
|||||||
|
|
||||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
||||||
import io.ebean.types.Cidr;
|
import io.ebean.types.Cidr;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.type;
|
|||||||
|
|
||||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
||||||
import io.ebean.types.Inet;
|
import io.ebean.types.Inet;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.type;
|
|||||||
|
|
||||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
import io.ebean.core.type.ScalarTypeBaseVarchar;
|
||||||
import io.ebean.text.TextException;
|
import io.ebean.text.TextException;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ package io.ebeaninternal.server.type;
|
|||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.*;
|
||||||
import io.ebean.core.type.DataReader;
|
|
||||||
import io.ebean.core.type.DocPropertyType;
|
|
||||||
import io.ebean.core.type.ScalarType;
|
|
||||||
import io.ebean.text.TextException;
|
import io.ebean.text.TextException;
|
||||||
import io.ebean.text.json.EJson;
|
import io.ebean.text.json.EJson;
|
||||||
import io.ebeaninternal.json.ModifyAwareList;
|
import io.ebeaninternal.json.ModifyAwareList;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.type;
|
|||||||
|
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ package io.ebeaninternal.server.type;
|
|||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.*;
|
||||||
import io.ebean.core.type.DataReader;
|
|
||||||
import io.ebean.core.type.DocPropertyType;
|
|
||||||
import io.ebean.core.type.ScalarType;
|
|
||||||
import io.ebean.text.TextException;
|
import io.ebean.text.TextException;
|
||||||
import io.ebean.text.json.EJson;
|
import io.ebean.text.json.EJson;
|
||||||
import io.ebeaninternal.json.ModifyAwareSet;
|
import io.ebeaninternal.json.ModifyAwareSet;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.type;
|
|||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebean.core.type.ScalarType;
|
import io.ebean.core.type.ScalarType;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import io.ebean.ModifyAwareType;
|
import io.ebean.ModifyAwareType;
|
||||||
import io.ebean.annotation.MutationDetection;
|
import io.ebean.annotation.MutationDetection;
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||||
|
|
||||||
final class TypeJsonManager {
|
final class TypeJsonManager {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ module io.ebean.core {
|
|||||||
uses io.ebean.config.dbplatform.DatabasePlatformProvider;
|
uses io.ebean.config.dbplatform.DatabasePlatformProvider;
|
||||||
uses io.ebean.datasource.DataSourceAlertFactory;
|
uses io.ebean.datasource.DataSourceAlertFactory;
|
||||||
uses io.ebean.core.type.ExtraTypeFactory;
|
uses io.ebean.core.type.ExtraTypeFactory;
|
||||||
|
uses io.ebean.core.type.ScalarTypeSetFactory;
|
||||||
uses io.ebeanservice.docstore.api.DocStoreFactory;
|
uses io.ebeanservice.docstore.api.DocStoreFactory;
|
||||||
uses io.ebean.migration.auto.AutoMigrationRunner;
|
uses io.ebean.migration.auto.AutoMigrationRunner;
|
||||||
uses io.avaje.classpath.scanner.ClassPathScannerFactory;
|
uses io.avaje.classpath.scanner.ClassPathScannerFactory;
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<artifactId>ebean-parent</artifactId>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ebean-json-node</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>19</maven.compiler.source>
|
||||||
|
<maven.compiler.target>19</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-core-type</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.avaje</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package io.ebean.jackson.jsonnode;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
|
import io.ebean.core.type.ScalarType;
|
||||||
|
import io.ebean.core.type.ScalarTypeSet;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
class JsonNodeSet implements ScalarTypeSet<JsonNode> {
|
||||||
|
|
||||||
|
final ScalarType<JsonNode> varchar;
|
||||||
|
final ScalarType<JsonNode> clob;
|
||||||
|
final ScalarType<JsonNode> blob;
|
||||||
|
final ScalarType<JsonNode> jsonb;
|
||||||
|
final ScalarType<JsonNode> json;
|
||||||
|
|
||||||
|
JsonNodeSet(ScalarType<JsonNode> varchar, ScalarType<JsonNode> clob, ScalarType<JsonNode> blob, ScalarType<JsonNode> jsonb, ScalarType<JsonNode> json) {
|
||||||
|
this.varchar = varchar;
|
||||||
|
this.clob = clob;
|
||||||
|
this.blob = blob;
|
||||||
|
this.jsonb = jsonb;
|
||||||
|
this.json = json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> type() {
|
||||||
|
return JsonNode.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScalarType<?> defaultType() {
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScalarType<JsonNode> forType(int dbType) {
|
||||||
|
switch (dbType) {
|
||||||
|
case Types.VARCHAR:
|
||||||
|
return varchar;
|
||||||
|
case Types.BLOB:
|
||||||
|
return blob;
|
||||||
|
case Types.CLOB:
|
||||||
|
return clob;
|
||||||
|
case DbPlatformType.JSONB:
|
||||||
|
return jsonb;
|
||||||
|
default:
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package io.ebean.jackson.jsonnode;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import io.ebean.config.DatabaseConfig;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
|
import io.ebean.core.type.ScalarType;
|
||||||
|
import io.ebean.core.type.ScalarTypeSet;
|
||||||
|
import io.ebean.core.type.ScalarTypeSetFactory;
|
||||||
|
|
||||||
|
public class JsonNodeTypeFactory implements ScalarTypeSetFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScalarTypeSet<?> createTypeSet(DatabaseConfig config, Object objectMapper) {
|
||||||
|
if (objectMapper == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMapper mapper = (ObjectMapper) objectMapper;
|
||||||
|
var varchar = new ScalarTypeJsonNode.Varchar(mapper);
|
||||||
|
var clob = new ScalarTypeJsonNode.Clob(mapper);
|
||||||
|
var blob = new ScalarTypeJsonNode.Blob(mapper);
|
||||||
|
ScalarType<JsonNode> json = clob; // Default for non-Postgres databases
|
||||||
|
ScalarType<JsonNode> jsonb = clob; // Default for non-Postgres databases
|
||||||
|
if (PostgresHelper.isPostgresCompatible(config.getDatabasePlatform())) {
|
||||||
|
json = new ScalarTypeJsonNodePostgres.JSON(mapper);
|
||||||
|
jsonb = new ScalarTypeJsonNodePostgres.JSONB(mapper);
|
||||||
|
}
|
||||||
|
return new JsonNodeSet(varchar, clob, blob, jsonb, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-7
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.jsonnode;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
@@ -11,11 +11,7 @@ import io.ebean.core.type.ScalarTypeBase;
|
|||||||
import io.ebean.text.TextException;
|
import io.ebean.text.TextException;
|
||||||
import io.ebean.util.IOUtils;
|
import io.ebean.util.IOUtils;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.*;
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
@@ -182,7 +178,8 @@ abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
dataOutput.writeBoolean(false);
|
dataOutput.writeBoolean(false);
|
||||||
} else {
|
} else {
|
||||||
ScalarHelp.writeUTF(dataOutput, format(value));
|
dataOutput.writeBoolean(true);
|
||||||
|
dataOutput.writeUTF(format(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-1
@@ -1,9 +1,10 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.jsonnode;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.ebean.config.dbplatform.DbPlatformType;
|
import io.ebean.config.dbplatform.DbPlatformType;
|
||||||
import io.ebean.core.type.DataBinder;
|
import io.ebean.core.type.DataBinder;
|
||||||
|
import io.ebean.core.type.PostgresHelper;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import io.ebean.jackson.jsonnode.JsonNodeTypeFactory;
|
||||||
|
|
||||||
|
module io.ebean.json.node {
|
||||||
|
|
||||||
|
requires io.ebean.core.type;
|
||||||
|
requires com.fasterxml.jackson.core;
|
||||||
|
requires com.fasterxml.jackson.databind;
|
||||||
|
|
||||||
|
provides io.ebean.core.type.ScalarTypeSetFactory with JsonNodeTypeFactory;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
io.ebean.jackson.jsonnode.JsonNodeTypeFactory
|
||||||
@@ -109,6 +109,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-json-node</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-platform-all</artifactId>
|
<artifactId>ebean-platform-all</artifactId>
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
<module>composites</module>
|
<module>composites</module>
|
||||||
<module>ebean-joda-time</module>
|
<module>ebean-joda-time</module>
|
||||||
<module>ebean-csv-reader</module>
|
<module>ebean-csv-reader</module>
|
||||||
|
<module>ebean-json-node</module>
|
||||||
<!-- <module>ebean-kotlin</module>-->
|
<!-- <module>ebean-kotlin</module>-->
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|||||||
Reference in new issue
Block a user