public final class H2Database extends AbstractDatabase
Database.Statistics, Database.Type
DATABASE_EMBEDDED, DATABASE_EMBEDDED_IN_MEMORY, DATABASE_HOST, DATABASE_INIT_SCRIPT, DATABASE_PORT, DATABASE_SID, DATABASE_TYPE, DEFAULT_LOGIN_TIMEOUT, PASSWORD_PROPERTY, USER_PROPERTY
Constructor and Description |
---|
H2Database()
Instantiates a new embedded H2Database, using
Database.DATABASE_HOST for database name. |
H2Database(java.lang.String databaseName)
Instantiates a new embedded H2Database.
|
H2Database(java.lang.String databaseName,
boolean embeddedInMemory)
Instantiates a new embedded H2Database.
|
H2Database(java.lang.String host,
java.lang.Integer port,
java.lang.String databaseName)
Instantiates a new networked H2Database.
|
H2Database(java.lang.String databaseName,
java.lang.String initScript)
Instantiates a new embedded H2Database instance, in memory, initialized with the given script, if any
|
H2Database(java.lang.String databaseName,
java.lang.String initScript,
boolean embeddedInMemory)
Instantiates a new embedded H2Database instance, initialized with the given script, if any
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAutoIncrementQuery(java.lang.String idSource)
Returns a query string for retrieving the last automatically generated id from the given id source
|
java.lang.String |
getSequenceQuery(java.lang.String sequenceName) |
java.lang.String |
getURL(java.util.Properties connectionProperties) |
boolean |
isAuthenticationException(java.sql.SQLException exception)
This default implementation returns false
|
boolean |
isReferentialIntegrityException(java.sql.SQLException exception)
This default implementation returns false
|
boolean |
isUniqueConstraintException(java.sql.SQLException exception) |
void |
runScript(java.lang.String scriptPath)
Runs the given script using the RunScript tool, with the default sysadmin username (sa) and default charset
|
void |
runScript(java.lang.String scriptPath,
java.lang.String username,
java.lang.String password,
java.nio.charset.Charset scriptCharset)
Runs the given script using the RunScript tool
|
addConnectionProperties, createConnection, getAuthenticationInfo, getCheckConnectionQuery, getDriverClassName, getErrorMessage, getHost, getLoginTimeout, getPort, getSid, getType, getUrlAppend, isEmbedded, setUrlAppend, shutdownEmbedded, supportsIsValid, supportsNowait, supportsSelectForUpdate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDatabaseType
public H2Database()
Database.DATABASE_HOST
for database name.public H2Database(java.lang.String databaseName)
databaseName
- the path to the database filespublic H2Database(java.lang.String databaseName, boolean embeddedInMemory)
databaseName
- the path to the database files or the database name if in-memoryembeddedInMemory
- if true then this instance is memory basedpublic H2Database(java.lang.String host, java.lang.Integer port, java.lang.String databaseName)
host
- the host nameport
- the port numberdatabaseName
- the database namepublic H2Database(java.lang.String databaseName, java.lang.String initScript)
databaseName
- the database nameinitScript
- a script to use for initializing the database, null if not requiredjava.lang.RuntimeException
- in case of an error during initializationpublic H2Database(java.lang.String databaseName, java.lang.String initScript, boolean embeddedInMemory)
databaseName
- the database nameinitScript
- a script to use for initializing the database, null if not requiredembeddedInMemory
- if true then the resulting database is in memoryjava.lang.RuntimeException
- in case of an error during initializationpublic java.lang.String getAutoIncrementQuery(java.lang.String idSource)
idSource
- the source for the id, for example a sequence name or in the case of Derby, the name of the table auto generating the valuepublic java.lang.String getSequenceQuery(java.lang.String sequenceName)
getSequenceQuery
in interface Database
getSequenceQuery
in class AbstractDatabase
sequenceName
- the name of the sequencepublic java.lang.String getURL(java.util.Properties connectionProperties)
connectionProperties
- the connection properties, used primarily to provide
embedded databases with user info for authentication purposespublic boolean isAuthenticationException(java.sql.SQLException exception)
isAuthenticationException
in interface Database
isAuthenticationException
in class AbstractDatabase
exception
- the exceptionpublic boolean isReferentialIntegrityException(java.sql.SQLException exception)
isReferentialIntegrityException
in interface Database
isReferentialIntegrityException
in class AbstractDatabase
exception
- the exceptionpublic boolean isUniqueConstraintException(java.sql.SQLException exception)
isUniqueConstraintException
in interface Database
isUniqueConstraintException
in class AbstractDatabase
exception
- the exceptionpublic void runScript(java.lang.String scriptPath) throws java.sql.SQLException
scriptPath
- the path to the scriptjava.sql.SQLException
- in case of an exceptionpublic void runScript(java.lang.String scriptPath, java.lang.String username, java.lang.String password, java.nio.charset.Charset scriptCharset) throws java.sql.SQLException
scriptPath
- the path to the scriptusername
- the username to run the script underpassword
- the passwordscriptCharset
- the script charactersetjava.sql.SQLException
- in case of an exception