Class DbManager

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class DbManager
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Author:
    Loc Ha
    • Constructor Detail

      • DbManager

        public DbManager()
                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • DbManager

        public DbManager​(javax.sql.DataSource dataSource)
                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
    • Method Detail

      • getConnection

        public java.sql.Connection getConnection()
      • setParameter

        protected void setParameter​(StatementImpl stat,
                                    java.lang.String parameterName,
                                    java.lang.Object val,
                                    int sqlType)
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setParameters

        protected void setParameters​(StatementImpl stat,
                                     java.util.Map<java.lang.String,​java.lang.Object> params)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • insert

        public java.lang.Object insert​(Record record,
                                       Table table)
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • insertBatch

        public void insertBatch​(Record record,
                                Table table)
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • insert

        protected java.lang.Object insert​(Record record,
                                          Table table,
                                          boolean addBatch)
                                   throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • update

        public int update​(Record record,
                          Table table)
                   throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • updateBatch

        public void updateBatch​(Record record,
                                Table table)
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • update

        protected int update​(Record record,
                             Table table,
                             boolean addBatch)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • delete

        public int delete​(Record key,
                          Table table)
                   throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • deleteBatch

        public void deleteBatch​(Record key,
                                Table table)
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • delete

        protected int delete​(Record key,
                             Table table,
                             boolean addBatch)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getRecord

        public Record getRecord​(Record key,
                                Table table)
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • exists

        public boolean exists​(Record key,
                              Table table)
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public java.util.List<Record> executeList​(java.lang.String sql)
                                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public <T> java.util.List<Record> executeList​(java.lang.String pSql,
                                                      java.util.Map<java.lang.String,​java.lang.Object> params)
                                               throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeSingle

        public Record executeSingle​(java.lang.String sql)
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeSingle

        public Record executeSingle​(java.lang.String pSql,
                                    java.util.Map<java.lang.String,​java.lang.Object> params)
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String pSql,
                                 java.util.Map<java.lang.String,​java.lang.Object> params)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String sql,
                                                               ResultSetMapper<K> keyMapper,
                                                               ResultSetMapper<V> valueMapper)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String sql,
                                                               ResultSetMapper<K> keyMapper,
                                                               ResultSetMapper<V> valueMapper,
                                                               java.util.Map<K,​V> map)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String pSql,
                                                               java.util.Map<java.lang.String,​java.lang.Object> params,
                                                               ResultSetMapper<K> keyMapper,
                                                               ResultSetMapper<V> valueMapper)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String pSql,
                                                               java.util.Map<java.lang.String,​java.lang.Object> params,
                                                               ResultSetMapper<K> keyMapper,
                                                               ResultSetMapper<V> valueMapper,
                                                               java.util.Map<K,​V> map)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String sql,
                                                               java.lang.String keyColumn,
                                                               java.lang.String valueColumn)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String sql,
                                                               java.lang.String keyColumn,
                                                               java.lang.String valueColumn,
                                                               java.util.Map<K,​V> map)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String pSql,
                                                               java.util.Map<java.lang.String,​java.lang.Object> params,
                                                               java.lang.String keyColumn,
                                                               java.lang.String valueColumn)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeMap

        public <K,​V> java.util.Map<K,​V> executeMap​(java.lang.String pSql,
                                                               java.util.Map<java.lang.String,​java.lang.Object> params,
                                                               java.lang.String keyColumn,
                                                               java.lang.String valueColumn,
                                                               java.util.Map<K,​V> map)
                                                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public <T> java.util.List<T> executeList​(java.lang.String sql,
                                                 ResultSetMapper<T> mapper)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public <T> java.util.List<T> executeList​(java.lang.String sql,
                                                 ResultSetMapper<T> mapper,
                                                 java.util.List<T> list)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public <T> java.util.List<T> executeList​(java.lang.String pSql,
                                                 java.util.Map<java.lang.String,​java.lang.Object> params,
                                                 ResultSetMapper<T> mapper)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeList

        public <T> java.util.List<T> executeList​(java.lang.String pSql,
                                                 java.util.Map<java.lang.String,​java.lang.Object> params,
                                                 ResultSetMapper<T> mapper,
                                                 java.util.List<T> list)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeSingle

        public <T> T executeSingle​(java.lang.String sql,
                                   ResultSetMapper<T> mapper)
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeSingle

        public <T> T executeSingle​(java.lang.String pSql,
                                   java.util.Map<java.lang.String,​java.lang.Object> params,
                                   ResultSetMapper<T> mapper)
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeScalar

        public <T> T executeScalar​(java.lang.String sql)
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeScalar

        public <T> T executeScalar​(java.lang.String pSql,
                                   java.util.Map<java.lang.String,​java.lang.Object> params)
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeQuery

        public void executeQuery​(java.lang.String sql,
                                 ResultSetHandler handler)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • executeQuery

        public void executeQuery​(java.lang.String pSql,
                                 java.util.Map<java.lang.String,​java.lang.Object> params,
                                 ResultSetHandler handler)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • executeBatch

        public void executeBatch()
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setAutoCommit

        public void setAutoCommit​(boolean autoCommit)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getAutoCommit

        public boolean getAutoCommit()
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • commit

        public void commit()
                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • rollback

        public void rollback()
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • assertNotAutoCommit

        protected void assertNotAutoCommit()
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • assertNotClosed

        protected void assertNotClosed()
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • close

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

        public static javax.sql.DataSource getDataSource()
                                                  throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • setDataSource

        public static void setDataSource​(javax.sql.DataSource ds)