Class BackendInfo

java.lang.Object
org.tentackle.sql.BackendInfo

public class BackendInfo extends Object
Configuration info for a backend.
Author:
harald
  • Constructor Summary

    Constructors
    Constructor
    Description
    BackendInfo(String backendName)
    Creates a backend info from a backend name.
    The info cannot be used to connect.
    BackendInfo(String url, String user, char[] password, String[] schemas)
    Creates a backend info.
    This info is able to create a connection.
    BackendInfo(EncryptedProperties backendProperties)
    Creates a backend info from backend properties.
    The info is able to create a connection.
    Creates a backend info from a backend.
    The info cannot be used to connect.
    BackendInfo(BackendInfo backendInfo, String user, char[] password)
    Creates a backend info from another one with a different user and password.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all passwords (stored in char[]-arrays) so that they are no more visible in memory.
    Creates a connection.
    Gets the backend.
    int
    Gets the optional database connection inactivity timeout.
    Gets the JNDI source.
    char[]
    Gets the connection password.
    Gets the schemas.
    Gets the connection url.
    Gets the username to connect.
    boolean
    Returns whether dummy selects should be sent periodically or only on re-use of an idle connection.
    boolean
    Returns whether backend info can be used to connect.
    boolean
    Returns whether this backend is remote.
    void
    setBackendKeepAliveEnabled(boolean backendKeepAliveEnabled)
    Sets whether a keep-alive SELECT should be sent periodically on idle connections.
    When true and backendTimeout is set, a dummy select will be sent to the backend, when the connection is idle for more than backendTimeout minutes.
    void
    setBackendTimeout(int backendTimeout)
    Sets the database connection inactivity timeout.
    Some databases close connections if being idle for a certain time, which cannot be deactivated especially in clouds.
    When this timeout is set, a dummy select will be sent to the backend, to make sure that the connection hasn't been closed in the meantime and/or to keep it alive periodically.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BackendInfo

      public BackendInfo(Backend backend)
      Creates a backend info from a backend.
      The info cannot be used to connect.
      Parameters:
      backend - the backend
    • BackendInfo

      public BackendInfo(String backendName)
      Creates a backend info from a backend name.
      The info cannot be used to connect.
      Parameters:
      backendName - the backend name
    • BackendInfo

      public BackendInfo(String url, String user, char[] password, String[] schemas)
      Creates a backend info.
      This info is able to create a connection.
      Parameters:
      url - the backend url
      user - the username
      password - the password
      schemas - the optional schemas, null if no schema check
    • BackendInfo

      public BackendInfo(EncryptedProperties backendProperties)
      Creates a backend info from backend properties.
      The info is able to create a connection.
      Parameters:
      backendProperties - the properties
    • BackendInfo

      public BackendInfo(BackendInfo backendInfo, String user, char[] password)
      Creates a backend info from another one with a different user and password.
      Parameters:
      backendInfo - the original backend info
      user - the username
      password - the password
  • Method Details

    • getBackend

      public Backend getBackend()
      Gets the backend.
      Returns:
      the backend
    • isRemote

      public boolean isRemote()
      Returns whether this backend is remote.
      Returns:
      true if remote
    • getJndiDataSource

      public DataSource getJndiDataSource()
      Gets the JNDI source.
      Returns:
      the JNDI datasource if this a JNDI connection
    • getUrl

      public String getUrl()
      Gets the connection url.
      Returns:
      the url, null if info cannot connect
    • getUser

      public String getUser()
      Gets the username to connect.
      Returns:
      the username
    • getPassword

      public char[] getPassword()
      Gets the connection password.
      Returns:
      the password
    • clearPassword

      public void clearPassword()
      Clears all passwords (stored in char[]-arrays) so that they are no more visible in memory.
    • getSchemas

      public String[] getSchemas()
      Gets the schemas.
      Returns:
      the schemas for migration
    • isConnectable

      public boolean isConnectable()
      Returns whether backend info can be used to connect.
      Returns:
      true if connectable
    • getBackendTimeout

      public int getBackendTimeout()
      Gets the optional database connection inactivity timeout.
      Returns:
      the timeout in minutes, 0 if none
    • setBackendTimeout

      public void setBackendTimeout(int backendTimeout)
      Sets the database connection inactivity timeout.
      Some databases close connections if being idle for a certain time, which cannot be deactivated especially in clouds.
      When this timeout is set, a dummy select will be sent to the backend, to make sure that the connection hasn't been closed in the meantime and/or to keep it alive periodically.
      Parameters:
      backendTimeout - the timeout in minutes, 0 if none
      See Also:
    • isBackendKeepAliveEnabled

      public boolean isBackendKeepAliveEnabled()
      Returns whether dummy selects should be sent periodically or only on re-use of an idle connection.
      Returns:
      true if periodically, false if on demand only
    • setBackendKeepAliveEnabled

      public void setBackendKeepAliveEnabled(boolean backendKeepAliveEnabled)
      Sets whether a keep-alive SELECT should be sent periodically on idle connections.
      When true and backendTimeout is set, a dummy select will be sent to the backend, when the connection is idle for more than backendTimeout minutes. Otherwise, the dummy select will be sent when the connection is re-used after at least backendTimeout minutes to test if the connection is still alive.
      Parameters:
      backendKeepAliveEnabled - true to keep alive periodically, false only before usage after
    • connect

      public Connection connect() throws SQLException
      Creates a connection.
      Returns:
      the connection in autocommit mode
      Throws:
      SQLException - if connection could not be created
    • toString

      public String toString()
      Overrides:
      toString in class Object