• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/exist-core/src/main/java/org/exist/xquery/functions/xmldb/XMLDBXUpdate.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.xquery.functions.xmldb;
50

51
import org.apache.logging.log4j.LogManager;
52
import org.apache.logging.log4j.Logger;
53

54
import org.exist.dom.QName;
55
import org.exist.util.serializer.DOMSerializer;
56
import org.exist.xquery.Cardinality;
57
import org.exist.xquery.FunctionSignature;
58
import org.exist.xquery.XPathException;
59
import org.exist.xquery.XQueryContext;
60
import org.exist.xquery.value.FunctionReturnSequenceType;
61
import org.exist.xquery.value.FunctionParameterSequenceType;
62
import org.exist.xquery.value.IntegerValue;
63
import org.exist.xquery.value.NodeValue;
64
import org.exist.xquery.value.Sequence;
65
import org.exist.xquery.value.SequenceType;
66
import org.exist.xquery.value.Type;
67
import org.xmldb.api.base.Collection;
68
import org.xmldb.api.base.XMLDBException;
69
import org.xmldb.api.modules.XUpdateQueryService;
70

71
import javax.xml.transform.OutputKeys;
72
import javax.xml.transform.TransformerException;
73
import java.io.StringWriter;
74
import java.util.Properties;
75

76
/**
77
 * 
78
 * @author wolf
79
 *
80
 */
81
public class XMLDBXUpdate extends XMLDBAbstractCollectionManipulator
82
{
83
        protected static final Logger logger = LogManager.getLogger(XMLDBXUpdate.class);
1✔
84

85
        public final static FunctionSignature signature = new FunctionSignature(
1✔
86
                        new QName("update", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
1✔
87
                        "Processes an XUpdate request, $modifications, against a collection $collection-uri. "
1✔
88
            + XMLDBModule.COLLECTION_URI 
89
            + "The modifications are passed in a "
90
            + "document conforming to the XUpdate specification. "
91
            + "http://rx4rdf.liminalzone.org/xupdate-wd.html#N1a32e0"
92
            + "The function returns the number of modifications caused by the XUpdate.",
93
                        new SequenceType[]{
1✔
94
                                        new FunctionParameterSequenceType("collection-uri", Type.STRING, Cardinality.EXACTLY_ONE, "The collection URI"),
1✔
95
                                        new FunctionParameterSequenceType("modifications", Type.NODE, Cardinality.EXACTLY_ONE, "The XUpdate modifications to be processed")},
1✔
96
                        new FunctionReturnSequenceType(Type.INTEGER, Cardinality.EXACTLY_ONE, "the number of modifications, as xs:integer, caused by the XUpdate"));
1✔
97

98
        public XMLDBXUpdate(XQueryContext context) {
99
                super(context, signature);
1✔
100
        }
1✔
101

102
        /* (non-Javadoc)
103
         * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
104
         */
105
        public Sequence evalWithCollection(Collection c, Sequence[] args, Sequence contextSequence)
106
        throws XPathException {
107
                final NodeValue data = (NodeValue) args[1].itemAt(0);
1✔
108
                final StringWriter writer = new StringWriter();
1✔
109
                final Properties properties = new Properties();
1✔
110
                properties.setProperty(OutputKeys.INDENT, "yes");
1✔
111
        final DOMSerializer serializer = new DOMSerializer(writer, properties);
1✔
112
                try {
113
                        serializer.serialize(data.getNode());
1✔
114
                } catch(final TransformerException e) {
1✔
115
                        logger.debug("Exception while serializing XUpdate document", e);
×
116
                        throw new XPathException(this, "Exception while serializing XUpdate document: " + e.getMessage(), e);
×
117
                }
118
                final String xupdate = writer.toString();
1✔
119

120
                long modifications = 0;
1✔
121
                try {
122
                        final XUpdateQueryService service = c.getService(XUpdateQueryService.class);
1✔
123
                        logger.debug("Processing XUpdate request: {}", xupdate);
1✔
124
                        modifications = service.update(xupdate);
1✔
125
                } catch(final XMLDBException e) {
1✔
126
                        throw new XPathException(this, "Exception while processing xupdate: " + e.getMessage(), e);
×
127
                }
128
                
129
                context.getRootExpression().resetState(false);
1✔
130
                return new IntegerValue(this, modifications);
1✔
131
        }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc