Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Mar 2, 2024
2 parents 7813092 + 440f830 commit 55d9026
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: release
- uses: fregante/setup-git-user@v2
- name: Set up JDK 11
uses: actions/setup-java@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: develop
- uses: fregante/setup-git-user@v2
- name: Set up JDK 11
uses: actions/setup-java@v4
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## Release 4.2.2

### Issue Fixes

- Fix for #916
- Fix for #911
- Version upgrade for several dependencies

## Release 4.2.1 - Feb 19, 2024

### Issue Fixes

- Fix for #901
- Fix for #902
- Version upgrade for several dependencies

## Release 4.2.0 - Jan 6, 2024

### New Changes
Expand Down Expand Up @@ -206,3 +222,4 @@
## First Release - Apr 25, 2017

- Initial release

2 changes: 1 addition & 1 deletion nitrite-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nitrite-jackson-mapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-jackson-mapper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.collection.NitriteCollection;
import org.dizitart.no2.common.mapper.JacksonMapperModule;
import org.dizitart.no2.exceptions.IndexingException;
import org.dizitart.no2.exceptions.NitriteIOException;
import org.dizitart.no2.exceptions.ValidationException;
import org.dizitart.no2.index.IndexOptions;
Expand Down Expand Up @@ -241,6 +242,24 @@ public void testGetCollectionInvalidName() {
db.getCollection(META_MAP_NAME);
}

@Test(expected = IndexingException.class)
public void testUniqueAndTextIndex() {
try (final Nitrite nitrite = Nitrite.builder()
.loadModule(new JacksonMapperModule())
.openOrCreate()) {
nitrite.getRepository(EntityUniqueFullText.class);
}
}

@Test(expected = IndexingException.class)
public void testNoUniqueAndTextIndex() {
try (final Nitrite nitrite = Nitrite.builder()
.loadModule(new JacksonMapperModule())
.openOrCreate()) {
nitrite.getRepository(EntityNoUniqueFullText.class);
}
}


@Data
@NoArgsConstructor
Expand All @@ -263,4 +282,26 @@ public enum Status {

public static class EmptyClass {
}

@Indices({
@Index(fields = "value", type = IndexType.FULL_TEXT),
@Index(fields = "value")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class EntityUniqueFullText {
private String value;
}

@Indices({
@Index(fields = "value", type = IndexType.FULL_TEXT),
@Index(fields = "value", type = IndexType.NON_UNIQUE)
})
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class EntityNoUniqueFullText {
private String value;
}
}
2 changes: 1 addition & 1 deletion nitrite-mvstore-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-mvstore-adapter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;

import static org.dizitart.no2.common.Constants.INDEX_PREFIX;
import static org.dizitart.no2.common.Constants.STORE_INFO;
import static org.dizitart.no2.common.Constants.*;
import static org.dizitart.no2.common.util.ObjectUtils.convertToObjectArray;
import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty;

Expand Down Expand Up @@ -91,9 +90,12 @@ private static void copyData(MVMap oldMap, org.h2.mvstore.MVMap newMap) {

if (key instanceof Compat.NitriteId) {
newKey = nitriteId((Compat.NitriteId) key);
} else if (oldMap.getName().contains(INDEX_META_PREFIX)) {
// index meta map, wrap with Field
newKey = key == null ? Fields.withNames() : Fields.withNames((String) key);
} else if (oldMap.getName().contains(INDEX_PREFIX)) {
// index map, wrap with DBValue
newKey = newKey == null ? DBNull.getInstance() : new DBValue((Comparable<?>) newKey);
newKey = key == null ? DBNull.getInstance() : new DBValue((Comparable<?>) key);
}

Object newValue = migrateValue(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,13 @@ public InputStream newInputStream() throws IOException {
}

static void freeMemoryAndFinalize() {
IOUtils.trace("freeMemoryAndFinalize", (String)null, (Object)null);
IOUtils.trace("freeMemoryAndFinalize", null, null);
Runtime var0 = Runtime.getRuntime();
long var1 = var0.freeMemory();

for(int var3 = 0; var3 < 16; ++var3) {
var0.gc();
long var4 = var0.freeMemory();
var0.runFinalization();
if (var4 == var1) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static org.dizitart.no2.collection.Document.createDocument;
import static org.dizitart.no2.common.Constants.INTERNAL_NAME_SEPARATOR;
import static org.dizitart.no2.common.Constants.META_MAP_NAME;
import static org.dizitart.no2.common.util.Iterables.listOf;
import static org.dizitart.no2.filters.Filter.ALL;
import static org.dizitart.no2.filters.Filter.and;
import static org.dizitart.no2.filters.FluentFilter.where;
Expand Down Expand Up @@ -186,38 +187,53 @@ public void testReopen() throws ParseException {
NitriteCollection testCollection = db.getCollection("test");
assertNotNull(testCollection);
long prevSize = testCollection.find().size();
ObjectRepository<Receipt> repository = db.getRepository(Receipt.class);
assertNotNull(repository);
long prevRepoSize = repository.size();

db.close();

db = null;

db = TestUtil.createDb(fileName, "test-user", "test-password");

db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter()));
assertNotNull(db);
testCollection = db.getCollection("test");
assertNotNull(testCollection);
long sizeNow = testCollection.find().size();
assertEquals(prevSize, sizeNow);
repository = db.getRepository(Receipt.class);
assertNotNull(repository);
long repoSizeNow = repository.size();
assertEquals(prevRepoSize, repoSizeNow);

db.close();
db = null;
db = TestUtil.createDb(fileName, "test-user", "test-password");
db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter()));

testCollection = db.getCollection("test");
testCollection.insert(createDocument("firstName", "fn12")
.put("lastName", "ln12")
.put("birthDay", simpleDateFormat.parse("2010-07-01T16:02:48.440Z"))
.put("data", new byte[]{10, 20, 30})
.put("body", "a quick brown fox jump over the lazy dog"));
repository = db.getRepository(Receipt.class);
Receipt r = new Receipt();
r.status = Receipt.Status.COMPLETED;
r.clientRef = "10";
r.synced = false;
repository.insert(r);

db.close();
db = null;
db = TestUtil.createDb(fileName, "test-user", "test-password");
db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter()));

testCollection = db.getCollection("test");
assertNotNull(testCollection);
sizeNow = testCollection.find().size();
assertEquals(prevSize + 1, sizeNow);
repository = db.getRepository(Receipt.class);
assertNotNull(repository);
repoSizeNow = repository.size();
assertEquals(prevRepoSize + 1, repoSizeNow);
}

@Test
Expand Down Expand Up @@ -491,9 +507,7 @@ public void testReadCompatibility() throws IOException {
Files.copy(stream, Paths.get(System.getProperty("java.io.tmpdir") + File.separator + "old.db"));

String oldDbFile = System.getProperty("java.io.tmpdir") + File.separator + "old.db";
Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password");
SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
documentMapper.registerEntityConverter(new Receipt.Converter());
Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password", listOf(new Receipt.Converter()));

NitriteCollection collection = db.getCollection("test");

Expand All @@ -517,6 +531,8 @@ public void testReadCompatibility() throws IOException {
assertNotNull(repository.getAttributes());

db.close();

//TODO: CHeck reopen with repo. That should also fails too.
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.extern.slf4j.Slf4j;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.common.mapper.EntityConverter;
import org.dizitart.no2.exceptions.ObjectMappingException;
import org.dizitart.no2.mvstore.MVStoreModule;

Expand Down Expand Up @@ -125,6 +126,20 @@ public static Nitrite createDb(String filePath, String user, String password) {
.openOrCreate(user, password);
}

public static Nitrite createDb(String filePath, String user, String password,
List<EntityConverter<?>> entityConverters) {
MVStoreModule storeModule = MVStoreModule.withConfig()
.filePath(filePath)
.compress(true)
.build();

return Nitrite.builder()
.loadModule(storeModule)
.loadModule(() -> new HashSet<>(entityConverters))
.fieldSeparator(".")
.openOrCreate(user, password);
}

public static Document parse(String json) {
try {
ObjectMapper objectMapper = createObjectMapper();
Expand Down
2 changes: 1 addition & 1 deletion nitrite-rocksdb-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-rocksdb-adapter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nitrite-spatial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-spatial</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dizitart.no2.exceptions.IndexingException;
import org.dizitart.no2.filters.FluentFilter;
import org.dizitart.no2.index.IndexOptions;
import org.dizitart.no2.index.IndexType;
import org.dizitart.no2.repository.Cursor;
import org.junit.Test;
import org.locationtech.jts.geom.Geometry;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void testNoIndex() throws ParseException {
@Test(expected = IndexingException.class)
public void testIndexExists() {
collection.createIndex(IndexOptions.indexOptions(SPATIAL_INDEX), "location");
collection.createIndex(IndexOptions.indexOptions(SPATIAL_INDEX), "location");
collection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "location");
}

@Test(expected = FilterException.class)
Expand Down
2 changes: 1 addition & 1 deletion nitrite-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite-support</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nitrite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-java</artifactId>
<version>4.2.1-SNAPSHOT</version>
<version>4.2.2-SNAPSHOT</version>
</parent>

<artifactId>nitrite</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ void createIndex(Fields fields, String indexType) {
// if no index create index
indexDescriptor = indexManager.createIndexDescriptor(fields, indexType);
} else {
// if index already there throw
throw new IndexingException("Index already exists on fields: " + fields);
// if index already there check if it is of same type, if not throw exception
if (!indexDescriptor.getIndexType().equals(indexType)) {
throw new IndexingException("Index already exists on fields: " + fields
+ " with type " + indexDescriptor.getIndexType());
} else {
// if index is of same type, return
return;
}
}

buildIndex(indexDescriptor, false);
Expand Down
11 changes: 3 additions & 8 deletions nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* @author Anindya Chatterjee
* @since 1.0
*/
@Setter
public class TextFilter extends StringFilter {
@Setter
private TextTokenizer textTokenizer;

/**
Expand Down Expand Up @@ -100,12 +100,7 @@ private LinkedHashSet<NitriteId> searchExactByIndex(NitriteMap<String, List<?>>
List<NitriteId> nitriteIds = (List<NitriteId>) indexMap.get(word);
if (nitriteIds != null) {
for (NitriteId id : nitriteIds) {
Integer score = scoreMap.get(id);
if (score == null) {
scoreMap.put(id, 1);
} else {
scoreMap.put(id, score + 1);
}
scoreMap.merge(id, 1, Integer::sum);
}
}
}
Expand Down Expand Up @@ -185,7 +180,7 @@ private LinkedHashSet<NitriteId> searchContains(NitriteMap<String, List<?>> inde

private LinkedHashSet<NitriteId> sortedIdsByScore(Map<NitriteId, Integer> unsortedMap) {
List<Map.Entry<NitriteId, Integer>> list = new LinkedList<>(unsortedMap.entrySet());
Collections.sort(list, (e1, e2) -> (e2.getValue()).compareTo(e1.getValue()));
list.sort((e1, e2) -> (e2.getValue()).compareTo(e1.getValue()));

LinkedHashSet<NitriteId> result = new LinkedHashSet<>();
for (Map.Entry<NitriteId, Integer> entry : list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public LinkedHashSet<NitriteId> findNitriteIds(FindPlan findPlan) {
textFilter.setTextTokenizer(textTokenizer);
return textFilter.applyOnTextIndex(indexMap);
}
throw new FilterException("Text index only supports a single TextFilter");
throw new FilterException("TextFilter can only be applied on text index.");
}

private NitriteMap<String, List<?>> findIndexMap() {
Expand Down
Loading

0 comments on commit 55d9026

Please sign in to comment.