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
|
||||
public ScalarType<?> scalarType(String cast) {
|
||||
return typeManager.getScalarType(cast);
|
||||
return typeManager.type(cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
DeployBeanDescriptor<?> targetDesc = targetDescriptor(oneToMany);
|
||||
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);
|
||||
orderProperty.setName(DeployOrderColumn.LOGICAL_NAME);
|
||||
orderProperty.setDbColumn(orderColumn.getName());
|
||||
|
||||
+3
-3
@@ -222,7 +222,7 @@ final class AnnotationAssocManys extends AnnotationAssoc {
|
||||
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);
|
||||
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()) {
|
||||
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;
|
||||
|
||||
@@ -427,7 +427,7 @@ final class AnnotationFields extends AnnotationParser {
|
||||
|
||||
private ScalarTypeBytesBase getDbEncryptType(DeployBeanProperty prop) {
|
||||
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) {
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ public final class DeployCreateProperties {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private DeployBeanProperty createManyType(DeployBeanDescriptor<?> desc, Class<?> targetType, ManyType manyType) {
|
||||
try {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(targetType);
|
||||
ScalarType<?> scalarType = typeManager.type(targetType);
|
||||
if (scalarType != null) {
|
||||
return new DeployBeanPropertySimpleCollection(desc, targetType, manyType);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public final class DeployCreateProperties {
|
||||
if (propertyType.isEnum() || propertyType.isPrimitive()) {
|
||||
return new DeployBeanProperty(desc, propertyType, null, null);
|
||||
}
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(propertyType);
|
||||
ScalarType<?> scalarType = typeManager.type(propertyType);
|
||||
if (scalarType != null) {
|
||||
return new DeployBeanProperty(desc, propertyType, scalarType, null);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public final class DeployUtil {
|
||||
try {
|
||||
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) enumType;
|
||||
EnumType type = enumerated != null ? enumerated.value() : null;
|
||||
ScalarType<?> scalarType = typeManager.createEnumScalarType(enumClass, type);
|
||||
ScalarType<?> scalarType = typeManager.enumType(enumClass, type);
|
||||
prop.setScalarType(scalarType);
|
||||
prop.setDbType(scalarType.jdbcType());
|
||||
} catch (IllegalStateException e) {
|
||||
@@ -137,7 +137,7 @@ public final class DeployUtil {
|
||||
// set via annotations
|
||||
Class<?> propType = property.getPropertyType();
|
||||
try {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(propType, property.getDbType());
|
||||
ScalarType<?> scalarType = typeManager.type(propType, property.getDbType());
|
||||
if (scalarType != null || property.isTransient()) {
|
||||
return scalarType;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public final class DeployUtil {
|
||||
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
||||
*/
|
||||
void setDbMap(DeployBeanProperty prop, DbMap dbMap) {
|
||||
ScalarType<?> scalarType = typeManager.getDbMapScalarType();
|
||||
ScalarType<?> scalarType = typeManager.dbMapType();
|
||||
int dbType = scalarType.jdbcType();
|
||||
prop.setDbType(dbType);
|
||||
prop.setScalarType(scalarType);
|
||||
@@ -172,7 +172,7 @@ public final class DeployUtil {
|
||||
*/
|
||||
void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||
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) {
|
||||
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) {
|
||||
prop.setDbType(dbType);
|
||||
prop.setMutationDetection(mutationDetection);
|
||||
ScalarType<?> scalarType = typeManager.getJsonScalarType(prop, dbType, dbLength);
|
||||
ScalarType<?> scalarType = typeManager.dbJsonType(prop, dbType, dbLength);
|
||||
if (scalarType == null) {
|
||||
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
|
||||
int lobType = isClobType(type) ? dbCLOBType : dbBLOBType;
|
||||
|
||||
scalarType = typeManager.getScalarType(type, lobType);
|
||||
scalarType = typeManager.type(type, lobType);
|
||||
if (scalarType == null) {
|
||||
// this should never occur actually
|
||||
throw new RuntimeException("No ScalarType for LOB type " + type + " dbType:" + lobType);
|
||||
|
||||
@@ -21,7 +21,7 @@ final class DtoMetaConstructor {
|
||||
this.types = constructor.getParameterTypes();
|
||||
this.scalarTypes = new ScalarType[types.length];
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ final class DtoMetaProperty implements DtoReadSet {
|
||||
this.name = name;
|
||||
if (writeMethod != null) {
|
||||
this.setter = lookupMethodHandle(dtoType, writeMethod);
|
||||
this.scalarType = typeManager.getScalarType(propertyType(writeMethod), propertyClass(writeMethod));
|
||||
this.scalarType = typeManager.type(propertyType(writeMethod), propertyClass(writeMethod));
|
||||
} else {
|
||||
this.scalarType = null;
|
||||
this.setter = null;
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class DJsonScalar {
|
||||
gen.writeRaw(']');
|
||||
|
||||
} else {
|
||||
ScalarType scalarType = typeManager.getScalarType(value.getClass());
|
||||
ScalarType scalarType = typeManager.type(value.getClass());
|
||||
if (scalarType == null) {
|
||||
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,
|
||||
DbExpressionHandler dbExpressionHandler, DataTimeZone dataTimeZone, MultiValueBind multiValueBind) {
|
||||
this.typeManager = typeManager;
|
||||
this.geoTypeBinder = typeManager.getGeoTypeBinder();
|
||||
this.geoTypeBinder = typeManager.geoTypeBinder();
|
||||
this.asOfBindCount = asOfBindCount;
|
||||
this.asOfStandardsBased = asOfStandardsBased;
|
||||
this.dbExpressionHandler = dbExpressionHandler;
|
||||
@@ -154,7 +154,7 @@ public final class Binder {
|
||||
}
|
||||
|
||||
public ScalarType<?> getScalarType(Class<?> clazz) {
|
||||
ScalarType<?> type = typeManager.getScalarType(clazz);
|
||||
ScalarType<?> type = typeManager.type(clazz);
|
||||
if (type == null) {
|
||||
throw new PersistenceException("No ScalarType registered for " + clazz);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScalarType<?> getScalarType(String cast) {
|
||||
public ScalarType<?> type(String 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.
|
||||
*/
|
||||
@Override
|
||||
public ScalarType<?> getScalarType(int jdbcType) {
|
||||
public ScalarType<?> type(int jdbcType) {
|
||||
return nativeMap.get(jdbcType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScalarType<?> getScalarType(Type propertyType, Class<?> propertyClass) {
|
||||
public ScalarType<?> type(Type propertyType, Class<?> propertyClass) {
|
||||
if (propertyType instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) propertyType;
|
||||
Type rawType = pt.getRawType();
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
public ScalarType<?> getScalarType(Class<?> type) {
|
||||
public ScalarType<?> type(Class<?> type) {
|
||||
ScalarType<?> found = typeMap.get(type);
|
||||
if (found == null) {
|
||||
if (type.getName().equals("org.joda.time.LocalTime")) {
|
||||
@@ -247,37 +247,37 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoTypeBinder getGeoTypeBinder() {
|
||||
public GeoTypeBinder geoTypeBinder() {
|
||||
return geoTypeBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScalarType<?> getDbMapScalarType() {
|
||||
public ScalarType<?> dbMapType() {
|
||||
return hstoreSupport() ? hstoreType : ScalarTypeJsonMap.typeFor(false, Types.VARCHAR, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScalarType<?> getArrayScalarType(Class<?> type, Type genericType, boolean nullable) {
|
||||
Type valueType = getValueType(genericType);
|
||||
public ScalarType<?> dbArrayType(Class<?> type, Type genericType, boolean nullable) {
|
||||
Type valueType = valueType(genericType);
|
||||
if (type.equals(List.class)) {
|
||||
return getArrayScalarTypeList(valueType, nullable);
|
||||
return dbArrayTypeList(valueType, nullable);
|
||||
} else if (type.equals(Set.class)) {
|
||||
return getArrayScalarTypeSet(valueType, nullable);
|
||||
return dbArrayTypeSet(valueType, nullable);
|
||||
} else {
|
||||
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)) {
|
||||
return arrayTypeSetFactory.typeForEnum(createEnumScalarType(asEnumClass(valueType), null), nullable);
|
||||
return arrayTypeSetFactory.typeForEnum(enumType(asEnumClass(valueType), null), nullable);
|
||||
}
|
||||
return arrayTypeSetFactory.typeFor(valueType, nullable);
|
||||
}
|
||||
|
||||
private ScalarType<?> getArrayScalarTypeList(Type valueType, boolean nullable) {
|
||||
private ScalarType<?> dbArrayTypeList(Type valueType, boolean nullable) {
|
||||
if (isEnumType(valueType)) {
|
||||
return arrayTypeListFactory.typeForEnum(createEnumScalarType(asEnumClass(valueType), null), nullable);
|
||||
return arrayTypeListFactory.typeForEnum(enumType(asEnumClass(valueType), null), nullable);
|
||||
}
|
||||
return arrayTypeListFactory.typeFor(valueType, nullable);
|
||||
}
|
||||
@@ -291,7 +291,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScalarType<?> getJsonScalarType(DeployBeanProperty prop, int dbType, int dbLength) {
|
||||
public ScalarType<?> dbJsonType(DeployBeanProperty prop, int dbType, int dbLength) {
|
||||
Class<?> type = prop.getPropertyType();
|
||||
Type genericType = prop.getGenericType();
|
||||
boolean hasJacksonAnnotations = objectMapperPresent && checkJacksonAnnotations(prop);
|
||||
@@ -300,7 +300,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
||||
}
|
||||
if (type.equals(List.class)) {
|
||||
DocPropertyType docType = getDocType(genericType);
|
||||
DocPropertyType docType = docType(genericType);
|
||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
||||
return ScalarTypeJsonList.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
||||
} else {
|
||||
@@ -308,7 +308,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
}
|
||||
if (type.equals(Set.class)) {
|
||||
DocPropertyType docType = getDocType(genericType);
|
||||
DocPropertyType docType = docType(genericType);
|
||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
||||
return ScalarTypeJsonSet.typeFor(postgres, dbType, docType, prop.isNullable(), jsonManager.keepSource(prop));
|
||||
} else {
|
||||
@@ -339,9 +339,9 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
return prop.getMetaAnnotation(com.fasterxml.jackson.annotation.JacksonAnnotation.class) != null;
|
||||
}
|
||||
|
||||
private DocPropertyType getDocType(Type genericType) {
|
||||
private DocPropertyType docType(Type genericType) {
|
||||
if (genericType instanceof Class<?>) {
|
||||
ScalarType<?> found = getScalarType((Class<?>) genericType);
|
||||
ScalarType<?> found = type((Class<?>) genericType);
|
||||
if (found != null) {
|
||||
return found.docType();
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
return String.class.equals(typeArg) || Long.class.equals(typeArg);
|
||||
}
|
||||
|
||||
private Type getValueType(Type collectionType) {
|
||||
private Type valueType(Type collectionType) {
|
||||
return TypeReflectHelper.getValueType(collectionType);
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
* different jdbcTypes in a single system.
|
||||
*/
|
||||
@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
|
||||
if (File.class.equals(type)) {
|
||||
return fileType;
|
||||
@@ -393,13 +393,13 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
// check for Clob, LongVarchar etc ...
|
||||
// the reason being that String maps to multiple jdbc types
|
||||
// varchar, clob, longVarchar.
|
||||
ScalarType<?> scalarType = getLobTypes(jdbcType);
|
||||
ScalarType<?> scalarType = lobTypes(jdbcType);
|
||||
if (scalarType != null) {
|
||||
// it is a specific Lob type...
|
||||
return scalarType;
|
||||
}
|
||||
|
||||
scalarType = getScalarType(type);
|
||||
scalarType = type(type);
|
||||
if (scalarType != null) {
|
||||
if (jdbcType == 0 || scalarType.jdbcType() == jdbcType) {
|
||||
// matching type
|
||||
@@ -425,8 +425,8 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
* types - like String - Varchar, LongVarchar, Clob. For this reason I check
|
||||
* for the specific Lob types first before looking for a matching type.
|
||||
*/
|
||||
private ScalarType<?> getLobTypes(int jdbcType) {
|
||||
return getScalarType(jdbcType);
|
||||
private ScalarType<?> lobTypes(int jdbcType) {
|
||||
return type(jdbcType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,7 +470,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
* <p>
|
||||
* Return null if the EnumValue annotations are not present/used.
|
||||
*/
|
||||
private ScalarTypeEnum<?> createEnumScalarType2(Class<?> enumType) {
|
||||
private ScalarTypeEnum<?> enumTypeEnumValue(Class<?> enumType) {
|
||||
boolean integerType = true;
|
||||
Map<String, String> nameValueMap = new LinkedHashMap<>();
|
||||
for (Field field : enumType.getDeclaredFields()) {
|
||||
@@ -499,8 +499,8 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
* much shorter codes used in the DB.
|
||||
*/
|
||||
@Override
|
||||
public ScalarType<?> createEnumScalarType(Class<? extends Enum<?>> enumType, EnumType type) {
|
||||
ScalarType<?> scalarType = getScalarType(enumType);
|
||||
public ScalarType<?> enumType(Class<? extends Enum<?>> enumType, EnumType type) {
|
||||
ScalarType<?> scalarType = type(enumType);
|
||||
if (scalarType instanceof ScalarTypeWrapper) {
|
||||
// no override or further mapping required
|
||||
return scalarType;
|
||||
@@ -512,16 +512,16 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
return scalarEnum;
|
||||
}
|
||||
scalarEnum = createEnumScalarTypePerExtentions(enumType);
|
||||
scalarEnum = enumTypePerExtensions(enumType);
|
||||
if (scalarEnum == null) {
|
||||
// use JPA normal Enum type (without mapping)
|
||||
scalarEnum = createEnumScalarTypePerSpec(enumType, type);
|
||||
scalarEnum = enumTypePerSpec(enumType, type);
|
||||
}
|
||||
add(scalarEnum);
|
||||
return scalarEnum;
|
||||
}
|
||||
|
||||
private ScalarTypeEnum<?> createEnumScalarTypePerSpec(Class<?> enumType, EnumType type) {
|
||||
private ScalarTypeEnum<?> enumTypePerSpec(Class<?> enumType, EnumType type) {
|
||||
if (type == null) {
|
||||
if (defaultEnumType == EnumType.ORDINAL) {
|
||||
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()) {
|
||||
DbEnumValue dbValue = AnnotationUtil.get(method, DbEnumValue.class);
|
||||
if (dbValue != null) {
|
||||
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
|
||||
return createEnumScalarType2(enumType);
|
||||
return enumTypeEnumValue(enumType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -552,7 +552,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
* <p>
|
||||
* 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<>();
|
||||
for (Enum<?> enumConstant : enumType.getEnumConstants()) {
|
||||
try {
|
||||
@@ -634,7 +634,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
Class<?> logicalType = paramTypes[0];
|
||||
Class<?> persistType = paramTypes[1];
|
||||
ScalarType<?> wrappedType = getScalarType(persistType);
|
||||
ScalarType<?> wrappedType = type(persistType);
|
||||
if (wrappedType == null) {
|
||||
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<?> persistType = paramTypes[1];
|
||||
ScalarType<?> wrappedType = getScalarType(persistType);
|
||||
ScalarType<?> wrappedType = type(persistType);
|
||||
if (wrappedType == null) {
|
||||
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) {
|
||||
|
||||
ZoneId zoneId = getZoneId(config);
|
||||
ZoneId zoneId = zoneId(config);
|
||||
|
||||
typeMap.put(java.nio.file.Path.class, new ScalarTypePath());
|
||||
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());
|
||||
}
|
||||
|
||||
private ZoneId getZoneId(DatabaseConfig config) {
|
||||
private ZoneId zoneId(DatabaseConfig config) {
|
||||
final String dataTimeZone = config.getDataTimeZone();
|
||||
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.
|
||||
*/
|
||||
ScalarType<?> getScalarType(String cast);
|
||||
ScalarType<?> type(String cast);
|
||||
|
||||
/**
|
||||
* Return the ScalarType for a given jdbc type.
|
||||
*
|
||||
* @param jdbcType as per java.sql.Types
|
||||
*/
|
||||
ScalarType<?> getScalarType(int jdbcType);
|
||||
ScalarType<?> type(int jdbcType);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* 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
|
||||
* or String which has limitations).
|
||||
* Create a ScalarType for an Enum using a mapping (rather than JPA Ordinal 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.
|
||||
@@ -54,20 +53,20 @@ public interface TypeManager {
|
||||
* Note that type expected to be JsonNode or Map.
|
||||
* </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.
|
||||
*/
|
||||
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>).
|
||||
*/
|
||||
ScalarType<?> getDbMapScalarType();
|
||||
ScalarType<?> dbMapType();
|
||||
|
||||
/**
|
||||
* Return the Geometry type binder if provided.
|
||||
*/
|
||||
GeoTypeBinder getGeoTypeBinder();
|
||||
GeoTypeBinder geoTypeBinder();
|
||||
}
|
||||
@@ -46,14 +46,14 @@ public class DefaultTypeManagerTest {
|
||||
public void enumDayMonth_builtIn_overrideAsString() {
|
||||
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");
|
||||
|
||||
// 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");
|
||||
try {
|
||||
typeManager.createEnumScalarType(Month.class, EnumType.ORDINAL);
|
||||
typeManager.enumType(Month.class, EnumType.ORDINAL);
|
||||
assertThat(true).isFalse().as("never get here");
|
||||
|
||||
} catch (IllegalStateException e) {
|
||||
@@ -66,10 +66,10 @@ public class DefaultTypeManagerTest {
|
||||
DefaultTypeManager typeManager = create();
|
||||
|
||||
// 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");
|
||||
try {
|
||||
typeManager.createEnumScalarType(Month.class, EnumType.STRING);
|
||||
typeManager.enumType(Month.class, EnumType.STRING);
|
||||
assertThat(true).isFalse().as("never get here");
|
||||
} catch (IllegalStateException e) {
|
||||
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() {
|
||||
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");
|
||||
|
||||
// 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");
|
||||
try {
|
||||
typeManager.createEnumScalarType(DayOfWeek.class, EnumType.ORDINAL);
|
||||
typeManager.enumType(DayOfWeek.class, EnumType.ORDINAL);
|
||||
assertThat(true).isFalse().as("never get here");
|
||||
} catch (IllegalStateException e) {
|
||||
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();
|
||||
|
||||
// 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");
|
||||
try {
|
||||
typeManager.createEnumScalarType(DayOfWeek.class, EnumType.STRING);
|
||||
typeManager.enumType(DayOfWeek.class, EnumType.STRING);
|
||||
assertThat(true).isFalse().as("never get here");
|
||||
} catch (IllegalStateException e) {
|
||||
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() {
|
||||
DefaultTypeManager typeManager = create();
|
||||
|
||||
ScalarType<?> type = typeManager.createEnumScalarType(VarcharEnum.class, EnumType.ORDINAL);
|
||||
ScalarType<?> type = typeManager.enumType(VarcharEnum.class, EnumType.ORDINAL);
|
||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
||||
// withConstraint false
|
||||
assertThat(((ScalarTypeEnumWithMapping) type).getDbCheckConstraintValues()).isNull();
|
||||
|
||||
type = typeManager.createEnumScalarType(IntEnum.class, EnumType.ORDINAL);
|
||||
type = typeManager.enumType(IntEnum.class, EnumType.ORDINAL);
|
||||
assertThat(type).isInstanceOf(ScalarTypeEnumWithMapping.class);
|
||||
ScalarTypeEnumWithMapping enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
||||
// withConstraint true
|
||||
assertThat(enumWithMapping.getDbCheckConstraintValues()).hasSize(3);
|
||||
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);
|
||||
enumWithMapping = (ScalarTypeEnumWithMapping) type;
|
||||
// withConstraint true
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestTypeManager extends BaseTest {
|
||||
void testEnumWithSubclasses() throws SQLException {
|
||||
DefaultTypeManager typeManager = createTypeManager();
|
||||
|
||||
ScalarType<?> type = typeManager.createEnumScalarType(MyEnum.class, null);
|
||||
ScalarType<?> type = typeManager.enumType(MyEnum.class, null);
|
||||
|
||||
DataReader reader = mock(DataReader.class);
|
||||
when(reader.getString()).thenReturn("A");
|
||||
@@ -44,17 +44,17 @@ class TestTypeManager extends BaseTest {
|
||||
val = type.read(reader);
|
||||
assertThat(val).isEqualTo(MyEnum.Cval);
|
||||
|
||||
ScalarType<?> typeGeneral = typeManager.getScalarType(MyEnum.class);
|
||||
ScalarType<?> typeGeneral = typeManager.type(MyEnum.class);
|
||||
assertThat(typeGeneral).isNotNull();
|
||||
ScalarType<?> typeB = typeManager.getScalarType(MyEnum.Bval.getClass());
|
||||
ScalarType<?> typeB = typeManager.type(MyEnum.Bval.getClass());
|
||||
assertThat(typeB).isNotNull();
|
||||
ScalarType<?> typeA = typeManager.getScalarType(MyEnum.Aval.getClass());
|
||||
ScalarType<?> typeA = typeManager.type(MyEnum.Aval.getClass());
|
||||
assertThat(typeA).isNotNull();
|
||||
ScalarType<?> typeC = typeManager.getScalarType(MyEnum.Cval.getClass());
|
||||
ScalarType<?> typeC = typeManager.type(MyEnum.Cval.getClass());
|
||||
assertThat(typeC).isNotNull();
|
||||
|
||||
try {
|
||||
typeManager.createEnumScalarType(MyEnum.class, EnumType.STRING);
|
||||
typeManager.enumType(MyEnum.class, EnumType.STRING);
|
||||
fail("never get here");
|
||||
} catch (IllegalStateException e) {
|
||||
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 {
|
||||
DefaultTypeManager typeManager = createTypeManager();
|
||||
|
||||
ScalarType<?> dayOfWeekType = typeManager.createEnumScalarType(MyDayOfWeek.class, null);
|
||||
ScalarType<?> dayOfWeekType = typeManager.enumType(MyDayOfWeek.class, null);
|
||||
DataReader reader = mock(DataReader.class);
|
||||
when(reader.getString()).thenReturn("MONDAY ");
|
||||
Object val = dayOfWeekType.read(reader);
|
||||
@@ -88,7 +88,7 @@ class TestTypeManager extends BaseTest {
|
||||
assertThat(val).isEqualTo(MyDayOfWeek.FRIDAY);
|
||||
|
||||
try {
|
||||
typeManager.createEnumScalarType(MyDayOfWeek.class, EnumType.ORDINAL);
|
||||
typeManager.enumType(MyDayOfWeek.class, EnumType.ORDINAL);
|
||||
fail("never get here");
|
||||
} catch (IllegalStateException e) {
|
||||
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() {
|
||||
DefaultTypeManager typeManager = createTypeManager();
|
||||
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(Money.class);
|
||||
ScalarType<?> scalarType = typeManager.type(Money.class);
|
||||
assertEquals(Types.DECIMAL, scalarType.jdbcType());
|
||||
assertFalse(scalarType.jdbcNative());
|
||||
assertEquals(Money.class, scalarType.type());
|
||||
@@ -108,15 +108,15 @@ class TestTypeManager extends BaseTest {
|
||||
@Test
|
||||
void testWithConfig() {
|
||||
DefaultTypeManager typeManager1 = createTypeManager();
|
||||
ScalarType<?> type1 = typeManager1.createEnumScalarType(MySex.class, null);
|
||||
ScalarType<?> type1 = typeManager1.enumType(MySex.class, null);
|
||||
assertThat(type1).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
||||
//
|
||||
DefaultTypeManager typeManager2 = createTypeManagerDefaultEnumTypeString();
|
||||
ScalarType<?> type2 = typeManager2.createEnumScalarType(MySex.class, null);
|
||||
ScalarType<?> type2 = typeManager2.enumType(MySex.class, null);
|
||||
assertThat(type2).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class);
|
||||
//
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class TestTypeManager extends BaseTest {
|
||||
@Test
|
||||
void testCalendar() {
|
||||
DefaultTypeManager typeManager = createTypeManager();
|
||||
ScalarType<?> typeB = typeManager.getScalarType(GregorianCalendar.class);
|
||||
ScalarType<?> typeB = typeManager.type(GregorianCalendar.class);
|
||||
assertThat(typeB).isInstanceOf(ScalarTypeCalendar.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user