You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Aaron Daubman (Created) (JIRA)" <ji...@apache.org> on 2012/04/06 05:45:20 UTC

[jira] [Created] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
----------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: CAMEL-5143
                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
             Project: Camel
          Issue Type: Improvement
          Components: camel-mybatis
    Affects Versions: 2.10.0
            Reporter: Aaron Daubman
            Priority: Minor
             Fix For: 2.10.0


The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
    <insert id="batchInsertdataCore" parameterType="java.util.List">
        INSERT INTO CORE_DATA (
        <include refid="dataCoreColumns"/>
        )
        VALUES (
        <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
            #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
        </foreach>
        )
    </insert>

This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
    event_id=111222333,
    start_time_val=Thu Mar 01 02:03:04 EST 2001,
    end_time_val=Thu Mar 01 02:03:05 EST 2001,
}
) was not iterable.
### The error may exist in mybatis/dataCore.xml
### The error may involve dataCore.batchInsertdataCore
### The error occurred while executing an update

---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
    private void doInsert(Exchange exchange) throws Exception {
        SqlSessionFactory client = endpoint.getSqlSessionFactory();
        SqlSession session = client.openSession();
        try {
            Object result;
            Object in = exchange.getIn().getBody();
            if (in != null) {
                // lets handle arrays or collections of objects
                Iterator<?> iter = ObjectHelper.createIterator(in);
                while (iter.hasNext()) {
                    Object value = iter.next();
                    LOG.trace("Inserting: {} using statement: {}", value, statement);
                    result = session.insert(statement, value);
                    doProcessResult(exchange, result);
                }
            } else {
                LOG.trace("Inserting using statement: {}", statement);
                result = session.insert(statement);
                doProcessResult(exchange, result);
            }
        } finally {
            session.commit();
            session.close();
        }
    }
---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---

It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.

Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
result = session.insert(statement, in);


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Aaron Daubman (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13248009#comment-13248009 ] 

Aaron Daubman commented on CAMEL-5143:
--------------------------------------

I will work to submit a patch for this tonight. I am guessing I do not have rights to assign myself this issue?
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Aaron Daubman (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Aaron Daubman updated CAMEL-5143:
---------------------------------

    Patch Info: Patch Available
    
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Aaron Daubman (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13248342#comment-13248342 ] 

Aaron Daubman commented on CAMEL-5143:
--------------------------------------

Whatever makes the most sense works for me... I just named it InsertList as it seemed the converse/analog to the already existing SelectList. Thanks for the quick work applying to trunk! 
InsertForEach might make good sense as well since you will probably need to set up some sort of foreach operation in your mybatis mapper to use what you pass in... although I'm a novice mybatis user (you might be able to use the input from this method for collection-referenced things as well which wouldn't require a foreach?)
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Claus Ibsen (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-5143.
--------------------------------

    Resolution: Fixed

Thanks for the patch. I have applied it to trunk, and updated the wiki documentation.
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Claus Ibsen (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13248169#comment-13248169 ] 

Claus Ibsen commented on CAMEL-5143:
------------------------------------

Just wonder if the InsertList should been named InsertForEach ?
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Claus Ibsen (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13249500#comment-13249500 ] 

Claus Ibsen commented on CAMEL-5143:
------------------------------------

No it should be MyBatis or camel-mybatis that should handle empty lists for InsertList.
BeanIO is a data format and will always transform the message, either to contain 0 or N models.

Ideally MyBatis itself should handle that, maybe a new configuration you can configure in the mapper file.
I suggest to ask on their user mailing list about this. And possible get this implemented in a future release of MyBatis.

In the mean time maybe we can possible detect this in camel-mybatis, and then dont execute MyBatis at all. Just like the Insert where we create the iterator, we can do that same, and then just check if there is at least 1 element in the iterator.
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Claus Ibsen (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned CAMEL-5143:
----------------------------------

    Assignee: Claus Ibsen
    
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Aaron Daubman (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Aaron Daubman updated CAMEL-5143:
---------------------------------

    Attachment: MyBatisInsertListTest.java
                Patch_for_CAMEL-5143.txt

Attached a patch for three modified files (created using IntelliJ IDEA) as well as the new test file.
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAMEL-5143) Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements

Posted by "Aaron Daubman (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAMEL-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13249472#comment-13249472 ] 

Aaron Daubman commented on CAMEL-5143:
--------------------------------------

Not sure if this needs to be updated to check for greater-than-zero elements in the list to be processed? I have run into an issue where further up the route BeanIO encounters an invalid record, and, having setIgnoreInvalidRecords set to true, ignores it. Ideally, there would be a parameter for camel-beanio (similar to camel-mybatis' consumer.routeEmptyResultSet) that would prevent beanio from routing an empty body, however, I did not see any such option. So, camel-beanio passes the empty list along to MyBatis, which then tries (with foreach) to iterate over the list to produce the insert statement for the DB... since the list is empty, the SQL is never fully formed, and results in a SQL Query format error.

Should:
1) The code I provided check to see if the list is >0 (if so, what should the behavior be if in.size() == 0)?
2) Should an option be added to camel-beanio to prevent routing of empty message bodies? If so, how should this be done?
                
> Add a new camel-mybatis statementType of 'InsertList' (similar to SelectOne versus SelectList) to allow for mybatis foreach driven batch insert statements
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5143
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5143
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-mybatis
>    Affects Versions: 2.10.0
>            Reporter: Aaron Daubman
>            Assignee: Claus Ibsen
>            Priority: Minor
>              Labels: batch, foreach, insert, mybatis
>             Fix For: 2.10.0
>
>         Attachments: MyBatisInsertListTest.java, Patch_for_CAMEL-5143.txt
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The camel-mybatis code will iterate over any list passed in and attempt to insert each item individually, bypassing foreach support in statements like:
>     <insert id="batchInsertdataCore" parameterType="java.util.List">
>         INSERT INTO CORE_DATA (
>         <include refid="dataCoreColumns"/>
>         )
>         VALUES (
>         <foreach item="dataCore" collection="_parameter" open="" close="" separator="),(">
>             #{dataCore.event_id}, #{dataCore.start_time_val}, #{dataCore.end_time_val}
>         </foreach>
>         )
>     </insert>
> This results in mybatis generating the following error even when the route is receiving a list of objects as desired:
> ### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '_parameter'.  Return value (dataCore{
>     event_id=111222333,
>     start_time_val=Thu Mar 01 02:03:04 EST 2001,
>     end_time_val=Thu Mar 01 02:03:05 EST 2001,
> }
> ) was not iterable.
> ### The error may exist in mybatis/dataCore.xml
> ### The error may involve dataCore.batchInsertdataCore
> ### The error occurred while executing an update
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
>     private void doInsert(Exchange exchange) throws Exception {
>         SqlSessionFactory client = endpoint.getSqlSessionFactory();
>         SqlSession session = client.openSession();
>         try {
>             Object result;
>             Object in = exchange.getIn().getBody();
>             if (in != null) {
>                 // lets handle arrays or collections of objects
>                 Iterator<?> iter = ObjectHelper.createIterator(in);
>                 while (iter.hasNext()) {
>                     Object value = iter.next();
>                     LOG.trace("Inserting: {} using statement: {}", value, statement);
>                     result = session.insert(statement, value);
>                     doProcessResult(exchange, result);
>                 }
>             } else {
>                 LOG.trace("Inserting using statement: {}", statement);
>                 result = session.insert(statement);
>                 doProcessResult(exchange, result);
>             }
>         } finally {
>             session.commit();
>             session.close();
>         }
>     }
> ---from camel/trunk/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java ---
> It should be simple to add a new statementType = 'InsertList' (similar to SelectOne versus SelectList) and add it to the switch statement further up in the MyBatisProducer.java code.
> Then a new doInsertBatch would be created, copying the code above and just emoving the iterator related code, simply calling:
> result = session.insert(statement, in);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira