Package org.sqlite
Class SQLiteConnection
java.lang.Object
org.sqlite.SQLiteConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
- Direct Known Subclasses:
JDBC3Connection
-
Field Summary
Fields inherited from interface java.sql.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 TypeMethodDescriptionvoid
void
addCommitListener
(SQLiteCommitListener listener) Add a listener for DB commit/rollback events, see https://www.sqlite.org/c3ref/commit_hook.htmlvoid
addUpdateListener
(SQLiteUpdateListener listener) Add a listener for DB update events, see https://www.sqlite.org/c3ref/update_hook.htmlprotected void
checkCursor
(int rst, int rsc, int rsh) Checks whether the type, concurrency, and holdability settings for aResultSet
are supported by the SQLite interface.protected void
Whether an SQLite library interface to the database has been established.void
close()
void
commit()
void
deserialize
(String schema, byte[] buff) Deserialize the schema using the given byte array.protected static String
extractPragmasFromFilename
(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.boolean
int
void
getLimit
(SQLiteLimits limit) int
int
getUrl()
boolean
isClosed()
boolean
void
removeCommitListener
(SQLiteCommitListener listener) Remove a listener registered for DB commit/rollback events.void
removeUpdateListener
(SQLiteUpdateListener listener) Remove a listener registered for DB update events.void
rollback()
byte[]
Returns a byte array representing the schema content.void
setAutoCommit
(boolean ac) void
setBusyTimeout
(int timeoutMillis) Sets the timeout value for the connection.void
setCurrentTransactionMode
(SQLiteConfig.TransactionMode currentTransactionMode) void
setFirstStatementExecuted
(boolean firstStatementExecuted) void
setLimit
(SQLiteLimits limit, int value) void
setNetworkTimeout
(Executor executor, int milliseconds) void
void
setTransactionIsolation
(int level) protected void
Sets the mode that will be used to start transactions on this connection.protected String
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.sql.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, setTypeMap
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
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:
getMetaData
in interfaceConnection
- Throws:
SQLException
-
getUrl
-
setSchema
- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Throws:
SQLException
-
abort
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
checkCursor
Checks whether the type, concurrency, and holdability settings for aResultSet
are 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:
getTransactionIsolation
in interfaceConnection
- See Also:
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
- See Also:
-
getDatabase
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
- See Also:
-
setAutoCommit
- Specified by:
setAutoCommit
in 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:
isClosed
in interfaceConnection
- Throws:
SQLException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:
commit
in interfaceConnection
- Throws:
SQLException
- See Also:
-
rollback
- Specified by:
rollback
in 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
-