Package org.sqlite
Class SQLiteConfig
- java.lang.Object
-
- org.sqlite.SQLiteConfig
-
public class SQLiteConfig extends Object
SQLite ConfigurationSee also https://www.sqlite.org/pragma.html
- Author:
- leo
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SQLiteConfig.DateClass
static class
SQLiteConfig.DatePrecision
static class
SQLiteConfig.Encoding
static class
SQLiteConfig.HexKeyMode
static class
SQLiteConfig.JournalMode
static class
SQLiteConfig.LockingMode
static class
SQLiteConfig.Pragma
static class
SQLiteConfig.SynchronousMode
static class
SQLiteConfig.TempStore
static class
SQLiteConfig.TransactionMode
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_DATE_STRING_FORMAT
-
Constructor Summary
Constructors Constructor Description SQLiteConfig()
Default constructor.SQLiteConfig(Properties prop)
Creates an SQLite configuration object using values from the given property object.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
apply(Connection conn)
Configures a connection.Connection
createConnection(String url)
Create a new JDBC connection using the current configurationvoid
deferForeignKeys(boolean enable)
Defers enforcement of foreign key constraints until the outermost transaction is committed.void
enableCaseSensitiveLike(boolean enable)
Enables or disables case sensitive for the LIKE operator.void
enableCountChanges(boolean enable)
Deprecated.Enables or disables the count-changes flag.void
enableEmptyResultCallBacks(boolean enable)
Deprecated.Enables or disables the empty_result_callbacks flag.void
enableFullColumnNames(boolean enable)
Deprecated.Enables or disables the full_column_name flag.void
enableFullSync(boolean enable)
Enables or disables the fullfsync flag.void
enableLoadExtension(boolean enable)
Enables or disables extension loading.void
enableRecursiveTriggers(boolean enable)
Enables or disables the recursive trigger capability.void
enableReverseUnorderedSelects(boolean enable)
Enables or disables the reverse_unordered_selects flag.void
enableShortColumnNames(boolean enable)
Enables or disables the short_column_names flag.void
enforceForeignKeys(boolean enforce)
Whether to enforce foreign key constraints.int
getBusyTimeout()
int
getOpenModeFlags()
SQLiteConfig.TransactionMode
getTransactionMode()
void
incrementalVacuum(int numberOfPagesToBeRemoved)
Sets the incremental_vacuum value; the number of pages to be removed from the freelist.boolean
isEnabledLoadExtension()
Checks if the load extension option is turned on.boolean
isEnabledSharedCache()
Checks if the shared cache option is turned on.boolean
isExplicitReadOnly()
boolean
isGetGeneratedKeys()
SQLiteConnectionConfig
newConnectionConfig()
void
resetOpenMode(SQLiteOpenMode mode)
Re-sets the open mode flags.void
setApplicationId(int id)
Set the value of the application-id.void
setBusyTimeout(int milliseconds)
void
setCacheSize(int numberOfPages)
Changes the maximum number of database disk pages that SQLite will hold in memory at once per open database file.void
setDateClass(String dateClass)
void
setDatePrecision(String datePrecision)
void
setDateStringFormat(String dateStringFormat)
void
setDefaultCacheSize(int numberOfPages)
Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file.void
setEncoding(SQLiteConfig.Encoding encoding)
Sets the text encoding used by the main database.void
setExplicitReadOnly(boolean readOnly)
Enable read only transactions after connection creation if explicit read only is true.void
setGetGeneratedKeys(boolean generatedKeys)
void
setHexKeyMode(SQLiteConfig.HexKeyMode mode)
Changes the setting of the "hexkey" flag.void
setJournalMode(SQLiteConfig.JournalMode mode)
Sets the journal mode for databases associated with the current database connection.void
setJournalSizeLimit(int limit)
Sets the journal_size_limit.void
setLegacyAlterTable(boolean flag)
Sets the value of the legacy_alter_table flag.void
setLockingMode(SQLiteConfig.LockingMode mode)
Sets the database connection locking-mode.void
setMaxPageCount(int numPages)
Sets the maximum number of pages in the database file.void
setOpenMode(SQLiteOpenMode mode)
Sets the open mode flags.void
setPageSize(int numBytes)
Sets the page size of the database.void
setPragma(SQLiteConfig.Pragma pragma, String value)
Sets a pragma's value.void
setReadOnly(boolean readOnly)
Sets the read-write mode for the database.void
setReadUncommitted(boolean useReadUncommittedIsolationMode)
Enables or disables useReadUncommittedIsolationMode.void
setSharedCache(boolean enable)
Enables or disables the sharing of the database cache and schema data structures between connections to the same database.void
setSynchronous(SQLiteConfig.SynchronousMode mode)
Changes the setting of the "synchronous" flag.void
setTempStore(SQLiteConfig.TempStore storeType)
Changes the setting of the "temp_store" parameter.void
setTempStoreDirectory(String directoryName)
Changes 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.void
setTransactionMode(SQLiteConfig.TransactionMode transactionMode)
Sets the mode that will be used to start transactions.void
setUserVersion(int version)
Set the value of the user-version.Properties
toProperties()
Convert this configuration into a Properties object, which can be passed to theDriverManager.getConnection(String, Properties)
.void
useLegacyFileFormat(boolean use)
Sets the value of the legacy_file_format flag.
-
-
-
Field Detail
-
DEFAULT_DATE_STRING_FORMAT
public static final String DEFAULT_DATE_STRING_FORMAT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SQLiteConfig
public SQLiteConfig()
Default constructor.
-
SQLiteConfig
public SQLiteConfig(Properties prop)
Creates an SQLite configuration object using values from the given property object.- Parameters:
prop
- The properties to apply to the configuration.
-
-
Method Detail
-
newConnectionConfig
public SQLiteConnectionConfig newConnectionConfig()
-
createConnection
public Connection createConnection(String url) throws SQLException
Create a new JDBC connection using the current configuration- Returns:
- The connection.
- Throws:
SQLException
-
apply
public void apply(Connection conn) throws SQLException
Configures a connection.- Parameters:
conn
- The connection to configure.- Throws:
SQLException
-
isEnabledSharedCache
public boolean isEnabledSharedCache()
Checks if the shared cache option is turned on.- Returns:
- True if turned on; false otherwise.
-
isEnabledLoadExtension
public boolean isEnabledLoadExtension()
Checks if the load extension option is turned on.- Returns:
- True if turned on; false otherwise.
-
getOpenModeFlags
public int getOpenModeFlags()
- Returns:
- The open mode flags.
-
setPragma
public void setPragma(SQLiteConfig.Pragma pragma, String value)
Sets a pragma's value.- Parameters:
pragma
- The pragma to change.value
- The value to set it to.
-
toProperties
public Properties toProperties()
Convert this configuration into a Properties object, which can be passed to theDriverManager.getConnection(String, Properties)
.- Returns:
- The property object.
-
isExplicitReadOnly
public boolean isExplicitReadOnly()
- Returns:
- true if explicit read only transactions are enabled
-
setExplicitReadOnly
public void setExplicitReadOnly(boolean readOnly)
Enable read only transactions after connection creation if explicit read only is true.- Parameters:
readOnly
- whether to enable explicit read only
-
setOpenMode
public void setOpenMode(SQLiteOpenMode mode)
Sets the open mode flags.- Parameters:
mode
- The open mode.- See Also:
- https://www.sqlite.org/c3ref/c_open_autoproxy.html
-
resetOpenMode
public void resetOpenMode(SQLiteOpenMode mode)
Re-sets the open mode flags.- Parameters:
mode
- The open mode.- See Also:
- https://www.sqlite.org/c3ref/c_open_autoproxy.html
-
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:
- www.sqlite.org/c3ref/enable_shared_cache.html
-
enableLoadExtension
public void enableLoadExtension(boolean enable)
Enables or disables extension loading.- Parameters:
enable
- True to enable; false to disable.- See Also:
- www.sqlite.org/c3ref/load_extension.html
-
setReadOnly
public void setReadOnly(boolean readOnly)
Sets the read-write mode for the database.- Parameters:
readOnly
- True for read-only; otherwise read-write.
-
setCacheSize
public void setCacheSize(int numberOfPages)
Changes the maximum number of database disk pages that SQLite will hold in memory at once per open database file.- Parameters:
numberOfPages
- Cache size in number of pages.- See Also:
- www.sqlite.org/pragma.html#pragma_cache_size
-
enableCaseSensitiveLike
public void enableCaseSensitiveLike(boolean enable)
Enables or disables case sensitive for the LIKE operator.- Parameters:
enable
- True to enable; false to disable.- See Also:
- www.sqlite.org/pragma.html#pragma_case_sensitive_like
-
enableCountChanges
@Deprecated public void enableCountChanges(boolean enable)
Deprecated.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:
- www.sqlite.org/pragma.html#pragma_count_changes
-
setDefaultCacheSize
public void setDefaultCacheSize(int numberOfPages)
Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file. The cache size set here persists across database connections.- Parameters:
numberOfPages
- Cache size in number of pages.- See Also:
- www.sqlite.org/pragma.html#pragma_cache_size
-
deferForeignKeys
public void deferForeignKeys(boolean enable)
Defers enforcement of foreign key constraints until the outermost transaction is committed.- Parameters:
enable
- True to enable; false to disable;- See Also:
- https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys
-
enableEmptyResultCallBacks
@Deprecated public void enableEmptyResultCallBacks(boolean enable)
Deprecated.Enables or disables the empty_result_callbacks flag.- Parameters:
enable
- True to enable; false to disable. false.- See Also:
- https://www.sqlite.org/pragma.html#pragma_empty_result_callbacks
-
setEncoding
public void setEncoding(SQLiteConfig.Encoding encoding)
Sets the text encoding used by the main database.- Parameters:
encoding
- One ofSQLiteConfig.Encoding
- See Also:
- www.sqlite.org/pragma.html#pragma_encoding
-
enforceForeignKeys
public void enforceForeignKeys(boolean enforce)
Whether to enforce foreign key constraints. This setting affects the execution of all statements prepared using the database connection, including those prepared before the setting was changed.- Parameters:
enforce
- True to enable; false to disable.- See Also:
- www.sqlite.org/pragma.html#pragma_foreign_keys
-
enableFullColumnNames
@Deprecated public void enableFullColumnNames(boolean enable)
Deprecated.Enables or disables the full_column_name 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:
- www.sqlite.org/pragma.html#pragma_full_column_names
-
enableFullSync
public void enableFullSync(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. The default value of the fullfsync flag is off. Only Mac OS X supports F_FULLFSYNC.- Parameters:
enable
- True to enable; false to disable.- See Also:
- www.sqlite.org/pragma.html#pragma_fullfsync
-
incrementalVacuum
public void incrementalVacuum(int numberOfPagesToBeRemoved)
Sets the incremental_vacuum value; the number of pages to be removed from the freelist. The database file is truncated by the same amount.- Parameters:
numberOfPagesToBeRemoved
- The number of pages to be removed.- See Also:
- www.sqlite.org/pragma.html#pragma_incremental_vacuum
-
setJournalMode
public void setJournalMode(SQLiteConfig.JournalMode mode)
Sets the journal mode for databases associated with the current database connection.- Parameters:
mode
- One ofSQLiteConfig.JournalMode
- See Also:
- www.sqlite.org/pragma.html#pragma_journal_mode
-
setJournalSizeLimit
public void setJournalSizeLimit(int limit)
Sets the journal_size_limit. This setting limits the size of the rollback-journal and WAL files left in the file-system after transactions or checkpoints.- Parameters:
limit
- Limit value in bytes. A negative number implies no limit.- See Also:
- www.sqlite.org/pragma.html#pragma_journal_size_limit
-
useLegacyFileFormat
public void useLegacyFileFormat(boolean use)
Sets the value of the legacy_file_format flag. When this flag is enabled, new SQLite 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 legacy file format; false to turn off.- See Also:
- 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(SQLiteConfig.LockingMode mode)
Sets the database connection locking-mode.- Parameters:
mode
- One ofSQLiteConfig.LockingMode
- See Also:
- www.sqlite.org/pragma.html#pragma_locking_mode
-
setPageSize
public void setPageSize(int numBytes)
Sets the page size of the database. The page size must be a power of two between 512 and 65536 inclusive.- Parameters:
numBytes
- A power of two between 512 and 65536 inclusive.- See Also:
- www.sqlite.org/pragma.html#pragma_page_size
-
setMaxPageCount
public void setMaxPageCount(int numPages)
Sets the maximum number of pages in the database file.- Parameters:
numPages
- Number of pages.- See Also:
- www.sqlite.org/pragma.html#pragma_max_page_count
-
setReadUncommitted
public void setReadUncommitted(boolean useReadUncommittedIsolationMode)
Enables or disables useReadUncommittedIsolationMode.- Parameters:
useReadUncommittedIsolationMode
- True to turn on; false to disable. disabled otherwise.- See Also:
- www.sqlite.org/pragma.html#pragma_read_uncommitted
-
enableRecursiveTriggers
public void enableRecursiveTriggers(boolean enable)
Enables or disables the recursive trigger capability.- Parameters:
enable
- True to enable the recursive trigger capability.- See Also:
- www.sqlite.org/pragma.html#pragma_recursive_triggers
-
enableReverseUnorderedSelects
public void enableReverseUnorderedSelects(boolean enable)
Enables or disables the reverse_unordered_selects flag. This setting causes SELECT statements without an ORDER BY clause to emit their results in the reverse order of what they normally would. This can help debug applications that are making invalid assumptions about the result order.- Parameters:
enable
- True to enable reverse_unordered_selects.- See Also:
- www.sqlite.org/pragma.html#pragma_reverse_unordered_selects
-
enableShortColumnNames
public void enableShortColumnNames(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 short_column_names.- See Also:
- www.sqlite.org/pragma.html#pragma_short_column_names
-
setSynchronous
public void setSynchronous(SQLiteConfig.SynchronousMode mode)
Changes the setting of the "synchronous" flag.- Parameters:
mode
- One ofSQLiteConfig.SynchronousMode
:- OFF - SQLite continues without syncing as soon as it has handed data off to the operating system
- NORMAL - the SQLite database engine will still sync at the most critical moments, but less often than in FULL mode
- FULL - the SQLite database engine will use the xSync method of the VFS to ensure that all content is safely written to the disk surface prior to continuing. This ensures that an operating system crash or power failure will not corrupt the database.
- See Also:
- www.sqlite.org/pragma.html#pragma_synchronous
-
setHexKeyMode
public void setHexKeyMode(SQLiteConfig.HexKeyMode mode)
Changes the setting of the "hexkey" flag.- Parameters:
mode
- One ofSQLiteConfig.HexKeyMode
:- NONE - SQLite uses a string based password
- SSE - the SQLite database engine will use pragma hexkey = '' to set the password
- SQLCIPHER - the SQLite database engine calls pragma key = "x''" to set the password
-
setTempStore
public void setTempStore(SQLiteConfig.TempStore storeType)
Changes the setting of the "temp_store" parameter.- Parameters:
storeType
- One ofSQLiteConfig.TempStore
:- DEFAULT - the compile-time C preprocessor macro SQLITE_TEMP_STORE is used to determine where temporary tables and indices are stored
- FILE - temporary tables and indices are stored in a file.
- MEMORY - temporary tables and indices are kept in as if they were pure in-memory databases memory
- See Also:
- www.sqlite.org/pragma.html#pragma_temp_store
-
setTempStoreDirectory
public void setTempStoreDirectory(String directoryName)
Changes 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
- Directory name for storing temporary tables and indices.- See Also:
- www.sqlite.org/pragma.html#pragma_temp_store_directory
-
setUserVersion
public void setUserVersion(int version)
Set the value of the user-version. The user-version is not used internally by SQLite. It may be used by applications for any purpose. The value is stored in the database header at offset 60.- Parameters:
version
- A big-endian 32-bit signed integer.- See Also:
- www.sqlite.org/pragma.html#pragma_user_version
-
setApplicationId
public void setApplicationId(int id)
Set the value of the application-id. The application-id is not used internally by SQLite. Applications that use SQLite as their application file-format should set the Application ID integer to a unique integer so that utilities such as file(1) can determine the specific file type. The value is stored in the database header at offset 68.- Parameters:
id
- A big-endian 32-bit unsigned integer.- See Also:
- www.sqlite.org/pragma.html#pragma_application_id
-
setTransactionMode
public void setTransactionMode(SQLiteConfig.TransactionMode transactionMode)
Sets the mode that will be used to start transactions.- Parameters:
transactionMode
- One ofSQLiteConfig.TransactionMode
.- See Also:
- https://www.sqlite.org/lang_transaction.html
-
setTransactionMode
public void setTransactionMode(String transactionMode)
Sets the mode that will be used to start transactions.- Parameters:
transactionMode
- One of DEFERRED, IMMEDIATE or EXCLUSIVE.- See Also:
- https://www.sqlite.org/lang_transaction.html
-
getTransactionMode
public SQLiteConfig.TransactionMode getTransactionMode()
- Returns:
- The transaction mode.
-
setDatePrecision
public void setDatePrecision(String datePrecision)
- Parameters:
datePrecision
- One of SECONDS or MILLISECONDS
-
setDateClass
public void setDateClass(String dateClass)
- Parameters:
dateClass
- One of INTEGER, TEXT or REAL
-
setDateStringFormat
public void setDateStringFormat(String dateStringFormat)
- Parameters:
dateStringFormat
- Format of date string
-
setBusyTimeout
public void setBusyTimeout(int milliseconds)
- Parameters:
milliseconds
- Connect to DB timeout in milliseconds
-
getBusyTimeout
public int getBusyTimeout()
-
isGetGeneratedKeys
public boolean isGetGeneratedKeys()
-
setGetGeneratedKeys
public void setGetGeneratedKeys(boolean generatedKeys)
-
-
-