Class GeoPackageCoreConnection

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public abstract class GeoPackageCoreConnection
    extends Object
    implements Closeable
    GeoPackage Connection used to define common functionality within different connection types
    Author:
    osbornb
    • Field Detail

      • connectionSource

        protected final ConnectionSource connectionSource
        Connection source
    • Constructor Detail

      • GeoPackageCoreConnection

        protected GeoPackageCoreConnection​(ConnectionSource connectionSource)
        Constructor
        Parameters:
        connectionSource - connection source
      • GeoPackageCoreConnection

        protected GeoPackageCoreConnection​(GeoPackageCoreConnection connection)
        Copy Constructor
        Parameters:
        connection - connection
        Since:
        3.4.0
    • Method Detail

      • getConnectionSource

        public ConnectionSource getConnectionSource()
        Get a connection source
        Returns:
        connection source
      • execSQL

        public abstract void execSQL​(String sql)
        Execute the sql
        Parameters:
        sql - sql statement
      • beginTransaction

        public abstract void beginTransaction()
        Begin a transaction
        Since:
        3.3.0
      • endTransaction

        public void endTransaction()
        End a transaction successfully
        Since:
        3.3.0
      • failTransaction

        public void failTransaction()
        Fail a transaction
        Since:
        3.3.0
      • endTransaction

        public abstract void endTransaction​(boolean successful)
        End a transaction
        Parameters:
        successful - true if the transaction was successful, false to rollback or not commit
        Since:
        3.3.0
      • endAndBeginTransaction

        public void endAndBeginTransaction()
        End a transaction as successful and begin a new transaction
        Since:
        3.3.0
      • commit

        public abstract void commit()
        Commit changes on the connection
        Since:
        3.3.0
      • inTransaction

        public abstract boolean inTransaction()
        Determine if currently within a transaction
        Returns:
        true if in transaction
        Since:
        3.3.0
      • enableForeignKeys

        public boolean enableForeignKeys()
        If foreign keys is disabled and there are no foreign key violations, enables foreign key checks, else logs violations
        Returns:
        true if enabled or already enabled, false if foreign key violations and not enabled
        Since:
        3.3.0
      • foreignKeys

        public boolean foreignKeys()
        Query for the foreign keys value
        Returns:
        true if enabled, false if disabled
        Since:
        3.3.0
      • foreignKeys

        public boolean foreignKeys​(boolean on)
        Change the foreign keys state
        Parameters:
        on - true to turn on, false to turn off
        Returns:
        previous foreign keys value
        Since:
        3.3.0
      • foreignKeyCheck

        public List<List<Object>> foreignKeyCheck()
        Perform a foreign key check
        Returns:
        empty list if valid or violation errors, 4 column values for each violation. see SQLite PRAGMA foreign_key_check
        Since:
        3.3.0
      • foreignKeyCheck

        public List<List<Object>> foreignKeyCheck​(String tableName)
        Perform a foreign key check
        Parameters:
        tableName - table name
        Returns:
        empty list if valid or violation errors, 4 column values for each violation. see SQLite PRAGMA foreign_key_check
        Since:
        3.3.0
      • delete

        public abstract int delete​(String table,
                                   String whereClause,
                                   String[] whereArgs)
        Convenience method for deleting rows in the database.
        Parameters:
        table - table name
        whereClause - where clause
        whereArgs - where arguments
        Returns:
        rows deleted
      • count

        public int count​(String table)
        Get a count of results
        Parameters:
        table - table name
        Returns:
        count
        Since:
        4.0.0
      • count

        public int count​(String table,
                         String where,
                         String[] args)
        Get a count of results
        Parameters:
        table - table name
        where - where clause
        args - arguments
        Returns:
        count
      • count

        public int count​(String table,
                         String column)
        Get a count of results
        Parameters:
        table - table name
        column - column name
        Returns:
        count
        Since:
        4.0.0
      • count

        public int count​(String table,
                         boolean distinct,
                         String column)
        Get a count of results
        Parameters:
        table - table name
        distinct - distinct column flag
        column - column name
        Returns:
        count
        Since:
        4.0.0
      • count

        public int count​(String table,
                         String column,
                         String where,
                         String[] args)
        Get a count of results
        Parameters:
        table - table name
        column - column name
        where - where clause
        args - arguments
        Returns:
        count
        Since:
        4.0.0
      • count

        public int count​(String table,
                         boolean distinct,
                         String column,
                         String where,
                         String[] args)
        Get a count of results
        Parameters:
        table - table name
        distinct - distinct column flag
        column - column name
        where - where clause
        args - arguments
        Returns:
        count
        Since:
        4.0.0
      • min

        public <T> T min​(String table,
                         String column)
        Get the min result of the column
        Type Parameters:
        T - return type
        Parameters:
        table - table name
        column - column name
        Returns:
        min or null
        Since:
        4.0.0
      • min

        public <T> T min​(String table,
                         String column,
                         String where,
                         String[] args)
        Get the min result of the column
        Type Parameters:
        T - return type
        Parameters:
        table - table name
        column - column name
        where - where clause
        args - where arguments
        Returns:
        min or null
        Since:
        4.0.0
      • max

        public <T> T max​(String table,
                         String column)
        Get the max result of the column
        Type Parameters:
        T - return type
        Parameters:
        table - table name
        column - column name
        Returns:
        max or null
        Since:
        4.0.0
      • max

        public <T> T max​(String table,
                         String column,
                         String where,
                         String[] args)
        Get the max result of the column
        Type Parameters:
        T - return type
        Parameters:
        table - table name
        column - column name
        where - where clause
        args - where arguments
        Returns:
        max or null
        Since:
        4.0.0
      • aggregateFunction

        public <T> T aggregateFunction​(String function,
                                       String table,
                                       String column)
        Execute an aggregate function
        Type Parameters:
        T - return type
        Parameters:
        function - aggregate function
        table - table name
        column - column name
        Returns:
        value or null
        Since:
        4.0.0
      • aggregateFunction

        public <T> T aggregateFunction​(String function,
                                       String table,
                                       boolean distinct,
                                       String column)
        Execute an aggregate function
        Type Parameters:
        T - return type
        Parameters:
        function - aggregate function
        table - table name
        distinct - distinct column flag
        column - column name
        Returns:
        value or null
        Since:
        4.0.0
      • aggregateFunction

        public <T> T aggregateFunction​(String function,
                                       String table,
                                       String column,
                                       String where,
                                       String[] args)
        Execute an aggregate function
        Type Parameters:
        T - return type
        Parameters:
        function - aggregate function
        table - table name
        column - column name
        where - where clause
        args - arguments
        Returns:
        value or null
        Since:
        4.0.0
      • aggregateFunction

        public <T> T aggregateFunction​(String function,
                                       String table,
                                       boolean distinct,
                                       String column,
                                       String where,
                                       String[] args)
        Execute an aggregate function
        Type Parameters:
        T - return type
        Parameters:
        function - aggregate function
        table - table name
        distinct - distinct column flag
        column - column name
        where - where clause
        args - arguments
        Returns:
        value or null
        Since:
        4.0.0
      • tableExists

        public boolean tableExists​(String tableName)
        Check if the table exists
        Parameters:
        tableName - table name
        Returns:
        true if exists
      • viewExists

        public boolean viewExists​(String viewName)
        Check if the view exists
        Parameters:
        viewName - view name
        Returns:
        true if exists
        Since:
        4.0.0
      • tableOrViewExists

        public boolean tableOrViewExists​(String name)
        Check if a table or view exists with the name
        Parameters:
        name - table or view name
        Returns:
        true if exists
        Since:
        4.0.0
      • columnExists

        public boolean columnExists​(String tableName,
                                    String columnName)
        Check if the table column exists
        Parameters:
        tableName - table name
        columnName - column name
        Returns:
        true if column exists
        Since:
        1.1.8
      • addColumn

        public void addColumn​(String tableName,
                              String columnName,
                              String columnDef)
        Add a new column to the table
        Parameters:
        tableName - table name
        columnName - column name
        columnDef - column definition
        Since:
        1.1.8
      • querySingleResult

        public Object querySingleResult​(String sql,
                                        String[] args)
        Query the SQL for a single result object in the first column
        Parameters:
        sql - sql statement
        args - sql arguments
        Returns:
        single result object
        Since:
        3.1.0
      • querySingleTypedResult

        public <T> T querySingleTypedResult​(String sql,
                                            String[] args)
        Query the SQL for a single result typed object in the first column
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - sql arguments
        Returns:
        single result object
        Since:
        3.1.0
      • querySingleResult

        public Object querySingleResult​(String sql,
                                        String[] args,
                                        GeoPackageDataType dataType)
        Query the SQL for a single result object in the first column with the expected data type
        Parameters:
        sql - sql statement
        args - sql arguments
        dataType - GeoPackage data type
        Returns:
        single result object
        Since:
        3.1.0
      • querySingleTypedResult

        public <T> T querySingleTypedResult​(String sql,
                                            String[] args,
                                            GeoPackageDataType dataType)
        Query the SQL for a single result typed object in the first column with the expected data type
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - sql arguments
        dataType - GeoPackage data type
        Returns:
        single result object
        Since:
        3.1.0
      • querySingleResult

        public Object querySingleResult​(String sql,
                                        String[] args,
                                        int column)
        Query the SQL for a single result object
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        Returns:
        result, null if no result
        Since:
        3.1.0
      • querySingleTypedResult

        public <T> T querySingleTypedResult​(String sql,
                                            String[] args,
                                            int column)
        Query the SQL for a single result typed object
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        Returns:
        result, null if no result
        Since:
        3.1.0
      • querySingleResult

        public abstract Object querySingleResult​(String sql,
                                                 String[] args,
                                                 int column,
                                                 GeoPackageDataType dataType)
        Query the SQL for a single result object with the expected data type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        Returns:
        result, null if no result
        Since:
        3.1.0
      • querySingleTypedResult

        public <T> T querySingleTypedResult​(String sql,
                                            String[] args,
                                            int column,
                                            GeoPackageDataType dataType)
        Query the SQL for a single result typed object with the expected data type
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        Returns:
        result, null if no result
        Since:
        3.1.0
      • querySingleColumnResults

        public List<Object> querySingleColumnResults​(String sql,
                                                     String[] args)
        Query for values from the first column
        Parameters:
        sql - sql statement
        args - sql arguments
        Returns:
        single column values
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args)
        Query for values from the first column
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - sql arguments
        Returns:
        single column values
        Since:
        3.1.0
      • querySingleColumnResults

        public List<Object> querySingleColumnResults​(String sql,
                                                     String[] args,
                                                     GeoPackageDataType dataType)
        Query for values from the first column
        Parameters:
        sql - sql statement
        args - arguments
        dataType - GeoPackage data type
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args,
                                                         GeoPackageDataType dataType)
        Query for typed values from the first column
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        dataType - GeoPackage data type
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnResults

        public List<Object> querySingleColumnResults​(String sql,
                                                     String[] args,
                                                     int column)
        Query for values from a single column
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args,
                                                         int column)
        Query for typed values from a single column
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnResults

        public List<Object> querySingleColumnResults​(String sql,
                                                     String[] args,
                                                     int column,
                                                     GeoPackageDataType dataType)
        Query for values from a single column
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args,
                                                         int column,
                                                         GeoPackageDataType dataType)
        Query for typed values from a single column
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnResults

        public List<Object> querySingleColumnResults​(String sql,
                                                     String[] args,
                                                     int column,
                                                     Integer limit)
        Query for values from a single column up to the limit
        Parameters:
        sql - sql statement
        args - arguments
        limit - result row limit
        column - column index
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args,
                                                         int column,
                                                         Integer limit)
        Query for typed values from a single column up to the limit
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        limit - result row limit
        column - column index
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnResults

        public abstract List<Object> querySingleColumnResults​(String sql,
                                                              String[] args,
                                                              int column,
                                                              GeoPackageDataType dataType,
                                                              Integer limit)
        Query for values from a single column up to the limit
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        limit - result row limit
        Returns:
        single column results
        Since:
        3.1.0
      • querySingleColumnTypedResults

        public <T> List<T> querySingleColumnTypedResults​(String sql,
                                                         String[] args,
                                                         int column,
                                                         GeoPackageDataType dataType,
                                                         Integer limit)
        Query for typed values from a single column up to the limit
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        column - column index
        dataType - GeoPackage data type
        limit - result row limit
        Returns:
        single column results
        Since:
        3.1.0
      • queryResults

        public List<List<Object>> queryResults​(String sql,
                                               String[] args)
        Query for values
        Parameters:
        sql - sql statement
        args - arguments
        Returns:
        results
        Since:
        3.1.0
      • queryTypedResults

        public <T> List<List<T>> queryTypedResults​(String sql,
                                                   String[] args)
        Query for typed values
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        Returns:
        results
        Since:
        3.1.0
      • queryResults

        public List<List<Object>> queryResults​(String sql,
                                               String[] args,
                                               GeoPackageDataType[] dataTypes)
        Query for values
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        Returns:
        results
        Since:
        3.1.0
      • queryTypedResults

        public <T> List<List<T>> queryTypedResults​(String sql,
                                                   String[] args,
                                                   GeoPackageDataType[] dataTypes)
        Query for typed values
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        Returns:
        results
        Since:
        3.1.0
      • querySingleRowResults

        public List<Object> querySingleRowResults​(String sql,
                                                  String[] args)
        Query for values in a single (first) row
        Parameters:
        sql - sql statement
        args - arguments
        Returns:
        single row results
        Since:
        3.1.0
      • querySingleRowTypedResults

        public <T> List<T> querySingleRowTypedResults​(String sql,
                                                      String[] args)
        Query for typed values in a single (first) row
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        Returns:
        single row results
        Since:
        3.1.0
      • querySingleRowResults

        public List<Object> querySingleRowResults​(String sql,
                                                  String[] args,
                                                  GeoPackageDataType[] dataTypes)
        Query for values in a single (first) row
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        Returns:
        single row results
        Since:
        3.1.0
      • querySingleRowTypedResults

        public <T> List<T> querySingleRowTypedResults​(String sql,
                                                      String[] args,
                                                      GeoPackageDataType[] dataTypes)
        Query for typed values in a single (first) row
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        Returns:
        single row results
        Since:
        3.1.0
      • queryResults

        public List<List<Object>> queryResults​(String sql,
                                               String[] args,
                                               Integer limit)
        Query for values
        Parameters:
        sql - sql statement
        args - arguments
        limit - result row limit
        Returns:
        results
        Since:
        3.1.0
      • queryTypedResults

        public <T> List<List<T>> queryTypedResults​(String sql,
                                                   String[] args,
                                                   Integer limit)
        Query for typed values
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        limit - result row limit
        Returns:
        results
        Since:
        3.1.0
      • queryResults

        public abstract List<List<Object>> queryResults​(String sql,
                                                        String[] args,
                                                        GeoPackageDataType[] dataTypes,
                                                        Integer limit)
        Query for values up to the limit
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        limit - result row limit
        Returns:
        results
        Since:
        3.1.0
      • queryTypedResults

        public <T> List<List<T>> queryTypedResults​(String sql,
                                                   String[] args,
                                                   GeoPackageDataType[] dataTypes,
                                                   Integer limit)
        Query for typed values up to the limit
        Type Parameters:
        T - result value type
        Parameters:
        sql - sql statement
        args - arguments
        dataTypes - column data types
        limit - result row limit
        Returns:
        results
        Since:
        3.1.0
      • setApplicationId

        public void setApplicationId()
        Set the GeoPackage application id
      • setApplicationId

        public void setApplicationId​(String applicationId)
        Set the GeoPackage application id
        Parameters:
        applicationId - application id
        Since:
        1.2.1
      • getApplicationId

        public String getApplicationId()
        Get the application id
        Returns:
        application id
        Since:
        1.2.1
      • getApplicationIdInteger

        public Integer getApplicationIdInteger()
        Get the application id integer
        Returns:
        application id integer
        Since:
        4.0.0
      • getApplicationIdHex

        public String getApplicationIdHex()
        Get the application id as a hex string prefixed with 0x
        Returns:
        application id hex string
        Since:
        4.0.0
      • getApplicationId

        public static String getApplicationId​(Integer applicationId)
        Get the application id string value for the application id integer
        Parameters:
        applicationId - application id integer
        Returns:
        application id
        Since:
        4.0.0
      • setUserVersion

        public void setUserVersion()
        Set the GeoPackage user version
        Since:
        1.2.1
      • setUserVersion

        public void setUserVersion​(int userVersion)
        Set the user version
        Parameters:
        userVersion - user version
        Since:
        1.2.1
      • getUserVersion

        public Integer getUserVersion()
        Get the user version
        Returns:
        user version
        Since:
        1.2.1
      • getUserVersionMajor

        public Integer getUserVersionMajor()
        Get the user version major
        Returns:
        user version major
        Since:
        4.0.0
      • getUserVersionMinor

        public Integer getUserVersionMinor()
        Get the user version minor
        Returns:
        user version minor
        Since:
        4.0.0
      • getUserVersionPatch

        public Integer getUserVersionPatch()
        Get the user version patch
        Returns:
        user version patch
        Since:
        4.0.0