Skip to content

Commit af1b6f8

Browse files
committed
Merge branch 'main' into develop
2 parents 2119307 + 32693e9 commit af1b6f8

File tree

19 files changed

+144
-94
lines changed

19 files changed

+144
-94
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
steps:
106106
- uses: actions/checkout@v4
107107

108-
- uses: graalvm/setup-graalvm@v1.2.8
108+
- uses: graalvm/setup-graalvm@v1.3.5
109109
with:
110110
java-version: ${{ matrix.java }}
111111
distribution: 'graalvm-community'

nitrite-jackson-mapper/src/main/java/org/dizitart/no2/mapper/jackson/modules/NitriteIdSerializer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ protected NitriteIdSerializer() {
3535

3636
@Override
3737
public void serialize(NitriteId value, JsonGenerator gen, SerializerProvider provider) throws IOException {
38-
if (value.getIdValue() != null) {
39-
gen.writeString(value.getIdValue());
40-
}
38+
gen.writeString(Long.toString(value.getIdValue()));
4139
}
4240
}

nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVRTreeMap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class NitriteMVRTreeMap<Key extends BoundingBox, Value> implements NitriteRTree<
4343

4444
@Override
4545
public void add(Key key, NitriteId nitriteId) {
46-
if (nitriteId != null && nitriteId.getIdValue() != null) {
47-
MVSpatialKey spatialKey = getKey(key, Long.parseLong(nitriteId.getIdValue()));
46+
if (nitriteId != null) {
47+
MVSpatialKey spatialKey = getKey(key, nitriteId.getIdValue());
4848
MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
4949
try {
5050
mvMap.add(spatialKey, key);
@@ -56,8 +56,8 @@ public void add(Key key, NitriteId nitriteId) {
5656

5757
@Override
5858
public void remove(Key key, NitriteId nitriteId) {
59-
if (nitriteId != null && nitriteId.getIdValue() != null) {
60-
MVSpatialKey spatialKey = getKey(key, Long.parseLong(nitriteId.getIdValue()));
59+
if (nitriteId != null) {
60+
MVSpatialKey spatialKey = getKey(key, nitriteId.getIdValue());
6161
MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
6262
try {
6363
mvMap.remove(spatialKey);

nitrite-native-tests/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222

2323
<assertj.version>3.27.3</assertj.version>
24-
<junit.version>5.11.4</junit.version>
25-
<native-build-tools-plugin.version>0.10.4</native-build-tools-plugin.version>
24+
<junit.version>5.12.2</junit.version>
25+
<native-build-tools-plugin.version>0.10.6</native-build-tools-plugin.version>
2626
</properties>
2727

2828
<dependencyManagement>

nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBRTree.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ public RocksDBRTree(RocksDBMap<SpatialKey, Key> backingMap) {
4646
@Override
4747
public void add(Key key, NitriteId nitriteId) {
4848
checkOpened();
49-
if (nitriteId != null && nitriteId.getIdValue() != null) {
50-
SpatialKey spatialKey = getKey(key, Long.parseLong(nitriteId.getIdValue()));
49+
if (nitriteId != null) {
50+
SpatialKey spatialKey = getKey(key, nitriteId.getIdValue());
5151
backingMap.put(spatialKey, key);
5252
}
5353
}
5454

5555
@Override
5656
public void remove(Key key, NitriteId nitriteId) {
5757
checkOpened();
58-
if (nitriteId != null && nitriteId.getIdValue() != null) {
59-
SpatialKey spatialKey = getKey(key, Long.parseLong(nitriteId.getIdValue()));
58+
if (nitriteId != null) {
59+
SpatialKey spatialKey = getKey(key, nitriteId.getIdValue());
6060
backingMap.remove(spatialKey);
6161
}
6262
}

nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/NitriteSerializers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private static class NitriteIdSerializer extends ComparableKeySerializer<Nitrite
3434

3535
@Override
3636
protected void writeKeyInternal(Kryo kryo, Output output, NitriteId object) {
37-
output.writeString(object.getIdValue());
37+
output.writeString(Long.toString(object.getIdValue()));
3838
}
3939

4040
@Override

nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,29 @@ public <T> T get(String field, Class<T> type) {
103103

104104
@Override
105105
public NitriteId getId() {
106-
String id;
106+
long id;
107+
Object retrievedId = null;
107108
try {
108109
// if _id field is not populated already, create a new id
109110
// and set, otherwise return the existing id
110111
if (!containsKey(DOC_ID)) {
111112
id = newId().getIdValue();
112113
super.put(DOC_ID, id);
113114
} else {
114-
id = (String) get(DOC_ID);
115+
retrievedId = get(DOC_ID);
116+
id = (long) get(DOC_ID);
115117
}
116118

117119
// create a nitrite id instance from the string value
118120
return createId(id);
119121
} catch (ClassCastException cce) {
122+
if (retrievedId != null && retrievedId instanceof String) {
123+
try {
124+
return createId((String) retrievedId);
125+
} catch (InvalidIdException ide) {
126+
// fall through to throw InvalidIdException below
127+
}
128+
}
120129
throw new InvalidIdException("Invalid _id found " + get(DOC_ID));
121130
}
122131
}

nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public final class NitriteId implements Comparable<NitriteId>, Serializable {
4747
private static final long serialVersionUID = 1477462375L;
4848
private static final SnowflakeIdGenerator generator = new SnowflakeIdGenerator();
4949

50-
/**
51-
* Gets the underlying value of the NitriteId.
52-
* <p>
53-
* The value is a string representation of a 64bit integer number.
54-
*/
55-
private String idValue;
50+
/** The underlying value of the NitriteId. */
51+
private long idValue;
5652

5753
private NitriteId() {
58-
this.idValue = Long.toString(generator.getId());
54+
this.idValue = generator.getId();
5955
}
6056

6157
private NitriteId(String value) {
58+
this.idValue = Long.parseLong(value);
59+
}
60+
61+
private NitriteId(long value) {
6262
this.idValue = value;
6363
}
6464

@@ -84,6 +84,17 @@ public static NitriteId createId(String value) {
8484
return new NitriteId(value);
8585
}
8686

87+
/**
88+
* Creates a {@link NitriteId} from a {@code long} value.
89+
*
90+
* @param value the value
91+
* @return the {@link NitriteId}
92+
*/
93+
public static NitriteId createId(long value) {
94+
validId(value);
95+
return new NitriteId(value);
96+
}
97+
8798
/**
8899
* Validates a value to be used as {@link NitriteId}.
89100
* <p>
@@ -106,26 +117,19 @@ public static boolean validId(Object value) {
106117

107118
@Override
108119
public int compareTo(NitriteId other) {
109-
if (other.idValue == null) {
110-
throw new InvalidIdException("Cannot compare with null id");
111-
}
112-
113-
return Long.compare(Long.parseLong(idValue), Long.parseLong(other.idValue));
120+
return Long.compare(idValue, other.idValue);
114121
}
115122

116123
@Override
117124
public String toString() {
118-
if (idValue != null) {
119-
return ID_PREFIX + idValue + ID_SUFFIX;
120-
}
121-
return "";
125+
return ID_PREFIX + idValue + ID_SUFFIX;
122126
}
123127

124128
private void writeObject(ObjectOutputStream stream) throws IOException {
125-
stream.writeUTF(idValue);
129+
stream.writeUTF(Long.toString(idValue));
126130
}
127131

128132
private void readObject(ObjectInputStream stream) throws IOException {
129-
idValue = stream.readUTF();
133+
idValue = Long.parseLong(stream.readUTF());
130134
}
131135
}

nitrite/src/main/java/org/dizitart/no2/collection/operation/ReadOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private RecordStream<Pair<NitriteId, Document>> findSuitableStream(FindPlan find
135135
// and or single filter
136136
if (findPlan.getByIdFilter() != null) {
137137
FieldBasedFilter byIdFilter = findPlan.getByIdFilter();
138-
NitriteId nitriteId = NitriteId.createId((String) byIdFilter.getValue());
138+
NitriteId nitriteId = NitriteId.createId((long) byIdFilter.getValue());
139139
if (nitriteMap.containsKey(nitriteId)) {
140140
Document document = nitriteMap.get(nitriteId);
141141
rawStream = RecordStream.single(pair(nitriteId, document));

nitrite/src/main/java/org/dizitart/no2/filters/StringFilter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* @since 1.0
2424
*/
2525
public abstract class StringFilter extends ComparableFilter {
26+
private final StringFilterHelper helper = new StringFilterHelper();
27+
2628
/**
2729
* Instantiates a new String filter.
2830
*
@@ -41,4 +43,15 @@ protected StringFilter(String field, String value) {
4143
public String getStringValue() {
4244
return (String) getValue();
4345
}
46+
47+
/**
48+
* Converts an object to a string safely.
49+
* @param obj the object to convert
50+
* @return the string representation, or empty if null
51+
*/
52+
protected String toStringValue(Object obj) {
53+
return helper.toStringValue(obj);
54+
}
55+
56+
public abstract boolean applyOnString(String value);
4457
}

0 commit comments

Comments
 (0)