Class FBManager
- java.lang.Object
-
- org.firebirdsql.management.FBManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable,FBManagerMBean
public class FBManager extends java.lang.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
FBManagerMBeanfor documentation.- Author:
- David Jencks
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Alias forFBManagerMBean.stop()voidcreateDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password)Create a database with the specified file name, username and password on the specifiedserverandport.voidcreateDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password, java.lang.String roleName)Create a database with the specified file name, username, password and role on the specifiedserverandport.voiddropDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password)Drop a database with the specified file name, username and password on the specifiedserverandport.voiddropDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password, java.lang.String roleName)Drop a database with the specified file name, username, password and role on the specifiedserverandport.java.lang.StringgetDefaultCharacterSet()intgetDialect()java.lang.StringgetFileName()java.lang.BooleangetForceWrite()java.lang.StringgetName()intgetPageSize()java.lang.StringgetPassword()intgetPort()java.lang.StringgetRoleName()java.lang.StringgetServer()java.lang.StringgetState()java.lang.StringgetType()java.lang.StringgetUserName()booleanisCreateOnStart()Get if the database will be created when callingFBManagerMBean.start().booleanisDatabaseExists(java.lang.String fileName, java.lang.String user, java.lang.String password)Check if a database exists with the specified file name, username and password on the specifiedserverandport.booleanisDropOnStop()Get if the database will be created when callingFBManagerMBean.stop().booleanisForceCreate()Get if the database will be dropped if exists when creating a database.voidsetCreateOnStart(boolean createOnStart)Set if the database will be created when callingFBManagerMBean.start().voidsetDefaultCharacterSet(java.lang.String firebirdCharsetName)Set the default database character set to use when creating a new database.voidsetDialect(int dialect)Set the database dialect to use when creating a new database.voidsetDropOnStop(boolean dropOnStop)Set if the database will be created when callingFBManagerMBean.stop().voidsetFileName(java.lang.String fileName)Set the file name or alias of the database.voidsetForceCreate(boolean forceCreate)Set if the database will be dropped if exists when creating a database.voidsetForceWrite(java.lang.Boolean forceWrite)Control force write behaviour of the created database.voidsetPageSize(int pageSize)Set the page size to use when creating a new database.voidsetPassword(java.lang.String password)Set the password.voidsetPort(int port)Set the port of the Firebird server.voidsetRoleName(java.lang.String roleName)voidsetServer(java.lang.String host)Set the host name of the Firebird server.voidsetType(java.lang.String type)Set the GDS plugin type to use.voidsetUserName(java.lang.String userName)Set the username.voidstart()Start this manager.voidstop()Stop this manager.
-
-
-
Constructor Detail
-
FBManager
public FBManager()
-
FBManager
public FBManager(GDSType type)
-
FBManager
public FBManager(java.lang.String type)
-
-
Method Detail
-
start
public void start() throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanStart this manager.If
FBManagerMBean.isCreateOnStart()istrue, will attempt to create a new database specified using theserver,port,fileNameand related properties. If the specified already exists, nothing will be created unlessFBManagerMBean.isForceCreate()istrue. WhenforceCreateistruean attempt will be made to drop the database.- Specified by:
startin interfaceFBManagerMBean- Throws:
java.lang.IllegalStateException- If this manager is not startedjava.lang.Exception- For failures to start or create the database
-
stop
public void stop() throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanStop this manager.If
FBManagerMBean.isDropOnStop()istrue, will attempt to drop the database specified using theserver,port,fileNameand related properties,If the manager is currently stopped, this method will do nothing.
- Specified by:
stopin interfaceFBManagerMBean- Throws:
java.lang.Exception- For failures to drop the database.
-
close
public void close() throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanAlias forFBManagerMBean.stop()- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceFBManagerMBean- Throws:
java.lang.Exception
-
getState
public java.lang.String getState()
- Specified by:
getStatein interfaceFBManagerMBean- Returns:
- Current state (
"Stopped"or"Started"
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceFBManagerMBean- Returns:
- Descriptive name of this manager
-
setServer
public void setServer(java.lang.String host)
Description copied from interface:FBManagerMBeanSet the host name of the Firebird server.- Specified by:
setServerin interfaceFBManagerMBean- Parameters:
host- Hostname
-
getServer
public java.lang.String getServer()
- Specified by:
getServerin interfaceFBManagerMBean- Returns:
- The host name of the Firebird server (default is
"localhost")
-
setPort
public void setPort(int port)
Description copied from interface:FBManagerMBeanSet the port of the Firebird server.- Specified by:
setPortin interfaceFBManagerMBean- Parameters:
port- Port of the Firebird server
-
getPort
public int getPort()
- Specified by:
getPortin interfaceFBManagerMBean- Returns:
- The port of the Firebird server (default is
3050)
-
getFileName
public java.lang.String getFileName()
- Specified by:
getFileNamein interfaceFBManagerMBean- Returns:
- File name or alias of the database
-
setFileName
public void setFileName(java.lang.String fileName)
Description copied from interface:FBManagerMBeanSet the file name or alias of the database.- Specified by:
setFileNamein interfaceFBManagerMBean- Parameters:
fileName- File name or alias of the database
-
getType
public java.lang.String getType()
- Specified by:
getTypein interfaceFBManagerMBean- Returns:
- GDS plugin type name (default is
GDSFactory.getDefaultGDSType())
-
setType
public void setType(java.lang.String type)
Description copied from interface:FBManagerMBeanSet the GDS plugin type to use.- Specified by:
setTypein interfaceFBManagerMBean- Parameters:
type- GDS plugin type name (PURE_JAVA,NATIVE,EMBEDDED)
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserNamein interfaceFBManagerMBean- Returns:
- User name
-
setUserName
public void setUserName(java.lang.String userName)
Description copied from interface:FBManagerMBeanSet the username.- Specified by:
setUserNamein interfaceFBManagerMBean- Parameters:
userName- Username
-
getPassword
public java.lang.String getPassword()
- Specified by:
getPasswordin interfaceFBManagerMBean- Returns:
- password
-
setPassword
public void setPassword(java.lang.String password)
Description copied from interface:FBManagerMBeanSet the password.- Specified by:
setPasswordin interfaceFBManagerMBean- Parameters:
password- Password
-
getRoleName
public java.lang.String getRoleName()
- Specified by:
getRoleNamein interfaceFBManagerMBean- Returns:
- SQL role to use.
-
setRoleName
public void setRoleName(java.lang.String roleName)
- Specified by:
setRoleNamein interfaceFBManagerMBean- Parameters:
roleName- SQL role to use.
-
setDialect
public void setDialect(int dialect)
Description copied from interface:FBManagerMBeanSet the database dialect to use when creating a new database.- Specified by:
setDialectin interfaceFBManagerMBean- Parameters:
dialect- Database dialect (1 or 3)- See Also:
FBManagerMBean.getDialect()
-
getDialect
public int getDialect()
- Specified by:
getDialectin interfaceFBManagerMBean- Returns:
- Database dialect (either 1 or 3), default is 3.
-
setPageSize
public void setPageSize(int pageSize)
Description copied from interface:FBManagerMBeanSet the page size to use when creating a new database.The value for
pageSizemust be one ofPageSizeConstants. The default value depends on the Firebird version.Some values are not valid on all Firebird versions.
- Specified by:
setPageSizein interfaceFBManagerMBean- Parameters:
pageSize- The page size to be used in the created database, seePageSizeConstants- See Also:
PageSizeConstants
-
getPageSize
public int getPageSize()
- Specified by:
getPageSizein interfaceFBManagerMBean- Returns:
- The page size to be used when creating a database, or
-1if the database default is used.
-
setDefaultCharacterSet
public void setDefaultCharacterSet(java.lang.String firebirdCharsetName)
Description copied from interface:FBManagerMBeanSet the default database character set to use when creating a new database.- Specified by:
setDefaultCharacterSetin interfaceFBManagerMBean- Parameters:
firebirdCharsetName- Character set name, use Firebird names only;nullwill use Firebird default (NONE). Specifying an invalid name will result in an exception during database creation.
-
getDefaultCharacterSet
public java.lang.String getDefaultCharacterSet()
- Specified by:
getDefaultCharacterSetin interfaceFBManagerMBean- Returns:
- The default character set name,
nullmeans not set. - See Also:
FBManagerMBean.setDefaultCharacterSet(String)
-
setForceWrite
public void setForceWrite(java.lang.Boolean forceWrite)
Description copied from interface:FBManagerMBeanControl 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 (
nullfor this method).- Specified by:
setForceWritein interfaceFBManagerMBean- 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 java.lang.Boolean getForceWrite()
- Specified by:
getForceWritein interfaceFBManagerMBean- Returns:
- The forced writes configuration
- See Also:
FBManagerMBean.setForceWrite(Boolean)
-
isCreateOnStart
public boolean isCreateOnStart()
Description copied from interface:FBManagerMBeanGet if the database will be created when callingFBManagerMBean.start().- Specified by:
isCreateOnStartin interfaceFBManagerMBean- Returns:
truewhen the database will be created on start,falseotherwise.
-
setCreateOnStart
public void setCreateOnStart(boolean createOnStart)
Description copied from interface:FBManagerMBeanSet if the database will be created when callingFBManagerMBean.start().- Specified by:
setCreateOnStartin interfaceFBManagerMBean- Parameters:
createOnStart-trueto create the database on start,falseto not create on start (default)
-
isDropOnStop
public boolean isDropOnStop()
Description copied from interface:FBManagerMBeanGet if the database will be created when callingFBManagerMBean.stop().- Specified by:
isDropOnStopin interfaceFBManagerMBean- Returns:
trueto drop the database on stop,falseotherwise
-
setDropOnStop
public void setDropOnStop(boolean dropOnStop)
Description copied from interface:FBManagerMBeanSet if the database will be created when callingFBManagerMBean.stop().- Specified by:
setDropOnStopin interfaceFBManagerMBean- Parameters:
dropOnStop-trueto drop the database on stop,falseto not drop on stop (default)
-
isForceCreate
public boolean isForceCreate()
Description copied from interface:FBManagerMBeanGet if the database will be dropped if exists when creating a database.- Specified by:
isForceCreatein interfaceFBManagerMBean- Returns:
trueto drop existing database on create,falseto not create a database if it exists.
-
setForceCreate
public void setForceCreate(boolean forceCreate)
Description copied from interface:FBManagerMBeanSet if the database will be dropped if exists when creating a database.- Specified by:
setForceCreatein interfaceFBManagerMBean- Parameters:
forceCreate-trueto drop existing database on create,falseto not create a database if it exists.
-
createDatabase
public void createDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanCreate a database with the specified file name, username and password on the specifiedserverandport.On creation, the following properties will used to configure the database:
dialect,pageSize,defaultCharacterSet.If the database already exists, and
forceCreateistrue, the database will be dropped. Iffalse, no database will be created.- Specified by:
createDatabasein interfaceFBManagerMBean- Parameters:
fileName- Database file name or aliasuser- User namepassword- Password- Throws:
java.lang.IllegalStateException- If this manager is not startedjava.lang.Exception- If database creation fails.
-
createDatabase
public void createDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password, java.lang.String roleName) throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanCreate a database with the specified file name, username, password and role on the specifiedserverandport.On creation, the following properties will used to configure the database:
dialect,pageSize,defaultCharacterSet.If the database already exists, and
forceCreateistrue, the database will be dropped. Iffalse, no database will be created.- Specified by:
createDatabasein interfaceFBManagerMBean- Parameters:
fileName- Database file name or aliasuser- User namepassword- PasswordroleName- Role name (ornullfor no role)- Throws:
java.lang.IllegalStateException- If this manager is not startedjava.lang.Exception- If database creation fails.
-
dropDatabase
public void dropDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanDrop a database with the specified file name, username and password on the specifiedserverandport.- Specified by:
dropDatabasein interfaceFBManagerMBean- Parameters:
fileName- Database file name or aliasuser- User namepassword- Password- Throws:
java.lang.Exception- If this manager is not started or database drop fails.
-
dropDatabase
public void dropDatabase(java.lang.String fileName, java.lang.String user, java.lang.String password, java.lang.String roleName) throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanDrop a database with the specified file name, username, password and role on the specifiedserverandport.- Specified by:
dropDatabasein interfaceFBManagerMBean- Parameters:
fileName- Database file name or aliasuser- User namepassword- PasswordroleName- Role name (ornullfor no role)- Throws:
java.lang.Exception- If this manager is not started or database drop fails.
-
isDatabaseExists
public boolean isDatabaseExists(java.lang.String fileName, java.lang.String user, java.lang.String password) throws java.lang.ExceptionDescription copied from interface:FBManagerMBeanCheck if a database exists with the specified file name, username and password on the specifiedserverandport.Existence is checked by connecting to the database, so any connection error, including invalid credentials, will report the database as not existing.
- Specified by:
isDatabaseExistsin interfaceFBManagerMBean- Parameters:
fileName- Database file name or aliasuser- User namepassword- Password- Returns:
trueif the database exists and can be connected,falseif the database does not exist or any other error occurred.- Throws:
java.lang.Exception- Currently no other exception is thrown, this may change in the future
-
-