Package org.postgresql.jdbc
Class TypeInfoCache
- java.lang.Object
-
- org.postgresql.jdbc.TypeInfoCache
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.Character>arrayOidToDelimiterprivate BaseConnectionconnprivate java.sql.PreparedStatementgetAllTypeInfoStatementprivate java.sql.PreparedStatementgetArrayDelimiterStatementprivate java.sql.PreparedStatementgetArrayElementOidStatementprivate java.sql.PreparedStatementgetNameStatementprivate java.sql.PreparedStatementgetOidStatementComplexArrayprivate java.sql.PreparedStatementgetOidStatementComplexNonArrayprivate java.sql.PreparedStatementgetOidStatementSimpleprivate java.sql.PreparedStatementgetTypeInfoStatementprivate static java.util.logging.LoggerLOGGERprivate java.util.Map<java.lang.Integer,java.lang.String>oidToPgNameprivate java.util.Map<java.lang.Integer,java.lang.Integer>pgArrayToPgTypeprivate java.util.Map<java.lang.String,java.lang.String>pgNameToJavaClassprivate java.util.Map<java.lang.String,java.lang.Integer>pgNameToOidprivate java.util.Map<java.lang.String,java.lang.Class<? extends PGobject>>pgNameToPgObjectprivate java.util.Map<java.lang.String,java.lang.Integer>pgNameToSQLTypeprivate static java.util.HashMap<java.lang.String,java.lang.String>typeAliasesPG maps several alias to real type names.private static java.lang.Object[][]typesprivate intunknownLength
-
Constructor Summary
Constructors Constructor Description TypeInfoCache(BaseConnection conn, int unknownLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCoreType(java.lang.String pgTypeName, java.lang.Integer oid, java.lang.Integer sqlType, java.lang.String javaClass, java.lang.Integer arrayOid)voidaddDataType(java.lang.String type, java.lang.Class<? extends PGobject> klass)voidcacheSQLTypes()protected 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)java.lang.StringgetJavaClass(int oid)intgetMaximumPrecision(int oid)private java.sql.PreparedStatementgetOidStatement(java.lang.String pgTypeName)intgetPGArrayElement(int oid)Look up the oid of an array's base type given the array's type oid.intgetPGArrayType(java.lang.String elementTypeName)Determine the oid of the given base postgresql type's array type.java.lang.Class<? extends PGobject>getPGobject(java.lang.String type)java.lang.StringgetPGType(int oid)Look up the postgresql type name for a given oid.intgetPGType(java.lang.String pgTypeName)Look up the oid for a given postgresql type name.java.util.Iterator<java.lang.String>getPGTypeNamesWithSQLTypes()intgetPrecision(int oid, int typmod)intgetScale(int oid, int typmod)intgetSQLType(int oid)Look up the SQL typecode for a given type oid.intgetSQLType(java.lang.String pgTypeName)Look up the SQL typecode for a given postgresql type name.private intgetSQLTypeFromQueryResult(java.sql.ResultSet rs)private java.lang.StringgetSQLTypeQuery(boolean typnameParam)java.lang.StringgetTypeForAlias(java.lang.String alias)booleanisCaseSensitive(int oid)booleanisSigned(int oid)private java.sql.PreparedStatementprepareGetAllTypeInfoStatement()private java.sql.PreparedStatementprepareGetArrayDelimiterStatement()private java.sql.PreparedStatementprepareGetArrayElementOidStatement()private java.sql.PreparedStatementprepareGetNameStatement()private java.sql.PreparedStatementprepareGetTypeInfoStatement()booleanrequiresQuoting(int oid)booleanrequiresQuotingSqlType(int sqlType)Returns true if particular sqlType requires quoting.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
pgNameToSQLType
private java.util.Map<java.lang.String,java.lang.Integer> pgNameToSQLType
-
pgNameToJavaClass
private java.util.Map<java.lang.String,java.lang.String> pgNameToJavaClass
-
oidToPgName
private java.util.Map<java.lang.Integer,java.lang.String> oidToPgName
-
pgNameToOid
private java.util.Map<java.lang.String,java.lang.Integer> pgNameToOid
-
pgNameToPgObject
private java.util.Map<java.lang.String,java.lang.Class<? extends PGobject>> pgNameToPgObject
-
pgArrayToPgType
private java.util.Map<java.lang.Integer,java.lang.Integer> pgArrayToPgType
-
arrayOidToDelimiter
private java.util.Map<java.lang.Integer,java.lang.Character> arrayOidToDelimiter
-
conn
private final BaseConnection conn
-
unknownLength
private final int unknownLength
-
getOidStatementSimple
private java.sql.PreparedStatement getOidStatementSimple
-
getOidStatementComplexNonArray
private java.sql.PreparedStatement getOidStatementComplexNonArray
-
getOidStatementComplexArray
private java.sql.PreparedStatement getOidStatementComplexArray
-
getNameStatement
private java.sql.PreparedStatement getNameStatement
-
getArrayElementOidStatement
private java.sql.PreparedStatement getArrayElementOidStatement
-
getArrayDelimiterStatement
private java.sql.PreparedStatement getArrayDelimiterStatement
-
getTypeInfoStatement
private java.sql.PreparedStatement getTypeInfoStatement
-
getAllTypeInfoStatement
private java.sql.PreparedStatement getAllTypeInfoStatement
-
types
private static final java.lang.Object[][] types
-
typeAliases
private static final java.util.HashMap<java.lang.String,java.lang.String> 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 Detail
-
TypeInfoCache
public TypeInfoCache(BaseConnection conn, int unknownLength)
-
-
Method Detail
-
addCoreType
public void addCoreType(java.lang.String pgTypeName, java.lang.Integer oid, java.lang.Integer sqlType, java.lang.String javaClass, java.lang.Integer arrayOid)- Specified by:
addCoreTypein interfaceTypeInfo
-
addDataType
public void addDataType(java.lang.String type, java.lang.Class<? extends PGobject> klass) throws java.sql.SQLException- Specified by:
addDataTypein interfaceTypeInfo- Throws:
java.sql.SQLException
-
getPGTypeNamesWithSQLTypes
public java.util.Iterator<java.lang.String> getPGTypeNamesWithSQLTypes()
- Specified by:
getPGTypeNamesWithSQLTypesin interfaceTypeInfo
-
getSQLTypeQuery
private java.lang.String getSQLTypeQuery(boolean typnameParam)
-
getSQLTypeFromQueryResult
private int getSQLTypeFromQueryResult(java.sql.ResultSet rs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
prepareGetAllTypeInfoStatement
private java.sql.PreparedStatement prepareGetAllTypeInfoStatement() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
cacheSQLTypes
public void cacheSQLTypes() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getSQLType
public int getSQLType(int oid) throws java.sql.SQLExceptionDescription copied from interface:TypeInfoLook up the SQL typecode for a given type oid.- Specified by:
getSQLTypein interfaceTypeInfo- Parameters:
oid- the type's OID- Returns:
- the SQL type code (a constant from
Types) for the type - Throws:
java.sql.SQLException- if an error occurs when retrieving sql type
-
prepareGetTypeInfoStatement
private java.sql.PreparedStatement prepareGetTypeInfoStatement() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getSQLType
public int getSQLType(java.lang.String pgTypeName) throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- if an error occurs when retrieving sql type
-
getOidStatement
private java.sql.PreparedStatement getOidStatement(java.lang.String pgTypeName) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getPGType
public int getPGType(java.lang.String pgTypeName) throws java.sql.SQLExceptionDescription copied from interface:TypeInfoLook up the oid for a given postgresql type name. This is the inverse ofTypeInfo.getPGType(int).
-
getPGType
public java.lang.String getPGType(int oid) throws java.sql.SQLExceptionDescription copied from interface:TypeInfoLook up the postgresql type name for a given oid. This is the inverse ofTypeInfo.getPGType(String).
-
prepareGetNameStatement
private java.sql.PreparedStatement prepareGetNameStatement() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getPGArrayType
public int getPGArrayType(java.lang.String elementTypeName) throws java.sql.SQLExceptionDescription 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:
java.sql.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
public char getArrayDelimiter(int oid) throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- if an error occurs when retrieving array delimiter
-
prepareGetArrayDelimiterStatement
private java.sql.PreparedStatement prepareGetArrayDelimiterStatement() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getPGArrayElement
public int getPGArrayElement(int oid) throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- if an error occurs when retrieving array element
-
prepareGetArrayElementOidStatement
private java.sql.PreparedStatement prepareGetArrayElementOidStatement() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getPGobject
public java.lang.Class<? extends PGobject> getPGobject(java.lang.String type)
- Specified by:
getPGobjectin interfaceTypeInfo
-
getJavaClass
public java.lang.String getJavaClass(int oid) throws java.sql.SQLException- Specified by:
getJavaClassin interfaceTypeInfo- Throws:
java.sql.SQLException
-
getTypeForAlias
public java.lang.String getTypeForAlias(java.lang.String alias)
- Specified by:
getTypeForAliasin interfaceTypeInfo
-
getPrecision
public int getPrecision(int oid, int typmod)- Specified by:
getPrecisionin interfaceTypeInfo
-
isCaseSensitive
public boolean isCaseSensitive(int oid)
- Specified by:
isCaseSensitivein interfaceTypeInfo
-
getDisplaySize
public int getDisplaySize(int oid, int typmod)- Specified by:
getDisplaySizein interfaceTypeInfo
-
getMaximumPrecision
public int getMaximumPrecision(int oid)
- Specified by:
getMaximumPrecisionin interfaceTypeInfo
-
requiresQuoting
public boolean requiresQuoting(int oid) throws java.sql.SQLException- Specified by:
requiresQuotingin interfaceTypeInfo- Throws:
java.sql.SQLException
-
requiresQuotingSqlType
public boolean requiresQuotingSqlType(int sqlType) throws java.sql.SQLExceptionReturns 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:
java.sql.SQLException- if something goes wrong
-
-