/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao;

import foam.box.RPCMessage;

/**
 * Extend the generated DAOSkeleton and map all non Context-Oriented methods
 * to their Context-Oriented equivalents. Ex.: from put() to put_().
 * This is so that the user's session is propogated to DAO calls.
 **/
public class SessionDAOSkeleton
  extends DAOSkeleton
{

  public void send(foam.box.Message message) {
    if ( ! ( message.getObject() instanceof foam.box.RPCMessage) ) {
      // TODO return an error?
      return;
    }

    RPCMessage rpc = (RPCMessage) message.getObject();
    String n = rpc.getName();

         if ( "put".equals(n)       ) { rpc.setName("put_"); }
    else if ( "remove".equals(n)    ) { rpc.setName("remove_"); }
    else if ( "find".equals(n)      ) { rpc.setName("find_"); }
    else if ( "select".equals(n)    ) { rpc.setName("select_"); }
    else if ( "removeAll".equals(n) ) { rpc.setName("removeAll_"); }
    else if ( "listen".equals(n)    ) { rpc.setName("listen_"); }
    else if ( "pipe".equals(n)      ) { rpc.setName("pipe_"); }
    else if ( "cmd".equals(n)       ) { rpc.setName("cmd_"); }

    super.send(message);
  }

}

@@ -163,16 +163,42 @@
 Message;
+%0Aimport foam.core.FObject;
 %0A%0A/**%0A *
@@ -1241,24 +1241,409 @@
 %22cmd_%22); %7D%0A%0A
+    if ( %22put_%22.equals(n) ) %7B%0A      synchronized ( this ) %7B%0A        FObject obj = (foam.core.FObject)(rpc.getArgs() != null && rpc.getArgs().length %3E 1 ? rpc.getArgs()%5B1%5D : null);%0A        if ( obj != null ) %7B%0A          FObject oldObj = getDelegate().find(obj);%0A          if ( oldObj != null ) %7B%0A            rpc.getArgs()%5B1%5D = oldObj.copyFrom(obj);%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A%0A
     super.se

Fix DAOSkeleton so that old property values aren't lost if not supplied over network.