Skip to content

Commit bc1c015

Browse files
authored
Merge pull request #127 from evolvedbinary/7.x.x/hotfix/xupdate-cleanup
[7.x.x] Cleanup and reduce the memory use of the XUpdate Implementation
2 parents af7da3c + e04b80b commit bc1c015

File tree

10 files changed

+605
-345
lines changed

10 files changed

+605
-345
lines changed

exist-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,15 @@
13321332
<include>src/main/java/org/exist/xquery/value/Type.java</include>
13331333
<include>src/main/java/org/exist/xslt/EXistURIResolver.java</include>
13341334
<include>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</include>
1335+
<include>src/main/java/org/exist/xupdate/Append.java</include>
13351336
<include>src/main/java/org/exist/xupdate/Conditional.java</include>
1337+
<include>src/main/java/org/exist/xupdate/Insert.java</include>
13361338
<include>src/main/java/org/exist/xupdate/Modification.java</include>
1339+
<include>src/main/java/org/exist/xupdate/Remove.java</include>
13371340
<include>src/test/java/org/exist/xupdate/RemoveAppendTest.java</include>
1341+
<include>src/main/java/org/exist/xupdate/Rename.java</include>
1342+
<include>src/main/java/org/exist/xupdate/Replace.java</include>
1343+
<include>src/main/java/org/exist/xupdate/Update.java</include>
13381344
<include>src/main/java/org/exist/xupdate/XUpdateProcessor.java</include>
13391345
<include>src/test/java/org/exist/xupdate/XUpdateTest.java</include>
13401346
</includes>
@@ -2044,9 +2050,15 @@
20442050
<exclude>src/main/java/org/exist/xquery/value/YearMonthDurationValue.java</exclude>
20452051
<exclude>src/main/java/org/exist/xslt/EXistURIResolver.java</exclude>
20462052
<exclude>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</exclude>
2053+
<exclude>src/main/java/org/exist/xupdate/Append.java</exclude>
20472054
<exclude>src/main/java/org/exist/xupdate/Conditional.java</exclude>
2055+
<exclude>src/main/java/org/exist/xupdate/Insert.java</exclude>
20482056
<exclude>src/main/java/org/exist/xupdate/Modification.java</exclude>
2057+
<exclude>src/main/java/org/exist/xupdate/Remove.java</exclude>
20492058
<exclude>src/test/java/org/exist/xupdate/RemoveAppendTest.java</exclude>
2059+
<exclude>src/main/java/org/exist/xupdate/Rename.java</exclude>
2060+
<exclude>src/main/java/org/exist/xupdate/Replace.java</exclude>
2061+
<exclude>src/main/java/org/exist/xupdate/Update.java</exclude>
20502062
<exclude>src/main/java/org/exist/xupdate/XUpdateProcessor.java</exclude>
20512063
<exclude>src/test/java/org/exist/xupdate/XUpdateTest.java</exclude>
20522064

exist-core/src/main/java/org/exist/xupdate/Append.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -38,6 +62,8 @@
3862
import org.exist.xquery.XPathException;
3963
import org.w3c.dom.NodeList;
4064

65+
import javax.annotation.Nullable;
66+
4167
/**
4268
* Implements an XUpate append statement.
4369
*
@@ -60,24 +86,24 @@ public class Append extends Modification {
6086
* @param namespaces the namespaces.
6187
* @param variables the variables.
6288
*/
63-
public Append(DBBroker broker, DocumentSet docs, String selectStmt,
64-
String childAttr, Map<String, String> namespaces, Map<String, Object> variables) {
89+
public Append(final DBBroker broker, final DocumentSet docs, final String selectStmt, final String childAttr, @Nullable final Map<String, String> namespaces, @Nullable final Map<String, Object> variables) {
6590
super(broker, docs, selectStmt, namespaces, variables);
66-
if(childAttr == null || "last()".equals(childAttr))
67-
{child = -1;}
68-
else
69-
{child = Integer.parseInt(childAttr);}
91+
if (childAttr == null || "last()".equals(childAttr)) {
92+
child = -1;
93+
} else {
94+
child = Integer.parseInt(childAttr);
95+
}
7096
}
7197

7298
@Override
73-
public long process(Txn transaction) throws PermissionDeniedException, LockException,
74-
EXistException, XPathException, TriggerException {
99+
public long process(final Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException, TriggerException {
75100
final NodeList children = content;
76-
if(children.getLength() == 0)
77-
{return 0;}
101+
if (children.getLength() == 0) {
102+
return 0;
103+
}
78104

79105
try {
80-
final StoredNode ql[] = selectAndLock(transaction);
106+
final StoredNode[] ql = selectAndLock(transaction);
81107
final NotificationService notifier = broker.getBrokerPool().getNotificationService();
82108
for (final StoredNode node : ql) {
83109
final DocumentImpl doc = node.getOwnerDocument();
@@ -86,11 +112,11 @@ public long process(Txn transaction) throws PermissionDeniedException, LockExcep
86112
}
87113
node.appendChildren(transaction, children, child);
88114
doc.setLastModified(System.currentTimeMillis());
89-
modifiedDocuments.add(doc);
115+
addModifiedDocument(doc);
90116
broker.storeXMLResource(transaction, doc);
91117
notifier.notifyUpdate(doc, UpdateListener.UPDATE);
92118
}
93-
checkFragmentation(transaction, modifiedDocuments);
119+
checkFragmentation(transaction);
94120
return ql.length;
95121
} finally {
96122
// release all acquired locks

exist-core/src/main/java/org/exist/xupdate/Conditional.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public class Conditional extends Modification {
8282
* @param namespaces the namespaces.
8383
* @param variables the variables.
8484
*/
85-
public Conditional(DBBroker broker, DocumentSet docs, String selectStmt,
86-
Map<String, String> namespaces, Map<String, Object> variables) {
85+
public Conditional(final DBBroker broker, final DocumentSet docs, final String selectStmt, @Nullable final Map<String, String> namespaces, @Nullable final Map<String, Object> variables) {
8786
super(broker, docs, selectStmt, namespaces, variables);
8887
}
8988

@@ -92,9 +91,11 @@ public void addModification(Modification mod) {
9291
}
9392

9493
@Override
95-
public long process(Txn transaction) throws PermissionDeniedException, LockException,
96-
EXistException, XPathException, TriggerException {
97-
LOG.debug("Processing xupdate:if ...");
94+
public long process(final Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException, TriggerException {
95+
if (LOG.isDebugEnabled()) {
96+
LOG.debug("Processing xupdate:if ...");
97+
}
98+
9899
final XQuery xquery = broker.getBrokerPool().getXQueryService();
99100
final XQueryPool pool = broker.getBrokerPool().getXQueryPool();
100101
final Source source = new StringSource(selectStmt);

exist-core/src/main/java/org/exist/xupdate/Insert.java

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -39,6 +63,8 @@
3963
import org.exist.xquery.XPathException;
4064
import org.w3c.dom.NodeList;
4165

66+
import javax.annotation.Nullable;
67+
4268
/**
4369
* Implements an XUpdate insert-after or insert-before modification.
4470
*
@@ -61,8 +87,7 @@ public class Insert extends Modification {
6187
* @param namespaces the namespaces.
6288
* @param variables the variables.
6389
*/
64-
public Insert(DBBroker broker, DocumentSet docs, String selectStmt,
65-
Map<String, String> namespaces, Map<String, Object> variables) {
90+
public Insert(final DBBroker broker, final DocumentSet docs, final String selectStmt, @Nullable final Map<String, String> namespaces, @Nullable final Map<String, Object> variables) {
6691
super(broker, docs, selectStmt, namespaces, variables);
6792
}
6893

@@ -76,44 +101,50 @@ public Insert(DBBroker broker, DocumentSet docs, String selectStmt,
76101
* @param namespaces the namespaces.
77102
* @param variables the variables.
78103
*/
79-
public Insert(DBBroker broker, DocumentSet docs, String selectStmt,
80-
int mode, Map<String, String> namespaces, Map<String, Object> variables) {
104+
public Insert(final DBBroker broker, final DocumentSet docs, final String selectStmt, final int mode, @Nullable final Map<String, String> namespaces, @Nullable final Map<String, Object> variables) {
81105
this(broker, docs, selectStmt, namespaces, variables);
82106
this.mode = mode;
83107
}
84108

85109
@Override
86-
public long process(Txn transaction) throws PermissionDeniedException, LockException,
87-
EXistException, XPathException, TriggerException {
110+
public long process(final Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException, TriggerException {
88111
final NodeList children = content;
89-
if (children.getLength() == 0) {return 0;}
112+
if (children.getLength() == 0) {
113+
return 0;
114+
}
115+
90116
try {
91117
final StoredNode[] ql = selectAndLock(transaction);
92118
final NotificationService notifier = broker.getBrokerPool().getNotificationService();
93119
final int len = children.getLength();
94-
if (LOG.isDebugEnabled())
95-
{
96-
LOG.debug("found {} nodes to insert", len);}
120+
if (LOG.isDebugEnabled()) {
121+
LOG.debug("found {} nodes to insert", len);
122+
}
123+
97124
for (final StoredNode node : ql) {
98125
final DocumentImpl doc = node.getOwnerDocument();
99126
if (!doc.getPermissions().validate(broker.getCurrentSubject(), Permission.WRITE)) {
100127
throw new PermissionDeniedException("permission to update document denied");
101128
}
129+
102130
final NodeImpl parent = (NodeImpl) getParent(node);
103131
switch (mode) {
132+
104133
case INSERT_BEFORE:
105134
parent.insertBefore(transaction, children, node);
106135
break;
136+
107137
case INSERT_AFTER:
108138
parent.insertAfter(transaction, children, node);
109139
break;
110140
}
141+
111142
doc.setLastModified(System.currentTimeMillis());
112-
modifiedDocuments.add(doc);
143+
addModifiedDocument(doc);
113144
broker.storeXMLResource(transaction, doc);
114145
notifier.notifyUpdate(doc, UpdateListener.UPDATE);
115146
}
116-
checkFragmentation(transaction, modifiedDocuments);
147+
checkFragmentation(transaction);
117148
return ql.length;
118149
} finally {
119150
unlockDocuments(transaction);

0 commit comments

Comments
 (0)