Package org.postgresql.jdbc
Class TypeInfoCache
java.lang.Object
org.postgresql.jdbc.TypeInfoCache
- All Implemented Interfaces:
TypeInfo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BaseConnection
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private static final Logger
PG maps several alias to real type names.private static final Object[][]
private final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addDataType
(String type, Class<? extends PGobject> klass) void
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.char
getArrayDelimiter
(int oid) Determine the delimiter for the elements of the given array type oid.int
getDisplaySize
(int oid, int typmod) getJavaClass
(int oid) int
getMaximumPrecision
(int oid) private PreparedStatement
getOidStatement
(String pgTypeName) int
getPGArrayElement
(int oid) Look up the oid of an array's base type given the array's type oid.int
getPGArrayType
(String elementTypeName) Determine the oid of the given base postgresql type's array type.getPGobject
(String type) getPGType
(int oid) Look up the postgresql type name for a given oid.int
Look up the oid for a given postgresql type name.int
getPrecision
(int oid, int typmod) int
getScale
(int oid, int typmod) int
getSQLType
(int oid) Look up the SQL typecode for a given type oid.int
getSQLType
(String pgTypeName) Look up the SQL typecode for a given postgresql type name.private int
private String
getSQLTypeQuery
(boolean typnameParam) getTypeForAlias
(String alias) boolean
isCaseSensitive
(int oid) boolean
isSigned
(int oid) boolean
requiresQuoting
(int oid) boolean
requiresQuotingSqlType
(int sqlType) Returns true if particular sqlType requires quoting.
-
Field Details
-
LOGGER
-
pgNameToSQLType
-
pgNameToJavaClass
-
oidToPgName
-
pgNameToOid
-
pgNameToPgObject
-
pgArrayToPgType
-
arrayOidToDelimiter
-
conn
-
unknownLength
private final int unknownLength -
getOidStatementSimple
-
getOidStatementComplexNonArray
-
getOidStatementComplexArray
-
getNameStatement
-
getArrayElementOidStatement
-
getArrayDelimiterStatement
-
getTypeInfoStatement
-
getAllTypeInfoStatement
-
types
-
typeAliases
PG maps several alias to real type names. When we do queries against pg_catalog, we must use the real type, not an alias, so use this mapping.
-
-
Constructor Details
-
TypeInfoCache
-
-
Method Details
-
addCoreType
public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, Integer arrayOid) - Specified by:
addCoreType
in interfaceTypeInfo
-
addDataType
- Specified by:
addDataType
in interfaceTypeInfo
- Throws:
SQLException
-
getPGTypeNamesWithSQLTypes
- Specified by:
getPGTypeNamesWithSQLTypes
in interfaceTypeInfo
-
getSQLTypeQuery
-
getSQLTypeFromQueryResult
- Throws:
SQLException
-
cacheSQLTypes
- Throws:
SQLException
-
getSQLType
Description copied from interface:TypeInfo
Look up the SQL typecode for a given type oid.- Specified by:
getSQLType
in interfaceTypeInfo
- Parameters:
oid
- 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
-
getSQLType
Description copied from interface:TypeInfo
Look up the SQL typecode for a given postgresql type name.- Specified by:
getSQLType
in 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
-
getOidStatement
- Throws:
SQLException
-
getPGType
Description copied from interface:TypeInfo
Look up the oid for a given postgresql type name. This is the inverse ofTypeInfo.getPGType(int)
.- Specified by:
getPGType
in 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:TypeInfo
Look up the postgresql type name for a given oid. This is the inverse ofTypeInfo.getPGType(String)
.- Specified by:
getPGType
in 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:TypeInfo
Determine the oid of the given base postgresql type's array type.- Specified by:
getPGArrayType
in 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:TypeInfo
Determine the delimiter for the elements of the given array type oid.- Specified by:
getArrayDelimiter
in 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:TypeInfo
Look up the oid of an array's base type given the array's type oid.- Specified by:
getPGArrayElement
in 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:
getPGobject
in interfaceTypeInfo
-
getJavaClass
- Specified by:
getJavaClass
in interfaceTypeInfo
- Throws:
SQLException
-
getTypeForAlias
- Specified by:
getTypeForAlias
in interfaceTypeInfo
-
getPrecision
public int getPrecision(int oid, int typmod) - Specified by:
getPrecision
in interfaceTypeInfo
-
getScale
public int getScale(int oid, int typmod) -
isCaseSensitive
public boolean isCaseSensitive(int oid) - Specified by:
isCaseSensitive
in interfaceTypeInfo
-
isSigned
public boolean isSigned(int oid) -
getDisplaySize
public int getDisplaySize(int oid, int typmod) - Specified by:
getDisplaySize
in interfaceTypeInfo
-
getMaximumPrecision
public int getMaximumPrecision(int oid) - Specified by:
getMaximumPrecision
in interfaceTypeInfo
-
requiresQuoting
- Specified by:
requiresQuoting
in 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:
requiresQuotingSqlType
in interfaceTypeInfo
- Parameters:
sqlType
- sql type as in java.sql.Types- Returns:
- true if the type requires quoting
- Throws:
SQLException
- if something goes wrong
-