camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9118: camel-pgevent, use pg_notify for sending notifications with postgres verion 9 and above. Thanks to James Lindstorff for the patch.
Date Mon, 07 Sep 2015 10:41:38 GMT
Repository: camel
Updated Branches:
  refs/heads/master b05da3804 -> a302c732e


CAMEL-9118: camel-pgevent, use pg_notify for sending notifications with postgres verion 9
and above. Thanks to James Lindstorff for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a302c732
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a302c732
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a302c732

Branch: refs/heads/master
Commit: a302c732e2582549baf3c623cbdc1aee46dff553
Parents: b05da38
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 7 12:42:30 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 7 12:42:30 2015 +0200

----------------------------------------------------------------------
 .../camel/component/pgevent/PgEventProducer.java    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a302c732/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventProducer.java
b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventProducer.java
index cfa7d57..a586a22 100644
--- a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventProducer.java
+++ b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventProducer.java
@@ -16,10 +16,12 @@
  */
 package org.apache.camel.component.pgevent;
 
+import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 import com.impossibl.postgres.api.jdbc.PGConnection;
+
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultAsyncProducer;
@@ -50,9 +52,17 @@ public class PgEventProducer extends DefaultAsyncProducer {
 
         try {
             String payload = exchange.getIn().getBody(String.class);
-            String sql = String.format("NOTIFY %s, '%s'", endpoint.getChannel(), payload);
-            try (PreparedStatement statement = dbConnection.prepareStatement(sql)) {
-                statement.execute();
+            if (dbConnection.isServerMinimumVersion(9, 0)) {
+                try (CallableStatement statement = dbConnection.prepareCall("{call pg_notify(?,
?)}")) {
+                    statement.setString(1, endpoint.getChannel());
+                    statement.setString(2, payload);
+                    statement.execute();
+                }
+            } else {
+                String sql = String.format("NOTIFY %s, '%s'", endpoint.getChannel(), payload);
+                try (PreparedStatement statement = dbConnection.prepareStatement(sql)) {
+                    statement.execute();
+                }
             }
         } catch (SQLException e) {
             exchange.setException(e);


Mime
View raw message