public static PostgresType fromAIS(Parameter aisParameter) {
return fromTInstance(aisParameter.getType());
}
public static PostgresType fromTInstance(TInstance type) {
TClass tClass = TInstance.tClass(type);
TypeOid oid;
switch (tClass.jdbcType()) {
case Types.CHAR:
case Types.NCHAR:
/* TODO: Should be:
oid = TypeOid.CHAR_TYPE_OID;
break;
*/
case Types.NVARCHAR:
case Types.VARCHAR:
oid = TypeOid.VARCHAR_TYPE_OID;
break;
case Types.BOOLEAN:
oid = TypeOid.BOOL_TYPE_OID;
break;
case Types.TINYINT:
oid = TypeOid.INT2_TYPE_OID; // No INT1
break;
case Types.SMALLINT:
if (tClass.isUnsigned())
oid = TypeOid.INT4_TYPE_OID;
else
oid = TypeOid.INT2_TYPE_OID;
break;
case Types.INTEGER:
if (tClass.isUnsigned())
oid = TypeOid.INT8_TYPE_OID;
else
oid = TypeOid.INT4_TYPE_OID;
break;
case Types.BIGINT:
if (tClass.isUnsigned())
// Closest exact numeric type capable of holding 64-bit unsigned is DEC(20).
return new PostgresType(TypeOid.NUMERIC_TYPE_OID, (short)8, (20 << 16) + 4,
type);
else
oid = TypeOid.INT8_TYPE_OID;
break;
case Types.DECIMAL:
case Types.NUMERIC:
oid = TypeOid.NUMERIC_TYPE_OID;
break;
case Types.FLOAT:
case Types.REAL:
oid = TypeOid.FLOAT4_TYPE_OID;
break;
case Types.DOUBLE:
oid = TypeOid.FLOAT8_TYPE_OID;
break;
case Types.DATE:
oid = TypeOid.DATE_TYPE_OID;
break;
case Types.TIME:
oid = TypeOid.TIME_TYPE_OID;
break;
case Types.TIMESTAMP:
oid = TypeOid.TIMESTAMP_TYPE_OID;
break;
case Types.BINARY:
case Types.BIT:
case Types.LONGVARBINARY:
case Types.VARBINARY:
case Types.BLOB:
oid = TypeOid.BYTEA_TYPE_OID;
break;
case Types.LONGNVARCHAR:
case Types.LONGVARCHAR:
case Types.CLOB:
oid = TypeOid.TEXT_TYPE_OID;
break;
case Types.OTHER:
if (tClass == AkGUID.INSTANCE){
oid = TypeOid.UUID_TYPE_OID;
break;
}
default:
// Tell Postgres layer to just parse / format a string.
oid = TypeOid.VARCHAR_TYPE_OID;
break;
}
short length = -1;
int modifier = -1;
if (tClass.hasFixedSerializationSize())
length = (short)tClass.fixedSerializationSize();
if (type.hasAttributes(StringAttribute.class)) {
// VARCHAR(n).
modifier = type.attribute(StringAttribute.MAX_LENGTH) + 4;
}