From b68ad228769306cf530834762aa84f845ec98b93 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 25 Jan 2004 15:37:42 +0000
Subject: [PATCH] added process message SQL

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@323 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/Activity/SQLDict.py        |  4 ++--
 .../activity/SQLDict_createMessageTable.zsql   |  2 ++
 .../skins/activity/SQLDict_processMessage.zsql | 18 ++++++++++++++++++
 .../skins/activity/SQLDict_readMessage.zsql    |  7 ++++---
 .../activity/SQLDict_readMessageList.zsql      |  9 ++++-----
 .../skins/activity/SQLDict_writeMessage.zsql   |  2 +-
 6 files changed, 31 insertions(+), 11 deletions(-)
 create mode 100755 product/CMFActivity/skins/activity/SQLDict_processMessage.zsql

diff --git a/product/CMFActivity/Activity/SQLDict.py b/product/CMFActivity/Activity/SQLDict.py
index 418437f051..987e3d6ed6 100755
--- a/product/CMFActivity/Activity/SQLDict.py
+++ b/product/CMFActivity/Activity/SQLDict.py
@@ -52,7 +52,7 @@ class SQLDict(RAMDict):
       path = line.path
       method_id = line.method_id
       # Make sure message can not be processed anylonger
-      activity_tool.SQLDict_assignMessage(path=path, method_id=method_id, processing_node = INVOKE_ERROR_STATE)
+      activity_tool.SQLDict_processMessage(path=path, method_id=method_id, processing_node = processing_node)
       get_transaction().commit() # Release locks before starting a potentially long calculation
       m = self.loadMessage(line.message)
       if m.validate(self, activity_tool):
@@ -62,7 +62,7 @@ class SQLDict(RAMDict):
           get_transaction().commit()                                        # If successful, commit
         else:
           get_transaction().abort()                                         # If not, abort transaction and start a new one
-          #activity_tool.SQLDict_assignMessage(path=path, method_id=method_id, processing_node = INVOKE_ERROR_STATE)
+          activity_tool.SQLDict_assignMessage(path=path, method_id=method_id, processing_node = INVOKE_ERROR_STATE)
                                                                             # Assign message back to 'error' state
           get_transaction().commit()                                        # and commit
       else:
diff --git a/product/CMFActivity/skins/activity/SQLDict_createMessageTable.zsql b/product/CMFActivity/skins/activity/SQLDict_createMessageTable.zsql
index 62f3c2e1f3..6bb9e0623e 100755
--- a/product/CMFActivity/skins/activity/SQLDict_createMessageTable.zsql
+++ b/product/CMFActivity/skins/activity/SQLDict_createMessageTable.zsql
@@ -12,8 +12,10 @@ CREATE TABLE `message` (
   `path` VARCHAR(255),
   `method_id` VARCHAR(40),
   `processing_node` INT DEFAULT -1,
+  `processing` INT DEFAULT 0,
   `message` BLOB,
   KEY `path` (`path`),
   KEY `method_id` (`method_id`),
   KEY `processing_node` (`processing_node`),
+  KEY `processing` (`processing`),
 ) TYPE = InnoDB;
diff --git a/product/CMFActivity/skins/activity/SQLDict_processMessage.zsql b/product/CMFActivity/skins/activity/SQLDict_processMessage.zsql
new file mode 100755
index 0000000000..61bdb07dc9
--- /dev/null
+++ b/product/CMFActivity/skins/activity/SQLDict_processMessage.zsql
@@ -0,0 +1,18 @@
+<dtml-comment>
+title:
+connection_id:erp5_sql_connection
+max_rows:1
+max_cache:0
+cache_time:0
+class_name:
+class_file:
+</dtml-comment>
+<params>path
+method_id
+processing_node</params>
+UPDATE message
+SET processing=1
+WHERE
+    path = <dtml-sqlvar path type="string">
+AND method_id = <dtml-sqlvar method_id type="string">
+AND processing_node = <dtml-sqlvar processing_node type="int">
diff --git a/product/CMFActivity/skins/activity/SQLDict_readMessage.zsql b/product/CMFActivity/skins/activity/SQLDict_readMessage.zsql
index ae22571b61..9a6a7b46be 100755
--- a/product/CMFActivity/skins/activity/SQLDict_readMessage.zsql
+++ b/product/CMFActivity/skins/activity/SQLDict_readMessage.zsql
@@ -9,8 +9,9 @@ class_file:
 </dtml-comment>
 <params>processing_node</params>
 SELECT * FROM
-  message
-<dtml-if processing_node>
+    message
 WHERE
-  processing_node = <dtml-sqlvar processing_node type="int">
+    processing = 1
+<dtml-if processing_node>
+AND processing_node = <dtml-sqlvar processing_node type="int">
 </dtml-if>
\ No newline at end of file
diff --git a/product/CMFActivity/skins/activity/SQLDict_readMessageList.zsql b/product/CMFActivity/skins/activity/SQLDict_readMessageList.zsql
index 91cd95603d..8a5211e2fa 100755
--- a/product/CMFActivity/skins/activity/SQLDict_readMessageList.zsql
+++ b/product/CMFActivity/skins/activity/SQLDict_readMessageList.zsql
@@ -12,9 +12,8 @@ method_id
 processing_node</params>
 SELECT * FROM
   message
-<dtml-if "path or method_id or processing_node">
 WHERE
-<dtml-if processing_node> processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
-<dtml-if path><dtml-if processing_node>AND</dtml-if> path = <dtml-sqlvar path type="string"></dtml-if>
-<dtml-if method_id><dtml-if "processing_node or path">AND</dtml-if> method_id = <dtml-sqlvar method_id type="string"></dtml-if>
-</dtml-if>
\ No newline at end of file
+    processing = 1
+<dtml-if processing_node>AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
+<dtml-if path>AND path = <dtml-sqlvar path type="string"></dtml-if>
+<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
diff --git a/product/CMFActivity/skins/activity/SQLDict_writeMessage.zsql b/product/CMFActivity/skins/activity/SQLDict_writeMessage.zsql
index 5d13141a54..adb89c1eab 100755
--- a/product/CMFActivity/skins/activity/SQLDict_writeMessage.zsql
+++ b/product/CMFActivity/skins/activity/SQLDict_writeMessage.zsql
@@ -12,4 +12,4 @@ method_id
 message</params>
 INSERT INTO message
 VALUES
- (<dtml-sqlvar path type="string">,<dtml-sqlvar method_id type="string">,-1,<dtml-sqlvar message type="string">);
+ (<dtml-sqlvar path type="string">,<dtml-sqlvar method_id type="string">,-1,0,<dtml-sqlvar message type="string">);
-- 
2.30.9