Package org.sqlite

Class SQLiteConfig


  • public class SQLiteConfig
    extends java.lang.Object
    SQLite Configuration See also http://www.sqlite.org/pragma.html
    • Field Detail

      • pragmaTable

        private final java.util.Properties pragmaTable
      • openModeFlag

        private int openModeFlag
      • busyTimeout

        public final int busyTimeout
      • DEFAULT_DATE_STRING_FORMAT

        public static final java.lang.String DEFAULT_DATE_STRING_FORMAT
        See Also:
        Constant Field Values
      • dateMultiplier

        public long dateMultiplier
      • dateStringFormat

        public java.lang.String dateStringFormat
      • OnOff

        private static final java.lang.String[] OnOff
    • Constructor Detail

      • SQLiteConfig

        public SQLiteConfig()
        Default constructor.
      • SQLiteConfig

        public SQLiteConfig​(java.util.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

      • 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 the DriverManager.getConnection(String, Properties).
        Returns:
        The property object.
      • getDriverPropertyInfo

        static java.sql.DriverPropertyInfo[] getDriverPropertyInfo()
        Returns:
        Array of DriverPropertyInfo objects.
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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 of SQLiteConfig.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 of SQLiteConfig.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​(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
      • 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