/**
  * Store the given I2CE_MagicDataNode into APC
  * @param I2CE_MagicDataNode $node
  * @returns boolean.  True on sucess
  */
 public function store($node)
 {
     $save_data = array('type' => $node->getType());
     if ($node->is_scalar()) {
         $save_data['value'] = $node->getSaveValue();
     } else {
         $save_data['value'] = null;
     }
     $children = $node->getKeys(null, true);
     if (count($children) > 0) {
         $save_data['children'] = $children;
     } else {
         $save_data['children'] = null;
     }
     if (!$this->memcached->set($this->getKey($node), $save_data, self::TIMEOUT)) {
         I2CE_MagicDataNode::raiseError("Error saving to Memcached " . $node->getPath() . " Type: " . $node->getType() . " Children: " . print_r($save_data['children'], true) . " Message: " . $this->memcached->getResultMessage() . " Stats: " . print_r($this->memcached->getStats(), true) . " Value: " . $save_data['value']);
         return false;
     } else {
         return true;
     }
 }
 /**
  * Store the given I2CE_MagicDataNode into mongodb
  * @param I2CE_MagicDataNode $node
  */
 public function store($node)
 {
     //first we need to see if it exists:
     $path = $node->getPath(false);
     $result = $this->mcoll->findOne(array(self::PATH => $path), array(self::PATH));
     if (!is_array($result) || count($result) == 0) {
         //does not exist
         $data = array(self::PATH => $path, self::TYPE => $node->getType(), self::VALUE => $node->getSaveValue(), self::CHILDREN => $node->getKeys(NULL, TRUE));
         if (!is_array($res = $this->mcoll->insert($data, array("safe" => true))) || array_key_exists('err', $res) && $res['err']) {
             I2CE::raiseError("Could not inset new node:" . print_r($res, true));
             return false;
         }
     } else {
         //it exists and we need to update
         $data = array(self::TYPE => $node->getType(), self::VALUE => $node->getSaveValue(), self::CHILDREN => $node->getKeys(NULL, TRUE));
         $newdata = array('$set' => $data);
         if (!is_array($res = $this->mcoll->update(array(self::PATH => $path), $newdata, array('safe' => true))) || array_key_exists('err', $res) && $res['err']) {
             I2CE::raiseError("Could not update existing node:" . print_r($res, true));
             return false;
         }
     }
     return true;
 }
 /**
  * Store the given I2CE_MagicDataNode into the database.
  * @param I2CE_MagicDataNode $node
  */
 public function store($node)
 {
     if ($node instanceof I2CE_MagicData) {
         $parent = '';
         $name = '';
         $path = '/';
     } else {
         $name = $node->getName();
         if (is_string($name) && strlen($name) == 0) {
             I2CE::raiseError("Non-existent name on a non-root magic data node");
             return false;
         }
         $parentNode = $node->getParent();
         if ($parentNode instanceof I2CE_MagicData) {
             $parent = '/';
             $path = '/' . $name;
         } else {
             $parent = $parentNode->getPath(false);
             $path = $parent . '/' . $name;
         }
     }
     $value = $node->getSaveValue();
     //$path_hash = md5($path);
     $path_hash = $this->getHash($node);
     if ($this->db_statements['store']->execute(array($path_hash, $parent, $name, $node->getType(), $value))) {
         return true;
     } else {
         I2CE_MagicDataNode::raiseError("Error saving to DB " . $node->getPath() . " Type: " . $node->getType() . " Value: " . $value);
         return false;
     }
 }