Ejemplo n.º 1
0
  /**
   * Very specifically get other siblings of the parent that have other xpaths, not the same as this
   *
   * @param tree
   * @return
   */
  public List<XMLNode> quickOtherSiblings(XMLNode tree) {
    List<XMLNode> l = Collections.emptyList();
    try {
      l =
          DB.getStatelessSession()
              .createSQLQuery(
                  "select * from xml_node_"
                      + tree.getXmlObject().getDbID()
                      + " where parent_node_id = :parent"
                      + " and (xpath_summary_id != :path "
                      + " or xml_node_id = :id ) "
                      + "order by xml_node_id")
              .addEntity(XMLNode.class)
              .setLong("parent", tree.getParentNode().getNodeId())
              .setLong("path", tree.getXpathHolder().getDbID())
              .setEntity("id", tree)
              .list();
    } catch (Exception e) {
      log.error("Query failed with ", e);
    }
    for (XMLNode node : l) {
      node.setXpathHolder(DB.getXpathHolderDAO().findById(node.getXpathHolder().getDbID(), false));
    }

    return l;
  }
Ejemplo n.º 2
0
 public XMLNode getStatelessByIdObject(XmlObject obj, Long id) {
   XMLNode x =
       (XMLNode)
           DB.getStatelessSession()
               .createSQLQuery(
                   "select * from xml_node_" + obj.getDbID() + " where xml_node_id = :nodeId")
               .addEntity(XMLNode.class)
               .setLong("nodeId", id)
               .uniqueResult();
   if (x != null) x.setChildren(new ArrayList<XMLNode>());
   x.setXpathHolder(DB.getXpathHolderDAO().findById(x.getXpathHolder().getDbID(), false));
   return x;
 }
Ejemplo n.º 3
0
 public List<XMLNode> getStatelessByXpathHolder(XpathHolder xp, long from, long count) {
   List<XMLNode> l =
       DB.getStatelessSession()
           .createSQLQuery(
               "select * from xml_node_"
                   + xp.getXmlObject().getDbID()
                   + " where xpath_summary_id = :xpath and xml_object_id = :xo "
                   + "order by xml_node_id asc")
           .addEntity(XMLNode.class)
           .setEntity("xpath", xp)
           .setEntity("xo", xp.getXmlObject())
           .setMaxResults((int) count)
           .setFirstResult((int) from)
           .list();
   for (XMLNode node : l) {
     node.setXpathHolder(DB.getXpathHolderDAO().findById(node.getXpathHolder().getDbID(), false));
   }
   return l;
 }
Ejemplo n.º 4
0
 /**
  * Quickly build a dom tree. Use per item, not for trees with more than 2000 nodes (or about
  * that). The XMLNodes are not in the Hibernate session and don't lazy load their parent or
  * anything else. They should not need to, though. The attached XpathHolders are in the session
  * and behave normally.
  *
  * @param parent
  * @return
  */
 public XMLNode getDOMTree(XMLNode parent) {
   StatelessSession ss = DB.getStatelessSession();
   List<XMLNode> l;
   int maxNodes = 10000;
   if (parent.getSize() < maxNodes) maxNodes = (int) parent.getSize();
   Stack<XMLNode> stack = new Stack<XMLNode>();
   HashMap<Long, XpathHolder> xpathCache = new HashMap<Long, XpathHolder>();
   l =
       ss.createSQLQuery(
               "select * from xml_node_"
                   + parent.getXmlObject().getDbID()
                   + " where xml_node_id >= :parentId order by xml_node_id")
           .addEntity(XMLNode.class)
           .setLong("parentId", parent.getNodeId())
           .setMaxResults(maxNodes)
           .list();
   // now every node has the wrong parent and XpathHolder and no Children..
   for (XMLNode x : l) {
     // find the right place in stack
     x.setChildren(new ArrayList<XMLNode>());
     while (!stack.isEmpty()) {
       if (stack.peek().getNodeId() != x.getParentNode().getNodeId()) stack.pop();
       else break;
     }
     if (!stack.isEmpty()) {
       x.setParentNode(stack.peek());
       stack.peek().getChildren().add(x);
     }
     stack.push(x);
     // now the xpathholder
     XpathHolder path = xpathCache.get(x.getXpathHolder().getDbID());
     if (path == null) {
       path = DB.getXpathHolderDAO().findById(x.getXpathHolder().getDbID(), false);
       xpathCache.put(path.getDbID(), path);
     }
     x.setXpathHolder(path);
     x.setXmlObject(parent.getXmlObject());
   }
   if (l.size() > 0) return l.get(0);
   else return null;
 }
Ejemplo n.º 5
0
  /**
   * Cursor over all nodes. (You still have to get XpathHolders the normal way) Call the index
   * function on given object. Proceeds in node order.
   *
   * @param xo
   * @param ni
   */
  public void indexNodes(XmlObject xo, NodeIndexer ni) {
    StatelessSession ss = DB.getStatelessSession();
    Stack<XMLNode> stack = new Stack<XMLNode>();
    HashMap<Long, XpathHolder> xpathCache = new HashMap<Long, XpathHolder>();
    ScrollableResults sr = null;

    try {
      sr =
          ss.createSQLQuery("select * from xml_node_" + xo.getDbID() + " order by xml_node_id")
              .addEntity(XMLNode.class)
              .scroll(ScrollMode.FORWARD_ONLY);

      while (sr.next()) {

        XMLNode x = (XMLNode) sr.get()[0];
        while (!stack.isEmpty()) {
          if ((x.getParentNode() == null)
              || (stack.peek().getNodeId() != x.getParentNode().getNodeId())) stack.pop();
          else break;
        }
        stack.push(x);
        // now the xpathholder
        XpathHolder path = xpathCache.get(x.getXpathHolder().getDbID());
        if (path == null) {
          path = DB.getXpathHolderDAO().findById(x.getXpathHolder().getDbID(), false);
          xpathCache.put(path.getDbID(), path);
        }
        x.setXpathHolder(path);
        x.setXmlObject(xo);
        // node ready to index
        ni.index(x);
      }
      ni.index(null);
    } catch (Exception e) {
      log.error("Error while scrolling XMLNodes for indexing.", e);
    } finally {
      if (sr != null) sr.close();
    }
  }