Skip to content

Commit

Permalink
upgraded to nitrite 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Nov 30, 2023
1 parent ad5fadc commit 0a1f655
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ $RECYCLE.BIN/
hs_err_pid*
.idea
*.iml
reports
reports
.diffblue
6 changes: 3 additions & 3 deletions nitrite-v3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3</version>
<version>3.42.0.0</version>
</dependency>

<dependency>
Expand All @@ -50,14 +50,14 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.8</version>
<version>1.10.0</version>
</dependency>

</dependencies>
Expand Down
18 changes: 7 additions & 11 deletions nitrite-v4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-bom</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.2.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -44,11 +44,6 @@
<artifactId>nitrite-rocksdb-adapter</artifactId>
</dependency>

<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-mapdb-adapter</artifactId>
</dependency>

<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite-jackson-mapper</artifactId>
Expand All @@ -57,7 +52,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3</version>
<version>3.42.0.0</version>
</dependency>

<dependency>
Expand All @@ -81,14 +76,14 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.8</version>
<version>1.10.0</version>
</dependency>

<dependency>
Expand All @@ -100,13 +95,14 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<version>2.15.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.2.9</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.dizitart.no2.v4.jmh;

import lombok.Data;
import lombok.experimental.Accessors;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.common.mapper.EntityConverter;
import org.dizitart.no2.common.mapper.NitriteMapper;
import org.dizitart.no2.repository.annotations.Id;

/**
* @author Anindya Chatterjee
*/
@Data
@Accessors(fluent = true, chain = true)
public class ArbitraryDataConverter implements EntityConverter<ArbitraryData> {
@Id
private Integer id;
private String text;
private Double number1;
private Double number2;
private Integer index1;
private Boolean flag1;
private Boolean flag2;

@Override
public Class<ArbitraryData> getEntityType() {
return ArbitraryData.class;
}

@Override
public Document toDocument(ArbitraryData arbitraryData, NitriteMapper nitriteMapper) {
return Document.createDocument("id", id)
.put("text", text)
.put("number1", number1)
.put("number2", number2)
.put("index1", index1)
.put("flag1", flag1)
.put("flag2", flag2);
}

@Override
public ArbitraryData fromDocument(Document document, NitriteMapper nitriteMapper) {
ArbitraryData arbitraryData = new ArbitraryData();
arbitraryData.id(document.get("id", Integer.class));
arbitraryData.text(document.get("text", String.class));
arbitraryData.number1(document.get("number1", Double.class));
arbitraryData.number2(document.get("number2", Double.class));
arbitraryData.index1(document.get("index1", Integer.class));
arbitraryData.flag1(document.get("flag1", Boolean.class));
arbitraryData.flag2(document.get("flag2", Boolean.class));
return arbitraryData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import lombok.*;
import lombok.experimental.Accessors;
import org.apache.commons.io.FileUtils;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.common.util.StringUtils;
import org.dizitart.no2.mapdb.MapDBModule;
import org.dizitart.no2.mvstore.MVStoreModule;
import org.dizitart.no2.rocksdb.RocksDBModule;
import org.dizitart.no2.store.StoreModule;
import org.jetbrains.annotations.Nullable;
import org.jooq.lambda.Unchecked;
import org.openjdk.jmh.annotations.*;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
Expand All @@ -37,10 +36,8 @@ public abstract class BaseExecutionPlan<T> {
"SQLITE_FILE",
"SQLITE_MEMORY",
"NITRITE_MVSTORE_FILE",
"NITRITE_MAPDB_FILE",
"NITRITE_ROCKSDB_FILE",
"NITRITE_MVSTORE_MEMORY",
"NITRITE_MAPDB_MEMORY"
})
protected Database database;

Expand All @@ -65,10 +62,8 @@ public void setup() throws Exception {
insertDataIntoSQLite(data);
break;
case NITRITE_MVSTORE_FILE:
case NITRITE_MAPDB_FILE:
case NITRITE_ROCKSDB_FILE:
case NITRITE_MVSTORE_MEMORY:
case NITRITE_MAPDB_MEMORY:
setupNitrite(database);
insertDataIntoNitrite(data);
break;
Expand All @@ -83,10 +78,8 @@ public void tearDown() throws IOException {
tearDownSQLite();
break;
case NITRITE_MVSTORE_FILE:
case NITRITE_MAPDB_FILE:
case NITRITE_ROCKSDB_FILE:
case NITRITE_MVSTORE_MEMORY:
case NITRITE_MAPDB_MEMORY:
tearDownNitrite(database);
break;
}
Expand All @@ -98,19 +91,11 @@ protected StoreModule getStoreModule(Database db) throws IOException {
case NITRITE_MVSTORE_MEMORY:
storeModule = MVStoreModule.withConfig().build();
break;
case NITRITE_MAPDB_MEMORY:
storeModule = MapDBModule.withConfig().build();
break;
case NITRITE_MVSTORE_FILE:
assert db.path != null;
Files.deleteIfExists(Paths.get(db.path));
storeModule = MVStoreModule.withConfig().filePath(db.path).build();
break;
case NITRITE_MAPDB_FILE:
assert db.path != null;
Files.deleteIfExists(Paths.get(db.path));
storeModule = MapDBModule.withConfig().filePath(db.path).build();
break;
case NITRITE_ROCKSDB_FILE:
assert db.path != null;
FileUtils.deleteDirectory(new File(db.path));
Expand Down Expand Up @@ -158,9 +143,7 @@ private void tearDownNitrite(Database db) throws IOException {
@RequiredArgsConstructor
public enum Database {
NITRITE_MVSTORE_MEMORY(null),
NITRITE_MAPDB_MEMORY(null),
NITRITE_MVSTORE_FILE(String.format("%s/nitrite-mvstore-v4.db", BenchmarkParam.TMP)),
NITRITE_MAPDB_FILE(String.format("%s/nitrite-mapdb-v4.db", BenchmarkParam.TMP)),
NITRITE_ROCKSDB_FILE(String.format("%s/nitrite-rocksdb-v4.db", BenchmarkParam.TMP)),
SQLITE_MEMORY(":memory:"),
SQLITE_FILE(String.format("%s/sqlite.db", BenchmarkParam.TMP));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.EqualsAndHashCode;
import lombok.val;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
import org.dizitart.no2.common.module.NitriteModule;
import org.dizitart.no2.exceptions.NitriteIOException;
import org.dizitart.no2.index.IndexOptions;
import org.dizitart.no2.index.IndexType;
Expand All @@ -28,42 +30,46 @@
@Data
@State(Scope.Benchmark)
@EqualsAndHashCode(callSuper = true)
public class MappableExecutionPlan extends BaseExecutionPlan<MappableArbitraryData> {
private ObjectRepository<MappableArbitraryData> repository = null;
public class EntityConverterExecutionPlan extends BaseExecutionPlan<ArbitraryDataConverter> {
private ObjectRepository<ArbitraryDataConverter> repository = null;

@Override
protected void setupNitrite(Database db) throws IOException {
StoreModule storeModule = getStoreModule(db);

SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper();
nitriteMapper.registerEntityConverter(new ArbitraryDataConverter());

if (storeModule != null) {
nitrite = Nitrite.builder()
.loadModule(storeModule)
.loadModule(NitriteModule.module(nitriteMapper))
.openOrCreate();
repository = nitrite.getRepository(MappableArbitraryData.class);
repository.createIndex("index1", IndexOptions.indexOptions(IndexType.NonUnique));
repository = nitrite.getRepository(ArbitraryDataConverter.class);
repository.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "index1");
} else {
throw new NitriteIOException("failed to setup nitrite database");
}
}

@Override
protected MappableArbitraryData[] randomData() {
protected ArbitraryDataConverter[] randomData() {
sequence = new AtomicInteger(0);
return IntStream.range(0, dataSetSize)
.mapToObj(index -> randomDatum())
.toArray(MappableArbitraryData[]::new);
.toArray(ArbitraryDataConverter[]::new);
}

@Override
protected void insertDataIntoNitrite(MappableArbitraryData[] data) {
protected void insertDataIntoNitrite(ArbitraryDataConverter[] data) {
repository.insert(data);
}

@Override
protected void insertDataIntoSQLite(MappableArbitraryData[] data) throws SQLException {
protected void insertDataIntoSQLite(ArbitraryDataConverter[] data) throws SQLException {
sqliteConnection.setAutoCommit(false);
val statement = sqliteConnection.prepareStatement(BenchmarkParam.INSERT_TABLE_STATEMENT);
for (MappableArbitraryData datum : data) {
for (ArbitraryDataConverter datum : data) {
statement.setInt(1, datum.id());
statement.setString(2, datum.text());
statement.setDouble(3, datum.number1());
Expand All @@ -78,19 +84,19 @@ protected void insertDataIntoSQLite(MappableArbitraryData[] data) throws SQLExce
}

@Override
public Collection<MappableArbitraryData> inquireNitrite(int indexValue, double value) {
public Collection<ArbitraryDataConverter> inquireNitrite(int indexValue, double value) {
return repository.find(where("index1").eq(indexValue).and(where("number1").eq(value))).toList();
}

@Override
public Collection<MappableArbitraryData> inquireSQLite(int indexValue, double value) throws SQLException {
public Collection<ArbitraryDataConverter> inquireSQLite(int indexValue, double value) throws SQLException {
sqliteQuery.clearParameters();
sqliteQuery.setInt(1, indexValue);
sqliteQuery.setDouble(2, value);
val result = sqliteQuery.executeQuery();
val data = new ArrayList<MappableArbitraryData>();
val data = new ArrayList<ArbitraryDataConverter>();
while (result.next()) {
val datum = new MappableArbitraryData()
val datum = new ArbitraryDataConverter()
.id(result.getInt("id"))
.text(result.getString("text"))
.number1(result.getDouble("number1"))
Expand All @@ -103,8 +109,8 @@ public Collection<MappableArbitraryData> inquireSQLite(int indexValue, double va
return data;
}

private MappableArbitraryData randomDatum() {
return new MappableArbitraryData()
private ArbitraryDataConverter randomDatum() {
return new ArbitraryDataConverter()
.id(sequence.incrementAndGet())
.flag1(BenchmarkParam.RANDOM.nextBoolean())
.flag2(BenchmarkParam.RANDOM.nextBoolean())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import lombok.EqualsAndHashCode;
import lombok.val;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.common.mapper.JacksonMapperModule;
import org.dizitart.no2.exceptions.NitriteIOException;
import org.dizitart.no2.index.IndexOptions;
import org.dizitart.no2.index.IndexType;
import org.dizitart.no2.mapper.JacksonMapperModule;
import org.dizitart.no2.repository.ObjectRepository;
import org.dizitart.no2.store.StoreModule;
import org.openjdk.jmh.annotations.Scope;
Expand Down Expand Up @@ -41,7 +41,7 @@ protected void setupNitrite(Database db) throws IOException {
.loadModule(new JacksonMapperModule())
.openOrCreate();
repository = nitrite.getRepository(ArbitraryData.class);
repository.createIndex("index1", IndexOptions.indexOptions(IndexType.NonUnique));
repository.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "index1");
} else {
throw new NitriteIOException("failed to setup nitrite database");
}
Expand Down
Loading

0 comments on commit 0a1f655

Please sign in to comment.