Class SQLiteConnection
java.lang.Object
org.sqlite.SQLiteConnection
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper
- Direct Known Subclasses:
JDBC3Connection, SQLitePooledConnectionHandle
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SQLiteConnectionConfigprivate SQLiteConfig.TransactionModeprivate final DBprivate booleanprivate CoreDatabaseMetaDataprivate static final StringFields inherited from interface Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionSQLiteConnection(String url, String fileName) Constructor to create a connection to a database at the given location.SQLiteConnection(String url, String fileName, Properties prop) Constructor to create a pre-configured connection to a database at the given location.SQLiteConnection(DB db) Connection constructor for reusing an existing DB handle -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddCommitListener(SQLiteCommitListener listener) Add a listener for DB commit/rollback events, see https://www.sqlite.org/c3ref/commit_hook.htmlvoidaddUpdateListener(SQLiteUpdateListener listener) Add a listener for DB update events, see https://www.sqlite.org/c3ref/update_hook.htmlprotected voidcheckCursor(int rst, int rsc, int rsh) Checks whether the type, concurrency, and holdability settings for aResultSetare supported by the SQLite interface.protected voidWhether an SQLite library interface to the database has been established.voidclose()voidcommit()voiddeserialize(String schema, byte[] buff) Deserialize the schema using the given byte array.protected static StringextractPragmasFromFilename(String url, String filename, Properties prop) Extracts PRAGMA values from the filename and sets them into the Properties object which will be used to build the SQLConfig.private static FileextractResource(URL resourceAddr) Returns a file name from the given resource address.booleanintvoidgetLimit(SQLiteLimits limit) intintgetUrl()booleanisClosed()booleanprivate static DBopen(String url, String origFileName, Properties props) Opens a connection to the database using an SQLite library.voidremoveCommitListener(SQLiteCommitListener listener) Remove a listener registered for DB commit/rollback events.voidremoveUpdateListener(SQLiteUpdateListener listener) Remove a listener registered for DB update events.voidrollback()byte[]Returns a byte array representing the schema content.voidsetAutoCommit(boolean ac) voidsetBusyTimeout(int timeoutMillis) Sets the timeout value for the connection.voidsetCurrentTransactionMode(SQLiteConfig.TransactionMode currentTransactionMode) voidsetFirstStatementExecuted(boolean firstStatementExecuted) voidsetLimit(SQLiteLimits limit, int value) voidsetNetworkTimeout(Executor executor, int milliseconds) voidvoidsetTransactionIsolation(int level) protected voidSets the mode that will be used to start transactions on this connection.protected StringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Connection
beginRequest, clearWarnings, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, endRequest, getCatalog, getClientInfo, getClientInfo, getHoldability, getTypeMap, getWarnings, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCatalog, setClientInfo, setClientInfo, setHoldability, setReadOnly, setSavepoint, setSavepoint, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTypeMapMethods inherited from interface Wrapper
isWrapperFor, unwrap
-
Field Details
-
RESOURCE_NAME_PREFIX
- See Also:
-
db
-
meta
-
connectionConfig
-
currentTransactionMode
-
firstStatementExecuted
private boolean firstStatementExecuted
-
-
Constructor Details
-
SQLiteConnection
Connection constructor for reusing an existing DB handle- Parameters:
db-
-
SQLiteConnection
Constructor to create a connection to a database at the given location.- Parameters:
url- The location of the database.fileName- The database.- Throws:
SQLException
-
SQLiteConnection
Constructor to create a pre-configured connection to a database at the given location.- Parameters:
url- The location of the database file.fileName- The database.prop- The configurations to apply.- Throws:
SQLException
-
-
Method Details
-
getCurrentTransactionMode
-
setCurrentTransactionMode
-
setFirstStatementExecuted
public void setFirstStatementExecuted(boolean firstStatementExecuted) -
isFirstStatementExecuted
public boolean isFirstStatementExecuted() -
getConnectionConfig
-
getSQLiteDatabaseMetaData
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
getUrl
-
setSchema
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
checkCursor
Checks whether the type, concurrency, and holdability settings for aResultSetare supported by the SQLite interface. Supported settings are:- type:
ResultSet.TYPE_FORWARD_ONLY - concurrency:
ResultSet.CONCUR_READ_ONLY) - holdability:
ResultSet.CLOSE_CURSORS_AT_COMMIT
- Parameters:
rst- the type setting.rsc- the concurrency setting.rsh- the holdability setting.- Throws:
SQLException
- type:
-
setTransactionMode
Sets the mode that will be used to start transactions on this connection.- Parameters:
mode- One ofSQLiteConfig.TransactionMode- See Also:
-
getTransactionIsolation
public int getTransactionIsolation()- Specified by:
getTransactionIsolationin interfaceConnection- See Also:
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException- See Also:
-
open
Opens a connection to the database using an SQLite library. * @throws SQLException- Throws:
SQLException- See Also:
-
extractResource
Returns a file name from the given resource address.- Parameters:
resourceAddr- The resource address.- Returns:
- The extracted file name.
- Throws:
IOException
-
getDatabase
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException- See Also:
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException- See Also:
-
getBusyTimeout
public int getBusyTimeout()- Returns:
- The busy timeout value for the connection.
- See Also:
-
setBusyTimeout
Sets the timeout value for the connection. A timeout value less than or equal to zero turns off all busy handlers.- Parameters:
timeoutMillis- The timeout value in milliseconds.- Throws:
SQLException- See Also:
-
setLimit
- Throws:
SQLException
-
getLimit
- Throws:
SQLException
-
isClosed
- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException- See Also:
-
checkOpen
Whether an SQLite library interface to the database has been established.- Throws:
SQLException
-
libversion
- Returns:
- Compile-time library version numbers.
- Throws:
SQLException- See Also:
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException- See Also:
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException- See Also:
-
addUpdateListener
Add a listener for DB update events, see https://www.sqlite.org/c3ref/update_hook.html- Parameters:
listener- The listener to receive update events
-
removeUpdateListener
Remove a listener registered for DB update events.- Parameters:
listener- The listener to no longer receive update events
-
addCommitListener
Add a listener for DB commit/rollback events, see https://www.sqlite.org/c3ref/commit_hook.html- Parameters:
listener- The listener to receive commit events
-
removeCommitListener
Remove a listener registered for DB commit/rollback events.- Parameters:
listener- The listener to no longer receive commit/rollback events.
-
extractPragmasFromFilename
protected static String extractPragmasFromFilename(String url, String filename, Properties prop) throws SQLException Extracts PRAGMA values from the filename and sets them into the Properties object which will be used to build the SQLConfig. The sanitized filename is returned.- Parameters:
filename-prop-- Returns:
- a PRAGMA-sanitized filename
- Throws:
SQLException
-
transactionPrefix
-
serialize
Returns a byte array representing the schema content. This method is intended for in-memory schemas. Serialized databases are limited to 2gb.- Parameters:
schema- The schema to serialize- Returns:
- A byte[] holding the database content
- Throws:
SQLException
-
deserialize
Deserialize the schema using the given byte array. This method is intended for in-memory database. The call will replace the content of an existing schema. To make sure there is an existing schema, first execute ATTACH ':memory:' AS schema_name- Parameters:
schema- The schema to serializebuff- The buffer to deserialize- Throws:
SQLException
-