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 Summary
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic 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 int
Gets the flavor of the JDBC used in the internal server database.static Connection
Gets a pooled connection for user processing to the internal server database.static int
Returns whether the Server internal database is ready for use, i.e.static String
Gets the Derby network database server host name for connections.static int
Gets 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_DIRECTORY
The default database directory: "db".- See Also:
Constructor Details
DBUtilities
public DBUtilities()
Method Details
getJDBCFlavor
public 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
setDBConfDir
Processes the database configuration directive. The directory is searched for a file named "dbconf.properties", and if it is missing, aFileNotFoundException
is thrown.- Parameters:
dirName
- The database configuration directory.- Throws:
FileNotFoundException
- ifdirName
is not found or not a directory, or if one of the filesdirName/dbconf.properties
is not found.
setFileURLResolver
Interface 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.
setAutoCreate
public static void setAutoCreate(boolean on) Sets the database auto-create flag.- Parameters:
on
- The automatic start flag.
setServerAutoStart
public static void setServerAutoStart(boolean on) Sets the Derby network database server auto-start flag.- Parameters:
on
- The automatic start flag.
setServerHost
Sets 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.
getServerHost
Gets the Derby network database server host name for connections.- Returns:
- The host for the Client Derby driver, default "localhost".
setServerPort
public 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.
getServerPort
public static int getServerPort()Gets the Derby network database server port for connections.- Returns:
- The port number for the Client Derby driver, default 1527.
setDirectory
Sets 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.
registerPoolProxy
Registers a database pool proxy.- Parameters:
proxy
- The proxy.- Throws:
SQLException
- For connection, class loader or instantiation failures.SecurityException
- If caller is not allowed.
getConnectionPool
public 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.
areTablesCreated
Checks if the tables already are created.- Parameters:
conn
- The connection.schema
- The schema.table
- The table.- Returns:
- true if the table exist, false otherwise.
getServerDatabaseReady
public 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.
getPooledConnection
Gets 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.
createTables
Creates 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.
createTables
public 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.
createTables
public 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.