Package org.sqlite
Class SQLiteDataSource
java.lang.Object
org.sqlite.SQLiteDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
- Direct Known Subclasses:
SQLiteConnectionPoolDataSource
Provides
DataSource
API for configuring SQLite database connection- Author:
- leo
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SQLiteDataSource
(SQLiteConfig config) Creates a data source based on the provided configuration. -
Method Summary
Modifier and TypeMethodDescriptiongetConnection
(String username, String password) int
getUrl()
boolean
isWrapperFor
(Class<?> iface) Determines if this object wraps a given class.void
setBusyTimeout
(int milliseconds) Sets the amount of time that the connection's busy handler will wait when a table is locked.void
setCacheSize
(int numberOfPages) Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file.void
setCaseSensitiveLike
(boolean enable) Enables or disables case sensitivity for the built-in LIKE operator.void
setConfig
(SQLiteConfig config) Sets a data source's configuration.void
setCountChanges
(boolean enable) Enables or disables the count-changes flag.void
setDatabaseName
(String databaseName) Sets the database name.void
setDefaultCacheSize
(int numberOfPages) Sets the default maximum number of database disk pages that SQLite will hold in memory at once per open database file.void
setEncoding
(String encoding) Sets the text encoding used by the main database.void
setEnforceForeignKeys
(boolean enforce) Enables or disables the enforcement of foreign key constraints.void
setFullColumnNames
(boolean enable) Enables or disables the full_column_names flag.void
setFullSync
(boolean enable) Enables or disables the fullfsync flag.void
setGetGeneratedKeys
(boolean generatedKeys) Configure where generated keys will be retrieved for this database.void
setIncrementalVacuum
(int numberOfPagesToBeRemoved) Set the incremental_vacuum value that causes up to N pages to be removed from the https://www.sqlite.org/fileformat2.html#freelist.void
setJournalMode
(String mode) Sets the journal mode for databases associated with the current database connection.void
setJournalSizeLimit
(int limit) Sets the limit of the size of rollback-journal and WAL files left in the file-system after transactions or checkpoints.void
setLegacyAlterTable
(boolean flag) Sets the value of the legacy_alter_table flag.void
setLegacyFileFormat
(boolean use) Set the value of the legacy_file_format flag.void
setLoadExtension
(boolean enable) Enables or disables extension loading.void
setLockingMode
(String mode) Sets the database connection locking-mode.void
setLoginTimeout
(int seconds) void
setLogWriter
(PrintWriter out) void
setMaxPageCount
(int numPages) Set the maximum number of pages in the database file.void
setPageSize
(int numBytes) Set the page size of the database.void
setReadOnly
(boolean readOnly) Sets the database to be opened in read-only modevoid
setReadUncommitted
(boolean useReadUncommittedIsolationMode) Set READ UNCOMMITTED isolationvoid
setRecursiveTriggers
(boolean enable) Enables or disables the recursive trigger capability.void
setReverseUnorderedSelects
(boolean enable) Enables or disables the reverse_unordered_selects flag.void
setSharedCache
(boolean enable) Enables or disables the sharing of the database cache and schema data structures between connections to the same database.void
setSharedCacheConnection
(boolean enable) Enables or disables the sharing of the database cache and schema data structures between connections to the same database.void
setShortColumnNames
(boolean enable) Enables or disables the short_column_names flag.void
setSynchronous
(String mode) Sets the setting of the "synchronous" flag.void
setTempStore
(String storeType) Set the temp_store type which is used to determine where temporary tables and indices are stored.void
setTempStoreDirectory
(String directoryName) Set the value of the sqlite3_temp_directory global variable, which many operating-system interface backends use to determine where to store temporary tables and indices.void
setTransactionMode
(String transactionMode) Sets the mode that will be used to start transactions for this database.void
Sets the location of the database file.void
setUserVersion
(int version) Sets the value of the user-version.<T> T
Casts this object to the given class.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
SQLiteDataSource
public SQLiteDataSource()Default constructor. -
SQLiteDataSource
Creates a data source based on the provided configuration.- Parameters:
config
- The configuration for the data source.
-
-
Method Details
-
setConfig
Sets a data source's configuration.- Parameters:
config
- The configuration.
-
getConfig
- Returns:
- The configuration for the data source.
-
setUrl
Sets the location of the database file.- Parameters:
url
- The location of the database file.
-
getUrl
- Returns:
- The location of the database file.
-
setDatabaseName
Sets the database name.- Parameters:
databaseName
- The name of the database
-
getDatabaseName
- Returns:
- The name of the database if one was set.
- See Also:
-
setLoadExtension
public void setLoadExtension(boolean enable) Enables or disables extension loading.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setReadOnly
public void setReadOnly(boolean readOnly) Sets the database to be opened in read-only mode- Parameters:
readOnly
- True to enable; false to disable.- See Also:
-
setBusyTimeout
public void setBusyTimeout(int milliseconds) Sets the amount of time that the connection's busy handler will wait when a table is locked.- Parameters:
milliseconds
- The number of milliseconds to wait.- See Also:
-
setCacheSize
public void setCacheSize(int numberOfPages) Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file.- Parameters:
numberOfPages
- The number of database disk pages.- See Also:
-
setCaseSensitiveLike
public void setCaseSensitiveLike(boolean enable) Enables or disables case sensitivity for the built-in LIKE operator.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setCountChanges
public void setCountChanges(boolean enable) Enables or disables the count-changes flag. When enabled INSERT, UPDATE and DELETE statements return the number of rows they modified.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setDefaultCacheSize
public void setDefaultCacheSize(int numberOfPages) Sets the default maximum number of database disk pages that SQLite will hold in memory at once per open database file.- Parameters:
numberOfPages
- The default suggested cache size.- See Also:
-
setEncoding
Sets the text encoding used by the main database.- Parameters:
encoding
- One of "UTF-8", "UTF-16le" (little-endian UTF-16) or "UTF-16be" (big-endian UTF-16).- See Also:
-
setEnforceForeignKeys
public void setEnforceForeignKeys(boolean enforce) Enables or disables the enforcement of foreign key constraints.- Parameters:
enforce
- True to enable; false to disable.- See Also:
-
setFullColumnNames
public void setFullColumnNames(boolean enable) Enables or disables the full_column_names flag. This flag together with the short_column_names flag determine the way SQLite assigns names to result columns of SELECT statements.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setFullSync
public void setFullSync(boolean enable) Enables or disables the fullfsync flag. This flag determines whether or not the F_FULLFSYNC syncing method is used on systems that support it.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setIncrementalVacuum
public void setIncrementalVacuum(int numberOfPagesToBeRemoved) Set the incremental_vacuum value that causes up to N pages to be removed from the https://www.sqlite.org/fileformat2.html#freelist.- Parameters:
numberOfPagesToBeRemoved
-- See Also:
-
setJournalMode
Sets the journal mode for databases associated with the current database connection.- Parameters:
mode
- One of DELETE, TRUNCATE, PERSIST, MEMORY, WAL or OFF.- See Also:
-
setJournalSizeLimit
public void setJournalSizeLimit(int limit) Sets the limit of the size of rollback-journal and WAL files left in the file-system after transactions or checkpoints.- Parameters:
limit
- The default journal size limit is -1 (no limit).- See Also:
-
setLegacyFileFormat
public void setLegacyFileFormat(boolean use) Set the value of the legacy_file_format flag. When this flag is on, new databases are created in a file format that is readable and writable by all versions of SQLite going back to 3.0.0. When the flag is off, new databases are created using the latest file format which might not be readable or writable by versions of SQLite prior to 3.3.0.- Parameters:
use
- True to turn on; false to turn off.- See Also:
-
setLegacyAlterTable
public void setLegacyAlterTable(boolean flag) Sets the value of the legacy_alter_table flag. When this flag is on, the ALTER TABLE RENAME command (for changing the name of a table) works as it did in SQLite 3.24.0 (2018-06-04) and earlier.When the flag is off, using the ALTER TABLE RENAME command will mean that all references to the table anywhere in the schema will be converted to the new name.- Parameters:
flag
- True to turn on legacy alter table behaviour; false to turn off.- See Also:
-
- invalid input: '<a href="https://www.sqlite.org/pragma.html#pragma_legacy_alter_table</a>'
-
setLockingMode
Sets the database connection locking-mode.- Parameters:
mode
- Either NORMAL or EXCLUSIVE.- See Also:
-
setPageSize
public void setPageSize(int numBytes) Set the page size of the database.- Parameters:
numBytes
- The page size must be a power of two between 512 and 65536 inclusive.- See Also:
-
setMaxPageCount
public void setMaxPageCount(int numPages) Set the maximum number of pages in the database file.- Parameters:
numPages
- The maximum page count cannot be reduced below the current database size.- See Also:
-
setReadUncommitted
public void setReadUncommitted(boolean useReadUncommittedIsolationMode) Set READ UNCOMMITTED isolation- Parameters:
useReadUncommittedIsolationMode
- True to turn on; false to turn off.- See Also:
-
setRecursiveTriggers
public void setRecursiveTriggers(boolean enable) Enables or disables the recursive trigger capability. Changing the recursive_triggers setting affects the execution of all statements prepared using the database connection, including those prepared before the setting was changed.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setReverseUnorderedSelects
public void setReverseUnorderedSelects(boolean enable) Enables or disables the reverse_unordered_selects flag. When enabled it causes SELECT statements without an ORDER BY clause to emit their results in the reverse order of what they normally would.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setShortColumnNames
public void setShortColumnNames(boolean enable) Enables or disables the short_column_names flag. This flag affects the way SQLite names columns of data returned by SELECT statements.- Parameters:
enable
- True to enable; false to disable.- See Also:
-
setSynchronous
Sets the setting of the "synchronous" flag.- Parameters:
mode
- One of OFF, NORMAL or FULL;- See Also:
-
setTempStore
Set the temp_store type which is used to determine where temporary tables and indices are stored.- Parameters:
storeType
- One of "DEFAULT", "FILE", "MEMORY"- See Also:
-
setTempStoreDirectory
Set the value of the sqlite3_temp_directory global variable, which many operating-system interface backends use to determine where to store temporary tables and indices.- Parameters:
directoryName
- The temporary directory name.- See Also:
-
setTransactionMode
Sets the mode that will be used to start transactions for this database.- Parameters:
transactionMode
- One of DEFERRED, IMMEDIATE or EXCLUSIVE.- See Also:
-
setGetGeneratedKeys
public void setGetGeneratedKeys(boolean generatedKeys) Configure where generated keys will be retrieved for this database.- Parameters:
generatedKeys
- true to retrieve generated keys
-
setUserVersion
public void setUserVersion(int version) Sets the value of the user-version. It is a big-endian 32-bit signed integer stored in the database header at offset 60.- Parameters:
version
-- See Also:
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
isWrapperFor
Determines if this object wraps a given class.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- The class to check.- Returns:
- True if it is an instance of the current class; false otherwise.
- Throws:
SQLException
-
unwrap
Casts this object to the given class.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- The class to cast to.- Returns:
- The casted class.
- Throws:
SQLException
-