Package org.mariadb.jdbc
Class Connection
- java.lang.Object
-
- org.mariadb.jdbc.Connection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Connection
,java.sql.Wrapper
public class Connection extends java.lang.Object implements java.sql.Connection
Public Connection class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Connection.MariaDbSavepoint
Internal Savepoint implementation
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
CALLABLE_STATEMENT_PATTERN
private boolean
canCachePrepStmts
private boolean
canUseServerMaxRows
private boolean
canUseServerTimeout
private Client
client
private java.util.Properties
clientInfo
private Configuration
conf
private int
defaultFetchSize
private ExceptionFactory
exceptionFactory
private boolean
forceTransactionEnd
private ClosableLock
lock
private int
lowercaseTableNames
private MariaDbPoolConnection
poolConnection
private QueryTimeoutHandler
queryTimeoutHandler
private boolean
readOnly
private java.util.concurrent.atomic.AtomicInteger
savepointId
-
Constructor Summary
Constructors Constructor Description Connection(Configuration conf, ClosableLock lock, Client client)
Connection construction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
__test_host()
for _TEST_ onlyvoid
abort(java.util.concurrent.Executor executor)
void
cancelCurrentQuery()
Cancels the current query - clones the current protocol and executes a query using the new connection.private void
checkNotClosed()
void
clearWarnings()
void
close()
void
commit()
java.sql.Array
createArrayOf(java.lang.String typeName, java.lang.Object elements)
java.sql.Array
createArrayOf(java.lang.String typeName, java.lang.Object[] elements)
java.sql.Blob
createBlob()
java.sql.Clob
createClob()
java.sql.NClob
createNClob()
java.sql.SQLXML
createSQLXML()
Statement
createStatement()
Statement
createStatement(int resultSetType, int resultSetConcurrency)
Statement
createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
java.sql.Struct
createStruct(java.lang.String typeName, java.lang.Object[] attributes)
void
fireStatementClosed(java.sql.PreparedStatement prep)
Fire event to indicate to StatementEventListeners registered on the connection that a PreparedStatement is closed.boolean
getAutoCommit()
java.lang.String
getCatalog()
Client
getClient()
Associate connection clientjava.util.Properties
getClientInfo()
java.lang.String
getClientInfo(java.lang.String name)
Context
getContext()
Connection context.private java.lang.String
getDatabase()
protected ExceptionFactory
getExceptionFactory()
Get connection exception factoryint
getHoldability()
protected ClosableLock
getLock()
Internal : retrieve internal ClosableLockint
getLowercaseTableNames()
Are table case-sensitive or not .DatabaseMetaData
getMetaData()
int
getNetworkTimeout()
java.lang.String
getSchema()
long
getThreadId()
Current server thread id.int
getTransactionIsolation()
java.util.Map<java.lang.String,java.lang.Class<?>>
getTypeMap()
java.sql.SQLWarning
getWarnings()
QueryTimeoutHandler
handleTimeout(int queryTimeout)
Return a QueryTimeoutHandler for old server that don't support Statement timeout.boolean
isClosed()
boolean
isReadOnly()
boolean
isValid(int timeout)
boolean
isWrapperFor(java.lang.Class<?> iface)
java.lang.String
nativeSQL(java.lang.String sql)
java.sql.CallableStatement
prepareCall(java.lang.String sql)
java.sql.CallableStatement
prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
java.sql.CallableStatement
prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
java.sql.PreparedStatement
prepareInternal(java.lang.String sql, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, boolean useBinary)
Prepare statement creationjava.sql.PreparedStatement
prepareStatement(java.lang.String sql)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int autoGeneratedKeys)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int[] columnIndexes)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
void
releaseSavepoint(java.sql.Savepoint savepoint)
void
reset()
Reset connection set has it was after creating a "fresh" new connection.void
rollback()
void
rollback(java.sql.Savepoint savepoint)
void
setAutoCommit(boolean autoCommit)
void
setCatalog(java.lang.String catalog)
void
setClientInfo(java.lang.String name, java.lang.String value)
void
setClientInfo(java.util.Properties properties)
private void
setDatabase(java.lang.String database)
void
setHoldability(int holdability)
void
setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds)
void
setPoolConnection(MariaDbPoolConnection poolConnection)
Internal method.void
setReadOnly(boolean readOnly)
java.sql.Savepoint
setSavepoint()
java.sql.Savepoint
setSavepoint(java.lang.String name)
void
setSchema(java.lang.String schema)
void
setTransactionIsolation(int level)
void
setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
<T> T
unwrap(java.lang.Class<T> iface)
-
-
-
Field Detail
-
CALLABLE_STATEMENT_PATTERN
private static final java.util.regex.Pattern CALLABLE_STATEMENT_PATTERN
-
lock
private final ClosableLock lock
-
conf
private final Configuration conf
-
client
private final Client client
-
clientInfo
private final java.util.Properties clientInfo
-
savepointId
private final java.util.concurrent.atomic.AtomicInteger savepointId
-
canUseServerTimeout
private final boolean canUseServerTimeout
-
canCachePrepStmts
private final boolean canCachePrepStmts
-
canUseServerMaxRows
private final boolean canUseServerMaxRows
-
defaultFetchSize
private final int defaultFetchSize
-
forceTransactionEnd
private final boolean forceTransactionEnd
-
exceptionFactory
private ExceptionFactory exceptionFactory
-
lowercaseTableNames
private int lowercaseTableNames
-
readOnly
private boolean readOnly
-
poolConnection
private MariaDbPoolConnection poolConnection
-
queryTimeoutHandler
private QueryTimeoutHandler queryTimeoutHandler
-
-
Constructor Detail
-
Connection
public Connection(Configuration conf, ClosableLock lock, Client client)
Connection construction.- Parameters:
conf
- configurationlock
- thread safe lockerclient
- client object
-
-
Method Detail
-
setPoolConnection
public void setPoolConnection(MariaDbPoolConnection poolConnection)
Internal method. Indicate that connection is created from internal pool- Parameters:
poolConnection
- PoolConnection
-
cancelCurrentQuery
public void cancelCurrentQuery() throws java.sql.SQLException
Cancels the current query - clones the current protocol and executes a query using the new connection.- Throws:
java.sql.SQLException
- never thrown
-
createStatement
public Statement createStatement()
- Specified by:
createStatement
in interfacejava.sql.Connection
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareInternal
public java.sql.PreparedStatement prepareInternal(java.lang.String sql, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, boolean useBinary) throws java.sql.SQLException
Prepare statement creation- Parameters:
sql
- sqlautoGeneratedKeys
- auto generated key requiredresultSetType
- result-set typeresultSetConcurrency
- concurrencyuseBinary
- use server prepare statement- Returns:
- prepared statement
- Throws:
java.sql.SQLException
- if Prepare fails
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
- Specified by:
prepareCall
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
nativeSQL
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLException
- Specified by:
nativeSQL
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getAutoCommit
public boolean getAutoCommit()
- Specified by:
getAutoCommit
in interfacejava.sql.Connection
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
- Specified by:
setAutoCommit
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
commit
public void commit() throws java.sql.SQLException
- Specified by:
commit
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
rollback
public void rollback() throws java.sql.SQLException
- Specified by:
rollback
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfacejava.sql.Connection
-
getContext
public Context getContext()
Connection context.- Returns:
- connection context.
-
getLowercaseTableNames
public int getLowercaseTableNames() throws java.sql.SQLException
Are table case-sensitive or not . Default Value: 0 (Unix), 1 (Windows), 2 (Mac OS X). If set to 0 (the default on Unix-based systems), table names and aliases and database names are compared in a case-sensitive manner. If set to 1 (the default on Windows), names are stored in lowercase and not compared in a case-sensitive manner. If set to 2 (the default on Mac OS X), names are stored as declared, but compared in lowercase.- Returns:
- int value.
- Throws:
java.sql.SQLException
- if a connection error occur
-
getMetaData
public DatabaseMetaData getMetaData()
- Specified by:
getMetaData
in interfacejava.sql.Connection
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfacejava.sql.Connection
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException
- Specified by:
setReadOnly
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getCatalog
public java.lang.String getCatalog() throws java.sql.SQLException
- Specified by:
getCatalog
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setCatalog
public void setCatalog(java.lang.String catalog) throws java.sql.SQLException
- Specified by:
setCatalog
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getSchema
public java.lang.String getSchema() throws java.sql.SQLException
- Specified by:
getSchema
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setSchema
public void setSchema(java.lang.String schema) throws java.sql.SQLException
- Specified by:
setSchema
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getDatabase
private java.lang.String getDatabase() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setDatabase
private void setDatabase(java.lang.String database) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getTransactionIsolation
public int getTransactionIsolation() throws java.sql.SQLException
- Specified by:
getTransactionIsolation
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws java.sql.SQLException
- Specified by:
setTransactionIsolation
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
- Specified by:
getWarnings
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings()
- Specified by:
clearWarnings
in interfacejava.sql.Connection
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Specified by:
createStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Specified by:
prepareCall
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getTypeMap
public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
- Specified by:
getTypeMap
in interfacejava.sql.Connection
-
setTypeMap
public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException
- Specified by:
setTypeMap
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getHoldability
public int getHoldability()
- Specified by:
getHoldability
in interfacejava.sql.Connection
-
setHoldability
public void setHoldability(int holdability)
- Specified by:
setHoldability
in interfacejava.sql.Connection
-
setSavepoint
public java.sql.Savepoint setSavepoint() throws java.sql.SQLException
- Specified by:
setSavepoint
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setSavepoint
public java.sql.Savepoint setSavepoint(java.lang.String name) throws java.sql.SQLException
- Specified by:
setSavepoint
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
rollback
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException
- Specified by:
rollback
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
releaseSavepoint
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException
- Specified by:
releaseSavepoint
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Specified by:
createStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Specified by:
prepareCall
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
createClob
public java.sql.Clob createClob()
- Specified by:
createClob
in interfacejava.sql.Connection
-
createBlob
public java.sql.Blob createBlob()
- Specified by:
createBlob
in interfacejava.sql.Connection
-
createNClob
public java.sql.NClob createNClob()
- Specified by:
createNClob
in interfacejava.sql.Connection
-
createSQLXML
public java.sql.SQLXML createSQLXML() throws java.sql.SQLException
- Specified by:
createSQLXML
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
checkNotClosed
private void checkNotClosed() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
isValid
public boolean isValid(int timeout) throws java.sql.SQLException
- Specified by:
isValid
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setClientInfo
public void setClientInfo(java.lang.String name, java.lang.String value)
- Specified by:
setClientInfo
in interfacejava.sql.Connection
-
getClientInfo
public java.lang.String getClientInfo(java.lang.String name)
- Specified by:
getClientInfo
in interfacejava.sql.Connection
-
getClientInfo
public java.util.Properties getClientInfo()
- Specified by:
getClientInfo
in interfacejava.sql.Connection
-
setClientInfo
public void setClientInfo(java.util.Properties properties)
- Specified by:
setClientInfo
in interfacejava.sql.Connection
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLException
- Specified by:
createArrayOf
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object elements) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
createStruct
public java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes) throws java.sql.SQLException
- Specified by:
createStruct
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException
- Specified by:
abort
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
setNetworkTimeout
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds) throws java.sql.SQLException
- Specified by:
setNetworkTimeout
in interfacejava.sql.Connection
- Throws:
java.sql.SQLException
-
getNetworkTimeout
public int getNetworkTimeout()
- Specified by:
getNetworkTimeout
in interfacejava.sql.Connection
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface)
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
-
getClient
public Client getClient()
Associate connection client- Returns:
- connection client
-
reset
public void reset() throws java.sql.SQLException
Reset connection set has it was after creating a "fresh" new connection. defaultTransactionIsolation must have been initialized.BUT : - session variable state are reset only if option useResetConnection is set and - if using the option "useServerPrepStmts", PREPARE statement are still prepared
- Throws:
java.sql.SQLException
- if resetting operation failed
-
getThreadId
public long getThreadId()
Current server thread id.- Returns:
- current server thread id
-
fireStatementClosed
public void fireStatementClosed(java.sql.PreparedStatement prep)
Fire event to indicate to StatementEventListeners registered on the connection that a PreparedStatement is closed.- Parameters:
prep
- prepare statement closing
-
getExceptionFactory
protected ExceptionFactory getExceptionFactory()
Get connection exception factory- Returns:
- connection exception factory
-
handleTimeout
public QueryTimeoutHandler handleTimeout(int queryTimeout)
Return a QueryTimeoutHandler for old server that don't support Statement timeout.- Parameters:
queryTimeout
- query timeout- Returns:
- a query timeout handler
-
getLock
protected ClosableLock getLock()
Internal : retrieve internal ClosableLock- Returns:
- ClosableLock
-
__test_host
public java.lang.String __test_host()
for _TEST_ only- Returns:
- current host
-
-