public class DataAccess extends Object
Users
, PublicKeys
, Containers
and Accesses
tables.Modifier and Type | Field and Description |
---|---|
static String |
DATABASE_LOCATION_SEED_SUFFIX |
Constructor and Description |
---|
DataAccess(String location,
String hexEncodedAes256Key)
Constructor with the
DatabaseWrapper 's location and hexEncodedAes256Key. |
DataAccess(String location,
String hexEncodedAes256Key,
int version)
Constructor with the
DatabaseWrapper 's location, hexEncodedAes256Key and version. |
Modifier and Type | Method and Description |
---|---|
void |
closeDatabase()
If the database is open this will close the JDBC
Connection . |
Statement |
createStatement()
Creates a
Statement using the JDBC Connection . |
void |
destroyDatabase()
This will close the JDBC
Connection and then delete the database file. |
long |
executeCountQueryWithParameters(ParameterizedSql parameterizedSql)
This will execute the count query with the given parameters and return the result.
|
int |
executeUpdateWithParameters(ParameterizedSql parameterizedSql)
The will execute the given sql as an update with the given parameters (insert, update, delete, etc).
|
int |
getVersion()
Get the version of the database.
|
DatabaseOpenState |
openOrCreateDatabase()
This will open or create the database.
|
PreparedStatement |
prepareStatement(ParameterizedSql parameterizedSql)
Create a
PreparedStatement for the given sql and fill the parameters. |
public static final String DATABASE_LOCATION_SEED_SUFFIX
public DataAccess(String location, String hexEncodedAes256Key)
DatabaseWrapper
's location and hexEncodedAes256Key. This will set the version of
the database to CURRENT_VERSION
.location
- the file location of the DatabaseWrapper
hexEncodedAes256Key
- the hex encoded AES 256 key of the DatabaseWrapper
public DataAccess(String location, String hexEncodedAes256Key, int version)
DatabaseWrapper
's location, hexEncodedAes256Key and version.location
- the file location of the DatabaseWrapper
hexEncodedAes256Key
- the hex encoded AES 256 key of the DatabaseWrapper
version
- the version of the databasepublic void closeDatabase() throws SQLException
Connection
.SQLException
- thrown if there was an issue closing the Connection
public Statement createStatement() throws SQLException
Statement
using the JDBC Connection
.
NOTE: the database must be open before you call this method.
Statement
SQLException
- thrown if there was an issue creating the Statement
public void destroyDatabase() throws IOException, SQLException
Connection
and then delete the database file.
NOTE: the database file will be deleted and cannot be recovered!
IOException
- thrown if there was an issue deleting the database fileSQLException
- thrown if there was an issue closing the Connection
public long executeCountQueryWithParameters(ParameterizedSql parameterizedSql) throws SQLException
NOTE: the database must be open before you call this method.
parameterizedSql
- the count query to run and the parameters for the querySQLException
- thrown if there was an issue executing the count querypublic int executeUpdateWithParameters(ParameterizedSql parameterizedSql) throws SQLException
NOTE: the database must be open before you call this method.
parameterizedSql
- the update sql to execute and the parameters to use in the executionSQLException
- thrown if there is an issue executing the updatepublic int getVersion()
public DatabaseOpenState openOrCreateDatabase() throws IOException, SQLException
IOException
- thrown if there was an issue with the database locationSQLException
- thrown if there was an issue creating or opening the databasepublic PreparedStatement prepareStatement(ParameterizedSql parameterizedSql) throws SQLException
PreparedStatement
for the given sql and fill the parameters.
NOTE: the database must be open before you call this method.
parameterizedSql
- the sql to create a PreparedStatement
with and the parameters to fill the
statement withPreparedStatement
SQLException
- thrown if there was an issue creating the PreparedStatement
Copyright © 2021. All rights reserved.