Package org.sqlite

Class SQLiteDataSource

  • All Implemented Interfaces:
    java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource
    Direct Known Subclasses:
    SQLiteConnectionPoolDataSource

    public class SQLiteDataSource
    extends java.lang.Object
    implements javax.sql.DataSource
    Provides DataSource API for configuring SQLite database connection
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SQLiteConfig getConfig()  
      java.sql.Connection getConnection()  
      SQLiteConnection getConnection​(java.lang.String username, java.lang.String password)  
      java.lang.String getDatabaseName()  
      int getLoginTimeout()  
      java.io.PrintWriter getLogWriter()  
      java.util.logging.Logger getParentLogger()  
      java.lang.String getUrl()  
      boolean isWrapperFor​(java.lang.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​(java.lang.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​(java.lang.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 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​(java.lang.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​(java.lang.String mode)
      Sets the database connection locking-mode.
      void setLoginTimeout​(int seconds)  
      void setLogWriter​(java.io.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 mode
      void setReadUncommitted​(boolean useReadUncommittedIsolationMode)
      Set READ UNCOMMITTED isolation
      void 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 setShortColumnNames​(boolean enable)
      Enables or disables the short_column_names flag.
      void setSynchronous​(java.lang.String mode)
      Sets the setting of the "synchronous" flag.
      void setTempStore​(java.lang.String storeType)
      Set the temp_store type which is used to determine where temporary tables and indices are stored.
      void setTempStoreDirectory​(java.lang.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​(java.lang.String transactionMode)
      Sets the mode that will be used to start transactions for this database.
      void setUrl​(java.lang.String url)
      Sets the location of the database file.
      void setUserVersion​(int version)
      Sets the value of the user-version.
      <T> T unwrap​(java.lang.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
    • Field Detail

      • logger

        private transient java.io.PrintWriter logger
      • loginTimeout

        private int loginTimeout
      • url

        private java.lang.String url
      • databaseName

        private java.lang.String databaseName
    • 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​(java.lang.String url)
        Sets the location of the database file.
        Parameters:
        url - The location of the database file.
      • getUrl

        public java.lang.String getUrl()
        Returns:
        The location of the database file.
      • setDatabaseName

        public void setDatabaseName​(java.lang.String databaseName)
        Sets the database name.
        Parameters:
        databaseName - The name of the database
      • getDatabaseName

        public java.lang.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
      • 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
      • 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​(java.lang.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
      • 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
      • setJournalMode

        public void setJournalMode​(java.lang.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:
        • 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
        • setTempStore

          public void setTempStore​(java.lang.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​(java.lang.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​(java.lang.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
        • getConnection

          public java.sql.Connection getConnection()
                                            throws java.sql.SQLException
          Specified by:
          getConnection in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.getConnection()
        • getConnection

          public SQLiteConnection getConnection​(java.lang.String username,
                                                java.lang.String password)
                                         throws java.sql.SQLException
          Specified by:
          getConnection in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.getConnection(java.lang.String, java.lang.String)
        • getLogWriter

          public java.io.PrintWriter getLogWriter()
                                           throws java.sql.SQLException
          Specified by:
          getLogWriter in interface javax.sql.CommonDataSource
          Specified by:
          getLogWriter in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.getLogWriter()
        • getLoginTimeout

          public int getLoginTimeout()
                              throws java.sql.SQLException
          Specified by:
          getLoginTimeout in interface javax.sql.CommonDataSource
          Specified by:
          getLoginTimeout in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.getLoginTimeout()
        • getParentLogger

          public java.util.logging.Logger getParentLogger()
                                                   throws java.sql.SQLFeatureNotSupportedException
          Specified by:
          getParentLogger in interface javax.sql.CommonDataSource
          Throws:
          java.sql.SQLFeatureNotSupportedException
        • setLogWriter

          public void setLogWriter​(java.io.PrintWriter out)
                            throws java.sql.SQLException
          Specified by:
          setLogWriter in interface javax.sql.CommonDataSource
          Specified by:
          setLogWriter in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.setLogWriter(java.io.PrintWriter)
        • setLoginTimeout

          public void setLoginTimeout​(int seconds)
                               throws java.sql.SQLException
          Specified by:
          setLoginTimeout in interface javax.sql.CommonDataSource
          Specified by:
          setLoginTimeout in interface javax.sql.DataSource
          Throws:
          java.sql.SQLException
          See Also:
          DataSource.setLoginTimeout(int)
        • isWrapperFor

          public boolean isWrapperFor​(java.lang.Class<?> iface)
                               throws java.sql.SQLException
          Determines if this object wraps a given class.
          Specified by:
          isWrapperFor in interface java.sql.Wrapper
          Parameters:
          iface - The class to check.
          Returns:
          True if it is an instance of the current class; false otherwise.
          Throws:
          java.sql.SQLException
        • unwrap

          public <T> T unwrap​(java.lang.Class<T> iface)
                       throws java.sql.SQLException
          Casts this object to the given class.
          Specified by:
          unwrap in interface java.sql.Wrapper
          Parameters:
          iface - The class to cast to.
          Returns:
          The casted class.
          Throws:
          java.sql.SQLException