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

      • CALLABLE_STATEMENT_PATTERN

        private static final java.util.regex.Pattern CALLABLE_STATEMENT_PATTERN
      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
      • client

        private final Client client
      • clientInfo

        private final java.util.Properties clientInfo
      • lowercaseTableNames

        private int lowercaseTableNames
      • savepointId

        private final java.util.concurrent.atomic.AtomicInteger savepointId
      • readOnly

        private boolean readOnly
      • canUseServerTimeout

        private final boolean canUseServerTimeout
      • canUseServerMaxRows

        private final boolean canUseServerMaxRows
      • defaultFetchSize

        private final int defaultFetchSize
    • Constructor Detail

      • Connection

        public Connection​(Configuration conf,
                          java.util.concurrent.locks.ReentrantLock lock,
                          Client client)
    • Method Detail

      • 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
        Throws:
        java.sql.SQLException
      • 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()
      • 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
      • 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 Connection.Savepoint setSavepoint()
                                          throws java.sql.SQLException
        Specified by:
        setSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSavepoint

        public Connection.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
      • 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
      • getSchema

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

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

        public int getWaitTimeout()
      • getClient

        public Client getClient()
      • 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()
      • fireStatementClosed

        public void fireStatementClosed​(java.sql.PreparedStatement prep)