use of org.datanucleus.store.types.converters.MultiColumnConverter in project datanucleus-core by datanucleus.
the class CompleteClassTable method getTypeConverterForMember.
protected TypeConverter getTypeConverterForMember(AbstractMemberMetaData mmd, ColumnMetaData[] colmds, TypeManager typeMgr) {
TypeConverter typeConv = null;
String typeConvName = mmd.getTypeConverterName();
if (typeConvName != null) {
// User has specified the TypeConverter
typeConv = typeMgr.getTypeConverterForName(typeConvName);
if (typeConv == null) {
throw new NucleusUserException(Localiser.msg("044062", mmd.getFullFieldName(), typeConvName));
}
} else {
// No explicit TypeConverter so maybe there is an auto-apply converter for this member type
typeConv = typeMgr.getAutoApplyTypeConverterForType(mmd.getType());
}
if (typeConv == null) {
// Try to find a TypeConverter matching any column JDBC type definition
if (colmds != null && colmds.length > 1) {
// Multiple columns, so try to find a converter with the right number of columns (note we could, in future, check the types of columns also)
Collection<TypeConverter> converters = typeMgr.getTypeConvertersForType(mmd.getType());
if (converters != null && !converters.isEmpty()) {
for (TypeConverter conv : converters) {
if (conv instanceof MultiColumnConverter && ((MultiColumnConverter) conv).getDatastoreColumnTypes().length == colmds.length) {
typeConv = conv;
break;
}
}
}
if (typeConv == null) {
// TODO Throw exception since user column specification leaves no possible converter
}
} else {
// Single column, so try to match the JDBC type if provided
JdbcType jdbcType = colmds != null && colmds.length > 0 ? colmds[0].getJdbcType() : null;
if (jdbcType != null) {
// JDBC type specified so don't just take the default
if (MetaDataUtils.isJdbcTypeString(jdbcType)) {
typeConv = typeMgr.getTypeConverterForType(mmd.getType(), String.class);
} else if (MetaDataUtils.isJdbcTypeNumeric(jdbcType)) {
typeConv = typeMgr.getTypeConverterForType(mmd.getType(), Long.class);
} else if (jdbcType == JdbcType.TIMESTAMP) {
typeConv = typeMgr.getTypeConverterForType(mmd.getType(), Timestamp.class);
} else if (jdbcType == JdbcType.TIME) {
typeConv = typeMgr.getTypeConverterForType(mmd.getType(), Time.class);
} else if (jdbcType == JdbcType.DATE) {
typeConv = typeMgr.getTypeConverterForType(mmd.getType(), Date.class);
}
// TODO Support other JDBC types
} else {
// Fallback to default type converter for this member type (if any)
typeConv = typeMgr.getDefaultTypeConverterForType(mmd.getType());
}
}
}
if (schemaVerifier != null) {
// Make sure that the schema verifier supports this conversion
typeConv = schemaVerifier.verifyTypeConverterForMember(mmd, typeConv);
}
return typeConv;
}
Aggregations