Top Fields Constructors Methods
org.postgresql.jdbc

public Class TypeInfoCache

extends Object
implements TypeInfo
Class Inheritance
All Implemented Interfaces
org.postgresql.core.TypeInfo
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

Field Summary

Modifier and TypeField and Description
private final Map<Integer, Character>
private final BaseConnection
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private @Nullable PreparedStatement
private final Map<String, Integer>
private final ResourceLock
private static final Logger
private final Map<Integer, String>
private final Map<Integer, Integer>
private final Map<Integer, Integer>
private final Map<String, String>
private final Map<String, Integer>
private final Map<String, Class<? extends PGobject>>
private final Map<String, Integer>
private static final ConcurrentMap<String, String>
TYPE_ALIASES

PG maps several alias to real type names.

private static final Object[][]
private final int

Constructor Summary

AccessConstructor and Description
public
TypeInfoCache(BaseConnection conn, int unknownLength)

Method Summary

Modifier and TypeMethod and Description
public void
addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, Integer arrayOid)

Implements org.postgresql.core.TypeInfo.addCoreType.

public void
public void
protected int

Returns:

oid of the array's base element or the provided oid (if not array)
convertArrayToBaseOid
(int
input oid
oid
)

Return the oid of the array's base element if it's an array, if not return the provided oid.

public char
getArrayDelimiter(int
the array type's OID
oid
)

Implements org.postgresql.core.TypeInfo.getArrayDelimiter.

Determine the delimiter for the elements of the given array type oid.

public int
public int
public String
public int
private PreparedStatement
getOidStatement(String pgTypeName)

public int
getPGArrayElement(int
the array type's OID
oid
)

Implements org.postgresql.core.TypeInfo.getPGArrayElement.

Look up the oid of an array's base type given the array's type oid.

public int
getPGArrayType(@Nullable String
the base type's
elementTypeName
)

Implements org.postgresql.core.TypeInfo.getPGArrayType.

Determine the oid of the given base postgresql type's array type.

public @Nullable Class<? extends PGobject>
public int
getPGType(String
the server type name to look up
pgTypeName
)

Implements org.postgresql.core.TypeInfo.getPGType.

Look up the oid for a given postgresql type name.

public @Nullable String
getPGType(int
the type's OID
oid
)

Implements org.postgresql.core.TypeInfo.getPGType.

Look up the postgresql type name for a given oid.

public Iterator<String>
public Iterator<Integer>
public int
public int
getScale(int oid, int typmod)

Implements org.postgresql.core.TypeInfo.getScale.

public int
getSQLType(String
the server type name to look up
pgTypeName
)

Implements org.postgresql.core.TypeInfo.getSQLType.

Look up the SQL typecode for a given postgresql type name.

public int
getSQLType(int
the type's OID
typeOid
)

Implements org.postgresql.core.TypeInfo.getSQLType.

Look up the SQL typecode for a given type oid.

private int
private String
getSQLTypeQuery(boolean typoidParam)

public @Nullable String
public long
intOidToLong(int
the (signed) integer oid to convert into a long.
oid
)

Implements org.postgresql.core.TypeInfo.intOidToLong.

Java Integers are signed 32-bit integers, but oids are unsigned 32-bit integers.

public boolean
public boolean
public int
longOidToInt(long
the oid as a long.
oid
)

Implements org.postgresql.core.TypeInfo.longOidToInt.

Java Integers are signed 32-bit integers, but oids are unsigned 32-bit integers.

private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
private PreparedStatement
public boolean
public boolean

Returns:

true if the type requires quoting
requiresQuotingSqlType
(int
sql type as in java.sql.Types
sqlType
)

Implements org.postgresql.core.TypeInfo.requiresQuotingSqlType.

Returns true if particular sqlType requires quoting.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayOidToDelimiterback to summary
private final Map<Integer, Character> arrayOidToDelimiter
connback to summary
private final BaseConnection conn
getAllTypeInfoStatementback to summary
private @Nullable PreparedStatement getAllTypeInfoStatement
getArrayDelimiterStatementback to summary
private @Nullable PreparedStatement getArrayDelimiterStatement
getArrayElementOidStatementback to summary
private @Nullable PreparedStatement getArrayElementOidStatement
getNameStatementback to summary
private @Nullable PreparedStatement getNameStatement
getOidStatementComplexArrayback to summary
private @Nullable PreparedStatement getOidStatementComplexArray
getOidStatementComplexNonArrayback to summary
private @Nullable PreparedStatement getOidStatementComplexNonArray
getOidStatementSimpleback to summary
private @Nullable PreparedStatement getOidStatementSimple
getTypeInfoStatementback to summary
private @Nullable PreparedStatement getTypeInfoStatement
javaArrayTypeToOidback to summary
private final Map<String, Integer> javaArrayTypeToOid
lockback to summary
private final ResourceLock lock
LOGGERback to summary
private static final Logger LOGGER
oidToPgNameback to summary
private final Map<Integer, String> oidToPgName
oidToSQLTypeback to summary
private final Map<Integer, Integer> oidToSQLType
pgArrayToPgTypeback to summary
private final Map<Integer, Integer> pgArrayToPgType
pgNameToJavaClassback to summary
private final Map<String, String> pgNameToJavaClass
pgNameToOidback to summary
private final Map<String, Integer> pgNameToOid
pgNameToPgObjectback to summary
private final Map<String, Class<? extends PGobject>> pgNameToPgObject
pgNameToSQLTypeback to summary
private final Map<String, Integer> pgNameToSQLType
TYPE_ALIASESback to summary
private static final ConcurrentMap<String, String> TYPE_ALIASES

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.

Additional values used at runtime (including case variants) will be added to the map.

typesback to summary
private static final Object[][] types
unknownLengthback to summary
private final int unknownLength

Constructor Detail

TypeInfoCacheback to summary
public TypeInfoCache(BaseConnection conn, int unknownLength)
Annotations
@SuppressWarnings:method.invocation

Method Detail

addCoreTypeback to summary
public void addCoreType(String pgTypeName, Integer oid, Integer sqlType, String javaClass, Integer arrayOid)

Implements org.postgresql.core.TypeInfo.addCoreType.

Annotations
@Override
addDataTypeback to summary
public void addDataType(String type, Class<? extends PGobject> klass) throws SQLException

Implements org.postgresql.core.TypeInfo.addDataType.

Annotations
@Override
cacheSQLTypesback to summary
public void cacheSQLTypes() throws SQLException
convertArrayToBaseOidback to summary
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:int

input oid

Returns:int

oid of the array's base element or the provided oid (if not array)

getArrayDelimiterback to summary
public char getArrayDelimiter(int oid) throws SQLException

Implements org.postgresql.core.TypeInfo.getArrayDelimiter.

Doc from org.postgresql.core.TypeInfo.getArrayDelimiter.

Determine the delimiter for the elements of the given array type oid.

Parameters
oid:int

the array type's OID

Returns:char

the base type's array type delimiter

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving array delimiter
getDisplaySizeback to summary
public int getDisplaySize(int oid, int typmod)

Implements org.postgresql.core.TypeInfo.getDisplaySize.

Annotations
@Override
getJavaArrayTypeback to summary
public int getJavaArrayType(String className) throws SQLException

Implements org.postgresql.core.TypeInfo.getJavaArrayType.

Annotations
@Override
getJavaClassback to summary
public String getJavaClass(int oid) throws SQLException

Implements org.postgresql.core.TypeInfo.getJavaClass.

Annotations
@Override
getMaximumPrecisionback to summary
public int getMaximumPrecision(int oid)

Implements org.postgresql.core.TypeInfo.getMaximumPrecision.

Annotations
@Override
getOidStatementback to summary
private PreparedStatement getOidStatement(String pgTypeName) throws SQLException
getPGArrayElementback to summary
public int getPGArrayElement(int oid) throws SQLException

Implements org.postgresql.core.TypeInfo.getPGArrayElement.

Doc from org.postgresql.core.TypeInfo.getPGArrayElement.

Look up the oid of an array's base type given the array's type oid.

Parameters
oid:int

the array type's OID

Returns:int

the base type's OID, or 0 if unknown

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving array element
getPGArrayTypeback to summary
public int getPGArrayType(@Nullable String elementTypeName) throws SQLException

Implements org.postgresql.core.TypeInfo.getPGArrayType.

Doc from org.postgresql.core.TypeInfo.getPGArrayType.

Determine the oid of the given base postgresql type's array type.

Parameters
elementTypeName:@Nullable String

the base type's

Returns:int

the array type's OID, or 0 if unknown

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving array type
getPGobjectback to summary
public @Nullable Class<? extends PGobject> getPGobject(String type)

Implements org.postgresql.core.TypeInfo.getPGobject.

Annotations
@Override
getPGTypeback to summary
public int getPGType(String pgTypeName) throws SQLException

Implements org.postgresql.core.TypeInfo.getPGType.

Doc from org.postgresql.core.TypeInfo.getPGType.

Look up the oid for a given postgresql type name. This is the inverse of getPGType(int).

Parameters
pgTypeName:String

the server type name to look up

Returns:int

the type's OID, or 0 if unknown

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving PG type
getPGTypeback to summary
public @Nullable String getPGType(int oid) throws SQLException

Implements org.postgresql.core.TypeInfo.getPGType.

Doc from org.postgresql.core.TypeInfo.getPGType.

Look up the postgresql type name for a given oid. This is the inverse of getPGType(String).

Parameters
oid:int

the type's OID

Returns:@Nullable String

the server type name for that OID or null if unknown

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving PG type
getPGTypeNamesWithSQLTypesback to summary
public Iterator<String> getPGTypeNamesWithSQLTypes()

Implements org.postgresql.core.TypeInfo.getPGTypeNamesWithSQLTypes.

Annotations
@Override
getPGTypeOidsWithSQLTypesback to summary
public Iterator<Integer> getPGTypeOidsWithSQLTypes()

Implements org.postgresql.core.TypeInfo.getPGTypeOidsWithSQLTypes.

Annotations
@Override
getPrecisionback to summary
public int getPrecision(int oid, int typmod)

Implements org.postgresql.core.TypeInfo.getPrecision.

Annotations
@Override
getScaleback to summary
public int getScale(int oid, int typmod)

Implements org.postgresql.core.TypeInfo.getScale.

Annotations
@Override
getSQLTypeback to summary
public int getSQLType(String pgTypeName) throws SQLException

Implements org.postgresql.core.TypeInfo.getSQLType.

Doc from org.postgresql.core.TypeInfo.getSQLType.

Look up the SQL typecode for a given postgresql type name.

Parameters
pgTypeName:String

the server type name to look up

Returns:int

the SQL type code (a constant from java.sql.Types) for the type

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving sql type
getSQLTypeback to summary
public int getSQLType(int typeOid) throws SQLException

Implements org.postgresql.core.TypeInfo.getSQLType.

Doc from org.postgresql.core.TypeInfo.getSQLType.

Look up the SQL typecode for a given type oid.

Parameters
typeOid:int

the type's OID

Returns:int

the SQL type code (a constant from java.sql.Types) for the type

Annotations
@Override
Exceptions
SQLException:
if an error occurs when retrieving sql type
getSQLTypeFromQueryResultback to summary
private int getSQLTypeFromQueryResult(ResultSet rs) throws SQLException
getSQLTypeQueryback to summary
private String getSQLTypeQuery(boolean typoidParam)
getTypeForAliasback to summary
public @Nullable String getTypeForAlias(@Nullable String alias)

Implements org.postgresql.core.TypeInfo.getTypeForAlias.

Annotations
@Override
intOidToLongback to summary
public long intOidToLong(int oid)

Implements org.postgresql.core.TypeInfo.intOidToLong.

Doc from org.postgresql.core.TypeInfo.intOidToLong.

Java 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.

Parameters
oid:int

the (signed) integer oid to convert into a long.

Returns:long

the non-negative value of this oid, stored as a java long.

Annotations
@Override
isCaseSensitiveback to summary
public boolean isCaseSensitive(int oid)

Implements org.postgresql.core.TypeInfo.isCaseSensitive.

Annotations
@Override
isSignedback to summary
public boolean isSigned(int oid)

Implements org.postgresql.core.TypeInfo.isSigned.

Annotations
@Override
longOidToIntback to summary
public int longOidToInt(long oid) throws SQLException

Implements org.postgresql.core.TypeInfo.longOidToInt.

Doc from org.postgresql.core.TypeInfo.longOidToInt.

Java 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.

Parameters
oid:long

the oid as a long.

Returns:int

the (internal) signed integer representation of the (unsigned) oid.

Annotations
@Override
Exceptions
SQLException:
if the long has a value outside of the range representable by uint32
prepareGetAllTypeInfoStatementback to summary
private PreparedStatement prepareGetAllTypeInfoStatement() throws SQLException
prepareGetArrayDelimiterStatementback to summary
private PreparedStatement prepareGetArrayDelimiterStatement() throws SQLException
prepareGetArrayElementOidStatementback to summary
private PreparedStatement prepareGetArrayElementOidStatement() throws SQLException
prepareGetNameStatementback to summary
private PreparedStatement prepareGetNameStatement() throws SQLException
prepareGetTypeInfoStatementback to summary
private PreparedStatement prepareGetTypeInfoStatement() throws SQLException
requiresQuotingback to summary
public boolean requiresQuoting(int oid) throws SQLException

Implements org.postgresql.core.TypeInfo.requiresQuoting.

Annotations
@Override
requiresQuotingSqlTypeback to summary
public boolean requiresQuotingSqlType(int sqlType) throws SQLException

Implements org.postgresql.core.TypeInfo.requiresQuotingSqlType.

Returns true if particular sqlType requires quoting. This method is used internally by the driver, so it might disappear without notice.

Parameters
sqlType:int

sql type as in java.sql.Types

Returns:boolean

true if the type requires quoting

Annotations
@Override
Exceptions
SQLException:
if something goes wrong