Class FBServiceManager

java.lang.Object
org.firebirdsql.management.FBServiceManager
All Implemented Interfaces:
AttachmentProperties, BaseProperties, ServiceConnectionProperties, ServiceManager
Direct Known Subclasses:
FBBackupManagerBase, FBMaintenanceManager, FBNBackupManager, FBStatisticsManager, FBTraceManager, FBUserManager

public class FBServiceManager extends Object implements ServiceManager
An implementation of the basic Firebird Service API functionality.
Author:
Roman Rokytskyy, Mark Rotteveel
  • Field Details

  • Constructor Details

    • FBServiceManager

      public FBServiceManager()
      Create a new instance of FBServiceManager based on the default GDSType.
    • FBServiceManager

      public FBServiceManager(String gdsType)
      Create a new instance of FBServiceManager based on a given GDSType.
      Parameters:
      gdsType - type must be PURE_JAVA, EMBEDDED, or NATIVE
    • FBServiceManager

      public FBServiceManager(GDSType gdsType)
      Create a new instance of FBServiceManager based on a given GDSType.
      Parameters:
      gdsType - The GDS implementation type to use
  • Method Details

    • setType

      public final void setType(String type)
      Specified by:
      setType in interface AttachmentProperties
      Parameters:
      type - type of the connection, for example, "PURE_JAVA", "NATIVE", "EMBEDDED", depends on the GDS implementations installed in the system.
    • setCharSet

      public void setCharSet(String charSet)
      Description copied from interface: AttachmentProperties
      Set the Java character set for the connection.

      It is possible to set both the charSet and encoding to achieve a character set conversion effect, but in general only one of both properties should be set.

      Specified by:
      setCharSet in interface AttachmentProperties
      Parameters:
      charSet - Character set for the connection. Similar to encoding property, but accepts Java names instead of Firebird ones.
      See Also:
    • getCharSet

      public String getCharSet()
      Description copied from interface: AttachmentProperties
      Java character set configured for the connection.

      After connect, the actual Java character set applied can be obtained from FbAttachment.getEncoding() (property charsetName), or FbAttachment.getEncodingFactory() (properties defaultEncoding.charsetName or {code defaultEncodingDefinition.javaCharset}).

      Specified by:
      getCharSet in interface AttachmentProperties
      Returns:
      Java character set for the connection (null when not explicitly configured).
    • setUser

      public void setUser(String user)
      Specified by:
      setUser in interface AttachmentProperties
      Parameters:
      user - Name of the user to authenticate to the server.
    • getUser

      public String getUser()
      Specified by:
      getUser in interface AttachmentProperties
      Returns:
      Name of the user to authenticate to the server.
    • setPassword

      public void setPassword(String password)
      Specified by:
      setPassword in interface AttachmentProperties
      Parameters:
      password - Password to authenticate to the server.
    • getPassword

      public String getPassword()
      Specified by:
      getPassword in interface AttachmentProperties
      Returns:
      Password to authenticate to the server.
    • getServerName

      public String getServerName()
      Description copied from interface: AttachmentProperties
      Get the hostname or IP address of the Firebird server.
      Specified by:
      getServerName in interface AttachmentProperties
      Returns:
      Hostname or IP address of the server
      See Also:
    • setServerName

      public void setServerName(String serverName)
      Description copied from interface: AttachmentProperties
      Set the hostname or IP address of the Firebird server.

      When set to null (the default), the databaseName or serviceName is used as the full identification of the database host, port and database path/alias. Protocol implementations, for example PURE_JAVA, may default to localhost when this property is null, but databaseName/serviceName does not (seem to) contain a host name.

      Specified by:
      setServerName in interface AttachmentProperties
      Parameters:
      serverName - Hostname or IP address of the server
    • getPortNumber

      public int getPortNumber()
      Description copied from interface: AttachmentProperties
      Get the port number of the server.
      Specified by:
      getPortNumber in interface AttachmentProperties
      Returns:
      Port number of the server
      See Also:
    • setPortNumber

      public void setPortNumber(int portNumber)
      Description copied from interface: AttachmentProperties
      Set the port number of the server.

      Defaults to 3050. This property value will be ignored if serverName is null, unless the protocol implementation needs a hostname, but cannot find a hostname in databaseName/serviceName.

      Specified by:
      setPortNumber in interface AttachmentProperties
      Parameters:
      portNumber - Port number of the server
      See Also:
    • getServiceName

      public String getServiceName()
      Description copied from interface: ServiceConnectionProperties
      Gets the service name (defaults to "service_mgr").
      Specified by:
      getServiceName in interface ServiceConnectionProperties
      Returns:
      database name
      See Also:
    • setServiceName

      public void setServiceName(String serviceName)
      Description copied from interface: ServiceConnectionProperties
      Sets the service name

      When serverName is null, then the value is taken as the URL of the service, and exact interpretation depends on the protocol implementation (type). Examples:

      • //localhost/ — PURE_JAVA, NATIVE (for NATIVE, this format is parsed and transformed to the next example; will fail on Firebird 2.5 and earlier)
      • localhost — NATIVE, PURE_JAVA,
      • //localhost:3051/ — PURE_JAVA, NATIVE (for NATIVE, this format is parsed and transformed to the next example; will fail on Firebird 2.5 and earlier)
      • //localhost/service_mgr — PURE_JAVA, NATIVE (for NATIVE, this format is parsed and transformed to the next example)
      • localhost:service_mgr — NATIVE, PURE_JAVA
      • //localhost:3051/service_mgr — PURE_JAVA, NATIVE (for NATIVE, this format is parsed and transformed to the next example)
      • localhost/3051:service_mgr — NATIVE, PURE_JAVA
      • service_mgr — NATIVE, EMBEDDED, PURE_JAVA (PURE_JAVA will use localhost as serverName, depending on the Firebird version and platform, NATIVE may use Firebird Embedded)
      • xnet://service_mgr — NATIVE (EMBEDDED will behave as NATIVE, protocols like PURE_JAVA may attempt to connect to a server called xnet)
      • other Firebird fbclient connection URLs — NATIVE, (EMBEDDED will behave as NATIVE, protocols like PURE_JAVA may interpret the protocol name as a host name
      • Custom type implementations may support other URL formats

      Some protocols, for example PURE_JAVA, when serverName is not set, but serviceName doesn't seem to contain a host name, may default to attempting to connect to localhost with serviceName as the service.

      When serverName is set, the value is taken as the database path or alias. Examples:

      • service_mgr
      • empty string
      • null
      Specified by:
      setServiceName in interface ServiceConnectionProperties
      Parameters:
      serviceName - service name
    • setExpectedDb

      public void setExpectedDb(String expectedDb)
      Filename or alias of the database expected to be accessed by the service operation (isc_spb_expected_db).

      For Firebird 3.0 and higher when using a non-default security database, so Firebird knows which database to use to authenticate. When using the default security database, this property does not need to be set.

      Some service implementations (e.g. BackupManager) may explicitly set this as part of their operation when its current value is null.

      NOTE: The setDatabase(String) property will also set this property, so in general this property doesn't need to be set explicitly.

      Specified by:
      setExpectedDb in interface ServiceConnectionProperties
      Parameters:
      expectedDb - Expected database
    • getExpectedDb

      public String getExpectedDb()
      Description copied from interface: ServiceConnectionProperties
      Gets the expected db (isc_spb_expected_db; defaults to null).
      Specified by:
      getExpectedDb in interface ServiceConnectionProperties
      Returns:
      expected database
      See Also:
    • setDatabase

      public void setDatabase(String database)
      Description copied from interface: ServiceManager
      Sets the database path for the connection to the service manager.

      Will also set the expectedDb property. If a different value must be used, it must be set after calling this method.

      Specified by:
      setDatabase in interface ServiceManager
      Parameters:
      database - path for the connection to the service manager.
    • getDatabase

      public String getDatabase()
      Description copied from interface: ServiceManager
      Returns the database path for the connection to the service manager.
      Specified by:
      getDatabase in interface ServiceManager
      Returns:
      the database path for the connection to the service manager.
    • getHost

      @Deprecated(since="5", forRemoval=true) public String getHost()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: ServiceManager
      Returns the host for the connection to the service manager.
      Specified by:
      getHost in interface ServiceManager
      Returns:
      the host for the connection to the service manager.
    • setHost

      @Deprecated(since="5", forRemoval=true) public void setHost(String host)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: ServiceManager
      Sets the host for the connection to the service manager.

      See AttachmentProperties.setServerName(String) for details.

      Specified by:
      setHost in interface ServiceManager
      Parameters:
      host - for the connection to the service manager.
    • getPort

      @Deprecated(since="5", forRemoval=true) public int getPort()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: ServiceManager
      Returns the port for the connection to the service manager.
      Specified by:
      getPort in interface ServiceManager
      Returns:
      the port for the connection to the service manager.
    • setPort

      @Deprecated(since="5", forRemoval=true) public void setPort(int port)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: ServiceManager
      Sets the port for the connection to the service manager.
      Specified by:
      setPort in interface ServiceManager
      Parameters:
      port - for the connection to the service manager.
    • getWireCrypt

      public String getWireCrypt()
      Description copied from interface: AttachmentProperties
      Get the wire encryption level.
      Specified by:
      getWireCrypt in interface AttachmentProperties
      Returns:
      Wire encryption level
    • getWireCryptAsEnum

      public WireCrypt getWireCryptAsEnum()
      Description copied from interface: ServiceManager
      Get the wire encryption level.
      Specified by:
      getWireCryptAsEnum in interface ServiceManager
      Returns:
      Wire encryption level
    • setWireCryptAsEnum

      public void setWireCryptAsEnum(WireCrypt wireCrypt)
      Description copied from interface: ServiceManager
      Set the wire encryption level.
      Specified by:
      setWireCryptAsEnum in interface ServiceManager
      Parameters:
      wireCrypt - Wire encryption level (null not allowed)
    • getDbCryptConfig

      public String getDbCryptConfig()
      Description copied from interface: AttachmentProperties
      Get the database encryption plugin configuration.
      Specified by:
      getDbCryptConfig in interface AttachmentProperties
      Returns:
      Database encryption plugin configuration, meaning plugin specific
    • setDbCryptConfig

      public void setDbCryptConfig(String dbCryptConfig)
      Description copied from interface: AttachmentProperties
      Sets the database encryption plugin configuration.
      Specified by:
      setDbCryptConfig in interface AttachmentProperties
      Parameters:
      dbCryptConfig - Database encryption plugin configuration, meaning plugin specific
    • getAuthPlugins

      public String getAuthPlugins()
      Description copied from interface: AttachmentProperties
      Get the list of authentication plugins to try.
      Specified by:
      getAuthPlugins in interface AttachmentProperties
      Returns:
      comma-separated list of authentication plugins
    • setAuthPlugins

      public void setAuthPlugins(String authPlugins)
      Description copied from interface: AttachmentProperties
      Sets the authentication plugins to try.

      Invalid names are skipped during authentication.

      Specified by:
      setAuthPlugins in interface AttachmentProperties
      Parameters:
      authPlugins - comma-separated list of authentication plugins
    • isWireCompression

      public boolean isWireCompression()
      Description copied from interface: AttachmentProperties
      Get if wire compression should be enabled.

      Wire compression requires Firebird 3 or higher, and the server must have the zlib library. If compression cannot be negotiated, the connection will be made without wire compression.

      This property will be ignored for native connections. For native connections, the configuration in firebird.conf read by the client library will be used.

      Specified by:
      isWireCompression in interface AttachmentProperties
      Returns:
      true wire compression enabled
    • setWireCompression

      public void setWireCompression(boolean wireCompression)
      Description copied from interface: AttachmentProperties
      Sets if the connection should try to enable wire compression.
      Specified by:
      setWireCompression in interface AttachmentProperties
      Parameters:
      wireCompression - true enable wire compression, false disable wire compression (the default)
      See Also:
    • getProperty

      public String getProperty(String name)
      Description copied from interface: BaseProperties
      Retrieves a string property value by name.

      For properties with an explicit default, this method should return the string presentation of that default, not null. For int or boolean the string equivalent is returned.

      Specified by:
      getProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      Returns:
      Value of the property, or null when not set or not a known property
    • setProperty

      public void setProperty(String name, String value)
      Description copied from interface: BaseProperties
      Sets a property by name.

      This method can be used to set all defined properties, but also properties not known by Jaybird. When setting int or boolean properties, the appropriate conversions are applied. Using null will reset to the default value. For boolean properties, an empty string is taken to mean true.

      Specified by:
      setProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      value - Property value (use null to apply default)
    • getIntProperty

      public Integer getIntProperty(String name)
      Description copied from interface: BaseProperties
      Retrieves an int property value by name.

      For properties with an explicit default, this method should return the integer presentation of that default. For implementation simplicity, it is allowed to convert any string property to int instead of checking if something is actually an int property

      Specified by:
      getIntProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      Returns:
      Integer with value of the property, or null when not set
    • setIntProperty

      public void setIntProperty(String name, Integer value)
      Description copied from interface: BaseProperties
      Sets an int property by name.

      For implementation simplicity, it is allowed to also set string properties. The value set will be the string equivalent.

      Specified by:
      setIntProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      value - Property value (use null to apply default)
    • getBooleanProperty

      public Boolean getBooleanProperty(String name)
      Description copied from interface: BaseProperties
      Retrieves a boolean property value by name.

      For properties with an explicit default, this method should return the boolean presentation of that default. For implementation simplicity, it is allowed to convert any string property to boolean instead of checking if something is actually a boolean property

      Specified by:
      getBooleanProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      Returns:
      Integer with value of the property, or null when not set
    • setBooleanProperty

      public void setBooleanProperty(String name, Boolean value)
      Description copied from interface: BaseProperties
      Sets a boolean property by name.

      For implementation simplicity, it is allowed to also set string properties. The value set will be the string equivalent.

      Specified by:
      setBooleanProperty in interface BaseProperties
      Parameters:
      name - Property name (not null or empty)
      value - Property value (use null to apply default)
    • connectionPropertyValues

      public Map<ConnectionProperty,Object> connectionPropertyValues()
      Description copied from interface: BaseProperties
      An unmodifiable view on the connection properties held by this BaseProperties implementation.

      Be aware, implementations can have additional properties that are not mapped from ConnectionProperty. Such properties will need to be retrieved in an implementation-specific manner.

      Specified by:
      connectionPropertyValues in interface BaseProperties
      Returns:
      An unmodifiable view on the property values held in this properties instance
    • getLogger

      public OutputStream getLogger()
      Description copied from interface: ServiceManager
      Returns the logger for the connection to the service manager.
      Specified by:
      getLogger in interface ServiceManager
      Returns:
      Returns the out.
    • setLogger

      public void setLogger(OutputStream logger)
      Description copied from interface: ServiceManager
      Sets the logger for the connection to the service manager.
      Specified by:
      setLogger in interface ServiceManager
      Parameters:
      logger - The out to set.
    • attachServiceManager

      public FbService attachServiceManager() throws SQLException
      Throws:
      SQLException
    • attachDatabase

      protected FbDatabase attachDatabase() throws SQLException
      Throws:
      SQLException
    • queueService

      public void queueService(FbService service) throws SQLException, IOException
      Throws:
      SQLException
      IOException
    • executeServicesOperation

      protected final void executeServicesOperation(FbService service, ServiceRequestBuffer srb) throws SQLException
      Execute a Services API operation in the database. All output from the operation is sent to this ServiceManager's logger.
      Parameters:
      service - service instance to execute on
      srb - The buffer containing the task request
      Throws:
      SQLException - if a database access error occurs or incorrect parameters are supplied
    • createRequestBuffer

      protected ServiceRequestBuffer createRequestBuffer(FbService service, int operation, int options)
    • getServerVersion

      public GDSServerVersion getServerVersion() throws SQLException
      Description copied from interface: ServiceManager
      Obtains the server version through a service call.
      Specified by:
      getServerVersion in interface ServiceManager
      Returns:
      Parsed server version, or GDSServerVersion.INVALID_VERSION if parsing failed.
      Throws:
      SQLException - For errors connecting to the service manager.