Package org.frankframework.jdbc
Class AbstractJdbcQuerySender<H>
java.lang.Object
org.frankframework.jdbc.JdbcFacade
org.frankframework.jdbc.AbstractJdbcSender<H>
org.frankframework.jdbc.AbstractJdbcQuerySender<H>
- All Implemented Interfaces:
FrankElement,HasApplicationContext,HasName,HasPhysicalDestination,IBlockEnabledSender<H>,IConfigurable,IScopeProvider,ISender,ISenderWithParameters,IWithParameters,IXAEnabled,NameAware,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:
DirectQuerySender,FixedQuerySender
This executes the query that is obtained from the (here still abstract) method getStatement.
Descendant classes can override getStatement to provide meaningful statements.
If used with parameters, the values of the parameters will be applied to the statement.
Each occurrence of a questionmark ('?') will be replaced by a parameter value. Parameters are applied
in order: The n-th questionmark is replaced by the value of the n-th parameter.
Note on using packages
The package processor makes some assumptions about the data types:- elements that start with a single quote are assumed to be Strings
- elements that contain a dash ('-') are assumed to be dates (yyyy-MM-dd) or timestamps (yyyy-MM-dd HH:mm:ss)
- elements containing a dot ('.') are assumed to be floats
- all other elements are assumed to be integers
- Since:
- 4.1
- Author:
- Gerrit van Brakel
- Parameters
- all parameters present are applied to the statement to be executed
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.frankframework.jdbc.AbstractJdbcSender
connection, paramListFields inherited from class org.frankframework.jdbc.JdbcFacade
logFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringadjustQueryAndParameterListForNamedParameters(ParameterList parameterList, String query) protected DB2XMLWriterprotected voidcloseConnectionForSendMessage(Connection connection, PipeLineSession session) protected voidcloseStatementSet(QueryExecutionContext queryExecutionContext) voidConfigure this component.protected StringconvertQuery(String query) protected MessageexecuteOtherQuery(Connection connection, PreparedStatement statement, String query, String resultQuery, PreparedStatement resStmt, Message message, PipeLineSession session, ParameterList parameterList) protected MessageexecuteOtherQuery(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) protected MessageexecutePackageQuery(QueryExecutionContext queryExecutionContext) protected SenderResultexecuteSelectQuery(PreparedStatement statement, Object blobSessionVar, Object clobSessionVar) protected SenderResultexecuteStatementSet(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) protected MessageexecuteUpdateBlobQuery(PreparedStatement statement, Message contents) protected MessageexecuteUpdateClobQuery(PreparedStatement statement, Message contents) protected StringfillParamArray(Object[] paramArray, String message) intprotected CallableStatementgetCallWithRowIdReturned(Connection con, String query) protected Connectionprotected abstract StringObtain a query to be executed.getQueryExecutionContext(Connection connection, Message message) protected Messageprotected Messageprotected ResultSetprotected final PreparedStatementgetStatement(Connection con, String query, AbstractJdbcQuerySender.QueryType queryType) protected MessagegetUpdateStatementResult(PreparedStatement statement, String resultQuery, PreparedStatement resStmt, int numRowsAffected) protected PreparedStatementprepareQuery(Connection con, String query, AbstractJdbcQuerySender.QueryType queryType) protected PreparedStatementprepareQueryWithColumnsReturned(Connection con, String query, String[] columnsReturned) protected PreparedStatementprepareQueryWithResultSet(Connection con, String query, int resultSetConcurrency) voidsetAvoidLocking(boolean avoidLocking) If true, then select queries are executed in a way that avoids taking locks, e.g. with isolation mode 'read committed' instead of 'repeatable read'.voidcontrols whether the streamed blobdata will need to be base64encodeordecodeor not.voidsetBlobCharset(String string) Deprecated, for removal: This API element is subject to removal in a future version.voidsetBlobColumn(int i) Only for querytype 'updateBlob': column that contains the BLOB to be updatedvoidsetBlobsCompressed(boolean b) controls whether blobdata is stored compressed in the databasevoidsetBlobSessionKey(String string) For querytype 'updateBlob': key of session variable that contains the data (String or InputStream) to be loaded to the BLOB.voidsetBlobSmartGet(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the databasevoidsetClobColumn(int i) Only for querytype 'updateClob': column that contains the CLOB to be updatedvoidsetClobSessionKey(String string) For querytype 'updateClob': key of session variable that contains the CLOB (String or InputStream) to be loaded to the CLOB.voidsetCloseOutputstreamOnExit(boolean b) When set tofalse, the Outputstream is not closed after BLOB or CLOB has been written to itvoidsetColumnsReturned(String string) Comma separated list of columns whose values are to be returned.voidsetIncludeFieldDefinition(boolean b) whentrue, the result contains besides the returned rows also includes a header with information about the fetched fieldsvoidsetLockRows(boolean b) When settrue, exclusive row-level locks are obtained on all the rows identified by the select statement (e.g. by appending ' FOR UPDATE NOWAIT SKIP LOCKED' to the end of the query)voidsetLockWait(int i) when set and >=0, ' FOR UPDATE WAIT #' is used instead of ' FOR UPDATE NOWAIT SKIP LOCKED'voidsetMaxRows(int i) The maximum number of rows to be returned from the output ofselectqueries, -1 means unlimited rowsvoidsetNullValue(String string) Value used in result as contents of fields that contain no value (sql-null)voidsetOutputFormat(DocumentFormat outputFormat) The type of output.voidsetPackageContent(String packageContent) Controls if the returned package content is db2 format or xml format.voidsetPrettyPrint(boolean prettyPrint) If true and scalar=false, multiline indented XML is producedvoidsetQueryType(AbstractJdbcQuerySender.QueryType queryType) Type of query to be executedvoidsetResultQuery(String string) Query that can be used to obtain result of side-effect of update-query, like generated value of sequence.voidsetRowIdSessionKey(String string) If specified, the rowid of the processed row is put in the pipelinesession under the specified key (only applicable forquerytype=other).voidsetScalar(boolean b) Whentrue, the value of the first column of the first row (or the startrow) is returned as the only result, as a simple non-xml valuevoidsetScalarExtended(boolean b) Whentrueandscalaris alsotrue, but returns no value, one of the following is returned: '[absent]' no row is found '[null]' a row is found, but the value is a SQL-NULL '[empty]' a row is found, but the value is a empty stringvoidsetSqlDialect(String string) If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialectvoidsetStartRow(int i) The number of the first row to be returned from the output ofselectqueries.voidsetStreamCharset(String string) Charset used when reading a stream (that is e.g. going to be written to a BLOB or CLOB).voidsetSynchronous(boolean synchronous) Whentrue, the result of sendMessage is the reply of the request.voidsetTrimSpaces(boolean b) Remove trailing blanks from all result values.voidNamed parameters will be auto-detected by default.voidstart()This method will be called to start the sender.Methods inherited from class org.frankframework.jdbc.AbstractJdbcSender
addParameter, getConnection, getParameterList, sendMessage, setTimeout, stop, toStringMethods inherited from class org.frankframework.jdbc.JdbcFacade
getConnectionWithTimeout, getDatasource, getDatasourceName, getDbmsSupport, getLogPrefix, getPassword, getPhysicalDestinationName, isConnectionsArePooled, isRunning, isTransacted, setAuthAlias, setConnectionsArePooled, setDatasourceName, setDbmsSupportFactory, setName, setPassword, setTransacted, setUsernameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface org.frankframework.lifecycle.ConfigurableLifecycle
getPhase, isAutoStartup, isConfiguredMethods inherited from interface org.frankframework.core.FrankElement
addConfigWarningMethods inherited from interface org.frankframework.core.HasApplicationContext
getApplicationContext, getConfigurationClassLoaderMethods inherited from interface org.frankframework.core.IBlockEnabledSender
closeBlock, openBlock, sendMessageMethods inherited from interface org.frankframework.core.ISender
isSynchronous, sendMessageOrThrowMethods inherited from interface org.frankframework.core.ISenderWithParameters
consumesSessionVariableMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Field Details
-
UNP_START
- See Also:
-
UNP_END
- See Also:
-
-
Constructor Details
-
AbstractJdbcQuerySender
public AbstractJdbcQuerySender()
-
-
Method Details
-
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- Overrides:
configurein classAbstractJdbcSender<H>- Throws:
ConfigurationException- in case it was not able to configure the component.
-
getQuery
Obtain a query to be executed. Method-stub to be overridden in descender-classes.- Throws:
SenderException
-
start
public void start()Description copied from interface:ISenderThis method will be called to start the sender. After this method is called the sendMessage method may be called. Purpose of this method is to reduce creating connections to databases etc. in thesendMessage()method.- Specified by:
startin interfaceConfigurableLifecycle- Specified by:
startin interfaceISender- Specified by:
startin interfaceorg.springframework.context.Lifecycle- Overrides:
startin classAbstractJdbcSender<H>
-
convertQuery
- Throws:
SQLExceptionDbmsException
-
getStatement
protected final PreparedStatement getStatement(@Nonnull Connection con, @Nonnull String query, @Nullable AbstractJdbcQuerySender.QueryType queryType) throws JdbcException, SQLException - Throws:
JdbcExceptionSQLException
-
prepareQuery
protected PreparedStatement prepareQuery(@Nonnull Connection con, @Nonnull String query, @Nullable AbstractJdbcQuerySender.QueryType queryType) throws SQLException, JdbcException - Throws:
SQLExceptionJdbcException
-
prepareQueryWithResultSet
protected PreparedStatement prepareQueryWithResultSet(Connection con, String query, int resultSetConcurrency) throws SQLException - Throws:
SQLException
-
prepareQueryWithColumnsReturned
protected PreparedStatement prepareQueryWithColumnsReturned(Connection con, String query, String[] columnsReturned) throws SQLException - Throws:
SQLException
-
getCallWithRowIdReturned
protected CallableStatement getCallWithRowIdReturned(Connection con, String query) throws SQLException - Throws:
SQLException
-
getReturnedColumns
- Throws:
SQLException
-
getQueryExecutionContext
public QueryExecutionContext getQueryExecutionContext(Connection connection, Message message) throws SenderException, SQLException, JdbcException - Throws:
SenderExceptionSQLExceptionJdbcException
-
getConnectionForSendMessage
- Throws:
JdbcExceptionTimeoutException
-
closeConnectionForSendMessage
-
closeStatementSet
-
executeStatementSet
protected SenderResult executeStatementSet(@Nonnull QueryExecutionContext queryExecutionContext, @Nonnull Message message, @Nonnull PipeLineSession session) throws SenderException, TimeoutException - Throws:
SenderExceptionTimeoutException
-
adjustQueryAndParameterListForNamedParameters
protected String adjustQueryAndParameterListForNamedParameters(ParameterList parameterList, String query) -
getResult
- Throws:
JdbcExceptionSQLExceptionIOException
-
getResult
protected Message getResult(ResultSet resultset, Object blobSessionVar, Object clobSessionVar) throws JdbcException, SQLException, IOException - Throws:
JdbcExceptionSQLExceptionIOException
-
buildDb2XMLWriter
-
executeUpdateBlobQuery
protected Message executeUpdateBlobQuery(PreparedStatement statement, Message contents) throws SenderException - Throws:
SenderException
-
executeUpdateClobQuery
protected Message executeUpdateClobQuery(PreparedStatement statement, Message contents) throws SenderException - Throws:
SenderException
-
executeSelectQuery
protected SenderResult executeSelectQuery(PreparedStatement statement, Object blobSessionVar, Object clobSessionVar) throws SenderException - Throws:
SenderException
-
executePackageQuery
protected Message executePackageQuery(QueryExecutionContext queryExecutionContext) throws SenderException, JdbcException, IOException - Throws:
SenderExceptionJdbcExceptionIOException
-
executeOtherQuery
protected Message executeOtherQuery(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) throws SenderException - Throws:
SenderException
-
executeOtherQuery
protected Message executeOtherQuery(@Nonnull Connection connection, @Nonnull PreparedStatement statement, @Nonnull String query, @Nullable String resultQuery, @Nullable PreparedStatement resStmt, @Nullable Message message, @Nullable PipeLineSession session, @Nullable ParameterList parameterList) throws SenderException - Throws:
SenderException
-
getUpdateStatementResult
protected Message getUpdateStatementResult(PreparedStatement statement, String resultQuery, PreparedStatement resStmt, int numRowsAffected) throws SQLException, JdbcException, IOException - Throws:
SQLExceptionJdbcExceptionIOException
-
fillParamArray
- Throws:
SenderException
-
setPackageContent
Controls if the returned package content is db2 format or xml format. Possible values:- select: xml content s expected
- anything else: db2 content is expected
-
setQueryType
Type of query to be executed- Default value
- OTHER
-
setScalar
public void setScalar(boolean b) Whentrue, the value of the first column of the first row (or the startrow) is returned as the only result, as a simple non-xml value- Default value
- false
-
setScalarExtended
public void setScalarExtended(boolean b) Whentrueandscalaris alsotrue, but returns no value, one of the following is returned:- '[absent]' no row is found
- '[null]' a row is found, but the value is a SQL-NULL
- '[empty]' a row is found, but the value is a empty string
- Default value
- false
-
setMaxRows
public void setMaxRows(int i) The maximum number of rows to be returned from the output ofselectqueries, -1 means unlimited rows- Default value
- -1
-
setStartRow
public void setStartRow(int i) The number of the first row to be returned from the output ofselectqueries. Rows before this are skipped from the output.- Default value
- 1
-
setNullValue
Value used in result as contents of fields that contain no value (sql-null)- Default value
- empty string
-
setResultQuery
Query that can be used to obtain result of side-effect of update-query, like generated value of sequence. Example: SELECT mysequence.currval FROM dual -
setColumnsReturned
Comma separated list of columns whose values are to be returned. Works only if the driver implements jdbc 3.0 getGeneratedKeys(). Note: not all drivers support multiple values and returned field names may vary between drivers. Works for H2 and Oracle. Could work for MS_SQL with a single identity column, with name GENERATED_KEYS, if a identity has been generated. Not supported for other DBMSes. -
setUseNamedParams
Named parameters will be auto-detected by default. Every string in the query which equals"?{"<H>paramname"}"<H>will be replaced by the value of the corresponding parameter. The parameters don't need to be in the correct order and unused parameters are skipped.- Default value
- null
-
setIncludeFieldDefinition
public void setIncludeFieldDefinition(boolean b) whentrue, the result contains besides the returned rows also includes a header with information about the fetched fields- Default value
- application default (true)
-
setTrimSpaces
public void setTrimSpaces(boolean b) Remove trailing blanks from all result values.- Default value
- true
-
setRowIdSessionKey
If specified, the rowid of the processed row is put in the pipelinesession under the specified key (only applicable forquerytype=other). Note: If multiple rows are processed a SqlException is thrown. -
setSqlDialect
If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialect -
setLockRows
public void setLockRows(boolean b) When settrue, exclusive row-level locks are obtained on all the rows identified by the select statement (e.g. by appending ' FOR UPDATE NOWAIT SKIP LOCKED' to the end of the query)- Default value
- false
-
setLockWait
public void setLockWait(int i) when set and >=0, ' FOR UPDATE WAIT #' is used instead of ' FOR UPDATE NOWAIT SKIP LOCKED'- Default value
- -1
-
setSynchronous
public void setSynchronous(boolean synchronous) Whentrue, the result of sendMessage is the reply of the request.- Default value
- true
-
setBlobColumn
public void setBlobColumn(int i) Only for querytype 'updateBlob': column that contains the BLOB to be updated- Default value
- 1
-
setBlobSessionKey
For querytype 'updateBlob': key of session variable that contains the data (String or InputStream) to be loaded to the BLOB. When empty, the input of the pipe, which then must be a String, is used. For querytype 'select': key of session variable that contains the OutputStream, Writer or Filename to write the BLOB to -
setBlobsCompressed
public void setBlobsCompressed(boolean b) controls whether blobdata is stored compressed in the database- Default value
- true
-
setBlobBase64Direction
controls whether the streamed blobdata will need to be base64encodeordecodeor not. -
setBlobCharset
@Deprecated(since="9.3.0", forRemoval=true) @ConfigurationWarning("BlobCharset property will be removed in a future version. ") 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 -
setBlobSmartGet
public void setBlobSmartGet(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the database- Default value
- false
-
setClobColumn
public void setClobColumn(int i) Only for querytype 'updateClob': column that contains the CLOB to be updated- Default value
- 1
-
setClobSessionKey
For querytype 'updateClob': key of session variable that contains the CLOB (String or InputStream) to be loaded to the CLOB. When empty, the input of the pipe, which then must be a String, is used. For querytype 'select': key of session variable that contains the OutputStream, Writer or Filename to write the CLOB to -
setCloseOutputstreamOnExit
public void setCloseOutputstreamOnExit(boolean b) When set tofalse, the Outputstream is not closed after BLOB or CLOB has been written to it- Default value
- true
-
setStreamCharset
Charset used when reading a stream (that is e.g. going to be written to a BLOB or CLOB). When empty, the stream is copied directly to the BLOB, without conversion -
setAvoidLocking
public void setAvoidLocking(boolean avoidLocking) If true, then select queries are executed in a way that avoids taking locks, e.g. with isolation mode 'read committed' instead of 'repeatable read'.- Default value
- false
-
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint) If true and scalar=false, multiline indented XML is produced- Default value
- false
-
setOutputFormat
The type of output. If not set then defaults to old-style XML. If set to XML, new-style XML is used. EXPERIMENTAL: datatypes like numbers are not yet rendered correctly- Default value
- false
-
getBatchSize
public int getBatchSize()
-