Examples of XUpdateProcessor


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 RemoteException(
                        "collection " + collectionName + " not found");
            }
            final DocumentSet docs =
                    collection.allDocs(broker, new DefaultDocumentSet(), true);
            final XUpdateProcessor processor =
                    new XUpdateProcessor(broker, docs, AccessContext.SOAP);
            final Modification modifications[] =
                    processor.parse(new InputSource(new StringReader(xupdate)));
            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

                throw new RemoteException(
                        "document " + documentName + " not found");
            }
            final MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(doc);
            final XUpdateProcessor processor =
                    new XUpdateProcessor(broker, docs, AccessContext.SOAP);
            final Modification modifications[] =
                    processor.parse(new InputSource(new StringReader(xupdate)));
            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

                transact.abort(transaction);
                throw new EXistException("collection " + collUri + " not found");
            }
            //TODO : register a lock (which one ?) in the transaction ?
            final DocumentSet docs = collection.allDocs(broker, new DefaultDocumentSet(), true);
            final XUpdateProcessor processor = new XUpdateProcessor(broker, docs, AccessContext.XMLRPC);
            final Modification modifications[] = processor.parse(new InputSource(new StringReader(xupdate)));
            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

                throw new EXistException("document " + docUri + " not found");
            }
            //TODO : register a lock (which one ?) within the transaction ?
            final MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(doc);
            final XUpdateProcessor processor = new XUpdateProcessor(broker, docs, AccessContext.XMLRPC);
            final Modification modifications[] = processor.parse(new InputSource(
                    new StringReader(xupdate)));
            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

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ngram:contains(., 'cha')]", 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:remove select=\"//item[@id='2']/price\"/>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, "892", 0);
            checkIndex(broker, docs, "tab", 1);
            checkIndex(broker, docs, "le8", 0);

            checkIndex(broker, docs, "cab", 1);

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

            checkIndex(broker, docs, "cab", 0);

            checkIndex(broker, docs, "att", 1);

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

            checkIndex(broker, docs, "att", 0);

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

            checkIndex(broker, docs, "cha", 0);
           
            transact.commit(transaction);
        } catch (Exception e) {
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, '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:remove select=\"//item[@id='2']/condition\"/>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 1);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 4);
            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "good", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "good", 0);
            Occurrences o[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "table", 1);
            assertEquals("table", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "cabinet", 1);
            assertEquals("cabinet", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "table", 1);
            assertEquals("table", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "cabinet", 1);
            assertEquals("cabinet", o[0].getTerm());

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

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

            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 1);
            assertEquals("table", o[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "chair", 0);
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            // Append to root node
            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            String xupdate =
                XUPDATE_START +
                "   <xu:append select=\"/test\">" +
                "       <item id='4'><description>Armchair</description> <condition>bad</condition></item>" +
                "   </xu:append>" +
                XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            Occurrences o[] = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 2);
            System.out.println("prices: " + o.length);
            for (int i = 0; i < o.length; i++) {
                System.out.println("occurance: " + o[i].getTerm() + ": " + o[i].getOccurrences());
            }
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 4);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 6);

            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "bad", 1);
            assertEquals("bad", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "armchair", 1);
            assertEquals("armchair", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "bad", 1);
            assertEquals("bad", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "armchair", 1);
            assertEquals("armchair", o[0].getTerm());

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

            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 5);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 8);

            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "poor", 1);
            assertEquals("poor", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wheelchair", 1);
            assertEquals("wheelchair", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "poor", 1);
            assertEquals("poor", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "wheelchair", 1);
            assertEquals("wheelchair", o[0].getTerm());

            // Insert after element
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "       <xu:insert-after select=\"//item[@id = '1']\">" +
                    "           <item id='1.1'><description>refrigerator</description> <condition>perfect</condition></item>" +
                    "       </xu:insert-after>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 4);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 6);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 10);

            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "perfect", 1);
            assertEquals("perfect", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "refrigerator", 1);
            assertEquals("refrigerator", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "perfect", 1);
            assertEquals("perfect", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "refrigerator", 1);
            assertEquals("refrigerator", o[0].getTerm());

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

            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 5);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 11);
            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "average", 1);
            assertEquals("average", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "average", 1);
            assertEquals("average", o[0].getTerm());

            // Insert before nested element
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "       <xu:insert-before select=\"//item[@id = '1']/description\">" +
                    "           <condition>awesome</condition>" +
                    "       </xu:insert-before>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 6);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 12);
            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "awesome", 1);
            assertEquals("awesome", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "awesome", 1);
            assertEquals("awesome", o[0].getTerm());

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

            QName qnattr[] = { new QName("attr", "", "") };
            qnattr[0].setNameType(ElementValue.ATTRIBUTE);
            o = checkIndex(docs, broker, qnattr, null, 1);
            assertEquals("abc", o[0].getTerm());
View Full Code Here

Examples of org.exist.xupdate.XUpdateProcessor

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ngram:contains(., 'cha')]", 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:append select=\"/test\">" +
                    "       <item id='4'><description>Armchair</description><price>340</price></item>" +
                    "   </xu:append>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, "arm", 1);

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

            checkIndex(broker, docs, "hee", 1);

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

            checkIndex(broker, docs, "ref", 1);

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

            checkIndex(broker, docs, "999", 1);
            checkIndex(broker, docs, "cha", 1);
            checkIndex(broker, docs, "ir9", 1);

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

            checkIndex(broker, docs, "999", 1);
            checkIndex(broker, docs, "888", 1);
            checkIndex(broker, docs, "88c", 1);

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

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

Examples of org.exist.xupdate.XUpdateProcessor

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ngram:contains(., 'cha')]", 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, "war", 1);
            checkIndex(broker, docs, "cha", 0);

            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, "whe", 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, "abc", 1);

            transact.commit(transaction);
        } catch (Exception e) {
            e.printStackTrace();
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.