Examples of XUpdateProcessor


Examples of org.exist.xupdate.XUpdateProcessor

            TransactionManager mgr = pool.getTransactionManager();
           
            IndexInfo info = init(broker, mgr);
            MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(info.getDocument());
            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
           
            Txn transaction = mgr.beginTransaction();
           
            String xupdate;
            Modification modifications[];
           
            // append some new element to records
            for (int i = 1; i <= 50; i++) {
                xupdate =
                    "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" +
                    "   <xu:append select=\"/products\">" +
                    "       <product>" +
                    "           <xu:attribute name=\"id\"><xu:value-of select=\"count(/products/product) + 1\"/></xu:attribute>" +
                    "           <description>Product " + i + "</description>" +
                    "           <price>" + (i * 2.5) + "</price>" +
                    "           <stock>" + (i * 10) + "</stock>" +
                    "       </product>" +
                    "   </xu:append>" +
                    "</xu:modifications>";
                proc.setBroker(broker);
                proc.setDocumentSet(docs);
                modifications = proc.parse(new InputSource(new StringReader(xupdate)));
                modifications[0].process(transaction);
                proc.reset();
            }
           
            mgr.commit(transaction);
           
            // the following transaction will not be committed and thus undone during recovery
            transaction = mgr.beginTransaction();
           
            // append new element
            for (int i = 1; i <= 50; i++) {
                xupdate =
                    "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" +
                    "   <xu:append select=\"/products/product[" + i + "]\">" +
                    "       <date><xu:value-of select=\"current-dateTime()\"/></date>" +
                    "   </xu:append>" +
                    "</xu:modifications>";
                proc.setBroker(broker);
                proc.setDocumentSet(docs);
                modifications = proc.parse(new InputSource(new StringReader(xupdate)));
                modifications[0].process(transaction);
                proc.reset();
            }
            pool.getTransactionManager().getJournal().flushToLog(true);
        } catch (Exception e) {           
            fail(e.getMessage());           
        } finally {
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[. = 'Chair']", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            String xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description\">Wardrobe</xu:update>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Chair"), 0);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wardrobe"), 1);

            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description/text()\">Wheelchair</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wardrobe"), 0);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wheelchair"), 1);

            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/@attr\">abc</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();
            checkIndex(broker, docs, null, new StringValue("abc"), 1);

            transact.commit(transaction);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

                        } else {
                            broker.getAllXMLResources(docs);
                        }
                    }

                    final XUpdateProcessor processor = new XUpdateProcessor(broker, docs, AccessContext.REST);
                    final Modification modifications[] = processor.parse(new InputSource(new StringReader(content)));
                    long mods = 0;
                    for (int i = 0; i < modifications.length; i++) {
                        mods += modifications[i].process(transaction);
                        broker.flush();
                    }
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

    try {
      // IMPORTANT: temporarily disable triggers on the collection.
      // We would end up in infinite recursion if we don't do that
      getCollection().setTriggersEnabled(false);
      // create the XUpdate processor
      XUpdateProcessor processor = new XUpdateProcessor(broker, docs, AccessContext.TRIGGER);
      // process the XUpdate
      Modification modifications[] = processor.parse(new InputSource(new StringReader(xupdate)));
      for(int i = 0; i < modifications.length; i++)
        modifications[i].process(null);
      broker.flush();
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

          throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Resource not found: " + resource);
                }
        docs.add(doc);
      }
      if(processor == null)
        {processor = new XUpdateProcessor(broker, docs, parent.getAccessContext());}
      else {
        processor.setBroker(broker);
        processor.setDocumentSet(docs);
      }
      final Modification modifications[] =
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.