Package org.postgresql.jdbc
Class TypeInfoCache
java.lang.Object
org.postgresql.jdbc.TypeInfoCache
- All Implemented Interfaces:
TypeInfo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddDataType(String type, Class<? extends PGobject> klass) voidprotected intconvertArrayToBaseOid(int oid) Return the oid of the array's base element if it's an array, if not return the provided oid.chargetArrayDelimiter(int oid) Determine the delimiter for the elements of the given array type oid.intgetDisplaySize(int oid, int typmod) intgetJavaArrayType(String className) getJavaClass(int oid) intgetMaximumPrecision(int oid) intgetPGArrayElement(int oid) Look up the oid of an array's base type given the array's type oid.intgetPGArrayType(@Nullable String elementTypeName) Determine the oid of the given base postgresql type's array type.getPGobject(String type) @Nullable StringgetPGType(int oid) Look up the postgresql type name for a given oid.intLook up the oid for a given postgresql type name.intgetPrecision(int oid, int typmod) intgetScale(int oid, int typmod) intgetSQLType(int typeOid) Look up the SQL typecode for a given type oid.intgetSQLType(String pgTypeName) Look up the SQL typecode for a given postgresql type name.@Nullable StringgetTypeForAlias(@Nullable String alias) longintOidToLong(int oid) Java Integers are signed 32-bit integers, but oids are unsigned 32-bit integers.booleanisCaseSensitive(int oid) booleanisSigned(int oid) intlongOidToInt(long oid) Java Integers are signed 32-bit integers, but oids are unsigned 32-bit integers.booleanrequiresQuoting(int oid) booleanrequiresQuotingSqlType(int sqlType) Returns true if particular sqlType requires quoting.
-
Constructor Details
-
TypeInfoCache
-
-
Method Details
-
addCoreType
public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, Integer arrayOid) - Specified by:
addCoreTypein interfaceTypeInfo
-
addDataType
- Specified by:
addDataTypein interfaceTypeInfo- Throws:
SQLException
-
getPGTypeNamesWithSQLTypes
- Specified by:
getPGTypeNamesWithSQLTypesin interfaceTypeInfo
-
getPGTypeOidsWithSQLTypes
- Specified by:
getPGTypeOidsWithSQLTypesin interfaceTypeInfo
-
cacheSQLTypes
- Throws:
SQLException
-
getSQLType
Description copied from interface:TypeInfoLook up the SQL typecode for a given postgresql type name.- Specified by:
getSQLTypein interfaceTypeInfo- Parameters:
pgTypeName- the server type name to look up- Returns:
- the SQL type code (a constant from
Types) for the type - Throws:
SQLException- if an error occurs when retrieving sql type
-
getJavaArrayType
- Specified by:
getJavaArrayTypein interfaceTypeInfo- Throws:
SQLException
-
getSQLType
Description copied from interface:TypeInfoLook up the SQL typecode for a given type oid.- Specified by:
getSQLTypein interfaceTypeInfo- Parameters:
typeOid- the type's OID- Returns:
- the SQL type code (a constant from
Types) for the type - Throws:
SQLException- if an error occurs when retrieving sql type
-
getPGType
Description copied from interface:TypeInfoLook up the oid for a given postgresql type name. This is the inverse ofTypeInfo.getPGType(int).- Specified by:
getPGTypein interfaceTypeInfo- Parameters:
pgTypeName- the server type name to look up- Returns:
- the type's OID, or 0 if unknown
- Throws:
SQLException- if an error occurs when retrieving PG type
-
getPGType
Description copied from interface:TypeInfoLook up the postgresql type name for a given oid. This is the inverse ofTypeInfo.getPGType(String).- Specified by:
getPGTypein interfaceTypeInfo- Parameters:
oid- the type's OID- Returns:
- the server type name for that OID or null if unknown
- Throws:
SQLException- if an error occurs when retrieving PG type
-
getPGArrayType
Description copied from interface:TypeInfoDetermine the oid of the given base postgresql type's array type.- Specified by:
getPGArrayTypein interfaceTypeInfo- Parameters:
elementTypeName- the base type's- Returns:
- the array type's OID, or 0 if unknown
- Throws:
SQLException- if an error occurs when retrieving array type
-
convertArrayToBaseOid
protected int convertArrayToBaseOid(int oid) Return the oid of the array's base element if it's an array, if not return the provided oid. This doesn't do any database lookups, so it's only useful for the originally provided type mappings. This is fine for it's intended uses where we only have intimate knowledge of types that are already known to the driver.- Parameters:
oid- input oid- Returns:
- oid of the array's base element or the provided oid (if not array)
-
getArrayDelimiter
Description copied from interface:TypeInfoDetermine the delimiter for the elements of the given array type oid.- Specified by:
getArrayDelimiterin interfaceTypeInfo- Parameters:
oid- the array type's OID- Returns:
- the base type's array type delimiter
- Throws:
SQLException- if an error occurs when retrieving array delimiter
-
getPGArrayElement
Description copied from interface:TypeInfoLook up the oid of an array's base type given the array's type oid.- Specified by:
getPGArrayElementin interfaceTypeInfo- Parameters:
oid- the array type's OID- Returns:
- the base type's OID, or 0 if unknown
- Throws:
SQLException- if an error occurs when retrieving array element
-
getPGobject
- Specified by:
getPGobjectin interfaceTypeInfo
-
getJavaClass
- Specified by:
getJavaClassin interfaceTypeInfo- Throws:
SQLException
-
getTypeForAlias
- Specified by:
getTypeForAliasin interfaceTypeInfo
-
getPrecision
public int getPrecision(int oid, int typmod) - Specified by:
getPrecisionin interfaceTypeInfo
-
getScale
public int getScale(int oid, int typmod) -
isCaseSensitive
public boolean isCaseSensitive(int oid) - Specified by:
isCaseSensitivein interfaceTypeInfo
-
isSigned
public boolean isSigned(int oid) -
getDisplaySize
public int getDisplaySize(int oid, int typmod) - Specified by:
getDisplaySizein interfaceTypeInfo
-
getMaximumPrecision
public int getMaximumPrecision(int oid) - Specified by:
getMaximumPrecisionin interfaceTypeInfo
-
requiresQuoting
- Specified by:
requiresQuotingin interfaceTypeInfo- Throws:
SQLException
-
requiresQuotingSqlType
Returns true if particular sqlType requires quoting. This method is used internally by the driver, so it might disappear without notice.- Specified by:
requiresQuotingSqlTypein interfaceTypeInfo- Parameters:
sqlType- sql type as in java.sql.Types- Returns:
- true if the type requires quoting
- Throws:
SQLException- if something goes wrong
-
longOidToInt
Description copied from interface:TypeInfoJava Integers are signed 32-bit integers, but oids are unsigned 32-bit integers. We therefore read them as positive long values and then force them into signed integers (wrapping around into negative values when required) or we'd be unable to correctly handle the upper half of the oid space.This function handles the mapping of uint32-values in the long to java integers, and throws for values that are out of range.
- Specified by:
longOidToIntin interfaceTypeInfo- Parameters:
oid- the oid as a long.- Returns:
- the (internal) signed integer representation of the (unsigned) oid.
- Throws:
SQLException- if the long has a value outside of the range representable by uint32
-
intOidToLong
public long intOidToLong(int oid) Description copied from interface:TypeInfoJava Integers are signed 32-bit integers, but oids are unsigned 32-bit integers. We must therefore first map the (internal) integer representation to a positive long value before sending it to postgresql, or we would be unable to correctly handle the upper half of the oid space because these negative values are disallowed as OID values.- Specified by:
intOidToLongin interfaceTypeInfo- Parameters:
oid- the (signed) integer oid to convert into a long.- Returns:
- the non-negative value of this oid, stored as a java long.
-