Class SQLiteBacked

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    AnnotationRepository

    public class SQLiteBacked
    extends java.lang.Object
    implements java.io.Closeable
    Provides a wrapper around a SQLite database. Intended to be extended by other classes which intend to leverage a SQLite database is some way.
    • Constructor Summary

      Constructors 
      Constructor Description
      SQLiteBacked​(java.io.File databaseFile)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void executeInsert​(java.lang.String sql, java.lang.Object... data)
      Executes an insert query against the SQLite database file
      void executeInsert​(java.lang.String sql, java.util.List<java.lang.Object> data)
      Executes an insert query against the SQLite database file
      java.lang.Long executeLongScalar​(java.lang.String sql)
      Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
      java.lang.Long executeLongScalar​(java.lang.String sql, java.lang.Object... data)
      Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
      java.lang.Long executeLongScalar​(java.lang.String sql, java.util.List<java.lang.Object> data)
      Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
      void executeQuery​(java.lang.String sql, java.util.List<java.lang.Object> data, java.util.function.Consumer<java.sql.ResultSet> resultConsumer)
      Executes a query which is expected to return row data, providing the result set to the provided callback.
      <T> T executeScalar​(java.lang.String sql, java.lang.Object... data)  
      java.lang.String executeStringScalar​(java.lang.String sql)
      Executes SQL which is expected to return a single string value.
      java.lang.String executeStringScalar​(java.lang.String sql, java.lang.Object... data)
      Executes SQL which is expected to return a single string value.
      java.lang.String executeStringScalar​(java.lang.String sql, java.util.List<java.lang.Object> data)
      Executes SQL which is expected to return a single string value.
      int executeUpdate​(java.lang.String sql)
      Executes an update query against the SQLite database file
      int executeUpdate​(java.lang.String sql, java.lang.Object... data)
      Executes an update query against the SQLite database file
      int executeUpdate​(java.lang.String sql, java.util.List<java.lang.Object> data)
      Executes an update query against the SQLite database file
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SQLiteBacked

        public SQLiteBacked​(java.io.File databaseFile)
    • Method Detail

      • executeUpdate

        public int executeUpdate​(java.lang.String sql,
                                 java.util.List<java.lang.Object> data)
                          throws java.sql.SQLException
        Executes an update query against the SQLite database file
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        Count of affected records
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeUpdate

        public int executeUpdate​(java.lang.String sql,
                                 java.lang.Object... data)
                          throws java.sql.SQLException
        Executes an update query against the SQLite database file
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        Count of affected records
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeUpdate

        public int executeUpdate​(java.lang.String sql)
                          throws java.sql.SQLException
        Executes an update query against the SQLite database file
        Parameters:
        sql - The SQL to execute
        Returns:
        either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeInsert

        public void executeInsert​(java.lang.String sql,
                                  java.util.List<java.lang.Object> data)
                           throws java.sql.SQLException
        Executes an insert query against the SQLite database file
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeInsert

        public void executeInsert​(java.lang.String sql,
                                  java.lang.Object... data)
                           throws java.sql.SQLException
        Executes an insert query against the SQLite database file
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeLongScalar

        public java.lang.Long executeLongScalar​(java.lang.String sql,
                                                java.lang.Object... data)
                                         throws java.sql.SQLException
        Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        The single long/int value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeLongScalar

        public java.lang.Long executeLongScalar​(java.lang.String sql,
                                                java.util.List<java.lang.Object> data)
                                         throws java.sql.SQLException
        Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        The single long/int value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeLongScalar

        public java.lang.Long executeLongScalar​(java.lang.String sql)
                                         throws java.sql.SQLException
        Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.
        Parameters:
        sql - The SQL to execute
        Returns:
        The single long/int value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeStringScalar

        public java.lang.String executeStringScalar​(java.lang.String sql,
                                                    java.lang.Object... data)
                                             throws java.sql.SQLException
        Executes SQL which is expected to return a single string value.
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        The single string value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeStringScalar

        public java.lang.String executeStringScalar​(java.lang.String sql,
                                                    java.util.List<java.lang.Object> data)
                                             throws java.sql.SQLException
        Executes SQL which is expected to return a single string value.
        Parameters:
        sql - The SQL to execute
        data - Optional list of associated data, can be null
        Returns:
        The single string value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeStringScalar

        public java.lang.String executeStringScalar​(java.lang.String sql)
                                             throws java.sql.SQLException
        Executes SQL which is expected to return a single string value.
        Parameters:
        sql - The SQL to execute
        Returns:
        The single string value returned by the provided SQL
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • executeScalar

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

        public void executeQuery​(java.lang.String sql,
                                 java.util.List<java.lang.Object> data,
                                 java.util.function.Consumer<java.sql.ResultSet> resultConsumer)
                          throws java.sql.SQLException
        Executes a query which is expected to return row data, providing the result set to the provided callback.
        Parameters:
        sql - The SQL query to execute
        data - Optional list of associated data, can be null
        resultConsumer - Callback which will be provided the result set. This is where you provide code to make use of the results.
        Throws:
        java.sql.SQLException - If the SQL bits throw an error
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException