Claus Ibsen created CAMEL-26056:
-----------------------------------

             Summary: camel-jdbc - an outputClass that does not resolve fails 
with a NullPointerException, and generated keys use outputClass
                 Key: CAMEL-26056
                 URL: https://issues.apache.org/jira/browse/CAMEL-26056
             Project: Camel
          Issue Type: Bug
          Components: camel-jdbc
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of jdbc (CAMEL-24961), checked with 
{{camel run}} with an H2 in-memory data source.

h4. 1. An outputClass that does not resolve fails with a NullPointerException

{{JdbcHelper}} resolves the class of outputClass and creates it without a check 
({{JdbcHelper}}, main 5aac7df76b83, lines 35-36), so a name that does not 
resolve fails with {{RuntimeCamelException: NullPointerException: Cannot invoke 
"java.lang.Class.getDeclaredConstructor(...)" because "type" is null}}, without 
the class name. Checked on 4.24.0-SNAPSHOT with {{camel run}}: 
outputClass=survey.NoSuchItem.

*Proposed change*: fail with a message that names the class that is not found.

h4. 2. Generated keys are mapped to outputClass

The generated keys go through {{extractRows}} (JdbcProducer, line 375), which 
applies outputClass and readSize (line 416 on). So with outputClass on the 
endpoint, {{CamelGeneratedKeysRows}} holds beans of that class, or the insert 
fails with "Cannot map all properties" when the key columns are not its 
properties, and with resetAutoCommit the insert is rolled back (read in the 
code). Checked on 4.24.0-SNAPSHOT with {{camel run}}: an insert with 
CamelRetrieveGeneratedKeys on an endpoint with outputClass gave beans of that 
class with only the id set.

h4. 3. A Blob cannot be read after the producer

A BLOB or CLOB value is a {{java.sql.Blob}} or {{Clob}} ({{ResultSetIterator}}, 
line 213), but the producer closes the connection before it returns, so the 
route cannot read it. useGetBytesForBlob gives a byte[] for a BLOB; nothing 
does it for a CLOB. Checked on 4.24.0-SNAPSHOT with {{camel run}}: a SelectOne 
of a BLOB column gave an {{org.h2.jdbc.JdbcBlob}}, and its length then failed 
with "The object is already closed".

h4. 4. A null body fails with a NullPointerException

The SQL is read with {{getBody(String.class)}} (lines 77 and 125), not 
mandatory, so no body fails with useHeadersAsParameters with 
{{NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because 
"this.text" is null}}, and otherwise with the error of the driver. Checked on 
4.24.0-SNAPSHOT with {{camel run}}.

*Proposed change*: read the body with {{getMandatoryBody(String.class)}}.

h4. 5. The docs say generated keys do not work with named parameters

{{jdbc-component.adoc}} line 75: "Using generated keys does not work together 
with named parameters.". They do: Checked on 4.24.0-SNAPSHOT with {{camel 
run}}, an insert with {{:?label}} and useHeadersAsParameters gave its key in 
CamelGeneratedKeysRows, and JdbcParameterizedQueryGeneratedKeysTest tests it.

h4. Also read in the code, not run

* The transacted option is not read anywhere ({{JdbcEndpoint}}, lines 49 and 
116-123), since CAMEL-3803.
* CamelJdbcRowCount is set for SelectList only, but its doc says for a select.
* Only the first result of a statement is read (no getMoreResults).
* StreamList with resetAutoCommit commits before the route reads the rows, 
which a driver that closes cursors at commit cannot read.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to