/**
  * Load and merge registry keys by userid and a path.
  * The user keys will get merged with the default keys (userid = 0).
  */
 public function loadByPath($userid, $path)
 {
     $repository = $this->getEntityManager()->getRepository('RegistryBundle:Registry');
     /*
     select * from
     (select * from registry
     where userid = 0
     and concat(registrykey, "/", name) not in (select concat(registrykey, "/", name) from registry where userid = 2)
     union
     select * from registry
     where userid = 2) x
     where x.registrykey like 'App/Test/J%'
     */
     $stmt = $this->getEntityManager()->getConnection()->prepare('SELECT r.* FROM
         (
             SELECT * FROM registry r1
             WHERE r1.userid = 0
             AND CONCAT(r1.registrykey, "/", r1.name) NOT IN (
                 SELECT CONCAT(r2.registrykey, "/", r2.name) FROM registry r2 WHERE r2.userid = :userid
             )
             UNION
             SELECT * FROM registry r3
             WHERE r3.userid = :userid
         ) r
         WHERE r.registrykey LIKE :path');
     $params = array('userid' => $userid, 'path' => $path);
     $stmt->execute($params);
     $result = array();
     while ($row = $stmt->fetch()) {
         $r = new Registry();
         $r->LoadByArray($row);
         $result[] = $r;
     }
     return $result;
 }