Package org.sqlite
Class SQLiteDataSource
- java.lang.Object
-
- org.sqlite.SQLiteDataSource
-
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
- Direct Known Subclasses:
SQLiteConnectionPoolDataSource
public class SQLiteDataSource extends Object implements DataSource
ProvidesDataSourceAPI for configuring SQLite database connection- Author:
- leo
-
-
Constructor Summary
Constructors Constructor Description SQLiteDataSource()Default constructor.SQLiteDataSource(SQLiteConfig config)Creates a data source based on the provided configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SQLiteConfiggetConfig()ConnectiongetConnection()SQLiteConnectiongetConnection(String username, String password)StringgetDatabaseName()intgetLoginTimeout()PrintWritergetLogWriter()LoggergetParentLogger()StringgetUrl()booleanisWrapperFor(Class<?> iface)Determines if this object wraps a given class.voidsetBusyTimeout(int milliseconds)Sets the amount of time that the connection's busy handler will wait when a table is locked.voidsetCacheSize(int numberOfPages)Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file.voidsetCaseSensitiveLike(boolean enable)Enables or disables case sensitivity for the built-in LIKE operator.voidsetConfig(SQLiteConfig config)Sets a data source's configuration.voidsetCountChanges(boolean enable)Enables or disables the count-changes flag.voidsetDatabaseName(String databaseName)Sets the database name.voidsetDefaultCacheSize(int numberOfPages)Sets the default maximum number of database disk pages that SQLite will hold in memory at once per open database file.voidsetEncoding(String encoding)Sets the text encoding used by the main database.voidsetEnforceForeignKeys(boolean enforce)Enables or disables the enforcement of foreign key constraints.voidsetFullColumnNames(boolean enable)Enables or disables the full_column_names flag.voidsetFullSync(boolean enable)Enables or disables the fullfsync flag.voidsetGetGeneratedKeys(boolean generatedKeys)Configure where generated keys will be retrieved for this database.voidsetIncrementalVacuum(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.voidsetJournalMode(String mode)Sets the journal mode for databases associated with the current database connection.voidsetJournalSizeLimit(int limit)Sets the limit of the size of rollback-journal and WAL files left in the file-system after transactions or checkpoints.voidsetLegacyAlterTable(boolean flag)Sets the value of the legacy_alter_table flag.voidsetLegacyFileFormat(boolean use)Set the value of the legacy_file_format flag.voidsetLoadExtension(boolean enable)Enables or disables extension loading.voidsetLockingMode(String mode)Sets the database connection locking-mode.voidsetLoginTimeout(int seconds)voidsetLogWriter(PrintWriter out)voidsetMaxPageCount(int numPages)Set the maximum number of pages in the database file.voidsetPageSize(int numBytes)Set the page size of the database.voidsetReadOnly(boolean readOnly)Sets the database to be opened in read-only modevoidsetReadUncommitted(boolean useReadUncommittedIsolationMode)Set READ UNCOMMITTED isolationvoidsetRecursiveTriggers(boolean enable)Enables or disables the recursive trigger capability.voidsetReverseUnorderedSelects(boolean enable)Enables or disables the reverse_unordered_selects flag.voidsetSharedCache(boolean enable)Enables or disables the sharing of the database cache and schema data structures between connections to the same database.voidsetSharedCacheConnection(boolean enable)Enables or disables the sharing of the database cache and schema data structures between connections to the same database.voidsetShortColumnNames(boolean enable)Enables or disables the short_column_names flag.voidsetSynchronous(String mode)Sets the setting of the "synchronous" flag.voidsetTempStore(String storeType)Set the temp_store type which is used to determine where temporary tables and indices are stored.voidsetTempStoreDirectory(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.voidsetTransactionMode(String transactionMode)Sets the mode that will be used to start transactions for this database.voidsetUrl(String url)Sets the location of the database file.voidsetUserVersion(int version)Sets the value of the user-version.<T> Tunwrap(Class<T> iface)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 Detail
-
SQLiteDataSource
public SQLiteDataSource()
Default constructor.
-
SQLiteDataSource
public SQLiteDataSource(SQLiteConfig config)
Creates a data source based on the provided configuration.- Parameters:
config- The configuration for the data source.
-
-
Method Detail
-
setConfig
public void setConfig(SQLiteConfig config)
Sets a data source's configuration.- Parameters:
config- The configuration.
-
getConfig
public SQLiteConfig getConfig()
- Returns:
- The configuration for the data source.
-
setUrl
public void setUrl(String url)
Sets the location of the database file.- Parameters:
url- The location of the database file.
-
getUrl
public String getUrl()
- Returns:
- The location of the database file.
-
setDatabaseName
public void setDatabaseName(String databaseName)
Sets the database name.- Parameters:
databaseName- The name of the database
-
getDatabaseName
public String getDatabaseName()
- Returns:
- The name of the database if one was set.
- See Also:
setDatabaseName(String)
-
setSharedCache
public void setSharedCache(boolean enable)
Enables or disables the sharing of the database cache and schema data structures between connections to the same database.- Parameters:
enable- True to enable; false to disable.- See Also:
- https://www.sqlite.org/c3ref/enable_shared_cache.html
-
setSharedCacheConnection
public void setSharedCacheConnection(boolean enable)
Enables or disables the sharing of the database cache and schema data structures between connections to the same database.- Parameters:
enable- True to enable; false to disable.- See Also:
- http://www.sqlite.org/c3ref/enable_shared_cache.html
-
setLoadExtension
public void setLoadExtension(boolean enable)
Enables or disables extension loading.- Parameters:
enable- True to enable; false to disable.- See Also:
- https://www.sqlite.org/c3ref/load_extension.html
-
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:
- https://www.sqlite.org/c3ref/c_open_autoproxy.html
-
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:
- https://www.sqlite.org/pragma.html#pragma_busy_timeout
-
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:
- https://www.sqlite.org/pragma.html#pragma_cache_size
-
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:
- https://www.sqlite.org/compile.html#case_sensitive_like
-
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:
- https://www.sqlite.org/pragma.html#pragma_count_changes
-
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:
- https://www.sqlite.org/pragma.html#pragma_cache_size
-
setEncoding
public void setEncoding(String encoding)
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:
- https://www.sqlite.org/pragma.html#pragma_encoding
-
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:
- https://www.sqlite.org/pragma.html#pragma_foreign_keys
-
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:
- https://www.sqlite.org/pragma.html#pragma_full_column_names
-
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:
- https://www.sqlite.org/pragma.html#pragma_fullfsync
-
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:
- https://www.sqlite.org/pragma.html#pragma_incremental_vacuum
-
setJournalMode
public void setJournalMode(String mode)
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:
- https://www.sqlite.org/pragma.html#pragma_journal_mode
-
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:
- https://www.sqlite.org/pragma.html#pragma_journal_size_limit
-
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:
- https://www.sqlite.org/pragma.html#pragma_legacy_file_format
-
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:
-
-
setLockingMode
public void setLockingMode(String mode)
Sets the database connection locking-mode.- Parameters:
mode- Either NORMAL or EXCLUSIVE.- See Also:
- https://www.sqlite.org/pragma.html#pragma_locking_mode
-
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:
- https://www.sqlite.org/pragma.html#pragma_page_size
-
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:
- https://www.sqlite.org/pragma.html#pragma_max_page_count
-
setReadUncommitted
public void setReadUncommitted(boolean useReadUncommittedIsolationMode)
Set READ UNCOMMITTED isolation- Parameters:
useReadUncommittedIsolationMode- True to turn on; false to turn off.- See Also:
- https://www.sqlite.org/pragma.html#pragma_read_uncommitted
-
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:
- https://www.sqlite.org/pragma.html#pragma_recursive_triggers
-
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:
- https://www.sqlite.org/pragma.html#pragma_reverse_unordered_selects
-
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:
- https://www.sqlite.org/pragma.html#pragma_short_column_names, https://www.sqlite.org/pragma.html#pragma_fullfsync
-
setSynchronous
public void setSynchronous(String mode)
Sets the setting of the "synchronous" flag.- Parameters:
mode- One of OFF, NORMAL or FULL;- See Also:
- https://www.sqlite.org/pragma.html#pragma_synchronous
-
setTempStore
public void setTempStore(String storeType)
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:
- https://www.sqlite.org/pragma.html#pragma_temp_store
-
setTempStoreDirectory
public 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.- Parameters:
directoryName- The temporary directory name.- See Also:
- https://www.sqlite.org/pragma.html#pragma_temp_store_directory
-
setTransactionMode
public void setTransactionMode(String transactionMode)
Sets the mode that will be used to start transactions for this database.- Parameters:
transactionMode- One of DEFERRED, IMMEDIATE or EXCLUSIVE.- See Also:
- https://www.sqlite.org/lang_transaction.html
-
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:
- https://www.sqlite.org/pragma.html#pragma_schema_version
-
getConnection
public Connection getConnection() throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.getConnection()
-
getConnection
public SQLiteConnection getConnection(String username, String password) throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.getConnection(java.lang.String, java.lang.String)
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.getLogWriter()
-
getLoginTimeout
public int getLoginTimeout() throws SQLException- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.getLoginTimeout()
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.setLogWriter(java.io.PrintWriter)
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException- See Also:
DataSource.setLoginTimeout(int)
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
Determines if this object wraps a given class.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
iface- The class to check.- Returns:
- True if it is an instance of the current class; false otherwise.
- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
Casts this object to the given class.- Specified by:
unwrapin interfaceWrapper- Parameters:
iface- The class to cast to.- Returns:
- The casted class.
- Throws:
SQLException
-
-
-