Skip to content

Commit eaf098f

Browse files
authored
Merge pull request #5296 from line-o/backport/5276
[6.x.x] Fix errors on update operations
2 parents 38ab96e + 6955588 commit eaf098f

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

exist-core/src/main/java/org/exist/storage/NativeBroker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,8 +3033,7 @@ public Object start() {
30333033
}
30343034
}.run();
30353035
// create a copy of the old doc to copy the nodes into it
3036-
final DocumentImpl tempDoc = new DocumentImpl(null, null, doc.getCollection(), doc.getDocId(), doc.getFileURI());
3037-
tempDoc.copyOf(this, doc, doc);
3036+
final DocumentImpl tempDoc = new DocumentImpl(null, pool, doc.getCollection(), doc.getDocId(), doc.getFileURI());
30383037
final StreamListener listener = getIndexController().getStreamListener(doc, ReindexMode.STORE);
30393038
// copy the nodes
30403039
final NodeList nodes = doc.getChildNodes();
@@ -3067,7 +3066,7 @@ public Object start() {
30673066
if (LOG.isDebugEnabled()) {
30683067
LOG.debug("Defragmentation took {} ms.", (System.currentTimeMillis() - start));
30693068
}
3070-
} catch(final PermissionDeniedException | IOException e) {
3069+
} catch(IOException e) {
30713070
LOG.error(e);
30723071
}
30733072
}

exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.IOException;
4343
import java.nio.file.Path;
4444
import java.util.Map;
45+
import java.util.Properties;
4546

4647
import static org.junit.Assert.assertEquals;
4748
import static org.junit.Assert.fail;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
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; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.xquery.update;
23+
24+
import com.evolvedbinary.j8fu.function.Consumer2E;
25+
import org.exist.EXistException;
26+
import org.exist.collections.Collection;
27+
import org.exist.security.PermissionDeniedException;
28+
import org.exist.source.StringSource;
29+
import org.exist.storage.BrokerPool;
30+
import org.exist.storage.DBBroker;
31+
import org.exist.storage.txn.Txn;
32+
import org.exist.test.ExistEmbeddedServer;
33+
import org.exist.test.TestConstants;
34+
import org.exist.util.MimeType;
35+
import org.exist.util.StringInputSource;
36+
import org.exist.xquery.XPathException;
37+
import org.exist.xquery.value.Sequence;
38+
import org.junit.Before;
39+
import org.junit.ClassRule;
40+
import org.junit.Test;
41+
42+
import java.io.IOException;
43+
import java.util.Optional;
44+
45+
import static org.exist.test.Util.executeQuery;
46+
import static org.exist.test.Util.withCompiledQuery;
47+
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
48+
import static org.junit.Assert.assertEquals;
49+
import static org.junit.Assert.assertTrue;
50+
51+
public class UpdateInsertTriggersDefragTest {
52+
53+
@ClassRule
54+
public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(propertiesBuilder().put(DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR, -1).build(), true, true);
55+
56+
@Before
57+
public void setUp() throws Exception {
58+
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
59+
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
60+
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
61+
62+
// store the test document in the test collection
63+
try (final Collection testCollection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
64+
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource("<list><item>initial</item></list>"), MimeType.XML_TYPE, testCollection);
65+
}
66+
67+
transaction.commit();
68+
}
69+
}
70+
71+
@Test
72+
public void triggerDefragAfterUpdate() throws Exception {
73+
final String updateQuery = "update insert <item>new node</item> into doc('" + TestConstants.TEST_COLLECTION_URI + "/" + TestConstants.TEST_XML_URI + "')//list";
74+
assertQuery(updateQuery, updateResults ->
75+
assertTrue("Update expression returns an empty sequence", updateResults.isEmpty())
76+
);
77+
78+
final String searchQuery = "doc('" + TestConstants.TEST_COLLECTION_URI + "/" + TestConstants.TEST_XML_URI + "')//item";
79+
assertQuery(searchQuery, searchResults ->
80+
assertEquals("Both items are returned", 2, searchResults.getItemCount())
81+
);
82+
}
83+
84+
private void assertQuery(final String query, final Consumer2E<Sequence, XPathException, PermissionDeniedException> assertions) throws EXistException, XPathException, PermissionDeniedException, IOException {
85+
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
86+
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
87+
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
88+
89+
withCompiledQuery(broker, new StringSource(query), compiledQuery -> {
90+
final Sequence results = executeQuery(broker, compiledQuery);
91+
assertions.accept(results);
92+
return null;
93+
});
94+
95+
transaction.commit();
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)