Claus Ibsen created CAMEL-27739:
-----------------------------------
Summary: camel-mybatis: dead mapper fallback, maxMessagesPerPoll
after select, executorType default
Key: CAMEL-27739
URL: https://issues.apache.org/jira/browse/CAMEL-27739
Project: Camel
Issue Type: Bug
Components: camel-mybatis
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while improving the option descriptions of camel-mybatis for CAMEL-23832
(commit
https://github.com/apache/camel/commit/b82eef5b59e581059179cfd3aa240e1194ec9c8c).
These are separate problems of the component; the descriptions commit only
documents the current behavior.
h4. 1. mybatis-bean: the class name fallback and the "No Mapper" error are
never reached
{{MyBatisBeanProducer.createBeanProcessor()}} first calls
{{TypeAliasRegistry.resolveAlias(beanName)}} and falls back to the Camel
{{ClassResolver}} when it returns null. In MyBatis 3.6.0 {{resolveAlias}} never
returns null for a name: it loads an unknown name with
{{Resources.classForName}} and throws a {{TypeException}} when that fails. So a
mapper class that only the Camel {{ClassResolver}} can load fails with
{{TypeException}}.
The same method checks {{session.getMapper(clazz) == null}} to throw "No Mapper
with typeAlias or class name ...", but {{getMapper}} throws a
{{BindingException}} for a mapper that is not registered, so the user never
sees that message.
Proposed change: catch the {{TypeException}} and then try the Camel
{{ClassResolver}}, and catch the {{BindingException}} to throw the clearer
message (or remove the dead null check).
h4. 2. mybatis consumer: maxMessagesPerPoll does not limit the select
{{MyBatisConsumer.poll()}} reads all the rows with {{selectList}} and creates
an exchange for every row, and only then {{processBatch()}} routes the first
{{maxMessagesPerPoll}} of them. The exchanges of the other rows are created but
never routed or released. With a large result every poll reads and wraps all
the rows to route a few.
Proposed change: create the exchange of a row only when {{processBatch()}}
routes it, and consider passing a {{RowBounds}} with the limit to
{{selectList}} in {{DefaultMyBatisProcessingStrategy.poll()}}.
h4. 3. executorType: the metadata default SIMPLE is not what happens when the
option is not set
{{BaseMyBatisEndpoint.executorType}} is declared with {{defaultValue =
"SIMPLE"}}, but the field is null by default. {{MyBatisProducer.process()}} and
{{MyBatisBeanProducer.process()}} then call {{openSession()}} without an
executor type, which uses the {{defaultExecutorType}} setting of the MyBatis
configuration. When that configuration sets {{defaultExecutorType}} to BATCH or
REUSE, the catalog says SIMPLE while the producer uses the other executor.
Proposed change: remove the {{defaultValue}} from the metadata (the
descriptions now say that the MyBatis configuration decides when the option is
not set).
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)