public interface FBManagerMBean
extends java.lang.AutoCloseable
FBManager
, for creating and dropping databases.
The class FBManager
provides an API to create and drop databases, including options to limit the lifetime
of a database
// Use try-with-resources to automatically stop (close) FBManager try (FBManager manager = new FBManager()) { manager.setServer("localhost"); manager.setUser("sysdba"); manager.setPassword("masterkey"); manager.setFileName("path/to/database.fdb"); manager.setPageSize(PageSizeConstants.SIZE_16K); manager.setDefaultCharacterSet("UTF8"); // Create database when manager is started manager.setCreateOnStart(true); // Drop database on creation if it already exists manager.setForceCreate(true); // Drop database when manager is stopped manager.setDropOnStop(true); manager.start(); // Use database... } // After end of try-with-resources, the database will be dropped
Modifier and Type | Method and Description |
---|---|
void |
close()
Alias for
stop() |
void |
createDatabase(java.lang.String fileName,
java.lang.String user,
java.lang.String password)
Create a database with the specified file name, user name and password on the specified
server
and port . |
void |
dropDatabase(java.lang.String fileName,
java.lang.String user,
java.lang.String password)
Drop a database with the specified file name, user name and password on the specified
server
and port . |
java.lang.String |
getDefaultCharacterSet() |
int |
getDialect() |
java.lang.String |
getFileName() |
java.lang.String |
getName() |
int |
getPageSize() |
java.lang.String |
getPassword() |
int |
getPort() |
java.lang.String |
getServer() |
java.lang.String |
getState() |
java.lang.String |
getType() |
java.lang.String |
getUserName() |
boolean |
isCreateOnStart()
Get if the database will be created when calling
start() . |
boolean |
isDatabaseExists(java.lang.String fileName,
java.lang.String user,
java.lang.String password)
Check if a database exists with the specified file name, user name and password on the specified
server
and port . |
boolean |
isDropOnStop()
Get if the database will be created when calling
stop() . |
boolean |
isForceCreate()
Get if the database will be be dropped if exists when creating a database.
|
void |
setCreateOnStart(boolean createOnStart)
Set if the database will be created when calling
start() . |
void |
setDefaultCharacterSet(java.lang.String firebirdCharsetName)
Set the default database character set to use when creating a new database.
|
void |
setDialect(int dialect)
Set the database dialect to use when creating a new database.
|
void |
setDropOnStop(boolean dropOnStop)
Set if the database will be created when calling
stop() . |
void |
setFileName(java.lang.String fileName)
Set the file name or alias of the database.
|
void |
setForceCreate(boolean forceCreate)
Set if the database will be be dropped if exists when creating a database.
|
void |
setPageSize(int pageSize)
Set the page size to use when creating a new database.
|
void |
setPassword(java.lang.String password)
Set the password.
|
void |
setPort(int port)
Set the port of the Firebird server.
|
void |
setServer(java.lang.String host)
Set the host name of the Firebird server.
|
void |
setType(java.lang.String type)
Set the GDS plugin type to use.
|
void |
setUserName(java.lang.String userName)
Set the user name.
|
void |
start()
Start this manager.
|
void |
stop()
Stop this manager.
|
void start() throws java.lang.Exception
If isCreateOnStart()
is true
, will attempt to create a new database specified using
the server
, port
, fileName
and related properties. If the specified already exists,
nothing will be created unless isForceCreate()
is true
. When forceCreate
is true
an attempt will be made to drop the database.
java.lang.IllegalStateException
- If this manager is not startedjava.lang.Exception
- For failures to start or create the databasevoid stop() throws java.lang.Exception
If isDropOnStop()
is true
, will attempt to drop the database specified using the server
,
port
, fileName
and related properties,
If the manager is currently stopped, this method will do nothing.
java.lang.Exception
- For failures to drop the database.void close() throws java.lang.Exception
stop()
close
in interface java.lang.AutoCloseable
java.lang.Exception
java.lang.String getName()
java.lang.String getState()
"Stopped"
or "Started"
void setServer(java.lang.String host)
host
- Hostnamejava.lang.String getServer()
"localhost"
)void setPort(int port)
port
- Port of the Firebird serverint getPort()
3050
)java.lang.String getFileName()
void setFileName(java.lang.String fileName)
fileName
- File name or alias of the databasejava.lang.String getType()
GDSFactory.getDefaultGDSType()
)void setType(java.lang.String type)
type
- GDS plugin type name (PURE_JAVA
, NATIVE
, EMBEDDED
, LOCAL
)java.lang.String getUserName()
void setUserName(java.lang.String userName)
userName
- User namejava.lang.String getPassword()
void setPassword(java.lang.String password)
password
- Passwordvoid setDialect(int dialect)
dialect
- Database dialect (1 or 3)java.lang.IllegalArgumentException
- if value is not 1 or 3getDialect()
int getDialect()
void setPageSize(int pageSize)
The value for pageSize
must be one of PageSizeConstants
. The default value depends on the
Firebird version.
Some values are not valid on all Firebird versions.
pageSize
- The page size to be used in the created database, see PageSizeConstants
PageSizeConstants
int getPageSize()
-1
if the database default is used.void setDefaultCharacterSet(java.lang.String firebirdCharsetName)
firebirdCharsetName
- Character set name, use Firebird names only; null
will use Firebird default (NONE
).
Specifying an invalid name will result in an exception during database creation.java.lang.String getDefaultCharacterSet()
null
means not set.setDefaultCharacterSet(String)
boolean isCreateOnStart()
start()
.true
when the database will be created on start, false
otherwise.void setCreateOnStart(boolean createOnStart)
start()
.createOnStart
- true
to create the database on start, false
to not create on start (default)boolean isDropOnStop()
stop()
.true
to drop the database on stop, false
otherwisevoid setDropOnStop(boolean dropOnStop)
stop()
.dropOnStop
- true
to drop the database on stop, false
to not drop on stop (default)boolean isForceCreate()
true
to drop existing database on create, false
to not create a database if it exists.void setForceCreate(boolean forceCreate)
forceCreate
- true
to drop existing database on create, false
to not create a database if it exists.void createDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.Exception
server
and port
.
On creation, the following properties will used to configure the database: dialect
, pageSize
,
defaultCharacterSet
.
If the database already exists, and forceCreate
is true
, the database will be dropped. If
false
, no database will be created.
fileName
- Database file name or aliasuser
- User namepassword
- Passwordjava.lang.IllegalStateException
- If this manager is not startedjava.lang.Exception
- If database creation fails.void dropDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.Exception
server
and port
.fileName
- Database file name or aliasuser
- User namepassword
- Passwordjava.lang.Exception
- If this manager is not started or database drop fails.boolean isDatabaseExists(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.Exception
server
and port
.
Existence is checked by connecting to the database, so any connection error, including invalid credentials, will report the database as not existing.
fileName
- Database file name or aliasuser
- User namepassword
- Passwordtrue
if the database exists and can be connected, false
if the database does not exist
or any other error occurred.java.lang.Exception
- Currently no other exception is thrown, this may change in the futureCopyright © 2001-2022 Jaybird (Firebird JDBC/JCA) team. All rights reserved.