Class SQLiteDB<T>
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.database.sqlite.SQLiteDB<T>
-
- Type Parameters:
T- Object Type
public abstract class SQLiteDB<T> extends Object
Class for Sqlite Database Connections
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdatabaseFileDatabase Fileprotected org.slf4j.LoggerloggerLogger for this classprotected StringtableNameTable Name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcloseAllDatabaseConnections()Closes all open database connectionsprotected abstract TconvertResultSetToObject(ResultSet result)Converts the entry, which the ResultSet currently points to, to an objectprotected abstract booleancreateDatabaseIfNotExist()Creates the database and tables if it does not existabstract booleandeleteEntries(List<T> entries)Deletes the given entries from the databaseabstract booleandeleteEntry(T entry)Deletes the given entry from the databaseabstract List<T>getAllEntries()Returns all entries from the databaseprotected ConnectiongetDatabaseConnection()Returns a connection to the databaseStringgetDatabaseFile()Returns the databaseFileabstract TgetEntry(int id)Returns the entry with given ID or null if the entry was not found or an error occurredStringgetTableName()Returns the tableNameabstract booleaninsertEntries(List<T> entries)Inserts the given entries into the databaseabstract booleaninsertEntry(T entry)Inserts the given entry into the databaseabstract booleanupdateEntries(List<T> entries)Updates the given entries in the databaseabstract booleanupdateEntry(T entry)Updates the given entry in the database
-
-
-
Constructor Detail
-
SQLiteDB
public SQLiteDB(String databaseFile, String tableName, boolean backupDatabaseOnStart, boolean defragDatabaseOnStart, long defragMinFileSize)
Constructor- Parameters:
databaseFile- Path to the database FiletableName- Table NamebackupDatabaseOnStart- True if database should be backed up on start, false otherwisedefragDatabaseOnStart- True if database should be deframented on start, false otherwisedefragMinFileSize- 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
-
getDatabaseConnection
protected Connection getDatabaseConnection() throws ClassNotFoundException, SQLException
Returns a connection to the database- Returns:
- Connection to the database
- Throws:
ClassNotFoundExceptionSQLException
-
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:
SQLExceptionjavax.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
-
-