- java.lang.Object
-
- org.postgresql.pljava.jdbc.SPIConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
public class SPIConnection extends Object implements Connection
Provides access to the current connection (session) the Java stored procedure is running in. It is returned from the driver manager withDriverManager.getConnection("jdbc:default:connection");
and cannot be managed in any way since it's already running inside a transaction. This means the following methods cannot be used.commit()
rollback()
setAutoCommit()
setTransactionIsolation()
- Author:
- Thomas Hallgren
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
JDBC_TYPE_NAMES
static int[]
JDBC_TYPE_NUMBERS
-
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
-
Constructor Summary
Constructors Constructor Description SPIConnection()
-
Method Summary
Modifier and Type Method Description void
abort(Executor executor)
void
clearWarnings()
Warnings are not yet supported.void
close()
This is a no-op.void
commit()
It's not legal to do a commit within a call from SQL.Array
createArrayOf(String typeName, Object[] elements)
Blob
createBlob()
Clob
createClob()
NClob
createNClob()
SQLXML
createSQLXML()
Statement
createStatement()
Creates a new instance ofSPIStatement
.Statement
createStatement(int resultSetType, int resultSetConcurrency)
Creates a new instance ofSPIStatement
.Statement
createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a new instance ofSPIStatement
.Struct
createStruct(String typeName, Object[] attributes)
boolean
getAutoCommit()
It is assumed that an SPI call is under transaction control.String
getCatalog()
Returns the database in which we are running.Properties
getClientInfo()
String
getClientInfo(String name)
static Connection
getDefault()
Returns a default connection instance.int
getHoldability()
ReturnsResultSet.CLOSE_CURSORS_AT_COMMIT
.DatabaseMetaData
getMetaData()
Retrieves an instance ofSPIDatabaseMetaData
representing thisConnection
object.int
getNetworkTimeout()
String
getPGType(Oid oid)
Map the Oid of a PostgreSQL type to its name (specifically, thetypname
attribute ofpg_type
.String
getSchema()
int
getSQLType(String pgTypeName)
Convert a PostgreSQL type name to aTypes
integer, using theJDBC_TYPE_NAMES
/JDBC_TYPE_NUMBERS
arrays; used inDatabaseMetaData
andResultSetMetaData
.int
getSQLType(Oid oid)
This returns theTypes
type for a PG type oid, by mapping it to a name usinggetPGType(org.postgresql.pljava.internal.Oid)
and then to the result viagetSQLType(String)
; used inResultSetMetaData
and five places inDatabaseMetaData
.int
getTransactionIsolation()
Map<String,Class<?>>
getTypeMap()
Returnsnull
.int[]
getVersionNumber()
Return the server version number as a three-elementint
array (of which the third may be null), as used in thegetDatabase...Version
methods ofDatabaseMetaData
.SQLWarning
getWarnings()
Warnings are not yet supported.boolean
isClosed()
Will always return false.boolean
isReadOnly()
Returnsfalse
.boolean
isValid(int timeout)
boolean
isWrapperFor(Class<?> iface)
String
nativeSQL(String sql)
Parse the JDBC SQL into PostgreSQL.String
nativeSQL(String sql, int[] paramCountRet)
CallableStatement
prepareCall(String sql)
Procedure calls are not yet implemented.CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency)
Procedure calls are not yet implemented.CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Procedure calls are not yet implemented.PreparedStatement
prepareStatement(String sql)
Creates a new instance ofSPIPreparedStatement
.PreparedStatement
prepareStatement(String sql, int autoGeneratedKeys)
Return of auto generated keys is not yet supported.PreparedStatement
prepareStatement(String sql, int[] columnIndexes)
Return of auto generated keys is not yet supported.PreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
Creates a new instance ofSPIPreparedStatement
.PreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a new instance ofSPIPreparedStatement
.PreparedStatement
prepareStatement(String sql, String[] columnNames)
Return of auto generated keys is not yet supported.void
releaseSavepoint(Savepoint savepoint)
void
rollback()
It's not legal to do a rollback within a call from SQL.void
rollback(Savepoint savepoint)
void
setAutoCommit(boolean autoCommit)
It is assumed that an SPI call is under transaction control.void
setCatalog(String catalog)
The catalog name cannot be set.void
setClientInfo(String name, String value)
void
setClientInfo(Properties properties)
void
setHoldability(int holdability)
Change of holdability is not supported.void
setNetworkTimeout(Executor executor, int milliseconds)
void
setReadOnly(boolean readOnly)
It is assumed that an inserts and updates can be performed using and SPIConnection.Savepoint
setSavepoint()
Savepoint
setSavepoint(String name)
void
setSchema(String schema)
void
setTransactionIsolation(int level)
Change of transaction isolation level is not supported.void
setTypeMap(Map<String,Class<?>> map)
Type map is not yet implemented.<T> T
unwrap(Class<T> iface)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
-
-
-
Field Detail
-
JDBC_TYPE_NAMES
public static final String[] JDBC_TYPE_NAMES
-
JDBC_TYPE_NUMBERS
public static final int[] JDBC_TYPE_NUMBERS
-
-
Method Detail
-
getDefault
public static Connection getDefault() throws SQLException
Returns a default connection instance. It is normally the caller's responsibility to close this instance, but asclose
is a no-op for this connection, that isn't critical.- Throws:
SQLException
-
getHoldability
public int getHoldability()
ReturnsResultSet.CLOSE_CURSORS_AT_COMMIT
.- Specified by:
getHoldability
in interfaceConnection
-
getTransactionIsolation
public int getTransactionIsolation()
- Specified by:
getTransactionIsolation
in interfaceConnection
-
clearWarnings
public void clearWarnings() throws SQLException
Warnings are not yet supported.- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
close
public void close()
This is a no-op. The default connection never closes.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
-
commit
public void commit() throws SQLException
It's not legal to do a commit within a call from SQL.- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
rollback
public void rollback() throws SQLException
It's not legal to do a rollback within a call from SQL.- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
getAutoCommit
public boolean getAutoCommit()
It is assumed that an SPI call is under transaction control. This method will always returnfalse
.- Specified by:
getAutoCommit
in interfaceConnection
-
isClosed
public boolean isClosed()
Will always return false.- Specified by:
isClosed
in interfaceConnection
-
isReadOnly
public boolean isReadOnly()
Returnsfalse
. The SPIConnection is not real-only.- Specified by:
isReadOnly
in interfaceConnection
-
setHoldability
public void setHoldability(int holdability) throws SQLException
Change of holdability is not supported.- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws SQLException
Change of transaction isolation level is not supported.- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws SQLException
It is assumed that an SPI call is under transaction control. Changing that is not supported.- Specified by:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLException
It is assumed that an inserts and updates can be performed using and SPIConnection. Changing that is not supported.- Specified by:
setReadOnly
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
getCatalog
public String getCatalog() throws SQLException
Returns the database in which we are running.- Specified by:
getCatalog
in interfaceConnection
- Throws:
SQLException
-
setCatalog
public void setCatalog(String catalog) throws SQLException
The catalog name cannot be set.- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
getMetaData
public DatabaseMetaData getMetaData()
Retrieves an instance ofSPIDatabaseMetaData
representing thisConnection
object. The metadata includes information about the SQL grammar supported by PostgreSQL, the capabilities of PL/Java, as well as the tables and stored procedures for this connection and so on.- Specified by:
getMetaData
in interfaceConnection
- Returns:
- an SPIDatabaseMetaData object for this
Connection
object
-
getWarnings
public SQLWarning getWarnings() throws SQLException
Warnings are not yet supported.- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws SQLException
- Specified by:
releaseSavepoint
in interfaceConnection
- Throws:
SQLException
-
rollback
public void rollback(Savepoint savepoint) throws SQLException
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement() throws SQLException
Creates a new instance ofSPIStatement
.- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
Creates a new instance ofSPIStatement
.- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
- if theresultSetType
differs fromResultSet.TYPE_FORWARD_ONLY
or if theresultSetConcurrencty
differs fromResultSet.CONCUR_READ_ONLY
.
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a new instance ofSPIStatement
.- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
- if theresultSetType
differs fromResultSet.TYPE_FORWARD_ONLY
, if theresultSetConcurrencty
differs fromResultSet.CONCUR_READ_ONLY
, or if the resultSetHoldability differs fromResultSet.CLOSE_CURSORS_AT_COMMIT
.
-
getTypeMap
public Map<String,Class<?>> getTypeMap() throws SQLException
Returnsnull
. Type map is not yet imlemented.- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
public void setTypeMap(Map<String,Class<?>> map) throws SQLException
Type map is not yet implemented.- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
nativeSQL
public String nativeSQL(String sql) throws SQLException
Parse the JDBC SQL into PostgreSQL.- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql) throws SQLException
Procedure calls are not yet implemented.- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Procedure calls are not yet implemented.- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Procedure calls are not yet implemented.- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareStatement
public PreparedStatement prepareStatement(String sql) throws SQLException
Creates a new instance ofSPIPreparedStatement
.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
Return of auto generated keys is not yet supported.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates a new instance ofSPIPreparedStatement
.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- if theresultSetType
differs fromResultSet.TYPE_FORWARD_ONLY
or if theresultSetConcurrencty
differs fromResultSet.CONCUR_READ_ONLY
.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a new instance ofSPIPreparedStatement
.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- if theresultSetType
differs fromResultSet.TYPE_FORWARD_ONLY
, if theresultSetConcurrencty
differs fromResultSet.CONCUR_READ_ONLY
, or if the resultSetHoldability differs fromResultSet.CLOSE_CURSORS_AT_COMMIT
.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
Return of auto generated keys is not yet supported.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
Return of auto generated keys is not yet supported.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setSavepoint
public Savepoint setSavepoint() throws SQLException
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
public Savepoint setSavepoint(String name) throws SQLException
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
getVersionNumber
public int[] getVersionNumber() throws SQLException
Return the server version number as a three-elementint
array (of which the third may be null), as used in thegetDatabase...Version
methods ofDatabaseMetaData
.- Throws:
SQLException
-
getSQLType
public int getSQLType(String pgTypeName)
Convert a PostgreSQL type name to aTypes
integer, using theJDBC_TYPE_NAMES
/JDBC_TYPE_NUMBERS
arrays; used inDatabaseMetaData
andResultSetMetaData
.
-
getSQLType
public int getSQLType(Oid oid) throws SQLException
This returns theTypes
type for a PG type oid, by mapping it to a name usinggetPGType(org.postgresql.pljava.internal.Oid)
and then to the result viagetSQLType(String)
; used inResultSetMetaData
and five places inDatabaseMetaData
.This method is a bit goofy, as it first maps from Oid to type name, and then from name to JDBC type, all to accomplish the inverse of the JDBC type / Oid mapping that already exists in Oid.c, and so the mapping arrays in this file have to be updated in sync with that. Look into future consolidation....
- Parameters:
oid
- PostgreSQL type oid- Returns:
- the java.sql.Types type
- Throws:
SQLException
- if a database access error occurs
-
getPGType
public String getPGType(Oid oid) throws SQLException
Map the Oid of a PostgreSQL type to its name (specifically, thetypname
attribute ofpg_type
. Used inDatabaseMetaData
andResultSetMetaData
.- Throws:
SQLException
-
isValid
public boolean isValid(int timeout) throws SQLException
- Specified by:
isValid
in interfaceConnection
- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
setClientInfo
public void setClientInfo(String name, String value) throws SQLClientInfoException
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
setClientInfo
public void setClientInfo(Properties properties) throws SQLClientInfoException
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
getClientInfo
public String getClientInfo(String name) throws SQLException
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
getClientInfo
public Properties getClientInfo() throws SQLException
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
public SQLXML createSQLXML() throws SQLException
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
createStruct
public Struct createStruct(String typeName, Object[] attributes) throws SQLException
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
createArrayOf
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
- Specified by:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
createNClob
public NClob createNClob() throws SQLException
- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createBlob
public Blob createBlob() throws SQLException
- Specified by:
createBlob
in interfaceConnection
- Throws:
SQLException
-
createClob
public Clob createClob() throws SQLException
- Specified by:
createClob
in interfaceConnection
- Throws:
SQLException
-
abort
public void abort(Executor executor) throws SQLException
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
public int getNetworkTimeout() throws SQLException
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
getSchema
public String getSchema() throws SQLException
- Specified by:
getSchema
in interfaceConnection
- Throws:
SQLException
-
setSchema
public void setSchema(String schema) throws SQLException
- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-
-