Class JDBCHelper
java.lang.Object
com.iizix.jdbc.JDBCHelper
Derby instance for iiziGo and iiziServer.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic intDisposes of created instance and stops the Derby network server if started.static IDBConnectionPoolConstructs the Derby database connection pool from a directory that can contain a "dbconf.properties" file.static IDBConnectionPoolConstructs 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: seefrom(String,File,BiFunction).static IDBConnectionPoolfrom(String name, PropCnr cnr, Properties driverProps) Creates a database connection pool from values stored in a property container.static IDBConnectionPoolConstructs the database connection pool from a directory that should contain a "dbconf.properties" file.static IDBConnectionPoolConstructs 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.static URL[]getClassLoaderURLs(File dir, String classPath) Parses the classPath into URL's with the specified directory as the relative directory.static Fileinitialize(IFileURLResolver resolver) Initializes the file resolver and looks up the[resources/]jdbc-driversdirectory.static StringsetUsePrivateDirectory(boolean doCopy) Sets the JDBC drivers directory to be the user's private directory "~/.iizi/jdbc-drivers".
Constructor Details
JDBCHelper
public JDBCHelper()
Method Details
setUsePrivateDirectory
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
Initializes the file resolver and looks up the[resources/]jdbc-driversdirectory.- Parameters:
resolver- The URL to File resolver.- Returns:
- The canonical directory for the
jdbc-drivers. - Throws:
IOException- If the the[resources/]jdbc-driversdirectory 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
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. Ifdirisnullthe 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 privateresolveEntry).- Returns:
- The URL's is never an empty array. If classPath is null or empty string, the URL is set to the
dirURL. - 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
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, throws IOException, SQLExceptionString> secrets) 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_SECRETand gives noIDBConnectionPool.PN_PASSWORD, or an empty one, gets its password fromsecrets; 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, throws IOException, SQLExceptionString> secrets) 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: seefrom(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 poolIOException- 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.