Skip to content

Commit 735513c

Browse files
authored
Merge pull request #39 from evolvedbinary/6.x.x/hotfix/binary-field-types
[6.x.x] Correct the data problems with Fields in the Lucene Full Text Index
2 parents 652d4be + e86902c commit 735513c

File tree

83 files changed

+7093
-1372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+7093
-1372
lines changed

exist-core/pom.xml

Lines changed: 113 additions & 1 deletion
Large diffs are not rendered by default.

exist-core/src/main/java/org/exist/collections/Collection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.exist.security.SecurityManager;
5555
import org.exist.storage.*;
5656
import org.exist.storage.io.VariableByteInput;
57-
import org.exist.storage.io.VariableByteOutputStream;
57+
import org.exist.storage.io.VariableByteOutput;
5858
import org.exist.storage.lock.*;
5959
import org.exist.storage.lock.Lock.LockMode;
6060
import org.exist.storage.txn.Txn;
@@ -1207,7 +1207,7 @@ BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, BinaryDocumen
12071207
* @throws IOException in case of I/O errors
12081208
12091209
*/
1210-
@EnsureContainerLocked(mode=READ_LOCK) void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException;
1210+
@EnsureContainerLocked(mode=READ_LOCK) void serialize(final VariableByteOutput outputStream) throws IOException, LockException;
12111211

12121212
@Override void close();
12131213

exist-core/src/main/java/org/exist/collections/LockedCollection.java

Lines changed: 26 additions & 2 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
*
@@ -29,7 +53,7 @@
2953
import org.exist.security.PermissionDeniedException;
3054
import org.exist.security.Subject;
3155
import org.exist.storage.*;
32-
import org.exist.storage.io.VariableByteOutputStream;
56+
import org.exist.storage.io.VariableByteOutput;
3357
import org.exist.storage.lock.Lock;
3458
import org.exist.storage.lock.LockedDocumentMap;
3559
import org.exist.storage.lock.ManagedCollectionLock;
@@ -473,7 +497,7 @@ public BinaryDocument addBinaryResource(final Txn transaction, final DBBroker br
473497
}
474498

475499
@Override
476-
public void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException {
500+
public void serialize(final VariableByteOutput outputStream) throws IOException, LockException {
477501
collection.serialize(outputStream);
478502
}
479503

exist-core/src/main/java/org/exist/collections/MutableCollection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
import org.exist.security.Subject;
7373
import org.exist.storage.*;
7474
import org.exist.storage.io.VariableByteInput;
75-
import org.exist.storage.io.VariableByteOutputStream;
75+
import org.exist.storage.io.VariableByteOutput;
7676
import org.exist.storage.lock.*;
7777
import org.exist.storage.lock.Lock.LockMode;
7878
import org.exist.storage.lock.Lock.LockType;
@@ -195,7 +195,7 @@ private MutableCollection(final DBBroker broker, final int collectionId,
195195
/**
196196
* Deserializes a Collection object
197197
*
198-
* Counterpart method to {@link #serialize(VariableByteOutputStream)}
198+
* Counterpart method to {@link #serialize(VariableByteOutput)}
199199
*
200200
* @param broker The database broker
201201
* @param path The path of the Collection
@@ -896,7 +896,7 @@ public Iterator<DocumentImpl> iteratorNoLock(final DBBroker broker) throws Permi
896896
* @param outputStream The output stream to write the collection contents to
897897
*/
898898
@Override
899-
public void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException {
899+
public void serialize(final VariableByteOutput outputStream) throws IOException, LockException {
900900
outputStream.writeInt(collectionId);
901901

902902
final int size;
@@ -926,7 +926,7 @@ public void close() {
926926
/**
927927
* Read collection contents from the stream
928928
*
929-
* Counterpart method to {@link #serialize(VariableByteOutputStream)}
929+
* Counterpart method to {@link #serialize(VariableByteOutput)}
930930
*
931931
* @param broker The database broker
932932
* @param path The path of the Collection

exist-core/src/main/java/org/exist/dom/QName.java

Lines changed: 99 additions & 6 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
*
@@ -26,16 +50,19 @@
2650
import org.exist.util.XMLNames;
2751
import org.exist.xquery.Constants;
2852

53+
import javax.annotation.Nullable;
2954
import javax.xml.XMLConstants;
3055
import java.util.regex.Matcher;
3156
import java.util.regex.Pattern;
3257

3358
import static org.exist.dom.QName.Validity.*;
59+
import static org.exist.util.StringUtil.isNullOrEmpty;
3460

3561
/**
3662
* Represents a QName, consisting of a local name, a namespace URI and a prefix.
3763
*
3864
* @author <a href="mailto:[email protected]">Wolfgang</a>
65+
* @author <a href="mailto:[email protected]">Adam Retter</a>
3966
*/
4067
public class QName implements Comparable<QName> {
4168

@@ -136,7 +163,18 @@ public byte getNameType() {
136163
* @return the string representation of this qualified name.
137164
* */
138165
public String getStringValue() {
139-
return getStringRepresentation(false);
166+
return getStringRepresentation(false, false);
167+
}
168+
169+
/**
170+
* Get an extended string representation of this qualified name.
171+
*
172+
* Will be of the format `local-name`, `{namespace}local-name`, or `{namespace}prefix:local-name`.
173+
*
174+
* @return the string representation of this qualified name.
175+
*/
176+
public String getExtendedStringValue() {
177+
return getStringRepresentation(false, true);
140178
}
141179

142180
/**
@@ -148,23 +186,32 @@ public String getStringValue() {
148186
*/
149187
@Override
150188
public String toString() {
151-
return getStringRepresentation(true);
189+
return getStringRepresentation(true, false);
152190
}
153191

154192
/**
155193
* Get a string representation of this qualified name.
156194
*
157195
* @param showNsWithoutPrefix true if the namespace should be shown even when there is no prefix, false otherwise.
158-
* When shown, it will be output using Clark notation, e.g. `{http://namespace}local-name`.
196+
* When shown, it will be output using Clark notation, e.g. `{namespace}local-name`.
197+
*
198+
* @param extended true if the namespace and prefix should be shown, requires showNsWithoutPrefix == false.
159199
*
160200
* @return the string representation of this qualified name.
161201
*/
162-
private String getStringRepresentation(final boolean showNsWithoutPrefix) {
202+
private String getStringRepresentation(final boolean showNsWithoutPrefix, final boolean extended) {
163203
if (prefix != null && !prefix.isEmpty()) {
164-
return prefix + COLON + localPart;
165-
} else if (showNsWithoutPrefix && namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
204+
if (extended) {
205+
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + prefix + COLON + localPart;
206+
} else {
207+
return prefix + COLON + localPart;
208+
}
209+
}
210+
211+
if (showNsWithoutPrefix && namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
166212
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + localPart;
167213
}
214+
168215
return localPart;
169216
}
170217

@@ -343,6 +390,52 @@ public static QName parse(final String namespaceURI, final String qname) throws
343390
private final static Pattern ptnClarkNotation = Pattern.compile("\\{([^&{}]*)\\}([^&{}:]+)");
344391
private final static Pattern ptnEqNameNotation = Pattern.compile("Q" + ptnClarkNotation);
345392

393+
/**
394+
* Extract a QName from a namespace and qualified name string.
395+
*
396+
* @param extendedStringValue a string representation as produced by {@link #getExtendedStringValue()}, i.e.: `local-name`, `{namespace}local-name`, or `{namespace}prefix:local-name`.
397+
* @return The QName
398+
* @throws IllegalQNameException if the qname component is invalid
399+
*/
400+
public static QName parse(String extendedStringValue) throws IllegalQNameException {
401+
if (isNullOrEmpty(extendedStringValue)) {
402+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName is empty");
403+
}
404+
405+
final String namespaceUri;
406+
if (extendedStringValue.charAt(0) == LEFT_BRACE) {
407+
final int idxNsEnd = extendedStringValue.indexOf(RIGHT_BRACE);
408+
if (idxNsEnd == Constants.STRING_NOT_FOUND) {
409+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName, missing right brace: '" + extendedStringValue + "'");
410+
}
411+
namespaceUri = extendedStringValue.substring(1, idxNsEnd);
412+
extendedStringValue = extendedStringValue.substring(idxNsEnd + 1);
413+
} else if (extendedStringValue.indexOf(RIGHT_BRACE) != Constants.STRING_NOT_FOUND) {
414+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName, missing left brace: '" + extendedStringValue + "'");
415+
} else {
416+
namespaceUri = XMLConstants.NULL_NS_URI;
417+
}
418+
419+
@Nullable final String prefix;
420+
final int idxColon = extendedStringValue.indexOf(COLON);
421+
if (idxColon == Constants.STRING_NOT_FOUND) {
422+
prefix = null;
423+
} else {
424+
prefix = extendedStringValue.substring(0, idxColon);
425+
if (!XMLNames.isNCName(prefix)) {
426+
throw new IllegalQNameException(INVALID_PREFIX.val, "Illegal extended string QName, invalid prefix: '" + extendedStringValue + "'");
427+
}
428+
extendedStringValue = extendedStringValue.substring(idxColon + 1);
429+
}
430+
431+
final String localPart = extendedStringValue;
432+
if (!XMLNames.isNCName(localPart)) {
433+
throw new IllegalQNameException(INVALID_LOCAL_PART.val, "Illegal extended string QName, invalid prefix: '" + extendedStringValue + "'");
434+
}
435+
436+
return new QName(localPart, namespaceUri, prefix);
437+
}
438+
346439
/**
347440
* Parses the given string into a QName. The method uses context to look up
348441
* a namespace URI for an existing prefix.

exist-core/src/main/java/org/exist/dom/persistent/BinaryDocument.java

Lines changed: 26 additions & 2 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
*
@@ -27,7 +51,7 @@
2751
import org.exist.storage.BrokerPool;
2852
import org.exist.storage.blob.BlobId;
2953
import org.exist.storage.io.VariableByteInput;
30-
import org.exist.storage.io.VariableByteOutputStream;
54+
import org.exist.storage.io.VariableByteOutput;
3155
import org.exist.xmldb.XmldbURI;
3256
import org.exist.xquery.Expression;
3357
import org.w3c.dom.DocumentType;
@@ -167,7 +191,7 @@ public void setBlobId(final BlobId blobId) {
167191
}
168192

169193
@Override
170-
public void write(final VariableByteOutputStream ostream) throws IOException {
194+
public void write(final VariableByteOutput ostream) throws IOException {
171195
ostream.writeInt(getDocId());
172196
ostream.writeUTF(getFileURI().toString());
173197

exist-core/src/main/java/org/exist/dom/persistent/DocumentImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import org.exist.security.*;
6060
import org.exist.storage.*;
6161
import org.exist.storage.io.VariableByteInput;
62-
import org.exist.storage.io.VariableByteOutputStream;
62+
import org.exist.storage.io.VariableByteOutput;
6363
import org.exist.storage.lock.EnsureContainerLocked;
6464
import org.exist.storage.lock.EnsureLocked;
6565
import org.exist.storage.txn.Txn;
@@ -797,11 +797,11 @@ public void appendChild(final NodeHandle child) throws DOMException {
797797
/**
798798
* The method <code>write</code>
799799
*
800-
* @param ostream a <code>VariableByteOutputStream</code> value
800+
* @param ostream a <code>VariableByteOutput</code> value
801801
* @throws IOException if an error occurs
802802
*/
803803
@EnsureContainerLocked(mode=READ_LOCK)
804-
public void write(final VariableByteOutputStream ostream) throws IOException {
804+
public void write(final VariableByteOutput ostream) throws IOException {
805805
try {
806806
ostream.writeInt(docId);
807807
ostream.writeUTF(fileURI.toString());
@@ -823,7 +823,7 @@ public void write(final VariableByteOutputStream ostream) throws IOException {
823823
}
824824
}
825825

826-
void writeDocumentAttributes(final SymbolTable symbolTable, final VariableByteOutputStream ostream) throws IOException {
826+
void writeDocumentAttributes(final SymbolTable symbolTable, final VariableByteOutput ostream) throws IOException {
827827
ostream.writeLong(created);
828828
ostream.writeLong(lastModified);
829829
ostream.writeInt(symbolTable.getMimeTypeId(mimeType));

exist-core/src/main/java/org/exist/dom/persistent/DocumentMetadata.java

Lines changed: 26 additions & 2 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
*
@@ -23,7 +47,7 @@
2347

2448
import org.exist.ResourceMetadata;
2549
import org.exist.storage.io.VariableByteInput;
26-
import org.exist.storage.io.VariableByteOutputStream;
50+
import org.exist.storage.io.VariableByteOutput;
2751
import org.w3c.dom.DocumentType;
2852

2953
import java.io.IOException;
@@ -100,7 +124,7 @@ public void decPageCount() {
100124
}
101125

102126
@Deprecated
103-
public void write(final SymbolTable symbolTable, final VariableByteOutputStream ostream) throws IOException {
127+
public void write(final SymbolTable symbolTable, final VariableByteOutput ostream) throws IOException {
104128
doc.writeDocumentAttributes(symbolTable, ostream);
105129
}
106130

0 commit comments

Comments
 (0)