java.lang.Object
org.postgresql.pljava.jdbc.SPIConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
Provides access to the current connection (session) the Java stored
procedure is running in. It is returned from the driver manager
with
DriverManager.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
FieldsFields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
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.createArrayOf
(String typeName, Object[] elements) Creates a new instance ofSPIStatement
.createStatement
(int resultSetType, int resultSetConcurrency) Creates a new instance ofSPIStatement
.createStatement
(int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a new instance ofSPIStatement
.createStruct
(String typeName, Object[] attributes) boolean
It is assumed that an SPI call is under transaction control.Returns the database in which we are running.getClientInfo
(String name) static Connection
Returns a default connection instance.int
ReturnsResultSet.CLOSE_CURSORS_AT_COMMIT
.Retrieves an instance ofSPIDatabaseMetaData
representing thisConnection
object.int
Map the Oid of a PostgreSQL type to its name (specifically, thetypname
attribute ofpg_type
.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
Returnsnull
.int[]
Return the server version number as a three-elementint
array (of which the third may be null), as used in thegetDatabase...Version
methods ofDatabaseMetaData
.Warnings are not yet supported.boolean
isClosed()
Will always return false.boolean
Returnsfalse
.boolean
isValid
(int timeout) boolean
isWrapperFor
(Class<?> iface) Parse the JDBC SQL into PostgreSQL.prepareCall
(String sql) Procedure calls are not yet implemented.prepareCall
(String sql, int resultSetType, int resultSetConcurrency) Procedure calls are not yet implemented.prepareCall
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Procedure calls are not yet implemented.prepareStatement
(String sql) Creates a new instance ofSPIPreparedStatement
.prepareStatement
(String sql, int autoGeneratedKeys) Return of auto generated keys is not yet supported.prepareStatement
(String sql, int[] columnIndexes) Return of auto generated keys is not yet supported.prepareStatement
(String sql, int resultSetType, int resultSetConcurrency) Creates a new instance ofSPIPreparedStatement
.prepareStatement
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a new instance ofSPIPreparedStatement
.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
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.setSavepoint
(String name) void
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
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 Details
-
JDBC_TYPE_NAMES
-
JDBC_TYPE_NUMBERS
public static final int[] JDBC_TYPE_NUMBERS
-
-
Constructor Details
-
SPIConnection
public SPIConnection()
-
-
Method Details
-
getDefault
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
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
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
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
Change of holdability is not supported.- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setTransactionIsolation
Change of transaction isolation level is not supported.- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setAutoCommit
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
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
Returns the database in which we are running.- Specified by:
getCatalog
in interfaceConnection
- Throws:
SQLException
-
setCatalog
The catalog name cannot be set.- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
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
Warnings are not yet supported.- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
releaseSavepoint
- Specified by:
releaseSavepoint
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
createStatement
Creates a new instance ofSPIStatement
.- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
createStatement
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
Returnsnull
. Type map is not yet imlemented.- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
Type map is not yet implemented.- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
nativeSQL
Parse the JDBC SQL into PostgreSQL.- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
nativeSQL
-
prepareCall
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
Creates a new instance ofSPIPreparedStatement
.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
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
Return of auto generated keys is not yet supported.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
prepareStatement
Return of auto generated keys is not yet supported.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
- indicating that this feature is not supported.
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in interfaceConnection
- Throws:
SQLException
-
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
.- Throws:
SQLException
-
getSQLType
Convert a PostgreSQL type name to aTypes
integer, using theJDBC_TYPE_NAMES
/JDBC_TYPE_NUMBERS
arrays; used inDatabaseMetaData
andResultSetMetaData
. -
getSQLType
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
Map the Oid of a PostgreSQL type to its name (specifically, thetypname
attribute ofpg_type
. Used inDatabaseMetaData
andResultSetMetaData
.- Throws:
SQLException
-
isValid
- Specified by:
isValid
in interfaceConnection
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
createNClob
- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createBlob
- Specified by:
createBlob
in interfaceConnection
- Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Throws:
SQLException
-
setSchema
- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-