org.jminor.common.db.dbms
Class H2Database

java.lang.Object
  extended by org.jminor.common.db.AbstractDatabase
      extended by org.jminor.common.db.dbms.H2Database
All Implemented Interfaces:
Database

public final class H2Database
extends AbstractDatabase

A Database implementation based on the H2 database.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jminor.common.db.Database
Database.Statistics
 
Field Summary
static String DATABASE_IN_MEMORY
          Specifies whether or not the database should be run in in-memory mode
Values: "true"/"false"
Default: "false"
static String DATABASE_INIT_SCRIPT
          The script to run when initializing an embedded database
 
Fields inherited from interface org.jminor.common.db.Database
DATABASE_EMBEDDED, DATABASE_HOST, DATABASE_IMPLEMENTATION_CLASS, DATABASE_POOL_STATISTICS, DATABASE_PORT, DATABASE_SID, DATABASE_TYPE, DEFAULT_LOGIN_TIMEOUT, DERBY, H2, HSQL, MYSQL, ORACLE, PASSWORD_PROPERTY, POSTGRESQL, SQLSERVER, USER_PROPERTY
 
Constructor Summary
H2Database()
          Instantiates a new H2Database.
H2Database(String databaseName)
          Instantiates a new embedded H2Database.
H2Database(String host, String port, String databaseName)
          Instantiates a new networked H2Database.
 
Method Summary
static void createEmbeddedH2Database(String scriptPath, boolean inMemory)
          Initializes a new H2 database, with the given script
 String getAutoIncrementValueSQL(String idSource)
          Returns a query string for retrieving the last automatically generated id from the given id source
 String getSequenceSQL(String sequenceName)
          
 String getURL(Properties connectionProperties)
          
 void loadDriver()
          Loads the database driver
 H2Database setUrlAppend(String urlAppend)
           
 
Methods inherited from class org.jminor.common.db.AbstractDatabase
addConnectionProperties, createConnection, getAuthenticationInfo, getCheckConnectionQuery, getDatabaseType, getErrorMessage, getHost, getLoginTimeout, getPort, getSid, isEmbedded, shutdownEmbedded, supportsIsValid, supportsNowait
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_IN_MEMORY

public static final String DATABASE_IN_MEMORY
Specifies whether or not the database should be run in in-memory mode
Values: "true"/"false"
Default: "false"

See Also:
Constant Field Values

DATABASE_INIT_SCRIPT

public static final String DATABASE_INIT_SCRIPT
The script to run when initializing an embedded database

See Also:
Constant Field Values
Constructor Detail

H2Database

public H2Database()
Instantiates a new H2Database.


H2Database

public H2Database(String databaseName)
Instantiates a new embedded H2Database.

Parameters:
databaseName - the path to the database files

H2Database

public H2Database(String host,
                  String port,
                  String databaseName)
Instantiates a new networked H2Database.

Parameters:
host - the host name
port - the port number
databaseName - the database name
Method Detail

setUrlAppend

public H2Database setUrlAppend(String urlAppend)
Parameters:
urlAppend - a string to append to the connection URL
Returns:
this H2Database instance

loadDriver

public void loadDriver()
                throws ClassNotFoundException
Loads the database driver

Throws:
ClassNotFoundException - in case the driver class in not found

getAutoIncrementValueSQL

public String getAutoIncrementValueSQL(String idSource)
Returns a query string for retrieving the last automatically generated id from the given id source

Parameters:
idSource - the source for the id, for example a sequence name or in the case of Derby, the name of the table
Returns:
a query string for retrieving the last auto-increment value from idSource

getSequenceSQL

public String getSequenceSQL(String sequenceName)

Specified by:
getSequenceSQL in interface Database
Overrides:
getSequenceSQL in class AbstractDatabase
Parameters:
sequenceName - the name of the sequence
Returns:
a query for selecting the next value from the given sequence

getURL

public String getURL(Properties connectionProperties)

Parameters:
connectionProperties - the connection properties, used primarily to provide embedded databases with user info for authentication purposes
Returns:
the database url of the active database, based on system properties

createEmbeddedH2Database

public static void createEmbeddedH2Database(String scriptPath,
                                            boolean inMemory)
                                     throws SQLException
Initializes a new H2 database, with the given script

Parameters:
scriptPath - the path to the initilization script
inMemory - true if the database should be created in memory only
Throws:
SQLException - in case of an exception