Class JdbcFacade

java.lang.Object
org.frankframework.jdbc.JdbcFacade
All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, IConfigurable, IScopeProvider, NameAware, TransactionAware, ConfigurableLifecycle, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
Direct Known Subclasses:
AbstractJdbcListener, AbstractJdbcMessageBrowser, AbstractJdbcSender, Locker, SimpleJdbcListener, Tibet2DatabaseStorage

Provides functions for JDBC connections.
N.B. Note on using XA transactions: If transactions are used, make sure that the database user can access the table SYS.DBA_PENDING_TRANSACTIONS. If not, transactions present when the server goes down cannot be properly recovered, resulting in exceptions like:
 The error code was XAER_RMERR. The exception stack trace follows: javax.transaction.xa.XAException
at oracle.jdbc.xa.OracleXAResource.recover(OracleXAResource.java:508)
Since:
4.1
Author:
Gerrit van Brakel
  • Field Details

    • log

      protected org.apache.logging.log4j.Logger log
  • Constructor Details

    • JdbcFacade

      public JdbcFacade()
  • Method Details

    • getLogPrefix

      protected String getLogPrefix()
    • configure

      public void configure() throws ConfigurationException
      Description copied from interface: IConfigurable
      Configure this component.

      configure() is called once at startup of the framework in the configure method of the owner of this IConfigurable. Purpose of this method is to check whether the static configuration of the object is correct. As much as possible class-instantiating should take place in the configure(), to improve performance.

      In the case of a container, this will propagate the configure signal to all components that apply.

      Specified by:
      configure in interface IConfigurable
      Throws:
      ConfigurationException - in case it was not able to configure the component.
    • start

      public void start()
      Specified by:
      start in interface ConfigurableLifecycle
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • getDatasource

      protected @NonNull DataSource getDatasource() throws JdbcException
      Throws:
      JdbcException
    • setDbmsSupportFactory

      public void setDbmsSupportFactory(DbmsSupportFactory dbmsSupportFactory)
    • getDbmsSupport

      public IDbmsSupport getDbmsSupport()
    • getConnection

      protected @NonNull Connection getConnection() throws JdbcException
      Obtains a connection to the datasource.
      Throws:
      JdbcException
    • withConnection

      protected <T, E extends Exception> T withConnection(ThrowingFunction<Connection, T, E> function) throws E
      Utility wrapper function to execute code with a database connection, handling exceptions and wrapping them in the generic E type. Returns a value of type T.
      Using this function can reduce the amount of exception-handling boilerplate in your code.
      Type Parameters:
      T - Return type of the code to be executed
      E - Exception type that can be thrown
      Parameters:
      function - Methord-reference or code to be executed with the connection. This method must have only a single parameter, the connection. If you need to call a function that takes multiple parameters or execute code that uses multiple local values, pass a lambda-function.
      Returns:
      Result of the executed code
      Throws:
      E - Exception of type E
    • withConnection

      protected <E extends Exception> void withConnection(ThrowingConsumer<Connection, E> consumer) throws E
      Utility wrapper method to execute code with a database connection, handling exceptions and wrapping them in the generic E type. Does not return any values.
      Using this method can reduce the amount of exception-handling boilerplate in your code.
      Type Parameters:
      E - Exception type that can be thrown
      Parameters:
      consumer - Method-reference or code to be executed with the connection. This method must have only a single parameter, the connection. If you need to call a method that takes multiple parameters or execute code that uses multiple local values, pass a lambda-function.
      Throws:
      E - Exception of type E
    • getConnectionWithTimeout

      public @NonNull Connection getConnectionWithTimeout(int timeout) throws JdbcException, TimeoutException
      Throws:
      JdbcException
      TimeoutException
    • convertQuery

      protected @NonNull String convertQuery(@NonNull String query) throws DbmsException
      Throws:
      DbmsException
    • getPhysicalDestinationName

      public @NonNull String getPhysicalDestinationName()
      Returns the name and location of the database that this objects operates on. If no previous connection was made or it cannot determine the destination it returns 'unknown'
      Specified by:
      getPhysicalDestinationName in interface HasPhysicalDestination
      See Also:
    • setName

      public void setName(String name)
      Name of the sender or the listener
      Specified by:
      setName in interface NameAware
    • setDatasourceName

      public void setDatasourceName(String datasourceName)
      JNDI name of datasource to be used, can be configured via jmsRealm, too
      Default value
      "jdbc.datasource.default"
    • getDatasourceName

      public String getDatasourceName()
    • setAuthAlias

      public void setAuthAlias(String authAlias)
      Authentication alias used to authenticate when connecting to database
    • setUsername

      public void setUsername(String username)
      User name for authentication when connecting to database, when none found from authAlias
    • setPassword

      public void setPassword(String password)
      Password for authentication when connecting to database, when none found from authAlias
    • getPassword

      protected String getPassword()
    • setSqlDialect

      public void setSqlDialect(String string)
      If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialect
    • setBlobsCompressed

      public void setBlobsCompressed(boolean b)
      Controls whether BLOB is considered stored compressed in the database
      Default value
      true
    • setBlobSmartGet

      public void setBlobSmartGet(boolean b)
      Controls automatically whether blobdata is stored compressed and/or serialized in the database. N.B. When set true, then the BLOB will be converted into a string
      Default value
      false
    • setBlobCharset

      @Deprecated(since="9.3.0", forRemoval=true) @ConfigurationWarning("Charset will be read from the message") public void setBlobCharset(String string)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Charset that is used to read and write BLOBs. This assumes the blob contains character data. If blobCharset and blobSmartGet are not set, BLOBs are returned as bytes. Before version 7.6, blobs were base64 encoded after being read to accommodate for the fact that senders need to return a String. This is no longer the case.