public class JdbcConnection extends TraceObject implements Connection, JdbcConnectionBackwardsCompat
Represents a connection (session) to a database.
Thread safety: the connection is thread-safe, because access is synchronized. However, for compatibility with other databases, a connection should only be used in one thread at any time.
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, STATEMENT, trace, XA_DATA_SOURCE, XID
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
Constructor and Description |
---|
JdbcConnection(ConnectionInfo ci,
boolean useBaseDir)
INTERNAL
|
JdbcConnection(JdbcConnection clone)
INTERNAL
|
JdbcConnection(SessionInterface session,
String user,
String url)
INTERNAL
|
JdbcConnection(String url,
Properties info)
INTERNAL
|
Modifier and Type | Method and Description |
---|---|
void |
abort(Executor executor)
[Not supported]
|
protected void |
afterWriting()
INTERNAL.
|
protected void |
checkClosed()
INTERNAL.
|
protected void |
checkClosed(boolean write)
INTERNAL.
|
void |
clearWarnings()
Clears all warnings.
|
void |
close()
Closes this connection.
|
void |
commit()
Commits the current transaction.
|
Array |
createArrayOf(String typeName,
Object[] elements)
Create a new Array object.
|
Blob |
createBlob()
Create a new empty Blob object.
|
Value |
createBlob(InputStream x,
long length)
Create a Blob value from this input stream.
|
Clob |
createClob()
Create a new empty Clob object.
|
Value |
createClob(Reader x,
long length)
Create a Clob value from this reader.
|
NClob |
createNClob()
Create a new empty NClob object.
|
SQLXML |
createSQLXML()
[Not supported] Create a new empty SQLXML object.
|
Statement |
createStatement()
Creates a new statement.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
Creates a statement with the specified result set type and concurrency.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates a statement with the specified result set type, concurrency, and
holdability.
|
Struct |
createStruct(String typeName,
Object[] attributes)
[Not supported] Create a new empty Struct object.
|
boolean |
getAutoCommit()
Gets the current setting for auto commit.
|
String |
getCatalog()
Gets the current catalog name.
|
Properties |
getClientInfo()
Get the client properties.
|
String |
getClientInfo(String name)
Get a client property.
|
int |
getHoldability()
Returns the current result set holdability.
|
DatabaseMetaData |
getMetaData()
Gets the database meta data for this database.
|
int |
getNetworkTimeout()
[Not supported]
|
int |
getPowerOffCount()
INTERNAL
|
String |
getSchema()
Retrieves this current schema name for this connection.
|
SessionInterface |
getSession()
INTERNAL
|
int |
getTransactionIsolation()
Returns the current transaction isolation level.
|
Map<String,Class<?>> |
getTypeMap()
Gets the type map.
|
SQLWarning |
getWarnings()
Gets the first warning reported by calls on this object.
|
boolean |
isClosed()
Returns true if this connection has been closed.
|
boolean |
isReadOnly()
Returns true if the database is read-only.
|
boolean |
isValid(int timeout)
Returns true if this connection is still valid.
|
boolean |
isWrapperFor(Class<?> iface)
Checks if unwrap can return an object of this class.
|
String |
nativeSQL(String sql)
Translates a SQL statement into the database grammar.
|
CallableStatement |
prepareCall(String sql)
Creates a new callable statement.
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
Creates a callable statement with the specified result set type and
concurrency.
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates a callable statement with the specified result set type,
concurrency, and holdability.
|
PreparedStatement |
prepareStatement(String sql)
Creates a new prepared statement.
|
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys)
Creates a new prepared statement.
|
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes)
Creates a new prepared statement.
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Creates a prepared statement with the specified result set type and
concurrency.
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates a prepared statement with the specified result set type,
concurrency, and holdability.
|
PreparedStatement |
prepareStatement(String sql,
String[] columnNames)
Creates a new prepared statement.
|
void |
releaseSavepoint(Savepoint savepoint)
Releases a savepoint.
|
void |
rollback()
Rolls back the current transaction.
|
void |
rollback(Savepoint savepoint)
Rolls back to a savepoint.
|
void |
setAutoCommit(boolean autoCommit)
Switches auto commit on or off.
|
void |
setCatalog(String catalog)
Set the default catalog name.
|
void |
setClientInfo(Properties properties)
Set the client properties.
|
void |
setClientInfo(String name,
String value)
Set a client property.
|
void |
setExecutingStatement(Statement stat)
INTERNAL
|
void |
setHoldability(int holdability)
Changes the current result set holdability.
|
void |
setNetworkTimeout(Executor executor,
int milliseconds)
[Not supported]
|
void |
setPowerOffCount(int count)
INTERNAL
|
void |
setQueryTimeout(int seconds)
INTERNAL
|
void |
setReadOnly(boolean readOnly)
According to the JDBC specs, this setting is only a hint to the database
to enable optimizations - it does not cause writes to be prohibited.
|
Savepoint |
setSavepoint()
Creates a new unnamed savepoint.
|
Savepoint |
setSavepoint(String name)
Creates a new named savepoint.
|
void |
setSchema(String schema)
Sets the given schema name to access.
|
void |
setTraceLevel(int level)
INTERNAL
|
void |
setTransactionIsolation(int level)
Changes the current transaction isolation level.
|
void |
setTypeMap(Map<String,Class<?>> map)
[Partially supported] Sets the type map.
|
String |
toString()
INTERNAL
|
<T> T |
unwrap(Class<T> iface)
Return an object of this class if possible.
|
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
public JdbcConnection(String url, Properties info) throws SQLException
SQLException
public JdbcConnection(ConnectionInfo ci, boolean useBaseDir) throws SQLException
SQLException
public JdbcConnection(JdbcConnection clone)
public JdbcConnection(SessionInterface session, String user, String url)
public Statement createStatement() throws SQLException
createStatement
in interface Connection
SQLException
- if the connection is closedpublic Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
createStatement
in interface Connection
resultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)SQLException
- if the connection is closed or the result set type
or concurrency are not supportedpublic Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
createStatement
in interface Connection
resultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)resultSetHoldability
- the holdability (ResultSet.HOLD* / CLOSE*)SQLException
- if the connection is closed or the result set type,
concurrency, or holdability are not supportedpublic PreparedStatement prepareStatement(String sql) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementSQLException
- if the connection is closedpublic DatabaseMetaData getMetaData() throws SQLException
getMetaData
in interface Connection
SQLException
- if the connection is closedpublic SessionInterface getSession()
public void close() throws SQLException
close
in interface AutoCloseable
close
in interface Connection
SQLException
public void setAutoCommit(boolean autoCommit) throws SQLException
setAutoCommit
in interface Connection
autoCommit
- true for auto commit on, false for offSQLException
- if the connection is closedpublic boolean getAutoCommit() throws SQLException
getAutoCommit
in interface Connection
SQLException
- if the connection is closedpublic void commit() throws SQLException
commit
in interface Connection
SQLException
- if the connection is closedpublic void rollback() throws SQLException
rollback
in interface Connection
SQLException
- if the connection is closedpublic boolean isClosed() throws SQLException
isClosed
in interface Connection
SQLException
public String nativeSQL(String sql) throws SQLException
nativeSQL
in interface Connection
sql
- the SQL statement with or without JDBC escape sequencesSQLException
- if the connection is closedpublic void setReadOnly(boolean readOnly) throws SQLException
setReadOnly
in interface Connection
readOnly
- ignoredSQLException
- if the connection is closedpublic boolean isReadOnly() throws SQLException
isReadOnly
in interface Connection
SQLException
- if the connection is closedpublic void setCatalog(String catalog) throws SQLException
setCatalog
in interface Connection
catalog
- ignoredSQLException
- if the connection is closedpublic String getCatalog() throws SQLException
getCatalog
in interface Connection
SQLException
- if the connection is closedpublic SQLWarning getWarnings() throws SQLException
getWarnings
in interface Connection
SQLException
public void clearWarnings() throws SQLException
clearWarnings
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementresultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)SQLException
- if the connection is closed or the result set type
or concurrency are not supportedpublic void setTransactionIsolation(int level) throws SQLException
setTransactionIsolation
in interface Connection
level
- the new transaction isolation level:
Connection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED, or
Connection.TRANSACTION_SERIALIZABLESQLException
- if the connection is closed or the isolation level
is not supportedpublic void setQueryTimeout(int seconds) throws SQLException
SQLException
public int getTransactionIsolation() throws SQLException
getTransactionIsolation
in interface Connection
SQLException
- if the connection is closedpublic void setHoldability(int holdability) throws SQLException
setHoldability
in interface Connection
holdability
- ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMIT;SQLException
- if the connection is closed or the holdability is
not supportedpublic int getHoldability() throws SQLException
getHoldability
in interface Connection
SQLException
- if the connection is closedpublic Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap
in interface Connection
SQLException
- if the connection is closedpublic void setTypeMap(Map<String,Class<?>> map) throws SQLException
setTypeMap
in interface Connection
SQLException
public CallableStatement prepareCall(String sql) throws SQLException
prepareCall
in interface Connection
sql
- the SQL statementSQLException
- if the connection is closed or the statement is not
validpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareCall
in interface Connection
sql
- the SQL statementresultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)SQLException
- if the connection is closed or the result set type
or concurrency are not supportedpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareCall
in interface Connection
sql
- the SQL statementresultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)resultSetHoldability
- the holdability (ResultSet.HOLD* / CLOSE*)SQLException
- if the connection is closed or the result set type,
concurrency, or holdability are not supportedpublic Savepoint setSavepoint() throws SQLException
setSavepoint
in interface Connection
SQLException
public Savepoint setSavepoint(String name) throws SQLException
setSavepoint
in interface Connection
name
- the savepoint nameSQLException
public void rollback(Savepoint savepoint) throws SQLException
rollback
in interface Connection
savepoint
- the savepointSQLException
public void releaseSavepoint(Savepoint savepoint) throws SQLException
releaseSavepoint
in interface Connection
savepoint
- the savepoint to releaseSQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementresultSetType
- the result set type (ResultSet.TYPE_*)resultSetConcurrency
- the concurrency (ResultSet.CONCUR_*)resultSetHoldability
- the holdability (ResultSet.HOLD* / CLOSE*)SQLException
- if the connection is closed or the result set type,
concurrency, or holdability are not supportedpublic PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementautoGeneratedKeys
- Statement.RETURN_GENERATED_KEYS
if generated keys should
be available for retrieval, Statement.NO_GENERATED_KEYS
if
generated keys should not be availableSQLException
- if the connection is closedpublic PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementcolumnIndexes
- an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowSQLException
- if the connection is closedpublic PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
prepareStatement
in interface Connection
sql
- the SQL statementcolumnNames
- an array of column names indicating the columns with generated
keys that should be returned from the inserted rowSQLException
- if the connection is closedprotected void checkClosed()
DbException
- if the connection or session is closedprotected void checkClosed(boolean write)
write
- if the next operation is possibly writingDbException
- if the connection or session is closedprotected void afterWriting()
public int getPowerOffCount()
public void setPowerOffCount(int count)
public void setExecutingStatement(Statement stat)
public Clob createClob() throws SQLException
createClob
in interface Connection
SQLException
public Blob createBlob() throws SQLException
createBlob
in interface Connection
SQLException
public NClob createNClob() throws SQLException
createNClob
in interface Connection
SQLException
public SQLXML createSQLXML() throws SQLException
createSQLXML
in interface Connection
SQLException
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf
in interface Connection
typeName
- the type nameelements
- the valuesSQLException
public Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct
in interface Connection
SQLException
public boolean isValid(int timeout)
isValid
in interface Connection
timeout
- the number of seconds to wait for the database to respond
(ignored)public void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo
in interface Connection
name
- the name of the propertyvalue
- the valueSQLClientInfoException
public void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo
in interface Connection
properties
- the properties (ignored)SQLClientInfoException
public Properties getClientInfo() throws SQLException
getClientInfo
in interface Connection
SQLException
public String getClientInfo(String name) throws SQLException
getClientInfo
in interface Connection
name
- the client info nameSQLException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
iface
- the classSQLException
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
iface
- the classSQLException
public Value createClob(Reader x, long length)
x
- the readerlength
- the length (if smaller or equal than 0, all data until the
end of file is read)public Value createBlob(InputStream x, long length)
x
- the input streamlength
- the length (if smaller or equal than 0, all data until the
end of file is read)public void setSchema(String schema) throws SQLException
setSchema
in interface Connection
schema
- the schema nameSQLException
public String getSchema() throws SQLException
getSchema
in interface Connection
SQLException
public void abort(Executor executor)
abort
in interface Connection
executor
- the executor used by this methodpublic void setNetworkTimeout(Executor executor, int milliseconds)
setNetworkTimeout
in interface Connection
executor
- the executor used by this methodmilliseconds
- the TCP connection timeoutpublic int getNetworkTimeout()
getNetworkTimeout
in interface Connection
public void setTraceLevel(int level)
Copyright © 2020 JBoss by Red Hat. All rights reserved.