예제 #1
0
 /*
  * Update of user tree for ordered menu nodes (favorites, create new list)
  * favorites @param menuIDs List<Integer> ordered list of menuIDs to put in
  * the tree @param menuTree MTree the tree to be reordered @return true if
  * updated
  */
 private boolean updateUserTree(List<Integer> menuIDs, MTree menuTree) {
   CTreeNode root = menuTree.getRoot();
   if (root != null) {
     Enumeration<?> nodes = root.preorderEnumeration();
     while (nodes.hasMoreElements()) {
       CTreeNode nd = (CTreeNode) nodes.nextElement();
       if (!menuIDs.contains(nd.getNode_ID())) {
         MTreeNodeMM node = null;
         if ((node = MTreeNodeMM.get(menuTree, nd.getNode_ID())) != null) {
           if (!node.delete(true)) return false;
         }
       }
     }
   }
   int seq = 0;
   for (int id : menuIDs) {
     MTreeNodeMM node = null;
     if ((node = MTreeNodeMM.get(menuTree, id)) == null) {
       node = new MTreeNodeMM(menuTree, id);
     }
     node.setSeqNo(++seq);
     if (!node.save()) return false;
   }
   return true;
 }
예제 #2
0
  /** this is really for embedded objects */
  int putObject(String name, BSONObject o) {

    if (o == null) throw new NullPointerException("can't save a null object");

    if (DEBUG)
      System.out.println(
          "putObject : " + name + " [" + o.getClass() + "]" + " # keys " + o.keySet().size());

    final int start = _buf.getPosition();

    byte myType = OBJECT;
    if (o instanceof List) myType = ARRAY;

    if (handleSpecialObjects(name, o)) return _buf.getPosition() - start;

    if (name != null) {
      _put(myType, name);
    }

    final int sizePos = _buf.getPosition();
    _buf.writeInt(0); // leaving space for this.  set it at the end

    List transientFields = null;
    boolean rewriteID = myType == OBJECT && name == null;

    if (myType == OBJECT) {
      if (rewriteID && o.containsField("_id")) _putObjectField("_id", o.get("_id"));

      {
        Object temp = o.get("_transientFields");
        if (temp instanceof List) transientFields = (List) temp;
      }
    }

    // TODO: reduce repeated code below.
    if (o instanceof Map) {
      for (Entry<String, Object> e : ((Map<String, Object>) o).entrySet()) {

        if (rewriteID && e.getKey().equals("_id")) continue;

        if (transientFields != null && transientFields.contains(e.getKey())) continue;

        _putObjectField(e.getKey(), e.getValue());
      }
    } else {
      for (String s : o.keySet()) {

        if (rewriteID && s.equals("_id")) continue;

        if (transientFields != null && transientFields.contains(s)) continue;

        Object val = o.get(s);

        _putObjectField(s, val);
      }
    }
    _buf.write(EOO);

    _buf.writeInt(sizePos, _buf.getPosition() - sizePos);
    return _buf.getPosition() - start;
  }