Package org.frankframework.jdbc
Class AbstractJdbcQuerySender<H>
java.lang.Object
org.frankframework.jndi.JndiBase
org.frankframework.jdbc.JdbcFacade
org.frankframework.jdbc.AbstractJdbcSender<H>
org.frankframework.jdbc.AbstractJdbcQuerySender<H>
- All Implemented Interfaces:
AdapterAware
,HasPhysicalDestination
,IBlockEnabledSender<H>
,IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,ISender
,ISenderWithParameters
,IWithParameters
,IXAEnabled
,HasStatistics
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- 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
-
Field Summary
Fields inherited from class org.frankframework.jdbc.AbstractJdbcSender
connection, paramList
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
adjustQueryAndParameterListForNamedParameters
(ParameterList parameterList, String query) protected DB2XMLWriter
protected void
closeConnectionForSendMessage
(Connection connection, PipeLineSession session) protected void
closeStatementSet
(QueryExecutionContext queryExecutionContext) void
configure()
is called once at startup of the framework in the configure method of the owner of this sender.protected String
convertQuery
(String query) protected Message
executeOtherQuery
(Connection connection, PreparedStatement statement, String query, String resultQuery, PreparedStatement resStmt, Message message, PipeLineSession session, ParameterList parameterList) protected Message
executeOtherQuery
(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) protected Message
executePackageQuery
(QueryExecutionContext queryExecutionContext) protected SenderResult
executeSelectQuery
(PreparedStatement statement, Object blobSessionVar, Object clobSessionVar) protected SenderResult
executeStatementSet
(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) protected Message
executeUpdateBlobQuery
(PreparedStatement statement, Message contents) protected Message
executeUpdateClobQuery
(PreparedStatement statement, Message contents) protected String
fillParamArray
(Object[] paramArray, String message) int
int
protected CallableStatement
getCallWithRowIdReturned
(Connection con, String query) int
String[]
protected Connection
int
int
protected abstract String
Obtain a query to be executed.getQueryExecutionContext
(Connection connection, Message message) protected Message
protected Message
protected Message
getResult
(ResultSet resultset, Object blobSessionVar, Object clobSessionVar, jakarta.servlet.http.HttpServletResponse response, String contentType, String contentDisposition) protected ResultSet
int
protected final PreparedStatement
getStatement
(Connection con, String query, AbstractJdbcQuerySender.QueryType queryType) protected Message
getUpdateStatementResult
(PreparedStatement statement, String resultQuery, PreparedStatement resStmt, int numRowsAffected) boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
isScalar()
boolean
boolean
boolean
Whentrue
, the result of sendMessage is the reply of the request.boolean
protected PreparedStatement
prepareQuery
(Connection con, String query, AbstractJdbcQuerySender.QueryType queryType) protected PreparedStatement
prepareQueryWithColumnsReturned
(Connection con, String query, String[] columnsReturned) protected PreparedStatement
prepareQueryWithResultSet
(Connection con, String query, int resultSetConcurrency) 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'.void
controls whether the streamed blobdata will need to be base64encode
ordecode
or not.void
setBlobCharset
(String string) Charset that is used to read and write BLOBs.void
setBlobColumn
(int i) Only for querytype 'updateBlob': column that contains the BLOB to be updatedvoid
setBlobsCompressed
(boolean b) controls whether blobdata is stored compressed in the databasevoid
setBlobSessionKey
(String string) For querytype 'updateBlob': key of session variable that contains the data (String or InputStream) to be loaded to the BLOB.void
setBlobSmartGet
(boolean b) Controls automatically whether blobdata is stored compressed and/or serialized in the databasevoid
setClobColumn
(int i) Only for querytype 'updateClob': column that contains the CLOB to be updatedvoid
setClobSessionKey
(String string) For querytype 'updateClob': key of session variable that contains the CLOB (String or InputStream) to be loaded to the CLOB.void
setCloseInputstreamOnExit
(boolean b) Deprecated, for removal: This API element is subject to removal in a future version.void
setCloseOutputstreamOnExit
(boolean b) When set tofalse
, the Outputstream is not closed after BLOB or CLOB has been written to itvoid
setColumnsReturned
(String string) Comma separated list of columns whose values are to be returned.void
setIncludeFieldDefinition
(boolean b) whentrue
, the result contains besides the returned rows also includes a header with information about the fetched fieldsvoid
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)void
setLockWait
(int i) when set and >=0, ' FOR UPDATE WAIT #' is used instead of ' FOR UPDATE NOWAIT SKIP LOCKED'void
setMaxRows
(int i) The maximum number of rows to be returned from the output ofselect
queries, -1 means unlimited rowsvoid
setNullValue
(String string) Value used in result as contents of fields that contain no value (sql-null)void
setOutputFormat
(DocumentFormat outputFormat) The type of output.void
setPackageContent
(String packageContent) Controls if the returned package content is db2 format or xml format.void
setPrettyPrint
(boolean prettyPrint) If true and scalar=false, multiline indented XML is producedvoid
setQueryType
(AbstractJdbcQuerySender.QueryType queryType) Type of query to be executedvoid
setResultQuery
(String string) Query that can be used to obtain result of side-effect of update-query, like generated value of sequence.void
setRowIdSessionKey
(String string) If specified, the rowid of the processed row is put in the pipelinesession under the specified key (only applicable forquerytype=other
).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 valuevoid
setScalarExtended
(boolean b) Whentrue
andscalar
is 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 stringvoid
setSqlDialect
(String string) If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialectvoid
setStartRow
(int i) The number of the first row to be returned from the output ofselect
queries.void
setStreamCharset
(String string) Charset used when reading a stream (that is e.g. going to be written to a BLOB or CLOB).void
setStreamResultToServlet
(boolean b) Deprecated, for removal: This API element is subject to removal in a future version.void
setSynchronous
(boolean synchronous) Whentrue
, the result of sendMessage is the reply of the request.void
setTrimSpaces
(boolean b) Remove trailing blanks from all result values.void
Named parameters will be auto-detected by default.void
start()
This method will be called to start the sender.Methods inherited from class org.frankframework.jdbc.AbstractJdbcSender
addParameter, getAdapter, getConnection, getParameterList, getTimeout, sendMessage, setAdapter, setConfigurationMetrics, setTimeout, stop, toString
Methods inherited from class org.frankframework.jdbc.JdbcFacade
getAuthAlias, getConnectionWithTimeout, getDatasource, getDataSourceFactory, getDatasourceInfo, getDatasourceName, getDbmsSupport, getDomain, getLogPrefix, getPassword, getPhysicalDestinationName, getUsername, isConnectionsArePooled, isTransacted, setAuthAlias, setConnectionsArePooled, setDataSourceFactory, setDatasourceName, setDbmsSupportFactory, setJmsRealm, setPassword, setTransacted, setUsername
Methods inherited from class org.frankframework.jndi.JndiBase
getApplicationContext, getAuthentication, getConfigurationClassLoader, getContext, getCredentials, getInitialContextFactoryName, getJmsRealmName, getJndiAuthAlias, getJndiContextPrefix, getJndiEnv, getJndiProperties, getName, getPrincipal, getProviderURL, getSecurityProtocol, getUrlPkgPrefixes, setApplicationContext, setAuthentication, setCredentials, setInitialContextFactoryName, setJndiAuthAlias, setJndiContextPrefix, setJndiProperties, setName, setPrincipal, setProviderURL, setSecurityProtocol, setUrlPkgPrefixes
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
Methods inherited from interface org.frankframework.core.IBlockEnabledSender
closeBlock, openBlock, sendMessage
Methods inherited from interface org.frankframework.core.IConfigurationAware
getApplicationContext, getName
Methods inherited from interface org.frankframework.core.INamedObject
getName, setName
Methods inherited from interface org.frankframework.core.IScopeProvider
getConfigurationClassLoader
Methods inherited from interface org.frankframework.core.ISender
sendMessageOrThrow
Methods inherited from interface org.frankframework.core.ISenderWithParameters
consumesSessionVariable
-
Field Details
-
UNP_START
- See Also:
-
UNP_END
- See Also:
-
-
Constructor Details
-
AbstractJdbcQuerySender
public AbstractJdbcQuerySender()
-
-
Method Details
-
configure
Description copied from interface:ISender
configure()
is called once at startup of the framework in the configure method of the owner of this sender. Purpose of this method is to check whether the static configuration of the sender is correct. As much as possible class-instantiating should take place in theconfigure()
oropen()
method, to improve performance.- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceISender
- Overrides:
configure
in classAbstractJdbcSender<H>
- Throws:
ConfigurationException
-
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:ISender
This 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:
start
in interfaceISender
- Overrides:
start
in classAbstractJdbcSender<H>
-
convertQuery
- Throws:
SQLException
DbmsException
-
getStatement
protected final PreparedStatement getStatement(@Nonnull Connection con, @Nonnull String query, @Nullable AbstractJdbcQuerySender.QueryType queryType) throws JdbcException, SQLException - Throws:
JdbcException
SQLException
-
prepareQuery
protected PreparedStatement prepareQuery(@Nonnull Connection con, @Nonnull String query, @Nullable AbstractJdbcQuerySender.QueryType queryType) throws SQLException, JdbcException - Throws:
SQLException
JdbcException
-
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:
SenderException
SQLException
JdbcException
-
getConnectionForSendMessage
- Throws:
JdbcException
TimeoutException
-
closeConnectionForSendMessage
-
closeStatementSet
-
executeStatementSet
protected SenderResult executeStatementSet(@Nonnull QueryExecutionContext queryExecutionContext, @Nonnull Message message, @Nonnull PipeLineSession session) throws SenderException, TimeoutException - Throws:
SenderException
TimeoutException
-
adjustQueryAndParameterListForNamedParameters
protected String adjustQueryAndParameterListForNamedParameters(ParameterList parameterList, String query) -
getResult
protected Message getResult(ResultSet resultset) throws JdbcException, SQLException, IOException, jakarta.jms.JMSException - Throws:
JdbcException
SQLException
IOException
jakarta.jms.JMSException
-
getResult
protected Message getResult(ResultSet resultset, Object blobSessionVar, Object clobSessionVar) throws JdbcException, SQLException, IOException - Throws:
JdbcException
SQLException
IOException
-
getResult
protected Message getResult(ResultSet resultset, Object blobSessionVar, Object clobSessionVar, jakarta.servlet.http.HttpServletResponse response, String contentType, String contentDisposition) throws JdbcException, SQLException, IOException - Throws:
JdbcException
SQLException
IOException
-
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, jakarta.jms.JMSException - Throws:
SenderException
JdbcException
IOException
jakarta.jms.JMSException
-
executeOtherQuery
protected Message executeOtherQuery(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session) throws SenderException - Throws:
SenderException
-
executeOtherQuery
protected Message executeOtherQuery(Connection connection, PreparedStatement statement, String query, String resultQuery, PreparedStatement resStmt, Message message, PipeLineSession session, ParameterList parameterList) throws SenderException - Throws:
SenderException
-
getUpdateStatementResult
protected Message getUpdateStatementResult(PreparedStatement statement, String resultQuery, PreparedStatement resStmt, int numRowsAffected) throws SQLException, JdbcException, IOException, jakarta.jms.JMSException - Throws:
SQLException
JdbcException
IOException
jakarta.jms.JMSException
-
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) Whentrue
andscalar
is 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 ofselect
queries, -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 ofselect
queries. 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"?{"paramname"}"
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. -
setStreamResultToServlet
Deprecated, for removal: This API element is subject to removal in a future version.If set, the result is streamed to the HttpServletResponse object of the RestServiceDispatcher (instead of passed as bytes or as a String)- Default value
- false
-
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 base64encode
ordecode
or not. -
setBlobCharset
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 -
setCloseInputstreamOnExit
Deprecated, for removal: This API element is subject to removal in a future version.When set tofalse
, the Inputstream is not closed after it has been used to update a BLOB or CLOB- Default value
- true
-
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() -
getQueryType
-
getMaxRows
public int getMaxRows() -
getStartRow
public int getStartRow() -
isScalar
public boolean isScalar() -
isScalarExtended
public boolean isScalarExtended() -
isSynchronous
public boolean isSynchronous()Description copied from interface:ISender
Whentrue
, the result of sendMessage is the reply of the request. -
getBlobColumn
public int getBlobColumn() -
getClobColumn
public int getClobColumn() -
getBlobSessionKey
-
getClobSessionKey
-
getNullValue
-
getColumnsReturned
-
getResultQuery
-
isTrimSpaces
public boolean isTrimSpaces() -
getBlobCharset
-
isCloseInputstreamOnExit
public boolean isCloseInputstreamOnExit() -
isCloseOutputstreamOnExit
public boolean isCloseOutputstreamOnExit() -
getBlobBase64Direction
-
getStreamCharset
-
isBlobsCompressed
public boolean isBlobsCompressed() -
isBlobSmartGet
public boolean isBlobSmartGet() -
getUseNamedParams
-
isIncludeFieldDefinition
public boolean isIncludeFieldDefinition() -
getRowIdSessionKey
-
getPackageContent
-
getColumnsReturnedList
-
isStreamResultToServlet
public boolean isStreamResultToServlet() -
getSqlDialect
-
isLockRows
public boolean isLockRows() -
getLockWait
public int getLockWait() -
isAvoidLocking
public boolean isAvoidLocking() -
getOutputFormat
-
isPrettyPrint
public boolean isPrettyPrint()
-