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
@DestinationType(JDBC)
public class JdbcFacade
extends Object
implements HasPhysicalDestination, TransactionAware, ConfigurableLifecycle, FrankElement, NameAware
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:
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 Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConfigure this component.protected @NonNull StringconvertQuery(@NonNull String query) protected @NonNull ConnectionObtains a connection to the datasource.@NonNull ConnectiongetConnectionWithTimeout(int timeout) protected @NonNull DataSourceprotected Stringprotected String@NonNull StringReturns the name and location of the database that this objects operates on.booleanvoidsetAuthAlias(String authAlias) Authentication alias used to authenticate when connecting to databasevoidsetBlobCharset(String string) Deprecated, for removal: This API element is subject to removal in a future version.voidsetBlobsCompressed(boolean b) Controls whether BLOB is considered stored compressed in the databasevoidsetBlobSmartGet(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the database.voidsetDatasourceName(String datasourceName) JNDI name of datasource to be used, can be configured via jmsRealm, toovoidsetDbmsSupportFactory(DbmsSupportFactory dbmsSupportFactory) voidName of the sender or the listenervoidsetPassword(String password) Password for authentication when connecting to database, when none found fromauthAliasvoidsetSqlDialect(String string) If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialectvoidsetUsername(String username) User name for authentication when connecting to database, when none found fromauthAliasvoidstart()voidstop()protected <E extends Exception>
voidwithConnection(ThrowingConsumer<Connection, E> consumer) Utility wrapper method to execute code with a database connection, handling exceptions and wrapping them in the generic E type.protected <T, E extends Exception>
TwithConnection(ThrowingFunction<Connection, T, E> function) Utility wrapper function to execute code with a database connection, handling exceptions and wrapping them in the generic E type.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface FrankElement
addConfigWarningMethods inherited from interface HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable, stop
-
Field Details
-
log
protected org.apache.logging.log4j.Logger log
-
-
Constructor Details
-
JdbcFacade
public JdbcFacade()
-
-
Method Details
-
getLogPrefix
-
configure
Description copied from interface:IConfigurableConfigure this component.configure()is called once at startup of the framework in the configure method of the owner of thisIConfigurable. 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 theconfigure(), to improve performance.In the case of a container, this will propagate the configure signal to all components that apply.
- Specified by:
configurein interfaceIConfigurable- Throws:
ConfigurationException- in case it was not able to configure the component.
-
start
public void start()- Specified by:
startin interfaceConfigurableLifecycle- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getDatasource
- Throws:
JdbcException
-
setDbmsSupportFactory
-
getDbmsSupport
-
getConnection
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 executedE- 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:
JdbcExceptionTimeoutException
-
convertQuery
- Throws:
DbmsException
-
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:
getPhysicalDestinationNamein interfaceHasPhysicalDestination- See Also:
-
setName
-
setDatasourceName
JNDI name of datasource to be used, can be configured via jmsRealm, too- Default value
- "jdbc.datasource.default"
-
getDatasourceName
-
setAuthAlias
Authentication alias used to authenticate when connecting to database -
setUsername
User name for authentication when connecting to database, when none found fromauthAlias -
setPassword
Password for authentication when connecting to database, when none found fromauthAlias -
getPassword
-
setSqlDialect
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.
-