Class SQLiteDB<T>

  • Type Parameters:
    T - Object Type

    public abstract class SQLiteDB<T>
    extends Object
    Class for Sqlite Database Connections
    • Field Detail

      • logger

        protected org.slf4j.Logger logger
        Logger for this class
      • databaseFile

        protected final String databaseFile
        Database File
      • tableName

        protected final String tableName
        Table Name
    • Constructor Detail

      • SQLiteDB

        public SQLiteDB​(String databaseFile,
                        String tableName,
                        boolean backupDatabaseOnStart,
                        boolean defragDatabaseOnStart,
                        long defragMinFileSize)
        Constructor
        Parameters:
        databaseFile - Path to the database File
        tableName - Table Name
        backupDatabaseOnStart - True if database should be backed up on start, false otherwise
        defragDatabaseOnStart - True if database should be deframented on start, false otherwise
        defragMinFileSize - Minimum filesize for decision if database is actually defragmented or not
    • Method Detail

      • getDatabaseFile

        public String getDatabaseFile()
        Returns the databaseFile
        Returns:
        databaseFile
      • getTableName

        public String getTableName()
        Returns the tableName
        Returns:
        tableName
      • closeAllDatabaseConnections

        public void closeAllDatabaseConnections()
        Closes all open database connections
      • createDatabaseIfNotExist

        protected abstract boolean createDatabaseIfNotExist()
        Creates the database and tables if it does not exist
        Returns:
        True if successful, false otherwise
      • convertResultSetToObject

        protected abstract T convertResultSetToObject​(ResultSet result)
                                               throws SQLException,
                                                      javax.xml.bind.JAXBException
        Converts the entry, which the ResultSet currently points to, to an object
        Parameters:
        result - Result
        Returns:
        Object
        Throws:
        SQLException
        javax.xml.bind.JAXBException
      • getAllEntries

        public abstract List<T> getAllEntries()
        Returns all entries from the database
        Returns:
        All entries
      • getEntry

        public abstract T getEntry​(int id)
        Returns the entry with given ID or null if the entry was not found or an error occurred
        Parameters:
        id - ID in database
        Returns:
        Entry or null if no entry with the ID found or an error occurred
      • insertEntry

        public abstract boolean insertEntry​(T entry)
        Inserts the given entry into the database
        Parameters:
        entry - Entry
        Returns:
        True if successful, false otherwise
      • insertEntries

        public abstract boolean insertEntries​(List<T> entries)
        Inserts the given entries into the database
        Parameters:
        entries - Entries
        Returns:
        True if successful, false otherwise
      • updateEntry

        public abstract boolean updateEntry​(T entry)
        Updates the given entry in the database
        Parameters:
        entry - Entry
        Returns:
        True if successful, false otherwise
      • updateEntries

        public abstract boolean updateEntries​(List<T> entries)
        Updates the given entries in the database
        Parameters:
        entries - Entries
        Returns:
        True if successful, false otherwise
      • deleteEntry

        public abstract boolean deleteEntry​(T entry)
        Deletes the given entry from the database
        Parameters:
        entry - Entry
        Returns:
        True if successful, false otherwise
      • deleteEntries

        public abstract boolean deleteEntries​(List<T> entries)
        Deletes the given entries from the database
        Parameters:
        entries - Entries
        Returns:
        True if successful, false otherwise