Class JDBCHelper

java.lang.Object
com.iizix.jdbc.JDBCHelper

public class JDBCHelper extends Object
Derby instance for iiziGo and iiziServer.
Author:
Christopher Mindus
  • Constructor Details

    • JDBCHelper

      public JDBCHelper()
  • Method Details

    • setUsePrivateDirectory

      public static String setUsePrivateDirectory(boolean doCopy)
      Sets the JDBC drivers directory to be the user's private directory "~/.iizi/jdbc-drivers".
      Parameters:
      doCopy - Flag to perform copy of the normal JDBC drivers directory to the user's private directory "~/.iizi/jdbc-drivers".
      Returns:
      Error message for failure, null for success.
    • initialize

      public static File initialize(IFileURLResolver resolver) throws IOException
      Initializes the file resolver and looks up the [resources/]jdbc-drivers directory.
      Parameters:
      resolver - The URL to File resolver.
      Returns:
      The canonical directory for the jdbc-drivers.
      Throws:
      IOException - If the the [resources/]jdbc-drivers directory is not found, or if the user's private directory for JDBC drivers "~/.iizi/jdbc-drivers" is not found or copy/update or drivers and files failed.
    • getClassLoaderURLs

      public static URL[] getClassLoaderURLs(File dir, String classPath) throws IOException
      Parses the classPath into URL's with the specified directory as the relative directory.
      Parameters:
      dir - The directory that is used for relative paths in the classpath for directories This directory is normally the one containing the 'dbconf*.properties' file to process the 'classpath' entry. If dir is null the classpath must either contain absolute paths or in case of no classpath, an empty URL array is returned.
      classPath - The classpath with a comma as separator (not the system separator ";" for Windows or ":" for other systems). To specify a comma, enter it twice. The path must consist of either directories or (Jar) files. A file name may hold '*' as a pattern for Jar files (postgresql/postgresql-*.jar): the newest matching Jar file of the directory is used; a versioned Jar file name that is not found (postgresql-42.7.13.jar) is replaced by the newest Jar file of its base name beside it, with a warning (the private resolveEntry).
      Returns:
      The URL's is never an empty array. If classPath is null or empty string, the URL is set to the dir URL.
      Throws:
      IOException - If the classPath references non-existent or erroneous paths, or the path part is a file that is does not have the '.jar' or '.zip' file extension.
    • from

      public static IDBConnectionPool from(String name, File dir) throws IOException, SQLException
      Constructs the database connection pool from a directory that should contain a "dbconf.properties" file.
      Parameters:
      name - The name of the database connection pool.
      dir - The directory where the "dbconf.properties" should be present.
      Throws:
      IOException - For I/O errors.
      SQLException - For errors in creating the database pool.
    • from

      public static IDBConnectionPool from(String name, File dir, BiFunction<String,File,String> secrets) throws IOException, SQLException
      Constructs the database connection pool from a directory that should contain a "dbconf.properties" file, the password taken from the secrets store of the machine when the file names a key instead of a value.

      A "dbconf.properties" that sets IDBConnectionPool.PN_PASSWORD_SECRET and gives no IDBConnectionPool.PN_PASSWORD, or an empty one, gets its password from secrets; a password given in the file is used as it is. This class does not know the secrets store: the caller that does hands it in.

      Parameters:
      name - The name of the database connection pool.
      dir - The directory where the "dbconf.properties" should be present.
      secrets - Gives the password of a secrets store key: it is called with the key and the "dbconf.properties" file naming it, and returns the password, or null when it has none, which it reports itself. Null when the caller has no secrets store: a file naming a key is then reported at SEVERE.
      Returns:
      The database connection pool.
      Throws:
      IOException - For I/O errors.
      SQLException - For errors in creating the database pool.
    • from

      public static IDBConnectionPool from(String name, DerbyImpl derbyImpl) throws IOException, SQLException
      Constructs the Derby database connection pool from a directory that can contain a "dbconf.properties" file.
      Parameters:
      name - The name of the database connection pool.
      derbyImpl - The Derby implementation.
      Returns:
      The database connection pool.
      Throws:
      IOException - For I/O errors.
      SQLException - For errors in creating the database pool.
    • from

      public static IDBConnectionPool from(String name, DerbyImpl derbyImpl, BiFunction<String,File,String> secrets) throws IOException, SQLException
      Constructs the Derby database connection pool from a directory that can contain a "dbconf.properties" file, the password of that file taken from the secrets store of the machine when it names a key instead of a value: see from(String,File,BiFunction).
      Parameters:
      name - The name of the database connection pool.
      derbyImpl - The Derby implementation.
      secrets - Gives the password of a secrets store key, null when the caller has no secrets store.
      Returns:
      The database connection pool.
      Throws:
      IOException - For I/O errors.
      SQLException - For errors in creating the database pool.
    • from

      public static IDBConnectionPool from(String name, PropCnr cnr, Properties driverProps) throws SQLException, IOException
      Creates a database connection pool from values stored in a property container.
      Parameters:
      name - The name of the database connection pool.
      cnr - The property container.
      driverProps - The driver properties, null for none.
      Returns:
      The database connection pool.
      Throws:
      SQLException - For errors in creating the database pool
      IOException - For I/O errors.
    • disposeAll

      public static int disposeAll()
      Disposes of created instance and stops the Derby network server if started.
      Returns:
      count of disposed instances, zero for none.