Module org.firebirdsql.jaybird
Package org.firebirdsql.management

# Class FBManager

java.lang.Object
org.firebirdsql.management.FBManager

All Implemented Interfaces:
  `AutoCloseable`, `FBManagerMBean`

public class FBManager extends Object implements FBManagerMBean
A tool for creating and dropping databases.

In particular, they can be created and dropped using the jboss service lifecycle operations start and stop.

See `FBManagerMBean` for documentation.

Author:
  David Jencks

## Constructor Summary

Constructors
Constructor
Description
`FBManager()`
`FBManager(String type)`
`FBManager(GDSType type)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Alias for `FBManagerMBean.stop()`
`void`
`createDatabase(String fileName, String user, String password)`
Create a database with the specified file name, username and password on the specified `server` and `port`.
`void`
`createDatabase(String fileName, String user, String password, String roleName)`
Create a database with the specified file name, username, password and role on the specified `server` and `port`.
`void`
`dropDatabase(String fileName, String user, String password)`
Drop a database with the specified file name, username and password on the specified `server` and `port`.
`void`
`dropDatabase(String fileName, String user, String password, String roleName)`
Drop a database with the specified file name, username, password and role on the specified `server` and `port`.
`String`
`getDefaultCharacterSet()`
`int`
`getDialect()`
`String`
`getEnableProtocol()`
`String`
`getFileName()`
`Boolean`
`getForceWrite()`
`String`
`getName()`
`int`
`getPageSize()`
`String`
`getPassword()`
`int`
`getPort()`
`String`
`getRoleName()`
`String`
`getServer()`
`String`
`getState()`
`String`
`getType()`
`String`
`getUserName()`
`boolean`
`isCreateOnStart()`
Get if the database will be created when calling `FBManagerMBean.start()`.
`boolean`
`isDatabaseExists(String fileName, String user, String password)`
Check if a database exists with the specified file name, username and password on the specified `server` and `port`.
`boolean`
`isDropOnStop()`
Get if the database will be created when calling `FBManagerMBean.stop()`.
`boolean`
`isForceCreate()`
Get if the database will be dropped if exists when creating a database.
`void`
`setCreateOnStart(boolean createOnStart)`
Set if the database will be created when calling `FBManagerMBean.start()`.
`void`
`setDefaultCharacterSet(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 `FBManagerMBean.stop()`.
`void`
`setEnableProtocol(String enableProtocol)`
Sets the enable protocol value.
`void`
`setFileName(String fileName)`
Set the file name or alias of the database.
`void`
`setForceCreate(boolean forceCreate)`
Set if the database will be dropped if exists when creating a database.
`void`
`setForceWrite(Boolean forceWrite)`
Control force write behaviour of the created database.
`void`
`setPageSize(int pageSize)`
Set the page size to use when creating a new database.
`void`
`setPassword(String password)`
Set the password.
`void`
`setPort(int port)`
Set the port of the Firebird server.
`void`
`setRoleName(String roleName)`
`void`
`setServer(String host)`
Set the host name of the Firebird server.
`void`
`setType(String type)`
Set the GDS plugin type to use.
`void`
`setUserName(String userName)`
Set the username.
`void`
`start()`
Start this manager.
`void`
`stop()`
Stop this manager.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### FBManager

public FBManager()

### FBManager

public FBManager(GDSType type)

### FBManager

public FBManager(String type)

## Method Details

### start

public void start() throws Exception
Description copied from interface: `FBManagerMBean`
Start this manager.

If `FBManagerMBean.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 `FBManagerMBean.isForceCreate()` is `true`. When `forceCreate` is `true` an attempt will be made to drop the database.

Specified by:
  `start` in interface `FBManagerMBean`
Throws:
  `IllegalStateException` - If this manager is not started
  `Exception` - For failures to start or create the database

### stop

public void stop() throws Exception
Description copied from interface: `FBManagerMBean`
Stop this manager.

If `FBManagerMBean.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.

Specified by:
  `stop` in interface `FBManagerMBean`
Throws:
  `Exception` - For failures to drop the database.

### close

public void close() throws Exception
Description copied from interface: `FBManagerMBean`
Alias for `FBManagerMBean.stop()`

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `FBManagerMBean`
Throws:
  `Exception`

### getState

public String getState()

Specified by:
  `getState` in interface `FBManagerMBean`
Returns:
  Current state (`"Stopped"` or `"Started"`

### getName

public String getName()

Specified by:
  `getName` in interface `FBManagerMBean`
Returns:
  Descriptive name of this manager

### setServer

public void setServer(String host)
Description copied from interface: `FBManagerMBean`
Set the host name of the Firebird server.

Specified by:
  `setServer` in interface `FBManagerMBean`
Parameters:
  `host` - Hostname

### getServer

public String getServer()

Specified by:
  `getServer` in interface `FBManagerMBean`
Returns:
  The host name of the Firebird server (default is `"localhost"`)

### setPort

public void setPort(int port)
Description copied from interface: `FBManagerMBean`
Set the port of the Firebird server.

Specified by:
  `setPort` in interface `FBManagerMBean`
Parameters:
  `port` - Port of the Firebird server

### getPort

public int getPort()

Specified by:
  `getPort` in interface `FBManagerMBean`
Returns:
  The port of the Firebird server (default is `3050`)

### getFileName

public String getFileName()

Specified by:
  `getFileName` in interface `FBManagerMBean`
Returns:
  File name or alias of the database

### setFileName

public void setFileName(String fileName)
Description copied from interface: `FBManagerMBean`
Set the file name or alias of the database.

Specified by:
  `setFileName` in interface `FBManagerMBean`
Parameters:
  `fileName` - File name or alias of the database

### getType

public String getType()

Specified by:
  `getType` in interface `FBManagerMBean`
Returns:
  GDS plugin type name (default is `GDSFactory.getDefaultGDSType()`)

### setType

public void setType(String type)
Description copied from interface: `FBManagerMBean`
Set the GDS plugin type to use.

Specified by:
  `setType` in interface `FBManagerMBean`
Parameters:
  `type` - GDS plugin type name (`PURE_JAVA`, `NATIVE`, `EMBEDDED`)

### getUserName

public String getUserName()

Specified by:
  `getUserName` in interface `FBManagerMBean`
Returns:
  User name

### setUserName

public void setUserName(String userName)
Description copied from interface: `FBManagerMBean`
Set the username.

Specified by:
  `setUserName` in interface `FBManagerMBean`
Parameters:
  `userName` - Username

### getPassword

public String getPassword()

Specified by:
  `getPassword` in interface `FBManagerMBean`
Returns:
  password

### setPassword

public void setPassword(String password)
Description copied from interface: `FBManagerMBean`
Set the password.

Specified by:
  `setPassword` in interface `FBManagerMBean`
Parameters:
  `password` - Password

### getRoleName

public String getRoleName()

Specified by:
  `getRoleName` in interface `FBManagerMBean`
Returns:
  SQL role to use.

### setRoleName

public void setRoleName(String roleName)

Specified by:
  `setRoleName` in interface `FBManagerMBean`
Parameters:
  `roleName` - SQL role to use.

### setEnableProtocol

public void setEnableProtocol(String enableProtocol)
Description copied from interface: `FBManagerMBean`
Sets the enable protocol value.

Specified by:
  `setEnableProtocol` in interface `FBManagerMBean`
Parameters:
  `enableProtocol` - enable protocol value

### getEnableProtocol

public String getEnableProtocol()

Specified by:
  `getEnableProtocol` in interface `FBManagerMBean`
Returns:
  enable protocol value (see also `AttachmentProperties.getEnableProtocol()`.

### setDialect

public void setDialect(int dialect)
Description copied from interface: `FBManagerMBean`
Set the database dialect to use when creating a new database.

Specified by:
  `setDialect` in interface `FBManagerMBean`
Parameters:
  `dialect` - Database dialect (1 or 3)
See Also:
  - `FBManagerMBean.getDialect()`

### getDialect

public int getDialect()

Specified by:
  `getDialect` in interface `FBManagerMBean`
Returns:
  Database dialect (either 1 or 3), default is 3.

### setPageSize

public void setPageSize(int pageSize)
Description copied from interface: `FBManagerMBean`
Set the page size to use when creating a new database.

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.

Specified by:
  `setPageSize` in interface `FBManagerMBean`
Parameters:
  `pageSize` - The page size to be used in the created database, see `PageSizeConstants`
See Also:
  - `PageSizeConstants`

### getPageSize

public int getPageSize()

Specified by:
  `getPageSize` in interface `FBManagerMBean`
Returns:
  The page size to be used when creating a database, or `-1` if the database default is used.

### setDefaultCharacterSet

public void setDefaultCharacterSet(String firebirdCharsetName)
Description copied from interface: `FBManagerMBean`
Set the default database character set to use when creating a new database.

Specified by:
  `setDefaultCharacterSet` in interface `FBManagerMBean`
Parameters:
  `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.

### getDefaultCharacterSet

public String getDefaultCharacterSet()

Specified by:
  `getDefaultCharacterSet` in interface `FBManagerMBean`
Returns:
  The default character set name, `null` means not set.
See Also:
  - `FBManagerMBean.setDefaultCharacterSet(String)`

### setForceWrite

public void setForceWrite(Boolean forceWrite)
Description copied from interface: `FBManagerMBean`
Control force write behaviour of the created database.

Only use this method if you know what you're doing, and if you can live with data loss and database corruption. In general it is advisable to use the Firebird default (`null` for this method).

Specified by:
  `setForceWrite` in interface `FBManagerMBean`
Parameters:
  `forceWrite` - `null` - default behaviour (force write enabled after database creation and initialization), `true` - enable force write at database creation, `false` - disable force write

### getForceWrite

public Boolean getForceWrite()

Specified by:
  `getForceWrite` in interface `FBManagerMBean`
Returns:
  The forced writes configuration
See Also:
  - `FBManagerMBean.setForceWrite(Boolean)`

### isCreateOnStart

public boolean isCreateOnStart()
Description copied from interface: `FBManagerMBean`
Get if the database will be created when calling `FBManagerMBean.start()`.

Specified by:
  `isCreateOnStart` in interface `FBManagerMBean`
Returns:
  `true` when the database will be created on start, `false` otherwise.

### setCreateOnStart

public void setCreateOnStart(boolean createOnStart)
Description copied from interface: `FBManagerMBean`
Set if the database will be created when calling `FBManagerMBean.start()`.

Specified by:
  `setCreateOnStart` in interface `FBManagerMBean`
Parameters:
  `createOnStart` - `true` to create the database on start, `false` to not create on start (default)

### isDropOnStop

public boolean isDropOnStop()
Description copied from interface: `FBManagerMBean`
Get if the database will be created when calling `FBManagerMBean.stop()`.

Specified by:
  `isDropOnStop` in interface `FBManagerMBean`
Returns:
  `true` to drop the database on stop, `false` otherwise

### setDropOnStop

public void setDropOnStop(boolean dropOnStop)
Description copied from interface: `FBManagerMBean`
Set if the database will be created when calling `FBManagerMBean.stop()`.

Specified by:
  `setDropOnStop` in interface `FBManagerMBean`
Parameters:
  `dropOnStop` - `true` to drop the database on stop, `false` to not drop on stop (default)

### isForceCreate

public boolean isForceCreate()
Description copied from interface: `FBManagerMBean`
Get if the database will be dropped if exists when creating a database.

Specified by:
  `isForceCreate` in interface `FBManagerMBean`
Returns:
  `true` to drop existing database on create, `false` to not create a database if it exists.

### setForceCreate

public void setForceCreate(boolean forceCreate)
Description copied from interface: `FBManagerMBean`
Set if the database will be dropped if exists when creating a database.

Specified by:
  `setForceCreate` in interface `FBManagerMBean`
Parameters:
  `forceCreate` - `true` to drop existing database on create, `false` to not create a database if it exists.

### createDatabase

public void createDatabase(String fileName, String user, String password) throws Exception
Description copied from interface: `FBManagerMBean`
Create a database with the specified file name, username and password on the specified `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.

Specified by:
  `createDatabase` in interface `FBManagerMBean`
Parameters:
  `fileName` - Database file name or alias
  `user` - User name
  `password` - Password
Throws:
  `IllegalStateException` - If this manager is not started
  `Exception` - If database creation fails.

### createDatabase

public void createDatabase(String fileName, String user, String password, String roleName) throws Exception
Description copied from interface: `FBManagerMBean`
Create a database with the specified file name, username, password and role on the specified `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.

Specified by:
  `createDatabase` in interface `FBManagerMBean`
Parameters:
  `fileName` - Database file name or alias
  `user` - User name
  `password` - Password
  `roleName` - Role name (or `null` for no role)
Throws:
  `IllegalStateException` - If this manager is not started
  `Exception` - If database creation fails.

### dropDatabase

public void dropDatabase(String fileName, String user, String password) throws Exception
Description copied from interface: `FBManagerMBean`
Drop a database with the specified file name, username and password on the specified `server` and `port`.

Specified by:
  `dropDatabase` in interface `FBManagerMBean`
Parameters:
  `fileName` - Database file name or alias
  `user` - User name
  `password` - Password
Throws:
  `Exception` - If this manager is not started or database drop fails.

### dropDatabase

public void dropDatabase(String fileName, String user, String password, String roleName) throws Exception
Description copied from interface: `FBManagerMBean`
Drop a database with the specified file name, username, password and role on the specified `server` and `port`.

Specified by:
  `dropDatabase` in interface `FBManagerMBean`
Parameters:
  `fileName` - Database file name or alias
  `user` - User name
  `password` - Password
  `roleName` - Role name (or `null` for no role)
Throws:
  `Exception` - If this manager is not started or database drop fails.

### isDatabaseExists

public boolean isDatabaseExists(String fileName, String user, String password) throws Exception
Description copied from interface: `FBManagerMBean`
Check if a database exists with the specified file name, username and password on the specified `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.

Specified by:
  `isDatabaseExists` in interface `FBManagerMBean`
Parameters:
  `fileName` - Database file name or alias
  `user` - User name
  `password` - Password
Returns:
  `true` if the database exists and can be connected, `false` if the database does not exist or any other error occurred.
Throws:
  `Exception` - Currently no other exception is thrown, this may change in the future