Package com.nuix.superutilities.misc
Class SQLiteBacked
- java.lang.Object
-
- com.nuix.superutilities.misc.SQLiteBacked
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
AnnotationRepository
public class SQLiteBacked extends java.lang.Object implements java.io.CloseableProvides 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 voidclose()voidexecuteInsert(java.lang.String sql, java.lang.Object... data)Executes an insert query against the SQLite database filevoidexecuteInsert(java.lang.String sql, java.util.List<java.lang.Object> data)Executes an insert query against the SQLite database filejava.lang.LongexecuteLongScalar(java.lang.String sql)Executes SQL which is expected to return a single long/int value, such as a COUNT statement would.java.lang.LongexecuteLongScalar(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.LongexecuteLongScalar(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.voidexecuteQuery(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> TexecuteScalar(java.lang.String sql, java.lang.Object... data)java.lang.StringexecuteStringScalar(java.lang.String sql)Executes SQL which is expected to return a single string value.java.lang.StringexecuteStringScalar(java.lang.String sql, java.lang.Object... data)Executes SQL which is expected to return a single string value.java.lang.StringexecuteStringScalar(java.lang.String sql, java.util.List<java.lang.Object> data)Executes SQL which is expected to return a single string value.intexecuteUpdate(java.lang.String sql)Executes an update query against the SQLite database fileintexecuteUpdate(java.lang.String sql, java.lang.Object... data)Executes an update query against the SQLite database fileintexecuteUpdate(java.lang.String sql, java.util.List<java.lang.Object> data)Executes an update query against the SQLite database file
-
-
-
Method Detail
-
executeUpdate
public int executeUpdate(java.lang.String sql, java.util.List<java.lang.Object> data) throws java.sql.SQLExceptionExecutes an update query against the SQLite database file- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes an update query against the SQLite database file- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes 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.SQLExceptionExecutes an insert query against the SQLite database file- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes an insert query against the SQLite database file- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes SQL which is expected to return a single long/int value, such as a COUNT statement would.- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes SQL which is expected to return a single long/int value, such as a COUNT statement would.- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes 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.SQLExceptionExecutes SQL which is expected to return a single string value.- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes SQL which is expected to return a single string value.- Parameters:
sql- The SQL to executedata- 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.SQLExceptionExecutes 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.SQLExceptionExecutes a query which is expected to return row data, providing the result set to the provided callback.- Parameters:
sql- The SQL query to executedata- Optional list of associated data, can be nullresultConsumer- 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-