Re: Suggestion: onPersist function call

Kris Leite <[email protected]>
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hi Hannes,

Attached is a patch for the 'onPersist' function call.  In version 1.6 I 
found that
the 'onInit' was moved from the Node class to NodeManager.  So I put the
'invokeOnPersist' in the NodeManager class to be consistent.  I also 
removed
the check for 'dbmap' in the 'onInit' section since that would only 
allow the routine
to be activated for only database configuration.  The documentation for 
'onInit'
indicated it was to be activated for both embedded and database persistence
storage.

Thanks,
Kris


Hannes Wallnoefer wrote:
> Hi Kris,
>
> 2007/4/3, Kris Leite <[email protected]>:
>   
>> I had a need to do some changes on a HopObject before it was
>> written into storage.  So I made a customized version Helma 1.5.3
>> to call 'onPersist' function when a HopObject was being written
>> into the embedded or relational database.
>>
>> It would be nice if this was added as a new feature for Helma 1.6.
>>
>> The way I implemented it was very similar to the 'onInit()' function
>> by making a copy of the "invokeOnInit" function in Node.java
>> and changing the names to 'OnPersist' then adding a call to
>> 'invokeOnPersist' in the NodeManager methods 'insertNode' and
>> 'updateNode'.
>>
>> I will be happy to provide the patches if you like.
>>     
>
> Yes, please send a patch.
>
> hannes
>
>   
>> Thanks,
>> Kris
>>
>>
>> _______________________________________________
>> Helma-user mailing list
>> [email protected]
>> http://helma.org/mailman/listinfo/helma-user
>>
>>     
> _______________________________________________
> Helma-user mailing list
> [email protected]
> http://helma.org/mailman/listinfo/helma-user
>
>

_______________________________________________
Helma-user mailing list
[email protected]
http://helma.org/mailman/listinfo/helma-user
onPersist.patch (text/plain, 2.7 KB)
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: D:\jRTsrc\helma-1.6\helma\src\helma\objectmodel\db
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: NodeManager.java
*** D:\jRTsrc\helma-1.6\helma\src\helma\objectmodel\db\NodeManager.java Base (1.153)
--- D:\jRTsrc\helma-1.6\helma\src\helma\objectmodel\db\NodeManager.java Locally Modified (Based On 1.153)
***************
*** 349,355 ****
          }
          // New node is going ot be used, invoke onInit() on it
          // Invoke onInit() if it is defined by this Node's prototype
-         if (node.dbmap != null) {
              try {
                  // We need to reach deap into helma.framework.core to invoke onInit(),
                  // but the functionality is really worth it.
--- 349,354 ----
***************
*** 360,366 ****
              } catch (Exception x) {
                  app.logError("Error invoking onInit()", x);
              }
-         }
          return node;
      }
  
--- 359,364 ----
***************
*** 421,426 ****
--- 419,425 ----
       */
      public void insertNode(IDatabase db, ITransaction txn, Node node)
                      throws IOException, SQLException, ClassNotFoundException {
+         invokeOnPersist(node);
          DbMapping dbm = node.getDbMapping();
  
          if ((dbm == null) || !dbm.isRelational()) {
***************
*** 531,536 ****
--- 530,551 ----
      }
  
      /**
+      *  calls onPersist function for the HopObject
+      */
+     private void invokeOnPersist(Node node) {
+         try {
+             // We need to reach deap into helma.framework.core to invoke onPersist(),
+             // but the functionality is really worth it.
+             RequestEvaluator reval = app.getCurrentRequestEvaluator();
+             if (reval != null) {
+                 reval.invokeDirectFunction(node, "onPersist", RequestEvaluator.EMPTY_ARGS);
+             }
+         } catch (Exception x) {
+             app.logError("Error invoking onPersist()", x);
+         }
+     }
+     
+     /**
       *  Updates a modified node in the embedded db or an external relational database, depending
       * on its database mapping.
       *
***************
*** 539,544 ****
--- 554,561 ----
       */
      public boolean updateNode(IDatabase db, ITransaction txn, Node node)
                      throws IOException, SQLException, ClassNotFoundException {
+         
+         invokeOnPersist(node);
          DbMapping dbm = node.getDbMapping();
          boolean markMappingAsUpdated = false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.