You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/06/26 22:13:07 UTC
[1/6] git commit: CAMEL-7407: file/ftp consumer should eager remove
in progress files in case pollDirectory throw exception.
Repository: camel
Updated Branches:
refs/heads/camel-2.12.x 741b0cab2 -> 53c75549f
refs/heads/camel-2.13.x c88d8eb85 -> 2bf29e331
refs/heads/master cd3515ab5 -> 53e95788f
CAMEL-7407: file/ftp consumer should eager remove in progress files in case pollDirectory throw exception.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1796abcb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1796abcb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1796abcb
Branch: refs/heads/master
Commit: 1796abcb47fd346a06695d57ff1e2eb4015152cc
Parents: cd3515a
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:35:24 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 21:35:24 2014 +0200
----------------------------------------------------------------------
.../component/file/GenericFileConsumer.java | 24 +++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1796abcb/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
index 2b86c7f..8a39211 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
@@ -114,7 +114,17 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
// time how long time it takes to poll
StopWatch stop = new StopWatch();
- boolean limitHit = !pollDirectory(name, files, 0);
+ boolean limitHit;
+ try {
+ limitHit = !pollDirectory(name, files, 0);
+ } catch (Exception e) {
+ // during poll directory we add files to the in progress repository, in case of any exception thrown after this work
+ // we must then drain the in progress files before rethrowing the exception
+ log.debug("Error occurred during poll directory: " + name + " due " + e.getMessage() + ". Removing " + files.size() + " files marked as in-progress.");
+ removeExcessiveInProgressFiles(files);
+ throw e;
+ }
+
long delta = stop.stop();
if (log.isDebugEnabled()) {
log.debug("Took {} to poll: {}", TimeUtils.printDuration(delta), name);
@@ -231,6 +241,18 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
}
/**
+ * Drain any in progress files as we are done with the files
+ *
+ * @param files the files
+ */
+ protected void removeExcessiveInProgressFiles(List<GenericFile<T>> files) {
+ for (GenericFile file : files) {
+ String key = file.getAbsoluteFilePath();
+ endpoint.getInProgressRepository().remove(key);
+ }
+ }
+
+ /**
* Whether or not we can continue polling for more files
*
* @param fileList the current list of gathered files
[4/6] git commit: CAMEL-7432: camel-mybatis should keep message body
as-is if calling stored procedure and it did not return data,
but are using OUT parameters etc.
Posted by da...@apache.org.
CAMEL-7432: camel-mybatis should keep message body as-is if calling stored procedure and it did not return data, but are using OUT parameters etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2bf29e33
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2bf29e33
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2bf29e33
Branch: refs/heads/camel-2.13.x
Commit: 2bf29e331c752a6bec2df3da484e8fc4241b0c4e
Parents: ea9ac3c
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:56:40 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 22:12:33 2014 +0200
----------------------------------------------------------------------
.../component/mybatis/MyBatisProducer.java | 50 +++++++++++++-------
1 file changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2bf29e33/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
index 03367e3..6465636 100644
--- a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
+++ b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
@@ -23,6 +23,7 @@ import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
@@ -105,7 +106,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectOne(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doSelectList(Exchange exchange, SqlSession session) throws Exception {
@@ -119,7 +120,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectList(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doInsert(Exchange exchange, SqlSession session) throws Exception {
@@ -132,12 +133,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Inserting: {} using statement: {}", value, statement);
result = session.insert(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -148,11 +149,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Inserting: {} using statement: {}", in, statement);
result = session.insert(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -166,12 +167,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Updating: {} using statement: {}", value, statement);
result = session.update(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -182,11 +183,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Updating: {} using statement: {}", in, statement);
result = session.update(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -200,12 +201,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Deleting: {} using statement: {}", value, statement);
result = session.delete(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -216,15 +217,15 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Deleting: {} using statement: {}", in, statement);
result = session.delete(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
- private void doProcessResult(Exchange exchange, Object result) {
+ private void doProcessResult(Exchange exchange, Object result, SqlSession session) {
if (endpoint.getStatementType() == StatementType.SelectList || endpoint.getStatementType() == StatementType.SelectOne) {
Message answer = exchange.getIn();
if (ExchangeHelper.isOutCapable(exchange)) {
@@ -232,8 +233,23 @@ public class MyBatisProducer extends DefaultProducer {
// preserve headers
answer.getHeaders().putAll(exchange.getIn().getHeaders());
}
- // set the result as body for insert
- answer.setBody(result);
+
+ // we should not set the body if its a stored procedure as the result is already in its OUT parameter
+ MappedStatement ms = session.getConfiguration().getMappedStatement(statement);
+ if (ms != null && ms.getStatementType() == org.apache.ibatis.mapping.StatementType.CALLABLE) {
+ if (result == null) {
+ LOG.trace("Setting result as existing body as MyBatis statement type is Callable, and there was no result.");
+ answer.setBody(exchange.getIn().getBody());
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
answer.setHeader(MyBatisConstants.MYBATIS_RESULT, result);
answer.setHeader(MyBatisConstants.MYBATIS_STATEMENT_NAME, statement);
[3/6] git commit: CAMEL-7407: file/ftp consumer should eager remove
in progress files in case pollDirectory throw exception.
Posted by da...@apache.org.
CAMEL-7407: file/ftp consumer should eager remove in progress files in case pollDirectory throw exception.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ea9ac3c0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea9ac3c0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea9ac3c0
Branch: refs/heads/camel-2.13.x
Commit: ea9ac3c0bb86e9f0f973222672c340673822ff07
Parents: c88d8eb
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:35:24 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 22:12:26 2014 +0200
----------------------------------------------------------------------
.../component/file/GenericFileConsumer.java | 24 +++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ea9ac3c0/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
index 2b86c7f..8a39211 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
@@ -114,7 +114,17 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
// time how long time it takes to poll
StopWatch stop = new StopWatch();
- boolean limitHit = !pollDirectory(name, files, 0);
+ boolean limitHit;
+ try {
+ limitHit = !pollDirectory(name, files, 0);
+ } catch (Exception e) {
+ // during poll directory we add files to the in progress repository, in case of any exception thrown after this work
+ // we must then drain the in progress files before rethrowing the exception
+ log.debug("Error occurred during poll directory: " + name + " due " + e.getMessage() + ". Removing " + files.size() + " files marked as in-progress.");
+ removeExcessiveInProgressFiles(files);
+ throw e;
+ }
+
long delta = stop.stop();
if (log.isDebugEnabled()) {
log.debug("Took {} to poll: {}", TimeUtils.printDuration(delta), name);
@@ -231,6 +241,18 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
}
/**
+ * Drain any in progress files as we are done with the files
+ *
+ * @param files the files
+ */
+ protected void removeExcessiveInProgressFiles(List<GenericFile<T>> files) {
+ for (GenericFile file : files) {
+ String key = file.getAbsoluteFilePath();
+ endpoint.getInProgressRepository().remove(key);
+ }
+ }
+
+ /**
* Whether or not we can continue polling for more files
*
* @param fileList the current list of gathered files
[5/6] git commit: CAMEL-7407: file/ftp consumer should eager remove
in progress files in case pollDirectory throw exception.
Posted by da...@apache.org.
CAMEL-7407: file/ftp consumer should eager remove in progress files in case pollDirectory throw exception.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1f861c66
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1f861c66
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1f861c66
Branch: refs/heads/camel-2.12.x
Commit: 1f861c6678e4aac8d1f2b07cc6f2ddefa08ebb0b
Parents: 741b0ca
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:35:24 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 22:12:43 2014 +0200
----------------------------------------------------------------------
.../component/file/GenericFileConsumer.java | 24 +++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1f861c66/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
index 2b86c7f..8a39211 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
@@ -114,7 +114,17 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
// time how long time it takes to poll
StopWatch stop = new StopWatch();
- boolean limitHit = !pollDirectory(name, files, 0);
+ boolean limitHit;
+ try {
+ limitHit = !pollDirectory(name, files, 0);
+ } catch (Exception e) {
+ // during poll directory we add files to the in progress repository, in case of any exception thrown after this work
+ // we must then drain the in progress files before rethrowing the exception
+ log.debug("Error occurred during poll directory: " + name + " due " + e.getMessage() + ". Removing " + files.size() + " files marked as in-progress.");
+ removeExcessiveInProgressFiles(files);
+ throw e;
+ }
+
long delta = stop.stop();
if (log.isDebugEnabled()) {
log.debug("Took {} to poll: {}", TimeUtils.printDuration(delta), name);
@@ -231,6 +241,18 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
}
/**
+ * Drain any in progress files as we are done with the files
+ *
+ * @param files the files
+ */
+ protected void removeExcessiveInProgressFiles(List<GenericFile<T>> files) {
+ for (GenericFile file : files) {
+ String key = file.getAbsoluteFilePath();
+ endpoint.getInProgressRepository().remove(key);
+ }
+ }
+
+ /**
* Whether or not we can continue polling for more files
*
* @param fileList the current list of gathered files
[6/6] git commit: CAMEL-7432: camel-mybatis should keep message body
as-is if calling stored procedure and it did not return data,
but are using OUT parameters etc.
Posted by da...@apache.org.
CAMEL-7432: camel-mybatis should keep message body as-is if calling stored procedure and it did not return data, but are using OUT parameters etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/53c75549
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/53c75549
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/53c75549
Branch: refs/heads/camel-2.12.x
Commit: 53c75549f55d515133b697fa33980b6228fd44bb
Parents: 1f861c6
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:56:40 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 22:12:48 2014 +0200
----------------------------------------------------------------------
.../component/mybatis/MyBatisProducer.java | 50 +++++++++++++-------
1 file changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/53c75549/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
index 03367e3..6465636 100644
--- a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
+++ b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
@@ -23,6 +23,7 @@ import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
@@ -105,7 +106,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectOne(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doSelectList(Exchange exchange, SqlSession session) throws Exception {
@@ -119,7 +120,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectList(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doInsert(Exchange exchange, SqlSession session) throws Exception {
@@ -132,12 +133,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Inserting: {} using statement: {}", value, statement);
result = session.insert(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -148,11 +149,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Inserting: {} using statement: {}", in, statement);
result = session.insert(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -166,12 +167,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Updating: {} using statement: {}", value, statement);
result = session.update(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -182,11 +183,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Updating: {} using statement: {}", in, statement);
result = session.update(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -200,12 +201,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Deleting: {} using statement: {}", value, statement);
result = session.delete(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -216,15 +217,15 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Deleting: {} using statement: {}", in, statement);
result = session.delete(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
- private void doProcessResult(Exchange exchange, Object result) {
+ private void doProcessResult(Exchange exchange, Object result, SqlSession session) {
if (endpoint.getStatementType() == StatementType.SelectList || endpoint.getStatementType() == StatementType.SelectOne) {
Message answer = exchange.getIn();
if (ExchangeHelper.isOutCapable(exchange)) {
@@ -232,8 +233,23 @@ public class MyBatisProducer extends DefaultProducer {
// preserve headers
answer.getHeaders().putAll(exchange.getIn().getHeaders());
}
- // set the result as body for insert
- answer.setBody(result);
+
+ // we should not set the body if its a stored procedure as the result is already in its OUT parameter
+ MappedStatement ms = session.getConfiguration().getMappedStatement(statement);
+ if (ms != null && ms.getStatementType() == org.apache.ibatis.mapping.StatementType.CALLABLE) {
+ if (result == null) {
+ LOG.trace("Setting result as existing body as MyBatis statement type is Callable, and there was no result.");
+ answer.setBody(exchange.getIn().getBody());
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
answer.setHeader(MyBatisConstants.MYBATIS_RESULT, result);
answer.setHeader(MyBatisConstants.MYBATIS_STATEMENT_NAME, statement);
[2/6] git commit: CAMEL-7432: camel-mybatis should keep message body
as-is if calling stored procedure and it did not return data,
but are using OUT parameters etc.
Posted by da...@apache.org.
CAMEL-7432: camel-mybatis should keep message body as-is if calling stored procedure and it did not return data, but are using OUT parameters etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/53e95788
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/53e95788
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/53e95788
Branch: refs/heads/master
Commit: 53e95788f7ebcd8efbffc633e177105fa0cfdadc
Parents: 1796abc
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 26 21:56:40 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 26 21:56:40 2014 +0200
----------------------------------------------------------------------
.../component/mybatis/MyBatisProducer.java | 50 +++++++++++++-------
1 file changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/53e95788/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
index 03367e3..6465636 100644
--- a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
+++ b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisProducer.java
@@ -23,6 +23,7 @@ import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
@@ -105,7 +106,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectOne(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doSelectList(Exchange exchange, SqlSession session) throws Exception {
@@ -119,7 +120,7 @@ public class MyBatisProducer extends DefaultProducer {
result = session.selectList(statement);
}
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
private void doInsert(Exchange exchange, SqlSession session) throws Exception {
@@ -132,12 +133,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Inserting: {} using statement: {}", value, statement);
result = session.insert(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -148,11 +149,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Inserting: {} using statement: {}", in, statement);
result = session.insert(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -166,12 +167,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Updating: {} using statement: {}", value, statement);
result = session.update(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -182,11 +183,11 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Updating: {} using statement: {}", in, statement);
result = session.update(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Updating using statement: {}", statement);
result = session.update(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -200,12 +201,12 @@ public class MyBatisProducer extends DefaultProducer {
Object value = iter.next();
LOG.trace("Deleting: {} using statement: {}", value, statement);
result = session.delete(statement, value);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
@@ -216,15 +217,15 @@ public class MyBatisProducer extends DefaultProducer {
// just pass in the body as Object and allow MyBatis to iterate using its own foreach statement
LOG.trace("Deleting: {} using statement: {}", in, statement);
result = session.delete(statement, in);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
} else {
LOG.trace("Deleting using statement: {}", statement);
result = session.delete(statement);
- doProcessResult(exchange, result);
+ doProcessResult(exchange, result, session);
}
}
- private void doProcessResult(Exchange exchange, Object result) {
+ private void doProcessResult(Exchange exchange, Object result, SqlSession session) {
if (endpoint.getStatementType() == StatementType.SelectList || endpoint.getStatementType() == StatementType.SelectOne) {
Message answer = exchange.getIn();
if (ExchangeHelper.isOutCapable(exchange)) {
@@ -232,8 +233,23 @@ public class MyBatisProducer extends DefaultProducer {
// preserve headers
answer.getHeaders().putAll(exchange.getIn().getHeaders());
}
- // set the result as body for insert
- answer.setBody(result);
+
+ // we should not set the body if its a stored procedure as the result is already in its OUT parameter
+ MappedStatement ms = session.getConfiguration().getMappedStatement(statement);
+ if (ms != null && ms.getStatementType() == org.apache.ibatis.mapping.StatementType.CALLABLE) {
+ if (result == null) {
+ LOG.trace("Setting result as existing body as MyBatis statement type is Callable, and there was no result.");
+ answer.setBody(exchange.getIn().getBody());
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
+ } else {
+ // set the result as body for insert
+ LOG.trace("Setting result as body: {}", result);
+ answer.setBody(result);
+ }
answer.setHeader(MyBatisConstants.MYBATIS_RESULT, result);
answer.setHeader(MyBatisConstants.MYBATIS_STATEMENT_NAME, statement);