Package org.sqlite
Class SQLiteConfig
- java.lang.Object
-
- org.sqlite.SQLiteConfig
-
public class SQLiteConfig extends java.lang.Object
SQLite Configuration See also http://www.sqlite.org/pragma.html
-
-
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.JournalMode
static class
SQLiteConfig.LockingMode
static class
SQLiteConfig.Pragma
private static interface
SQLiteConfig.PragmaValue
The common interface for retrieving the available pragma parameter values.static class
SQLiteConfig.SynchronousMode
static class
SQLiteConfig.TempStore
static class
SQLiteConfig.TransactionMode
-
Field Summary
Fields Modifier and Type Field Description int
busyTimeout
SQLiteConfig.DateClass
dateClass
long
dateMultiplier
SQLiteConfig.DatePrecision
datePrecision
java.lang.String
dateStringFormat
static java.lang.String
DEFAULT_DATE_STRING_FORMAT
private static java.lang.String[]
OnOff
private int
openModeFlag
private java.util.Properties
pragmaTable
private SQLiteConfig.TransactionMode
transactionMode
-
Constructor Summary
Constructors Constructor Description SQLiteConfig()
Default constructor.SQLiteConfig(java.util.Properties prop)
Creates an SQLite configuration object using values from the given property object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
apply(java.sql.Connection conn)
Configures a connection.java.sql.Connection
createConnection(java.lang.String url)
Create a new JDBC connection using the current configurationvoid
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.private boolean
getBoolean(SQLiteConfig.Pragma pragma, java.lang.String defaultValue)
Checks if the provided value is the default for a given pragma.(package private) static java.sql.DriverPropertyInfo[]
getDriverPropertyInfo()
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.void
resetOpenMode(SQLiteOpenMode mode)
Re-sets the open mode flags.private void
set(SQLiteConfig.Pragma pragma, boolean flag)
Sets a pragma to the given boolean value.private void
set(SQLiteConfig.Pragma pragma, int num)
Sets a pragma to the given int value.void
setBusyTimeout(java.lang.String 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(java.lang.String dateClass)
void
setDatePrecision(java.lang.String datePrecision)
void
setDateStringFormat(java.lang.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
setJounalSizeLimit(int limit)
Sets the journal_size_limit.void
setJournalMode(SQLiteConfig.JournalMode mode)
Sets the journal mode for databases associated with the current database connection.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, java.lang.String value)
Sets a pragma's value.void
setReadOnly(boolean readOnly)
Sets the read-write mode for the database.void
setReadUncommited(boolean useReadUncommitedIsolationMode)
Enables or disables useReadUncommitedIsolationMode.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(java.lang.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(java.lang.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.java.util.Properties
toProperties()
Convert this configuration into a Properties object, which can be passed to theDriverManager.getConnection(String, Properties)
.private static java.lang.String[]
toStringArray(SQLiteConfig.PragmaValue[] list)
Convert the given enum values to a string arrayvoid
useLegacyFileFormat(boolean use)
Sets the value of the legacy_file_format flag.
-
-
-
Field Detail
-
pragmaTable
private final java.util.Properties pragmaTable
-
openModeFlag
private int openModeFlag
-
transactionMode
private SQLiteConfig.TransactionMode transactionMode
-
busyTimeout
public final int busyTimeout
-
DEFAULT_DATE_STRING_FORMAT
public static final java.lang.String DEFAULT_DATE_STRING_FORMAT
- See Also:
- Constant Field Values
-
dateClass
public SQLiteConfig.DateClass dateClass
-
datePrecision
public SQLiteConfig.DatePrecision datePrecision
-
dateMultiplier
public long dateMultiplier
-
dateStringFormat
public java.lang.String dateStringFormat
-
OnOff
private static final java.lang.String[] OnOff
-
-
Method Detail
-
createConnection
public java.sql.Connection createConnection(java.lang.String url) throws java.sql.SQLException
Create a new JDBC connection using the current configuration- Returns:
- The connection.
- Throws:
java.sql.SQLException
-
apply
public void apply(java.sql.Connection conn) throws java.sql.SQLException
Configures a connection.- Parameters:
conn
- The connection to configure.- Throws:
java.sql.SQLException
-
set
private void set(SQLiteConfig.Pragma pragma, boolean flag)
Sets a pragma to the given boolean value.- Parameters:
pragma
- The pragma to set.flag
- The boolean value.
-
set
private void set(SQLiteConfig.Pragma pragma, int num)
Sets a pragma to the given int value.- Parameters:
pragma
- The pragma to set.num
- The int value.
-
getBoolean
private boolean getBoolean(SQLiteConfig.Pragma pragma, java.lang.String defaultValue)
Checks if the provided value is the default for a given pragma.- Parameters:
pragma
- The pragma on which to check.defaultValue
- The value to check for.- Returns:
- True if the given value is the default value; false otherwise.
-
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, java.lang.String value)
Sets a pragma's value.- Parameters:
pragma
- The pragma to change.value
- The value to set it to.
-
toProperties
public java.util.Properties toProperties()
Convert this configuration into a Properties object, which can be passed to theDriverManager.getConnection(String, Properties)
.- Returns:
- The property object.
-
getDriverPropertyInfo
static java.sql.DriverPropertyInfo[] getDriverPropertyInfo()
- Returns:
- Array of DriverPropertyInfo objects.
-
setOpenMode
public void setOpenMode(SQLiteOpenMode mode)
Sets the open mode flags.- Parameters:
mode
- The open mode.- See Also:
- http://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:
- http://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
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
-
enableEmptyResultCallBacks
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:
- http://www.sqlite.org/pragma.html#pragma_empty_result_callbacks
-
toStringArray
private static java.lang.String[] toStringArray(SQLiteConfig.PragmaValue[] list)
Convert the given enum values to a string array- Parameters:
list
- Array if PragmaValue.- Returns:
- String array of Enum values
-
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
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
-
setJounalSizeLimit
public void setJounalSizeLimit(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
-
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
-
setReadUncommited
public void setReadUncommited(boolean useReadUncommitedIsolationMode)
Enables or disables useReadUncommitedIsolationMode.- Parameters:
useReadUncommitedIsolationMode
- 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
-
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 kept in as if they were pure in-memory databases memory
- MEMORY - temporary tables and indices are stored in a file.
- See Also:
- www.sqlite.org/pragma.html#pragma_temp_store
-
setTempStoreDirectory
public void setTempStoreDirectory(java.lang.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
-
setTransactionMode
public void setTransactionMode(SQLiteConfig.TransactionMode transactionMode)
Sets the mode that will be used to start transactions.- Parameters:
transactionMode
- One ofSQLiteConfig.TransactionMode
.- See Also:
- http://www.sqlite.org/lang_transaction.html
-
setTransactionMode
public void setTransactionMode(java.lang.String transactionMode)
Sets the mode that will be used to start transactions.- Parameters:
transactionMode
- One of DEFFERED, IMMEDIATE or EXCLUSIVE.- See Also:
- http://www.sqlite.org/lang_transaction.html
-
getTransactionMode
public SQLiteConfig.TransactionMode getTransactionMode()
- Returns:
- The transaction mode.
-
setDatePrecision
public void setDatePrecision(java.lang.String datePrecision) throws java.sql.SQLException
- Parameters:
datePrecision
- One of SECONDS or MILLISECONDS- Throws:
java.sql.SQLException
-
setDateClass
public void setDateClass(java.lang.String dateClass)
- Parameters:
dateClass
- One of INTEGER, TEXT or REAL
-
setDateStringFormat
public void setDateStringFormat(java.lang.String dateStringFormat)
- Parameters:
dateStringFormat
- Format of date string
-
setBusyTimeout
public void setBusyTimeout(java.lang.String milliseconds)
- Parameters:
milliseconds
- Connect to DB timeout in milliseconds
-
-