From ac7bd25a0547011f69c7e21a12937af9c6c2dc5b Mon Sep 17 00:00:00 2001
From: Simon Boulet <simon@nostalgeek.com>
Date: Fri, 5 Jul 2013 13:15:29 -0400
Subject: [PATCH] feature #1734: Add support for UPDATE hook


Signed-off-by: Simon Boulet <simon@nostalgeek.com>
---
 include/Hook.h      |   23 +++++++++++++++++++++--
 src/pool/PoolSQL.cc |    8 ++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/Hook.h b/include/Hook.h
index 5dd29a8..83cf250 100644
--- a/include/Hook.h
+++ b/include/Hook.h
@@ -164,13 +164,13 @@ public:
 
 /**
  *  This class is general ObjectSQL Remove Hook that executes a command
- *  when the ObjectSQL is inserted in the database.
+ *  when the ObjectSQL is deleted from the database.
  */
 class RemoveHook : public AllocateRemoveHook
 {
 public:
     // -------------------------------------------------------------------------
-    // Init a hook of ALLOCATE type
+    // Init a hook of REMOVE type
     // -------------------------------------------------------------------------
     RemoveHook(const string& name,
                const string& cmd,
@@ -182,6 +182,25 @@ public:
 };
 
 /**
+ *  This class is general ObjectSQL Update Hook that executes a command
+ *  when the ObjectSQL is updated from the database.
+ */
+class UpdateHook : public AllocateRemoveHook
+{
+public:
+    // -------------------------------------------------------------------------
+    // Init a hook of UPDATE type
+    // -------------------------------------------------------------------------
+    UpdateHook(const string& name,
+               const string& cmd,
+               const string& args,
+               bool          remote):
+        AllocateRemoveHook(name, cmd, args, Hook::UPDATE, remote){};
+
+    virtual ~UpdateHook(){};
+};
+
+/**
  *  Objects that inherits from hookable will allow others to hook into it. The
  *  Hookable interface handles the list of hooks and provide a method to invoke
  *  the hooks.
diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc
index a971f83..6c82332 100644
--- a/src/pool/PoolSQL.cc
+++ b/src/pool/PoolSQL.cc
@@ -754,5 +754,13 @@ void PoolSQL::register_hooks(vector<const Attribute *> hook_mads,
 
             add_hook(hook);
         }
+        else if ( on == "UPDATE" )
+        {
+            UpdateHook * hook;
+
+            hook = new UpdateHook(name, cmd, arg, false);
+
+            add_hook(hook);
+        }
     }
 }
-- 
1.7.2.5

