Class 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
    • Field Detail

      • CALLABLE_STATEMENT_PATTERN

        private static final java.util.regex.Pattern CALLABLE_STATEMENT_PATTERN
      • 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
      • lowercaseTableNames

        private int lowercaseTableNames
      • readOnly

        private boolean readOnly
    • Constructor Detail

      • Connection

        public Connection​(Configuration conf,
                          ClosableLock lock,
                          Client client)
        Connection construction.
        Parameters:
        conf - configuration
        lock - thread safe locker
        client - 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 interface java.sql.Connection
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.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 - sql
        autoGeneratedKeys - auto generated key required
        resultSetType - result-set type
        resultSetConcurrency - concurrency
        useBinary - 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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • nativeSQL

        public java.lang.String nativeSQL​(java.lang.String sql)
                                   throws java.sql.SQLException
        Specified by:
        nativeSQL in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getAutoCommit

        public boolean getAutoCommit()
        Specified by:
        getAutoCommit in interface java.sql.Connection
      • setAutoCommit

        public void setAutoCommit​(boolean autoCommit)
                           throws java.sql.SQLException
        Specified by:
        setAutoCommit in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • commit

        public void commit()
                    throws java.sql.SQLException
        Specified by:
        commit in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • rollback

        public void rollback()
                      throws java.sql.SQLException
        Specified by:
        rollback in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • close

        public void close()
                   throws java.sql.SQLException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface java.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 interface java.sql.Connection
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface java.sql.Connection
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
                         throws java.sql.SQLException
        Specified by:
        setReadOnly in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getCatalog

        public java.lang.String getCatalog()
                                    throws java.sql.SQLException
        Specified by:
        getCatalog in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setCatalog

        public void setCatalog​(java.lang.String catalog)
                        throws java.sql.SQLException
        Specified by:
        setCatalog in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getSchema

        public java.lang.String getSchema()
                                   throws java.sql.SQLException
        Specified by:
        getSchema in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSchema

        public void setSchema​(java.lang.String schema)
                       throws java.sql.SQLException
        Specified by:
        setSchema in interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setTransactionIsolation

        public void setTransactionIsolation​(int level)
                                     throws java.sql.SQLException
        Specified by:
        setTransactionIsolation in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getWarnings

        public java.sql.SQLWarning getWarnings()
                                        throws java.sql.SQLException
        Specified by:
        getWarnings in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • clearWarnings

        public void clearWarnings()
        Specified by:
        clearWarnings in interface java.sql.Connection
      • createStatement

        public Statement createStatement​(int resultSetType,
                                         int resultSetConcurrency)
                                  throws java.sql.SQLException
        Specified by:
        createStatement in interface java.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 interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getTypeMap

        public java.util.Map<java.lang.String,​java.lang.Class<?>> getTypeMap()
        Specified by:
        getTypeMap in interface java.sql.Connection
      • setTypeMap

        public void setTypeMap​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                        throws java.sql.SQLException
        Specified by:
        setTypeMap in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getHoldability

        public int getHoldability()
        Specified by:
        getHoldability in interface java.sql.Connection
      • setHoldability

        public void setHoldability​(int holdability)
        Specified by:
        setHoldability in interface java.sql.Connection
      • setSavepoint

        public java.sql.Savepoint setSavepoint()
                                        throws java.sql.SQLException
        Specified by:
        setSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSavepoint

        public java.sql.Savepoint setSavepoint​(java.lang.String name)
                                        throws java.sql.SQLException
        Specified by:
        setSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • rollback

        public void rollback​(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
        Specified by:
        rollback in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • releaseSavepoint

        public void releaseSavepoint​(java.sql.Savepoint savepoint)
                              throws java.sql.SQLException
        Specified by:
        releaseSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • createStatement

        public Statement createStatement​(int resultSetType,
                                         int resultSetConcurrency,
                                         int resultSetHoldability)
                                  throws java.sql.SQLException
        Specified by:
        createStatement in interface java.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 interface java.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 interface java.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 interface java.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 interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • createClob

        public java.sql.Clob createClob()
        Specified by:
        createClob in interface java.sql.Connection
      • createBlob

        public java.sql.Blob createBlob()
        Specified by:
        createBlob in interface java.sql.Connection
      • createNClob

        public java.sql.NClob createNClob()
        Specified by:
        createNClob in interface java.sql.Connection
      • createSQLXML

        public java.sql.SQLXML createSQLXML()
                                     throws java.sql.SQLException
        Specified by:
        createSQLXML in interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setClientInfo

        public void setClientInfo​(java.lang.String name,
                                  java.lang.String value)
        Specified by:
        setClientInfo in interface java.sql.Connection
      • getClientInfo

        public java.lang.String getClientInfo​(java.lang.String name)
        Specified by:
        getClientInfo in interface java.sql.Connection
      • getClientInfo

        public java.util.Properties getClientInfo()
        Specified by:
        getClientInfo in interface java.sql.Connection
      • setClientInfo

        public void setClientInfo​(java.util.Properties properties)
        Specified by:
        setClientInfo in interface java.sql.Connection
      • createArrayOf

        public java.sql.Array createArrayOf​(java.lang.String typeName,
                                            java.lang.Object[] elements)
                                     throws java.sql.SQLException
        Specified by:
        createArrayOf in interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • abort

        public void abort​(java.util.concurrent.Executor executor)
                   throws java.sql.SQLException
        Specified by:
        abort in interface java.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 interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getNetworkTimeout

        public int getNetworkTimeout()
        Specified by:
        getNetworkTimeout in interface java.sql.Connection
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> iface)
                     throws java.sql.SQLException
        Specified by:
        unwrap in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • isWrapperFor

        public boolean isWrapperFor​(java.lang.Class<?> iface)
        Specified by:
        isWrapperFor in interface java.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