public class DerbyResourceConfig extends Object
EmbeddedDerbyResource
.
This class provides a fluid interface to build the config object to pass to the constructor of the resource. Example usage:
EmbeddedDerbyResource derbyResource = new EmbeddedDerbyResource( DerbyResourceConfig.buildDefault().);
Some methods in this class, for example the methods setting the subSubProtocol, can be mutually exclusive and unset /
alter values set by other methods. Certain configuration values have valid values as null
and do not
have corresponding getDefaultXXX
methods.
Constructor and Description |
---|
DerbyResourceConfig() |
Modifier and Type | Method and Description |
---|---|
DerbyResourceConfig |
addPostInitScript(String postInitScript)
Adds a post init script to the config.
|
static DerbyResourceConfig |
buildDefault()
Sets up a default config that can be used as is to start a database.
|
DerbyResourceConfig |
createDatabaseFrom(File dbBackupDir)
Create a new database from a backup copy.
|
String |
getDatabasePath()
Returns the name/path of the database to use.
|
File |
getDbCreateFromRestoreFrom()
The location of the database backup to use.
|
DbCreateFromRestroreMode |
getDbCreateFromRestoreMode()
Controls if the database should be created or restored from a backup.
|
File |
getDbRecoveryLogDevice()
Archive log location for roll-forward database recovery.
|
static String |
getDefaultDatabasePathName()
Returns the default database name value, which is a UUID string.
|
static ErrorLoggingMode |
getDefaultErrorLoggingMode()
The default logging setup.
|
static JdbcDerbySubSubProtocol |
getDefaultSubSubProtocol()
The default sub-sub protocol value.
|
ErrorLoggingMode |
getErrorLoggingMode()
The configured error logging mode.
|
String |
getJarDatabaseJarFile()
Returns the Jar database jar file path.
|
List<String> |
getPostInitScripts()
Gets the configured post init scripts in the config; or an empty list.
|
JdbcDerbySubSubProtocol |
getSubSubProtocol()
The JDBC sub-sub protocol to use for the embedded database.
|
boolean |
isDirectoryDatabaseSkipCreate()
For a database using the
JdbcDerbySubSubProtocol.Directory subsubprotocol, skip the
create=true attribute. |
DerbyResourceConfig |
recoverDatabaseFrom(File dbBackupDir,
File recoveryLogDevice)
Restore a database with roll forward recovery, optionally with archive logs.
|
DerbyResourceConfig |
restoreDatabaseFrom(File dbBackupDir)
Restore a database from a backup location.
|
DerbyResourceConfig |
useClasspathSubSubProtocol(String dbPath)
Use the
:classpath: Derby sub sub protocol. |
DerbyResourceConfig |
useDatabaseInDirectory()
Use the
:directory: Derby sub sub protocol. |
DerbyResourceConfig |
useDatabaseInDirectory(String directorpyDbPath)
Use the
:directory: Derby sub sub protocol, with the database in the specified
directorpyDbPath . |
DerbyResourceConfig |
useDatabaseInDirectory(String directorpyDbPath,
boolean skipCreateAttribute)
Use the
:directory: Derby sub sub protocol, with the database in the specified
directorpyDbPath . |
DerbyResourceConfig |
useDefaultErrorLogging()
Sets the
getErrorLoggingMode() value to ErrorLoggingMode.Default ; and clears other logging
properties. |
DerbyResourceConfig |
useDevNullErrorLogging()
Sets the
getErrorLoggingMode() value to ErrorLoggingMode.Null ; and clears other logging
properties. |
DerbyResourceConfig |
useInMemoryDatabase()
Will have the database start up as an in-memory database with a database name generated using
getDefaultDatabasePathName() . |
DerbyResourceConfig |
useInMemoryDatabase(String databaseName)
Will have the database start up as an in-memory database with the specified database name.
|
DerbyResourceConfig |
useJarSubSubProtocol(String jarFilePath,
String dbPath)
Use the
:jar: Derby sub sub protocol. |
public static DerbyResourceConfig buildDefault()
getDefaultXXX
methods to see the default values.public String getJarDatabaseJarFile()
:jar:
protocol for the jar file.
Returns the file path of the jar file with the read only database.useJarSubSubProtocol(String, String)
,
Accessing a read-only database
in a zip/jar filepublic String getDatabasePath()
Consult the documentation for Derby Sub Sub Protocols on database name formats and use.
getDefaultDatabasePathName()
,
Syntax of db connection URLspublic boolean isDirectoryDatabaseSkipCreate()
JdbcDerbySubSubProtocol.Directory
subsubprotocol, skip the
create=true
attribute.public static String getDefaultDatabasePathName()
public DerbyResourceConfig useInMemoryDatabase()
getDefaultDatabasePathName()
.public DerbyResourceConfig useInMemoryDatabase(String databaseName)
databaseName
- The name of the databasepublic DerbyResourceConfig useDatabaseInDirectory()
:directory:
Derby sub sub protocol. The database will be created in a directory named
with the getDefaultDatabasePathName()
as the directory name.public DerbyResourceConfig useDatabaseInDirectory(String directorpyDbPath)
:directory:
Derby sub sub protocol, with the database in the specified
directorpyDbPath
. The path is either relative or absolute as interpreted by the Derby engine.directorpyDbPath
- The relative or absolute path where the database is created.public DerbyResourceConfig useDatabaseInDirectory(String directorpyDbPath, boolean skipCreateAttribute)
:directory:
Derby sub sub protocol, with the database in the specified
directorpyDbPath
. The path is either relative or absolute as interpreted by the Derby engine. If the
skipCreateAttribute
attribute is set to true
, the Database will be initialized without
the create=true
attribute.directorpyDbPath
- The relative or absolute path where the database is created.skipCreateAttribute
- Skip the create=true
attribute in the connection URLpublic DerbyResourceConfig useJarSubSubProtocol(String jarFilePath, String dbPath)
:jar:
Derby sub sub protocol. The jar file containing the read only database is a relative
or absolute path in jarFilePath
and the database path in the dbPath
parameter. The
jarFilePath
is either relative or absolute as interpreted by the Derby engine.
For more format information see Accessing a read-only database in a zip/jar file and Accessing databases from a jar or zip file in the Derby Developer's guide.
jarFilePath
- The relative or absolute path where the jar file with the read-only database.dbPath
- The path of the database inside the jar file.public DerbyResourceConfig useClasspathSubSubProtocol(String dbPath)
:classpath:
Derby sub sub protocol. This allows access to a read only database in the
classpath (see Derby documentation on Accessing databases from the classpath). The database can be either in a Jar file or directly in the
classpath.
The dbPath
parameter designates the path to the database in the classpath. All databaseNames must
begin with at least a slash, because you specify them "relative" to the classpath directory or archive. See also
Syntax of database connection URLs for
applications with embedded databases and Accessing databases within a jar file
using the classpath.
dbPath
- The path of the database in the classpathpublic JdbcDerbySubSubProtocol getSubSubProtocol()
public static JdbcDerbySubSubProtocol getDefaultSubSubProtocol()
JdbcDerbySubSubProtocol.Memory
public DbCreateFromRestroreMode getDbCreateFromRestoreMode()
null
value returned from
this method means no restore. If this is not null, the location of the backup database is returned from
getDbCreateFromRestoreFrom()
; and for roll-forward recovery, the log device is at
getDbRecoveryLogDevice()
.
See the Backing up and restoring a database section of the Derby Administration guide for more information on means to backup and restore a database.
EmbeddedDerbyResource.backupLiveDatabase(File, boolean, boolean, boolean)
public File getDbCreateFromRestoreFrom()
getDbCreateFromRestoreMode()
public File getDbRecoveryLogDevice()
public DerbyResourceConfig restoreDatabaseFrom(File dbBackupDir)
dbBackupDir
- The backup location.public DerbyResourceConfig createDatabaseFrom(File dbBackupDir)
dbBackupDir
- The location of the database backup.public DerbyResourceConfig recoverDatabaseFrom(File dbBackupDir, File recoveryLogDevice)
dbBackupDir
- The database backup location.recoveryLogDevice
- The archive log location.public DerbyResourceConfig useDevNullErrorLogging()
getErrorLoggingMode()
value to ErrorLoggingMode.Null
; and clears other logging
properties.public DerbyResourceConfig useDefaultErrorLogging()
getErrorLoggingMode()
value to ErrorLoggingMode.Default
; and clears other logging
properties.public ErrorLoggingMode getErrorLoggingMode()
public static ErrorLoggingMode getDefaultErrorLoggingMode()
ErrorLoggingMode.Default
public List<String> getPostInitScripts()
public DerbyResourceConfig addPostInitScript(String postInitScript)
A post init script should refer to a file containing SQL DDL or DML statements that will be executed against the new derby instance. Script locations can be on the classpath or file system or on a HTTP(s) location, for format, see UrlResourceUtil.
postInitScript
- A post init script to addCopyright © 2015-2016 Development Entropy (deventropy.org) Contributors