Package com.iizix.server.db
Class DBUtilities
java.lang.Object
com.iizix.server.db.DBUtilities
The utilities class is used e.g. to create the database and the database tables used by the stand-alone or development servers.
- Author:
- Christopher Mindus
- Field SummaryFields
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- static boolean- areTablesCreated- (Connection conn, String schema, String table) Checks if the tables already are created.- static void- createTables- (int jdbcFlavor, Connection conn, InputStream in, Charset charSet, int textLength) Creates tables.- static void- createTables- (Connection conn, InputStream in) Creates tables.- static void- createTables- (Connection conn, InputStream in, String originalSchema, String newSchema) Creates the tables with a change of the schema from "original" to "new".- static IDBConnectionPool- getConnectionPool- (IFileURLResolver fileURLResolver) Creates the connection pool.- static intGets the flavor of the JDBC used in the internal server database.- static ConnectionGets a pooled connection for user processing to the internal server database.- static intReturns whether the Server internal database is ready for use, i.e.- static StringGets the Derby network database server host name for connections.- static intGets the Derby network database server port for connections.- static void- registerPoolProxy- (IDBPoolProxy proxy) Registers a database pool proxy.- static void- setAutoCreate- (boolean on) Sets the database auto-create flag.- static void- setDBConfDir- (String dirName) Processes the database configuration directive.- static void- setDirectory- (String dir) Sets the database directory for the internal server.- static void- setFileURLResolver- (IFileURLResolver resolver) Interface used to resolve URL's to files for the Designer.- static void- setServerAutoStart- (boolean on) Sets the Derby network database server auto-start flag.- static void- setServerHost- (String host) Sets the Derby network database server host name for connections.- static void- setServerPort- (int port) Sets the Derby network database server port for connections.
- Field Details- DEFAULT_DATABASE_DIRECTORYThe default database directory: "db".- See Also:
 
 
- Constructor Details- DBUtilitiespublic DBUtilities()
 
- Method Details- getJDBCFlavorpublic static int getJDBCFlavor()Gets the flavor of the JDBC used in the internal server database. This value is computed when the connection pool is created.- See the FLAVOR_* values. - Returns:
- A flavor value as:- -1 = Undefined
- 0 = Derby
- 1 = MySQL
- 2 = PostgreSQL
- 3 = SQL Server
- 4 = DB2
 
 
- setDBConfDirProcesses the database configuration directive. The directory is searched for a file named "dbconf.properties", and if it is missing, a- FileNotFoundExceptionis thrown.- Parameters:
- dirName- The database configuration directory.
- Throws:
- FileNotFoundException- if- dirNameis not found or not a directory, or if one of the files- dirName/dbconf.propertiesis not found.
 
- setFileURLResolverInterface used to resolve URL's to files for the Designer. In other products, the same URL is returned unchanged.- Parameters:
- resolver- The resolver instance.
- Throws:
- NullPointerException- If the resolver is null.
 
- setAutoCreatepublic static void setAutoCreate- (boolean on) Sets the database auto-create flag.- Parameters:
- on- The automatic start flag.
 
- setServerAutoStartpublic static void setServerAutoStart- (boolean on) Sets the Derby network database server auto-start flag.- Parameters:
- on- The automatic start flag.
 
- setServerHostSets the Derby network database server host name for connections.- Parameters:
- host- The host for the Client Derby driver.
- Throws:
- NullPointerException- If the host name is null.
- IllegalArgumentException- If the host is invalid.
 
- getServerHostGets the Derby network database server host name for connections.- Returns:
- The host for the Client Derby driver, default "localhost".
 
- setServerPortpublic static void setServerPort- (int port) Sets the Derby network database server port for connections.- Parameters:
- port- The port number for the Client Derby driver.
- Throws:
- IllegalArgumentException- If the number is invalid.
 
- getServerPortpublic static int getServerPort()Gets the Derby network database server port for connections.- Returns:
- The port number for the Client Derby driver, default 1527.
 
- setDirectorySets the database directory for the internal server. The default directory is "db" (it is already appended with 'iiziServer').- Parameters:
- dir- The new directory. The database name will be "iiziServer"
- Throws:
- FileNotFoundException- If the parent directory does not exist.
- IOException- For file system errors.
 
- registerPoolProxyRegisters a database pool proxy.- Parameters:
- proxy- The proxy.
- Throws:
- SQLException- For connection, class loader or instantiation failures.
- SecurityException- If caller is not allowed.
 
- getConnectionPoolpublic static IDBConnectionPool getConnectionPool- (IFileURLResolver fileURLResolver) throws SQLException Creates the connection pool.- Parameters:
- fileURLResolver- File resolver from an URL.
- Returns:
- The connection pool.
- Throws:
- SQLException- For connection, class loader or instantiation failures.
- SecurityException- If the caller is not allowed to access the server database connection pool.
 
- areTablesCreatedChecks if the tables already are created.- Parameters:
- conn- The connection.
- schema- The schema.
- table- The table.
- Returns:
- true if the table exist, false otherwise.
 
- getServerDatabaseReadypublic static int getServerDatabaseReady()Returns whether the Server internal database is ready for use, i.e. database server potentially started and the connection pool ready.- Returns:
- The codes are:
 1 = started and ready,
 0 = starting or will start and not ready; and
 -1 = failed starting and ready won't start, i.e. server database has failed and server will exit.
 
- getPooledConnectionGets a pooled connection for user processing to the internal server database.- Returns:
- The pooled connection that MUST be released and not closed.
- Throws:
- SQLException- For SQL errors.
 
- createTablesCreates tables.- The length of a MySQL TEXT when creating a Derby table using VARCHAR instead is set to 4096. Use the method - {@link #createTables(int, Connection, InputStream, Charset, int)}to specify another length.- The Database Flavor is assumed to be the one from the IIZI Internal Database pool. - Parameters:
- conn- The connection.
- in- Input stream to a creation of tables SQL file. The input stream is closed regardless of exceptions. The input stream is processed using UTF-8.
- Throws:
- SQLException- For SQL errors.
 
- createTablespublic static void createTables- (int jdbcFlavor, Connection conn, InputStream in, Charset charSet, int textLength) throws SQLException Creates tables.- Parameters:
- jdbcFlavor- The JDBC flavor used to convert SQL statements between Database Flavors, accepted values:- IDBConnectionPool.FLAVOR_DERBY,
- IDBConnectionPool.FLAVOR_MYSQL,
- others values are ignored and makes no change in the SQL.
 
- conn- The connection.
- in- Input stream to a "createTables.sql" file. The input stream is closed regardless of exceptions. The input stream is processed using UTF-8.
- textLength- The length of a MySQL TEXT when creating a Derby table using VARCHAR instead.
- Throws:
- SQLException- For SQL errors.
 
- createTablespublic static void createTables- (Connection conn, InputStream in, String originalSchema, String newSchema) throws SQLException Creates the tables with a change of the schema from "original" to "new".- Parameters:
- conn- The connection.
- in- Input stream to a "createTables.sql" file. The input stream is closed regardless of exceptions.
- originalSchema- The original schema name (upper case).
- newSchema- The new schema name (upper case).
- Throws:
- SQLException- For SQL errors.