mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Refactor internal TypeManager change/improve its method names
This commit is contained in:
1 parent
aeb4b8ed25
commit
27beab2980
13 files changed
+98
-100
No files matched your search
@@ -184,12 +184,12 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> scalarType(String cast) {
|
public ScalarType<?> scalarType(String cast) {
|
||||||
return typeManager.getScalarType(cast);
|
return typeManager.type(cast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> scalarType(int jdbcType) {
|
public ScalarType<?> scalarType(int jdbcType) {
|
||||||
return typeManager.getScalarType(jdbcType);
|
return typeManager.type(jdbcType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -884,7 +884,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
|||||||
private void makeOrderColumn(DeployBeanPropertyAssocMany<?> oneToMany) {
|
private void makeOrderColumn(DeployBeanPropertyAssocMany<?> oneToMany) {
|
||||||
DeployBeanDescriptor<?> targetDesc = targetDescriptor(oneToMany);
|
DeployBeanDescriptor<?> targetDesc = targetDescriptor(oneToMany);
|
||||||
DeployOrderColumn orderColumn = oneToMany.getOrderColumn();
|
DeployOrderColumn orderColumn = oneToMany.getOrderColumn();
|
||||||
final ScalarType<?> scalarType = typeManager.getScalarType(Integer.class);
|
final ScalarType<?> scalarType = typeManager.type(Integer.class);
|
||||||
DeployBeanProperty orderProperty = new DeployBeanProperty(targetDesc, Integer.class, scalarType, null);
|
DeployBeanProperty orderProperty = new DeployBeanProperty(targetDesc, Integer.class, scalarType, null);
|
||||||
orderProperty.setName(DeployOrderColumn.LOGICAL_NAME);
|
orderProperty.setName(DeployOrderColumn.LOGICAL_NAME);
|
||||||
orderProperty.setDbColumn(orderColumn.getName());
|
orderProperty.setDbColumn(orderColumn.getName());
|
||||||
|
|||||||
+3
-3
@@ -222,7 +222,7 @@ final class AnnotationAssocManys extends AnnotationAssoc {
|
|||||||
dbKeyColumn = mapKeyColumn.name();
|
dbKeyColumn = mapKeyColumn.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScalarType<?> keyScalarType = util.getTypeManager().getScalarType(prop.getMapKeyType());
|
ScalarType<?> keyScalarType = util.getTypeManager().type(prop.getMapKeyType());
|
||||||
|
|
||||||
DeployBeanProperty keyProp = new DeployBeanProperty(elementDescriptor, elementType, keyScalarType, null);
|
DeployBeanProperty keyProp = new DeployBeanProperty(elementDescriptor, elementType, keyScalarType, null);
|
||||||
setElementProperty(keyProp, "key", dbKeyColumn, sortOrder++);
|
setElementProperty(keyProp, "key", dbKeyColumn, sortOrder++);
|
||||||
@@ -234,10 +234,10 @@ final class AnnotationAssocManys extends AnnotationAssoc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScalarType<?> valueScalarType = util.getTypeManager().getScalarType(elementType);
|
ScalarType<?> valueScalarType = util.getTypeManager().type(elementType);
|
||||||
if (valueScalarType == null && elementType.isEnum()) {
|
if (valueScalarType == null && elementType.isEnum()) {
|
||||||
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>)elementType;
|
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>)elementType;
|
||||||
valueScalarType = util.getTypeManager().createEnumScalarType(enumClass, EnumType.STRING);
|
valueScalarType = util.getTypeManager().enumType(enumClass, EnumType.STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean scalar = true;
|
boolean scalar = true;
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ final class AnnotationFields extends AnnotationParser {
|
|||||||
|
|
||||||
private ScalarTypeBytesBase getDbEncryptType(DeployBeanProperty prop) {
|
private ScalarTypeBytesBase getDbEncryptType(DeployBeanProperty prop) {
|
||||||
int dbType = prop.isLob() ? Types.BLOB : Types.VARBINARY;
|
int dbType = prop.isLob() ? Types.BLOB : Types.VARBINARY;
|
||||||
return (ScalarTypeBytesBase) util.getTypeManager().getScalarType(dbType);
|
return (ScalarTypeBytesBase) util.getTypeManager().type(dbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataEncryptSupport createDataEncryptSupport(DeployBeanProperty prop) {
|
private DataEncryptSupport createDataEncryptSupport(DeployBeanProperty prop) {
|
||||||
|
|||||||
+2
-2
@@ -108,7 +108,7 @@ public final class DeployCreateProperties {
|
|||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
private DeployBeanProperty createManyType(DeployBeanDescriptor<?> desc, Class<?> targetType, ManyType manyType) {
|
private DeployBeanProperty createManyType(DeployBeanDescriptor<?> desc, Class<?> targetType, ManyType manyType) {
|
||||||
try {
|
try {
|
||||||
ScalarType<?> scalarType = typeManager.getScalarType(targetType);
|
ScalarType<?> scalarType = typeManager.type(targetType);
|
||||||
if (scalarType != null) {
|
if (scalarType != null) {
|
||||||
return new DeployBeanPropertySimpleCollection(desc, targetType, manyType);
|
return new DeployBeanPropertySimpleCollection(desc, targetType, manyType);
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public final class DeployCreateProperties {
|
|||||||
if (propertyType.isEnum() || propertyType.isPrimitive()) {
|
if (propertyType.isEnum() || propertyType.isPrimitive()) {
|
||||||
return new DeployBeanProperty(desc, propertyType, null, null);
|
return new DeployBeanProperty(desc, propertyType, null, null);
|
||||||
}
|
}
|
||||||
ScalarType<?> scalarType = typeManager.getScalarType(propertyType);
|
ScalarType<?> scalarType = typeManager.type(propertyType);
|
||||||
if (scalarType != null) {
|
if (scalarType != null) {
|
||||||
return new DeployBeanProperty(desc, propertyType, scalarType, null);
|
return new DeployBeanProperty(desc, propertyType, scalarType, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public final class DeployUtil {
|
|||||||
try {
|
try {
|
||||||
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) enumType;
|
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) enumType;
|
||||||
EnumType type = enumerated != null ? enumerated.value() : null;
|
EnumType type = enumerated != null ? enumerated.value() : null;
|
||||||
ScalarType<?> scalarType = typeManager.createEnumScalarType(enumClass, type);
|
ScalarType<?> scalarType = typeManager.enumType(enumClass, type);
|
||||||
prop.setScalarType(scalarType);
|
prop.setScalarType(scalarType);
|
||||||
prop.setDbType(scalarType.jdbcType());
|
prop.setDbType(scalarType.jdbcType());
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@@ -137,7 +137,7 @@ public final class DeployUtil {
|
|||||||
// set via annotations
|
// set via annotations
|
||||||
Class<?> propType = property.getPropertyType();
|
Class<?> propType = property.getPropertyType();
|
||||||
try {
|
try {
|
||||||
ScalarType<?> scalarType = typeManager.getScalarType(propType, property.getDbType());
|
ScalarType<?> scalarType = typeManager.type(propType, property.getDbType());
|
||||||
if (scalarType != null || property.isTransient()) {
|
if (scalarType != null || property.isTransient()) {
|
||||||
return scalarType;
|
return scalarType;
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ public final class DeployUtil {
|
|||||||
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
||||||
*/
|
*/
|
||||||
void setDbMap(DeployBeanProperty prop, DbMap dbMap) {
|
void setDbMap(DeployBeanProperty prop, DbMap dbMap) {
|
||||||
ScalarType<?> scalarType = typeManager.getDbMapScalarType();
|
ScalarType<?> scalarType = typeManager.dbMapType();
|
||||||
int dbType = scalarType.jdbcType();
|
int dbType = scalarType.jdbcType();
|
||||||
prop.setDbType(dbType);
|
prop.setDbType(dbType);
|
||||||
prop.setScalarType(scalarType);
|
prop.setScalarType(scalarType);
|
||||||
@@ -172,7 +172,7 @@ public final class DeployUtil {
|
|||||||
*/
|
*/
|
||||||
void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||||
Class<?> type = prop.getPropertyType();
|
Class<?> type = prop.getPropertyType();
|
||||||
ScalarType<?> scalarType = typeManager.getArrayScalarType(type, prop.getGenericType(), prop.isNullable());
|
ScalarType<?> scalarType = typeManager.dbArrayType(type, prop.getGenericType(), prop.isNullable());
|
||||||
if (scalarType == null) {
|
if (scalarType == null) {
|
||||||
throw new RuntimeException("No ScalarType for @DbArray type for " + prop.getFullBeanName());
|
throw new RuntimeException("No ScalarType for @DbArray type for " + prop.getFullBeanName());
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ public final class DeployUtil {
|
|||||||
private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength, MutationDetection mutationDetection) {
|
private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength, MutationDetection mutationDetection) {
|
||||||
prop.setDbType(dbType);
|
prop.setDbType(dbType);
|
||||||
prop.setMutationDetection(mutationDetection);
|
prop.setMutationDetection(mutationDetection);
|
||||||
ScalarType<?> scalarType = typeManager.getJsonScalarType(prop, dbType, dbLength);
|
ScalarType<?> scalarType = typeManager.dbJsonType(prop, dbType, dbLength);
|
||||||
if (scalarType == null) {
|
if (scalarType == null) {
|
||||||
throw new RuntimeException("No ScalarType for JSON property " + prop + " dbType:" + dbType);
|
throw new RuntimeException("No ScalarType for JSON property " + prop + " dbType:" + dbType);
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ public final class DeployUtil {
|
|||||||
// this also sets the lob flag on DeployBeanProperty
|
// this also sets the lob flag on DeployBeanProperty
|
||||||
int lobType = isClobType(type) ? dbCLOBType : dbBLOBType;
|
int lobType = isClobType(type) ? dbCLOBType : dbBLOBType;
|
||||||
|
|
||||||
scalarType = typeManager.getScalarType(type, lobType);
|
scalarType = typeManager.type(type, lobType);
|
||||||
if (scalarType == null) {
|
if (scalarType == null) {
|
||||||
// this should never occur actually
|
// this should never occur actually
|
||||||
throw new RuntimeException("No ScalarType for LOB type " + type + " dbType:" + lobType);
|
throw new RuntimeException("No ScalarType for LOB type " + type + " dbType:" + lobType);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ final class DtoMetaConstructor {
|
|||||||
this.types = constructor.getParameterTypes();
|
this.types = constructor.getParameterTypes();
|
||||||
this.scalarTypes = new ScalarType[types.length];
|
this.scalarTypes = new ScalarType[types.length];
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
scalarTypes[i] = typeManager.getScalarType(types[i]);
|
scalarTypes[i] = typeManager.type(types[i]);
|
||||||
}
|
}
|
||||||
this.handle = LOOKUP.findConstructor(someClass, typeFor(types));
|
this.handle = LOOKUP.findConstructor(someClass, typeFor(types));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ final class DtoMetaProperty implements DtoReadSet {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
if (writeMethod != null) {
|
if (writeMethod != null) {
|
||||||
this.setter = lookupMethodHandle(dtoType, writeMethod);
|
this.setter = lookupMethodHandle(dtoType, writeMethod);
|
||||||
this.scalarType = typeManager.getScalarType(propertyType(writeMethod), propertyClass(writeMethod));
|
this.scalarType = typeManager.type(propertyType(writeMethod), propertyClass(writeMethod));
|
||||||
} else {
|
} else {
|
||||||
this.scalarType = null;
|
this.scalarType = null;
|
||||||
this.setter = null;
|
this.setter = null;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public final class DJsonScalar {
|
|||||||
gen.writeRaw(']');
|
gen.writeRaw(']');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ScalarType scalarType = typeManager.getScalarType(value.getClass());
|
ScalarType scalarType = typeManager.type(value.getClass());
|
||||||
if (scalarType == null) {
|
if (scalarType == null) {
|
||||||
throw new IllegalArgumentException("unhandled type " + value.getClass());
|
throw new IllegalArgumentException("unhandled type " + value.getClass());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public final class Binder {
|
|||||||
public Binder(TypeManager typeManager, SpiLogManager logManager, int asOfBindCount, boolean asOfStandardsBased,
|
public Binder(TypeManager typeManager, SpiLogManager logManager, int asOfBindCount, boolean asOfStandardsBased,
|
||||||
DbExpressionHandler dbExpressionHandler, DataTimeZone dataTimeZone, MultiValueBind multiValueBind) {
|
DbExpressionHandler dbExpressionHandler, DataTimeZone dataTimeZone, MultiValueBind multiValueBind) {
|
||||||
this.typeManager = typeManager;
|
this.typeManager = typeManager;
|
||||||
this.geoTypeBinder = typeManager.getGeoTypeBinder();
|
this.geoTypeBinder = typeManager.geoTypeBinder();
|
||||||
this.asOfBindCount = asOfBindCount;
|
this.asOfBindCount = asOfBindCount;
|
||||||
this.asOfStandardsBased = asOfStandardsBased;
|
this.asOfStandardsBased = asOfStandardsBased;
|
||||||
this.dbExpressionHandler = dbExpressionHandler;
|
this.dbExpressionHandler = dbExpressionHandler;
|
||||||
@@ -154,7 +154,7 @@ public final class Binder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ScalarType<?> getScalarType(Class<?> clazz) {
|
public ScalarType<?> getScalarType(Class<?> clazz) {
|
||||||
ScalarType<?> type = typeManager.getScalarType(clazz);
|
ScalarType<?> type = typeManager.type(clazz);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new PersistenceException("No ScalarType registered for " + clazz);
|
throw new PersistenceException("No ScalarType registered for " + clazz);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getScalarType(String cast) {
|
public ScalarType<?> type(String cast) {
|
||||||
return logicalMap.get(cast);
|
return logicalMap.get(cast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,27 +179,27 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* Return the ScalarType for the given jdbc type as per java.sql.Types.
|
* Return the ScalarType for the given jdbc type as per java.sql.Types.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getScalarType(int jdbcType) {
|
public ScalarType<?> type(int jdbcType) {
|
||||||
return nativeMap.get(jdbcType);
|
return nativeMap.get(jdbcType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getScalarType(Type propertyType, Class<?> propertyClass) {
|
public ScalarType<?> type(Type propertyType, Class<?> propertyClass) {
|
||||||
if (propertyType instanceof ParameterizedType) {
|
if (propertyType instanceof ParameterizedType) {
|
||||||
ParameterizedType pt = (ParameterizedType) propertyType;
|
ParameterizedType pt = (ParameterizedType) propertyType;
|
||||||
Type rawType = pt.getRawType();
|
Type rawType = pt.getRawType();
|
||||||
if (List.class == rawType || Set.class == rawType) {
|
if (List.class == rawType || Set.class == rawType) {
|
||||||
return getArrayScalarType((Class<?>) rawType, propertyType, true);
|
return dbArrayType((Class<?>) rawType, propertyType, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getScalarType(propertyClass);
|
return type(propertyClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This can return null if no matching ScalarType is found.
|
* This can return null if no matching ScalarType is found.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getScalarType(Class<?> type) {
|
public ScalarType<?> type(Class<?> type) {
|
||||||
ScalarType<?> found = typeMap.get(type);
|
ScalarType<?> found = typeMap.get(type);
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
if (type.getName().equals("org.joda.time.LocalTime")) {
|
if (type.getName().equals("org.joda.time.LocalTime")) {
|
||||||
@@ -247,37 +247,37 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoTypeBinder getGeoTypeBinder() {
|
public GeoTypeBinder geoTypeBinder() {
|
||||||
return geoTypeBinder;
|
return geoTypeBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getDbMapScalarType() {
|
public ScalarType<?> dbMapType() {
|
||||||
return hstoreSupport() ? hstoreType : ScalarTypeJsonMap.typeFor(false, Types.VARCHAR, false);
|
return hstoreSupport() ? hstoreType : ScalarTypeJsonMap.typeFor(false, Types.VARCHAR, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getArrayScalarType(Class<?> type, Type genericType, boolean nullable) {
|
public ScalarType<?> dbArrayType(Class<?> type, Type genericType, boolean nullable) {
|
||||||
Type valueType = getValueType(genericType);
|
Type valueType = valueType(genericType);
|
||||||
if (type.equals(List.class)) {
|
if (type.equals(List.class)) {
|
||||||
return getArrayScalarTypeList(valueType, nullable);
|
return dbArrayTypeList(valueType, nullable);
|
||||||
} else if (type.equals(Set.class)) {
|
} else if (type.equals(Set.class)) {
|
||||||
return getArrayScalarTypeSet(valueType, nullable);
|
return dbArrayTypeSet(valueType, nullable);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("@DbArray does not support type " + type);
|
throw new IllegalStateException("@DbArray does not support type " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScalarType<?> getArrayScalarTypeSet(Type valueType, boolean nullable) {
|
private ScalarType<?> dbArrayTypeSet(Type valueType, boolean nullable) {
|
||||||
if (isEnumType(valueType)) {
|
if (isEnumType(valueType)) {
|
||||||
return arrayTypeSetFactory.typeForEnum(createEnumScalarType(asEnumClass(valueType), null), nullable);
|
return arrayTypeSetFactory.typeForEnum(enumType(asEnumClass(valueType), null), nullable);
|
||||||
}
|
}
|
||||||
return arrayTypeSetFactory.typeFor(valueType, nullable);
|
return arrayTypeSetFactory.typeFor(valueType, nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScalarType<?> getArrayScalarTypeList(Type valueType, boolean nullable) {
|
private ScalarType<?> dbArrayTypeList(Type valueType, boolean nullable) {
|
||||||
if (isEnumType(valueType)) {
|
if (isEnumType(valueType)) {
|
||||||
return arrayTypeListFactory.typeForEnum(createEnumScalarType(asEnumClass(valueType), null), nullable);
|
return arrayTypeListFactory.typeForEnum(enumType(asEnumClass(valueType), null), nullable);
|
||||||
}
|
}
|
||||||
return arrayTypeListFactory.typeFor(valueType, nullable);
|
return arrayTypeListFactory.typeFor(valueType, nullable);
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getJsonScalarType(DeployBeanProperty prop, int dbType, int dbLength) {
|
public ScalarType<?> dbJsonType(DeployBeanProperty prop, int dbType, int dbLength) {
|
||||||
Class<?> type = prop.getPropertyType();
|
Class<?> type = prop.getPropertyType();
|
||||||
Type genericType = prop.getGenericType();
|
Type genericType = prop.getGenericType();
|
||||||
boolean hasJacksonAnnotations = objectMapperPresent && checkJacksonAnnotations(prop);
|
boolean hasJacksonAnnotations = objectMapperPresent && checkJacksonAnnotations(prop);
|
||||||
@@ -300,7 +300,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
||||||
}
|
}
|
||||||
if (type.equals(List.class)) {
|
if (type.equals(List.class)) {
|
||||||
DocPropertyType docType = getDocType(genericType);
|
DocPropertyType docType = docType(genericType);
|
||||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
||||||
return ScalarTypeJsonList.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
return ScalarTypeJsonList.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
||||||
} else {
|
} else {
|
||||||
@@ -308,7 +308,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type.equals(Set.class)) {
|
if (type.equals(Set.class)) {
|
||||||
DocPropertyType docType = getDocType(genericType);
|
DocPropertyType docType = docType(genericType);
|
||||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
||||||
return ScalarTypeJsonSet.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
return ScalarTypeJsonSet.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
||||||
} else {
|
} else {
|
||||||
@@ -339,9 +339,9 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
return prop.getMetaAnnotation(com.fasterxml.jackson.annotation.JacksonAnnotation.class) != null;
|
return prop.getMetaAnnotation(com.fasterxml.jackson.annotation.JacksonAnnotation.class) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DocPropertyType getDocType(Type genericType) {
|
private DocPropertyType docType(Type genericType) {
|
||||||
if (genericType instanceof Class<?>) {
|
if (genericType instanceof Class<?>) {
|
||||||
ScalarType<?> found = getScalarType((Class<?>) genericType);
|
ScalarType<?> found = type((Class<?>) genericType);
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
return found.docType();
|
return found.docType();
|
||||||
}
|
}
|
||||||
@@ -357,7 +357,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
return String.class.equals(typeArg) || Long.class.equals(typeArg);
|
return String.class.equals(typeArg) || Long.class.equals(typeArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type getValueType(Type collectionType) {
|
private Type valueType(Type collectionType) {
|
||||||
return TypeReflectHelper.getValueType(collectionType);
|
return TypeReflectHelper.getValueType(collectionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* different jdbcTypes in a single system.
|
* different jdbcTypes in a single system.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> getScalarType(Class<?> type, int jdbcType) {
|
public ScalarType<?> type(Class<?> type, int jdbcType) {
|
||||||
// File is a special Lob so check for that first
|
// File is a special Lob so check for that first
|
||||||
if (File.class.equals(type)) {
|
if (File.class.equals(type)) {
|
||||||
return fileType;
|
return fileType;
|
||||||
@@ -393,13 +393,13 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
// check for Clob, LongVarchar etc ...
|
// check for Clob, LongVarchar etc ...
|
||||||
// the reason being that String maps to multiple jdbc types
|
// the reason being that String maps to multiple jdbc types
|
||||||
// varchar, clob, longVarchar.
|
// varchar, clob, longVarchar.
|
||||||
ScalarType<?> scalarType = getLobTypes(jdbcType);
|
ScalarType<?> scalarType = lobTypes(jdbcType);
|
||||||
if (scalarType != null) {
|
if (scalarType != null) {
|
||||||
// it is a specific Lob type...
|
// it is a specific Lob type...
|
||||||
return scalarType;
|
return scalarType;
|
||||||
}
|
}
|
||||||
|
|
||||||
scalarType = getScalarType(type);
|
scalarType = type(type);
|
||||||
if (scalarType != null) {
|
if (scalarType != null) {
|
||||||
if (jdbcType == 0 || scalarType.jdbcType() == jdbcType) {
|
if (jdbcType == 0 || scalarType.jdbcType() == jdbcType) {
|
||||||
// matching type
|
// matching type
|
||||||
@@ -425,8 +425,8 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* types - like String - Varchar, LongVarchar, Clob. For this reason I check
|
* types - like String - Varchar, LongVarchar, Clob. For this reason I check
|
||||||
* for the specific Lob types first before looking for a matching type.
|
* for the specific Lob types first before looking for a matching type.
|
||||||
*/
|
*/
|
||||||
private ScalarType<?> getLobTypes(int jdbcType) {
|
private ScalarType<?> lobTypes(int jdbcType) {
|
||||||
return getScalarType(jdbcType);
|
return type(jdbcType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -470,7 +470,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* <p>
|
* <p>
|
||||||
* Return null if the EnumValue annotations are not present/used.
|
* Return null if the EnumValue annotations are not present/used.
|
||||||
*/
|
*/
|
||||||
private ScalarTypeEnum<?> createEnumScalarType2(Class<?> enumType) {
|
private ScalarTypeEnum<?> enumTypeEnumValue(Class<?> enumType) {
|
||||||
boolean integerType = true;
|
boolean integerType = true;
|
||||||
Map<String, String> nameValueMap = new LinkedHashMap<>();
|
Map<String, String> nameValueMap = new LinkedHashMap<>();
|
||||||
for (Field field : enumType.getDeclaredFields()) {
|
for (Field field : enumType.getDeclaredFields()) {
|
||||||
@@ -499,8 +499,8 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* much shorter codes used in the DB.
|
* much shorter codes used in the DB.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ScalarType<?> createEnumScalarType(Class<? extends Enum<?>> enumType, EnumType type) {
|
public ScalarType<?> enumType(Class<? extends Enum<?>> enumType, EnumType type) {
|
||||||
ScalarType<?> scalarType = getScalarType(enumType);
|
ScalarType<?> scalarType = type(enumType);
|
||||||
if (scalarType instanceof ScalarTypeWrapper) {
|
if (scalarType instanceof ScalarTypeWrapper) {
|
||||||
// no override or further mapping required
|
// no override or further mapping required
|
||||||
return scalarType;
|
return scalarType;
|
||||||
@@ -512,16 +512,16 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
return scalarEnum;
|
return scalarEnum;
|
||||||
}
|
}
|
||||||
scalarEnum = createEnumScalarTypePerExtentions(enumType);
|
scalarEnum = enumTypePerExtensions(enumType);
|
||||||
if (scalarEnum == null) {
|
if (scalarEnum == null) {
|
||||||
// use JPA normal Enum type (without mapping)
|
// use JPA normal Enum type (without mapping)
|
||||||
scalarEnum = createEnumScalarTypePerSpec(enumType, type);
|
scalarEnum = enumTypePerSpec(enumType, type);
|
||||||
}
|
}
|
||||||
add(scalarEnum);
|
add(scalarEnum);
|
||||||
return scalarEnum;
|
return scalarEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScalarTypeEnum<?> createEnumScalarTypePerSpec(Class<?> enumType, EnumType type) {
|
private ScalarTypeEnum<?> enumTypePerSpec(Class<?> enumType, EnumType type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
if (defaultEnumType == EnumType.ORDINAL) {
|
if (defaultEnumType == EnumType.ORDINAL) {
|
||||||
return new ScalarTypeEnumStandard.OrdinalEnum(enumType);
|
return new ScalarTypeEnumStandard.OrdinalEnum(enumType);
|
||||||
@@ -535,16 +535,16 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScalarTypeEnum<?> createEnumScalarTypePerExtentions(Class<? extends Enum<?>> enumType) {
|
private ScalarTypeEnum<?> enumTypePerExtensions(Class<? extends Enum<?>> enumType) {
|
||||||
for (Method method : enumType.getMethods()) {
|
for (Method method : enumType.getMethods()) {
|
||||||
DbEnumValue dbValue = AnnotationUtil.get(method, DbEnumValue.class);
|
DbEnumValue dbValue = AnnotationUtil.get(method, DbEnumValue.class);
|
||||||
if (dbValue != null) {
|
if (dbValue != null) {
|
||||||
boolean integerValues = DbEnumType.INTEGER == dbValue.storage();
|
boolean integerValues = DbEnumType.INTEGER == dbValue.storage();
|
||||||
return createEnumScalarTypeDbValue(enumType, method, integerValues, dbValue.length(), dbValue.withConstraint());
|
return enumTypeDbValue(enumType, method, integerValues, dbValue.length(), dbValue.withConstraint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// look for EnumValue annotations instead
|
// look for EnumValue annotations instead
|
||||||
return createEnumScalarType2(enumType);
|
return enumTypeEnumValue(enumType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -552,7 +552,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
* <p>
|
* <p>
|
||||||
* Return null if the EnumValue annotations are not present/used.
|
* Return null if the EnumValue annotations are not present/used.
|
||||||
*/
|
*/
|
||||||
private ScalarTypeEnum<?> createEnumScalarTypeDbValue(Class<? extends Enum<?>> enumType, Method method, boolean integerType, int length, boolean withConstraint) {
|
private ScalarTypeEnum<?> enumTypeDbValue(Class<? extends Enum<?>> enumType, Method method, boolean integerType, int length, boolean withConstraint) {
|
||||||
Map<String, String> nameValueMap = new LinkedHashMap<>();
|
Map<String, String> nameValueMap = new LinkedHashMap<>();
|
||||||
for (Enum<?> enumConstant : enumType.getEnumConstants()) {
|
for (Enum<?> enumConstant : enumType.getEnumConstants()) {
|
||||||
try {
|
try {
|
||||||
@@ -634,7 +634,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
Class<?> logicalType = paramTypes[0];
|
Class<?> logicalType = paramTypes[0];
|
||||||
Class<?> persistType = paramTypes[1];
|
Class<?> persistType = paramTypes[1];
|
||||||
ScalarType<?> wrappedType = getScalarType(persistType);
|
ScalarType<?> wrappedType = type(persistType);
|
||||||
if (wrappedType == null) {
|
if (wrappedType == null) {
|
||||||
throw new IllegalStateException("Could not find ScalarType for: " + paramTypes[1]);
|
throw new IllegalStateException("Could not find ScalarType for: " + paramTypes[1]);
|
||||||
}
|
}
|
||||||
@@ -658,7 +658,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
Class<?> logicalType = paramTypes[0];
|
Class<?> logicalType = paramTypes[0];
|
||||||
Class<?> persistType = paramTypes[1];
|
Class<?> persistType = paramTypes[1];
|
||||||
ScalarType<?> wrappedType = getScalarType(persistType);
|
ScalarType<?> wrappedType = type(persistType);
|
||||||
if (wrappedType == null) {
|
if (wrappedType == null) {
|
||||||
throw new IllegalStateException("Could not find ScalarType for: " + paramTypes[1]);
|
throw new IllegalStateException("Could not find ScalarType for: " + paramTypes[1]);
|
||||||
}
|
}
|
||||||
@@ -674,8 +674,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
|
|
||||||
|
|
||||||
private void initialiseJavaTimeTypes(DatabaseConfig config) {
|
private void initialiseJavaTimeTypes(DatabaseConfig config) {
|
||||||
|
ZoneId zoneId = zoneId(config);
|
||||||
ZoneId zoneId = getZoneId(config);
|
|
||||||
|
|
||||||
typeMap.put(java.nio.file.Path.class, new ScalarTypePath());
|
typeMap.put(java.nio.file.Path.class, new ScalarTypePath());
|
||||||
addType(java.time.Period.class, new ScalarTypePeriod());
|
addType(java.time.Period.class, new ScalarTypePeriod());
|
||||||
@@ -702,7 +701,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
addType(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration());
|
addType(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZoneId getZoneId(DatabaseConfig config) {
|
private ZoneId zoneId(DatabaseConfig config) {
|
||||||
final String dataTimeZone = config.getDataTimeZone();
|
final String dataTimeZone = config.getDataTimeZone();
|
||||||
return (dataTimeZone == null) ? ZoneOffset.systemDefault() : TimeZone.getTimeZone(dataTimeZone).toZoneId();
|
return (dataTimeZone == null) ? ZoneOffset.systemDefault() : TimeZone.getTimeZone(dataTimeZone).toZoneId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,39 +14,38 @@ public interface TypeManager {
|
|||||||
/**
|
/**
|
||||||
* Return the scalar type for the given logical type.
|
* Return the scalar type for the given logical type.
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getScalarType(String cast);
|
ScalarType<?> type(String cast);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ScalarType for a given jdbc type.
|
* Return the ScalarType for a given jdbc type.
|
||||||
*
|
*
|
||||||
* @param jdbcType as per java.sql.Types
|
* @param jdbcType as per java.sql.Types
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getScalarType(int jdbcType);
|
ScalarType<?> type(int jdbcType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ScalarType for a given logical type.
|
* Return the ScalarType for a given logical type.
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getScalarType(Class<?> type);
|
ScalarType<?> type(Class<?> type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For java.util.Date and java.util.Calendar additionally pass the jdbc type
|
* For java.util.Date and java.util.Calendar additionally pass the jdbc type
|
||||||
* that you would like the ScalarType to map to. This is because these types
|
* that you would like the ScalarType to map to. This is because these types
|
||||||
* can map to different java.sql.Types depending on the property.
|
* can map to different java.sql.Types depending on the property.
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getScalarType(Class<?> type, int jdbcType);
|
ScalarType<?> type(Class<?> type, int jdbcType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find and return the ScalarType taking into account the property type with generics.
|
* Find and return the ScalarType taking into account the property type with generics.
|
||||||
* <p>
|
* <p>
|
||||||
* For example Array based ScalarType for types like {@code List<String>}.
|
* For example Array based ScalarType for types like {@code List<String>}.
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getScalarType(Type propertyType, Class<?> type);
|
ScalarType<?> type(Type propertyType, Class<?> type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a ScalarType for an Enum using a mapping (rather than JPA Ordinal
|
* Create a ScalarType for an Enum using a mapping (rather than JPA Ordinal or String which has limitations).
|
||||||
* or String which has limitations).
|
|
||||||
*/
|
*/
|
||||||
ScalarType<?> createEnumScalarType(Class<? extends Enum<?>> enumType, EnumType enumerated);
|
ScalarType<?> enumType(Class<? extends Enum<?>> enumType, EnumType enumerated);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ScalarType used to handle JSON content.
|
* Return the ScalarType used to handle JSON content.
|
||||||
@@ -54,20 +53,20 @@ public interface TypeManager {
|
|||||||
* Note that type expected to be JsonNode or Map.
|
* Note that type expected to be JsonNode or Map.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getJsonScalarType(DeployBeanProperty prop, int dbType, int dbLength);
|
ScalarType<?> dbJsonType(DeployBeanProperty prop, int dbType, int dbLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ScalarType used to handle DB ARRAY.
|
* Return the ScalarType used to handle DB ARRAY.
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getArrayScalarType(Class<?> type, Type genericType, boolean nullable);
|
ScalarType<?> dbArrayType(Class<?> type, Type genericType, boolean nullable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ScalarType used to handle HSTORE (Map<String,String>).
|
* Return the ScalarType used to handle HSTORE (Map<String,String>).
|
||||||
*/
|
*/
|
||||||
ScalarType<?> getDbMapScalarType();
|
ScalarType<?> dbMapType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Geometry type binder if provided.
|
* Return the Geometry type binder if provided.
|
||||||
*/
|
*/
|
||||||
GeoTypeBinder getGeoTypeBinder();
|
GeoTypeBinder geoTypeBinder();
|
||||||
}
|
}
|
||||||
@@ -46,14 +46,14 @@ public class DefaultTypeManagerTest {
|
|||||||
public void enumDayMonth_builtIn_overrideAsString() {
|
public void enumDayMonth_builtIn_overrideAsString() {
|
||||||
DefaultTypeManager typeManager = create();
|
DefaultTypeManager typeManager = create();
|
||||||
|
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(Month.class, null);
|
ScalarType<?> type = typeManager.enumType(Month.class, null);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class).as("built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class).as("built in type");
|
||||||
|
|
||||||
// mapped explicitly as JPA EnumType.STRING
|
// mapped explicitly as JPA EnumType.STRING
|
||||||
type = typeManager.createEnumScalarType(Month.class, EnumType.STRING);
|
type = typeManager.enumType(Month.class, EnumType.STRING);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class).as("override built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class).as("override built in type");
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(Month.class, EnumType.ORDINAL);
|
typeManager.enumType(Month.class, EnumType.ORDINAL);
|
||||||
assertThat(true).isFalse().as("never get here");
|
assertThat(true).isFalse().as("never get here");
|
||||||
|
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@@ -66,10 +66,10 @@ public class DefaultTypeManagerTest {
|
|||||||
DefaultTypeManager typeManager = create();
|
DefaultTypeManager typeManager = create();
|
||||||
|
|
||||||
// mapped explicitly as JPA EnumType.STRING
|
// mapped explicitly as JPA EnumType.STRING
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(Month.class, EnumType.ORDINAL);
|
ScalarType<?> type = typeManager.enumType(Month.class, EnumType.ORDINAL);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class).as("override built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class).as("override built in type");
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(Month.class, EnumType.STRING);
|
typeManager.enumType(Month.class, EnumType.STRING);
|
||||||
assertThat(true).isFalse().as("never get here");
|
assertThat(true).isFalse().as("never get here");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
||||||
@@ -80,14 +80,14 @@ public class DefaultTypeManagerTest {
|
|||||||
public void enumDayOfWeek_builtIn_overrideAsString() {
|
public void enumDayOfWeek_builtIn_overrideAsString() {
|
||||||
DefaultTypeManager typeManager = create();
|
DefaultTypeManager typeManager = create();
|
||||||
|
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(DayOfWeek.class, null);
|
ScalarType<?> type = typeManager.enumType(DayOfWeek.class, null);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class).as("built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class).as("built in type");
|
||||||
|
|
||||||
// mapped explicitly as JPA EnumType.STRING
|
// mapped explicitly as JPA EnumType.STRING
|
||||||
type = typeManager.createEnumScalarType(DayOfWeek.class, EnumType.STRING);
|
type = typeManager.enumType(DayOfWeek.class, EnumType.STRING);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class).as("override built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class).as("override built in type");
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(DayOfWeek.class, EnumType.ORDINAL);
|
typeManager.enumType(DayOfWeek.class, EnumType.ORDINAL);
|
||||||
assertThat(true).isFalse().as("never get here");
|
assertThat(true).isFalse().as("never get here");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
||||||
@@ -99,10 +99,10 @@ public class DefaultTypeManagerTest {
|
|||||||
DefaultTypeManager typeManager = create();
|
DefaultTypeManager typeManager = create();
|
||||||
|
|
||||||
// mapped explicitly as JPA EnumType.STRING
|
// mapped explicitly as JPA EnumType.STRING
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(DayOfWeek.class, EnumType.ORDINAL);
|
ScalarType<?> type = typeManager.enumType(DayOfWeek.class, EnumType.ORDINAL);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class).as("override built in type");
|
assertThat(type).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class).as("override built in type");
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(DayOfWeek.class, EnumType.STRING);
|
typeManager.enumType(DayOfWeek.class, EnumType.STRING);
|
||||||
assertThat(true).isFalse().as("never get here");
|
assertThat(true).isFalse().as("never get here");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
||||||
@@ -113,19 +113,19 @@ public class DefaultTypeManagerTest {
|
|||||||
public void createEnumScalarTypePerExtentions() {
|
public void createEnumScalarTypePerExtentions() {
|
||||||
DefaultTypeManager typeManager = create();
|
DefaultTypeManager typeManager = create();
|
||||||
|
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(VarcharEnum.class, EnumType.ORDINAL);
|
ScalarType<?> type = typeManager.enumType(VarcharEnum.class, EnumType.ORDINAL);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
||||||
// withConstraint false
|
// withConstraint false
|
||||||
assertThat(((ScalarTypeEnumWithMapping) type).getDbCheckConstraintValues()).isNull();
|
assertThat(((ScalarTypeEnumWithMapping) type).getDbCheckConstraintValues()).isNull();
|
||||||
|
|
||||||
type = typeManager.createEnumScalarType(IntEnum.class, EnumType.ORDINAL);
|
type = typeManager.enumType(IntEnum.class, EnumType.ORDINAL);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
||||||
ScalarTypeEnumWithMapping enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
ScalarTypeEnumWithMapping enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
||||||
// withConstraint true
|
// withConstraint true
|
||||||
assertThat(enumWithMapping.getDbCheckConstraintValues()).hasSize(3);
|
assertThat(enumWithMapping.getDbCheckConstraintValues()).hasSize(3);
|
||||||
assertThat(enumWithMapping.getDbCheckConstraintValues()).contains("100", "101", "102");
|
assertThat(enumWithMapping.getDbCheckConstraintValues()).contains("100", "101", "102");
|
||||||
|
|
||||||
type = typeManager.createEnumScalarType(Car.Size.class, EnumType.ORDINAL);
|
type = typeManager.enumType(Car.Size.class, EnumType.ORDINAL);
|
||||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
||||||
enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
||||||
// withConstraint true
|
// withConstraint true
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class TestTypeManager extends BaseTest {
|
|||||||
void testEnumWithSubclasses() throws SQLException {
|
void testEnumWithSubclasses() throws SQLException {
|
||||||
DefaultTypeManager typeManager = createTypeManager();
|
DefaultTypeManager typeManager = createTypeManager();
|
||||||
|
|
||||||
ScalarType<?> type = typeManager.createEnumScalarType(MyEnum.class, null);
|
ScalarType<?> type = typeManager.enumType(MyEnum.class, null);
|
||||||
|
|
||||||
DataReader reader = mock(DataReader.class);
|
DataReader reader = mock(DataReader.class);
|
||||||
when(reader.getString()).thenReturn("A");
|
when(reader.getString()).thenReturn("A");
|
||||||
@@ -44,17 +44,17 @@ class TestTypeManager extends BaseTest {
|
|||||||
val = type.read(reader);
|
val = type.read(reader);
|
||||||
assertThat(val).isEqualTo(MyEnum.Cval);
|
assertThat(val).isEqualTo(MyEnum.Cval);
|
||||||
|
|
||||||
ScalarType<?> typeGeneral = typeManager.getScalarType(MyEnum.class);
|
ScalarType<?> typeGeneral = typeManager.type(MyEnum.class);
|
||||||
assertThat(typeGeneral).isNotNull();
|
assertThat(typeGeneral).isNotNull();
|
||||||
ScalarType<?> typeB = typeManager.getScalarType(MyEnum.Bval.getClass());
|
ScalarType<?> typeB = typeManager.type(MyEnum.Bval.getClass());
|
||||||
assertThat(typeB).isNotNull();
|
assertThat(typeB).isNotNull();
|
||||||
ScalarType<?> typeA = typeManager.getScalarType(MyEnum.Aval.getClass());
|
ScalarType<?> typeA = typeManager.type(MyEnum.Aval.getClass());
|
||||||
assertThat(typeA).isNotNull();
|
assertThat(typeA).isNotNull();
|
||||||
ScalarType<?> typeC = typeManager.getScalarType(MyEnum.Cval.getClass());
|
ScalarType<?> typeC = typeManager.type(MyEnum.Cval.getClass());
|
||||||
assertThat(typeC).isNotNull();
|
assertThat(typeC).isNotNull();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(MyEnum.class, EnumType.STRING);
|
typeManager.enumType(MyEnum.class, EnumType.STRING);
|
||||||
fail("never get here");
|
fail("never get here");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
||||||
@@ -65,7 +65,7 @@ class TestTypeManager extends BaseTest {
|
|||||||
void testEnumWithChar() throws SQLException {
|
void testEnumWithChar() throws SQLException {
|
||||||
DefaultTypeManager typeManager = createTypeManager();
|
DefaultTypeManager typeManager = createTypeManager();
|
||||||
|
|
||||||
ScalarType<?> dayOfWeekType = typeManager.createEnumScalarType(MyDayOfWeek.class, null);
|
ScalarType<?> dayOfWeekType = typeManager.enumType(MyDayOfWeek.class, null);
|
||||||
DataReader reader = mock(DataReader.class);
|
DataReader reader = mock(DataReader.class);
|
||||||
when(reader.getString()).thenReturn("MONDAY ");
|
when(reader.getString()).thenReturn("MONDAY ");
|
||||||
Object val = dayOfWeekType.read(reader);
|
Object val = dayOfWeekType.read(reader);
|
||||||
@@ -88,7 +88,7 @@ class TestTypeManager extends BaseTest {
|
|||||||
assertThat(val).isEqualTo(MyDayOfWeek.FRIDAY);
|
assertThat(val).isEqualTo(MyDayOfWeek.FRIDAY);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
typeManager.createEnumScalarType(MyDayOfWeek.class, EnumType.ORDINAL);
|
typeManager.enumType(MyDayOfWeek.class, EnumType.ORDINAL);
|
||||||
fail("never get here");
|
fail("never get here");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
assertThat(e.getMessage()).contains("It is mapped using 2 different modes when only one is supported");
|
||||||
@@ -99,7 +99,7 @@ class TestTypeManager extends BaseTest {
|
|||||||
void test() {
|
void test() {
|
||||||
DefaultTypeManager typeManager = createTypeManager();
|
DefaultTypeManager typeManager = createTypeManager();
|
||||||
|
|
||||||
ScalarType<?> scalarType = typeManager.getScalarType(Money.class);
|
ScalarType<?> scalarType = typeManager.type(Money.class);
|
||||||
assertEquals(Types.DECIMAL, scalarType.jdbcType());
|
assertEquals(Types.DECIMAL, scalarType.jdbcType());
|
||||||
assertFalse(scalarType.jdbcNative());
|
assertFalse(scalarType.jdbcNative());
|
||||||
assertEquals(Money.class, scalarType.type());
|
assertEquals(Money.class, scalarType.type());
|
||||||
@@ -108,15 +108,15 @@ class TestTypeManager extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
void testWithConfig() {
|
void testWithConfig() {
|
||||||
DefaultTypeManager typeManager1 = createTypeManager();
|
DefaultTypeManager typeManager1 = createTypeManager();
|
||||||
ScalarType<?> type1 = typeManager1.createEnumScalarType(MySex.class, null);
|
ScalarType<?> type1 = typeManager1.enumType(MySex.class, null);
|
||||||
assertThat(type1).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
assertThat(type1).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
||||||
//
|
//
|
||||||
DefaultTypeManager typeManager2 = createTypeManagerDefaultEnumTypeString();
|
DefaultTypeManager typeManager2 = createTypeManagerDefaultEnumTypeString();
|
||||||
ScalarType<?> type2 = typeManager2.createEnumScalarType(MySex.class, null);
|
ScalarType<?> type2 = typeManager2.enumType(MySex.class, null);
|
||||||
assertThat(type2).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class);
|
assertThat(type2).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class);
|
||||||
//
|
//
|
||||||
DefaultTypeManager typeManager3 = createTypeManagerDefaultEnumTypeString();
|
DefaultTypeManager typeManager3 = createTypeManagerDefaultEnumTypeString();
|
||||||
ScalarType<?> type3 = typeManager3.createEnumScalarType(MySex.class, EnumType.ORDINAL);
|
ScalarType<?> type3 = typeManager3.enumType(MySex.class, EnumType.ORDINAL);
|
||||||
assertThat(type3).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
assertThat(type3).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ class TestTypeManager extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
void testCalendar() {
|
void testCalendar() {
|
||||||
DefaultTypeManager typeManager = createTypeManager();
|
DefaultTypeManager typeManager = createTypeManager();
|
||||||
ScalarType<?> typeB = typeManager.getScalarType(GregorianCalendar.class);
|
ScalarType<?> typeB = typeManager.type(GregorianCalendar.class);
|
||||||
assertThat(typeB).isInstanceOf(ScalarTypeCalendar.class);
|
assertThat(typeB).isInstanceOf(ScalarTypeCalendar.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user