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.ConnectionPublic Connection class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classConnection.MariaDbSavepointInternal Savepoint implementation
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternCALLABLE_STATEMENT_PATTERNprivate booleancanCachePrepStmtsprivate booleancanUseServerMaxRowsprivate booleancanUseServerTimeoutprivate Clientclientprivate java.util.PropertiesclientInfoprivate Configurationconfprivate intdefaultFetchSizeprivate ExceptionFactoryexceptionFactoryprivate booleanforceTransactionEndprivate ClosableLocklockprivate intlowercaseTableNamesprivate MariaDbPoolConnectionpoolConnectionprivate QueryTimeoutHandlerqueryTimeoutHandlerprivate booleanreadOnlyprivate java.util.concurrent.atomic.AtomicIntegersavepointId
-
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_ onlyvoidabort(java.util.concurrent.Executor executor)voidcancelCurrentQuery()Cancels the current query - clones the current protocol and executes a query using the new connection.private voidcheckNotClosed()voidclearWarnings()voidclose()voidcommit()java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object elements)java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object[] elements)java.sql.BlobcreateBlob()java.sql.ClobcreateClob()java.sql.NClobcreateNClob()java.sql.SQLXMLcreateSQLXML()StatementcreateStatement()StatementcreateStatement(int resultSetType, int resultSetConcurrency)StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.StructcreateStruct(java.lang.String typeName, java.lang.Object[] attributes)voidfireStatementClosed(java.sql.PreparedStatement prep)Fire event to indicate to StatementEventListeners registered on the connection that a PreparedStatement is closed.booleangetAutoCommit()java.lang.StringgetCatalog()ClientgetClient()Associate connection clientjava.util.PropertiesgetClientInfo()java.lang.StringgetClientInfo(java.lang.String name)ContextgetContext()Connection context.private java.lang.StringgetDatabase()protected ExceptionFactorygetExceptionFactory()Get connection exception factoryintgetHoldability()protected ClosableLockgetLock()Internal : retrieve internal ClosableLockintgetLowercaseTableNames()Are table case-sensitive or not .DatabaseMetaDatagetMetaData()intgetNetworkTimeout()java.lang.StringgetSchema()longgetThreadId()Current server thread id.intgetTransactionIsolation()java.util.Map<java.lang.String,java.lang.Class<?>>getTypeMap()java.sql.SQLWarninggetWarnings()QueryTimeoutHandlerhandleTimeout(int queryTimeout)Return a QueryTimeoutHandler for old server that don't support Statement timeout.booleanisClosed()booleanisReadOnly()booleanisValid(int timeout)booleanisWrapperFor(java.lang.Class<?> iface)java.lang.StringnativeSQL(java.lang.String sql)java.sql.CallableStatementprepareCall(java.lang.String sql)java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareInternal(java.lang.String sql, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, boolean useBinary)Prepare statement creationjava.sql.PreparedStatementprepareStatement(java.lang.String sql)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)voidreleaseSavepoint(java.sql.Savepoint savepoint)voidreset()Reset connection set has it was after creating a "fresh" new connection.voidrollback()voidrollback(java.sql.Savepoint savepoint)voidsetAutoCommit(boolean autoCommit)voidsetCatalog(java.lang.String catalog)voidsetClientInfo(java.lang.String name, java.lang.String value)voidsetClientInfo(java.util.Properties properties)private voidsetDatabase(java.lang.String database)voidsetHoldability(int holdability)voidsetNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds)voidsetPoolConnection(MariaDbPoolConnection poolConnection)Internal method.voidsetReadOnly(boolean readOnly)java.sql.SavepointsetSavepoint()java.sql.SavepointsetSavepoint(java.lang.String name)voidsetSchema(java.lang.String schema)voidsetTransactionIsolation(int level)voidsetTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)<T> Tunwrap(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.SQLExceptionCancels 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:
createStatementin interfacejava.sql.Connection
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException- Specified by:
prepareStatementin 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.SQLExceptionPrepare 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:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
nativeSQL
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLException- Specified by:
nativeSQLin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getAutoCommit
public boolean getAutoCommit()
- Specified by:
getAutoCommitin interfacejava.sql.Connection
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException- Specified by:
setAutoCommitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
commit
public void commit() throws java.sql.SQLException- Specified by:
commitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
rollback
public void rollback() throws java.sql.SQLException- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfacejava.sql.Connection
-
getContext
public Context getContext()
Connection context.- Returns:
- connection context.
-
getLowercaseTableNames
public int getLowercaseTableNames() throws java.sql.SQLExceptionAre 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:
getMetaDatain interfacejava.sql.Connection
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfacejava.sql.Connection
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException- Specified by:
setReadOnlyin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getCatalog
public java.lang.String getCatalog() throws java.sql.SQLException- Specified by:
getCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setCatalog
public void setCatalog(java.lang.String catalog) throws java.sql.SQLException- Specified by:
setCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getSchema
public java.lang.String getSchema() throws java.sql.SQLException- Specified by:
getSchemain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSchema
public void setSchema(java.lang.String schema) throws java.sql.SQLException- Specified by:
setSchemain 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:
getTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws java.sql.SQLException- Specified by:
setTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException- Specified by:
getWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings()
- Specified by:
clearWarningsin interfacejava.sql.Connection
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Specified by:
createStatementin 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:
prepareStatementin 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:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTypeMap
public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
- Specified by:
getTypeMapin interfacejava.sql.Connection
-
setTypeMap
public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException- Specified by:
setTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getHoldability
public int getHoldability()
- Specified by:
getHoldabilityin interfacejava.sql.Connection
-
setHoldability
public void setHoldability(int holdability)
- Specified by:
setHoldabilityin interfacejava.sql.Connection
-
setSavepoint
public java.sql.Savepoint setSavepoint() throws java.sql.SQLException- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSavepoint
public java.sql.Savepoint setSavepoint(java.lang.String name) throws java.sql.SQLException- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
rollback
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
releaseSavepoint
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException- Specified by:
releaseSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Specified by:
createStatementin 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:
prepareStatementin 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:
prepareCallin 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:
prepareStatementin 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:
prepareStatementin 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:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createClob
public java.sql.Clob createClob()
- Specified by:
createClobin interfacejava.sql.Connection
-
createBlob
public java.sql.Blob createBlob()
- Specified by:
createBlobin interfacejava.sql.Connection
-
createNClob
public java.sql.NClob createNClob()
- Specified by:
createNClobin interfacejava.sql.Connection
-
createSQLXML
public java.sql.SQLXML createSQLXML() throws java.sql.SQLException- Specified by:
createSQLXMLin 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:
isValidin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setClientInfo
public void setClientInfo(java.lang.String name, java.lang.String value)- Specified by:
setClientInfoin interfacejava.sql.Connection
-
getClientInfo
public java.lang.String getClientInfo(java.lang.String name)
- Specified by:
getClientInfoin interfacejava.sql.Connection
-
getClientInfo
public java.util.Properties getClientInfo()
- Specified by:
getClientInfoin interfacejava.sql.Connection
-
setClientInfo
public void setClientInfo(java.util.Properties properties)
- Specified by:
setClientInfoin interfacejava.sql.Connection
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLException- Specified by:
createArrayOfin 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:
createStructin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException- Specified by:
abortin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setNetworkTimeout
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds) throws java.sql.SQLException- Specified by:
setNetworkTimeoutin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getNetworkTimeout
public int getNetworkTimeout()
- Specified by:
getNetworkTimeoutin interfacejava.sql.Connection
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface)
- Specified by:
isWrapperForin interfacejava.sql.Wrapper
-
getClient
public Client getClient()
Associate connection client- Returns:
- connection client
-
reset
public void reset() throws java.sql.SQLExceptionReset 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
-
-