Package org.sqlite

Class SQLiteJDBCLoader


  • public class SQLiteJDBCLoader
    extends java.lang.Object
    Set the system properties, org.sqlite.lib.path, org.sqlite.lib.name, appropriately so that the SQLite JDBC driver can find *.dll, *.dylib and *.so files, according to the current OS (win, linux, mac).

    The library files are automatically extracted from this project's package (JAR).

    usage: call initialize() before using SQLite JDBC driver.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SQLiteJDBCLoader.VersionHolder
      This class will load the version from resources during .
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean extracted  
      private static java.lang.String LOCK_EXT  
      private static Logger logger  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void cleanup()
      Deleted old native libraries e.g.
      private static boolean contentsEquals​(java.io.InputStream in1, java.io.InputStream in2)  
      private static boolean extractAndLoadLibraryFile​(java.lang.String libFolderForCurrentOS, java.lang.String libraryFileName, java.lang.String targetFolder)
      Extracts and loads the specified library file to the target folder
      static int getMajorVersion()  
      static int getMinorVersion()  
      private static void getNativeLibraryFolderForTheCurrentOS()  
      private static java.io.InputStream getResourceAsStream​(java.lang.String name)  
      private static java.io.File getTempDir()  
      static java.lang.String getVersion()  
      static boolean initialize()
      Loads SQLite native JDBC library.
      static boolean isNativeMode()
      Checks if the SQLite JDBC driver is set to native mode.
      private static boolean loadNativeLibrary​(java.lang.String path, java.lang.String name)
      Loads native library using the given path and name of the library.
      private static boolean loadNativeLibraryJdk()  
      private static void loadSQLiteNativeLibrary()
      Loads SQLite native library using given path and name of the library.
      (package private) static java.lang.String md5sum​(java.io.InputStream input)
      Computes the MD5 value of the input stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final Logger logger
      • extracted

        private static boolean extracted
    • Constructor Detail

      • SQLiteJDBCLoader

        public SQLiteJDBCLoader()
    • Method Detail

      • initialize

        public static boolean initialize()
                                  throws java.lang.Exception
        Loads SQLite native JDBC library.
        Returns:
        True if SQLite native library is successfully loaded; false otherwise.
        Throws:
        java.lang.Exception
      • getTempDir

        private static java.io.File getTempDir()
      • cleanup

        static void cleanup()
        Deleted old native libraries e.g. on Windows the DLL file is not removed on VM-Exit (bug #80)
      • isNativeMode

        public static boolean isNativeMode()
                                    throws java.lang.Exception
        Checks if the SQLite JDBC driver is set to native mode.
        Returns:
        True if the SQLite JDBC driver is set to native Java mode; false otherwise.
        Throws:
        java.lang.Exception
      • md5sum

        static java.lang.String md5sum​(java.io.InputStream input)
                                throws java.io.IOException
        Computes the MD5 value of the input stream.
        Parameters:
        input - InputStream.
        Returns:
        Encrypted string for the InputStream.
        Throws:
        java.io.IOException
        java.security.NoSuchAlgorithmException
      • contentsEquals

        private static boolean contentsEquals​(java.io.InputStream in1,
                                              java.io.InputStream in2)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • extractAndLoadLibraryFile

        private static boolean extractAndLoadLibraryFile​(java.lang.String libFolderForCurrentOS,
                                                         java.lang.String libraryFileName,
                                                         java.lang.String targetFolder)
                                                  throws FileException
        Extracts and loads the specified library file to the target folder
        Parameters:
        libFolderForCurrentOS - Library path.
        libraryFileName - Library name.
        targetFolder - Target folder.
        Returns:
        Throws:
        FileException
      • getResourceAsStream

        private static java.io.InputStream getResourceAsStream​(java.lang.String name)
      • loadNativeLibrary

        private static boolean loadNativeLibrary​(java.lang.String path,
                                                 java.lang.String name)
        Loads native library using the given path and name of the library.
        Parameters:
        path - Path of the native library.
        name - Name of the native library.
        Returns:
        True for successfully loading; false otherwise.
      • loadNativeLibraryJdk

        private static boolean loadNativeLibraryJdk()
      • loadSQLiteNativeLibrary

        private static void loadSQLiteNativeLibrary()
                                             throws java.lang.Exception
        Loads SQLite native library using given path and name of the library.
        Throws:
        java.lang.Exception
      • getNativeLibraryFolderForTheCurrentOS

        private static void getNativeLibraryFolderForTheCurrentOS()
      • getMajorVersion

        public static int getMajorVersion()
        Returns:
        The major version of the SQLite JDBC driver.
      • getMinorVersion

        public static int getMinorVersion()
        Returns:
        The minor version of the SQLite JDBC driver.
      • getVersion

        public static java.lang.String getVersion()
        Returns:
        The version of the SQLite JDBC driver.