From 8aa9feb6fc2e416bb97cb2928358d0d117cf59dc Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Tue, 8 Aug 2023 13:04:52 +0530 Subject: [PATCH 01/18] work in progress --- .../dizitart/no2/support/ExportOptions.java | 72 +++++++++++++++---- .../org/dizitart/no2/support/Exporter.java | 47 +++++------- .../dizitart/no2/support/ImportOptions.java | 41 +++++++++++ .../dizitart/no2/support/NitriteFactory.java | 21 ++++++ .../no2/support/NitriteJsonExporter.java | 60 ++++++++++++---- .../main/java/org/dizitart/no2/Nitrite.java | 2 +- 6 files changed, 187 insertions(+), 56 deletions(-) create mode 100644 nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java create mode 100644 nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java index 8ec537883..7f0d4b9fe 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java @@ -16,12 +16,11 @@ package org.dizitart.no2.support; +import com.fasterxml.jackson.core.JsonFactory; import lombok.Getter; import lombok.Setter; -import org.dizitart.no2.common.PersistentCollection; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * Represents export options. @@ -33,12 +32,38 @@ @Getter @Setter public class ExportOptions { + /** + * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This + * instance will be used to export the collections and data. + *

+ * This is a mandatory field. If not specified, the export operation will fail. + * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so + * the database must not be open elsewhere. Upon completion of the export operation, the + * {@link org.dizitart.no2.Nitrite} instance will be closed. + * + * @param nitriteFactory the nitriteFactory. + * @return the nitriteFactory. + */ + private NitriteFactory nitriteFactory; + + /** + * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. + * This instance will be used to write the export data to a file. + *

+ * This is an optional field. If not specified, a default one will be created. + * + * @param jsonFactory the jsonFactory. + * @return the jsonFactory. + */ + private JsonFactory jsonFactory; /** * Indicates if the export operation exports indices information. *

- * [icon="{@docRoot}/note.png"] - * NOTE: Default value is `true`. + * If `true`, the export operation will export indices information. If `false`, the export + * operation will not export indices information. + *

+ * This is an optional field. If not specified, it will be set to `true`. * * @param exportIndices a value indicating if indices information will be exported. * @return `true` if indices information is exported; otherwise, `false`. @@ -48,8 +73,10 @@ public class ExportOptions { /** * Indicates if the export operation exports collection data. *

- * [icon="{@docRoot}/note.png"] - * NOTE: Default value is `true`. + * If `true`, the export operation will export collection data. If `false`, the export + * operation will not export collection data. + *

+ * This is an optional field. If not specified, it will be set to `true`. * * @param exportData a value indicating if collection data will be exported. * @return `true` if collection data is exported; otherwise, `false`. @@ -57,13 +84,32 @@ public class ExportOptions { private boolean exportData = true; /** - * Specifies a list of {@link PersistentCollection}s to be exported. + * Specifies a list of {@link org.dizitart.no2.collection.NitriteCollection} names to be exported. + *

+ * If not specified, all collections will be exported. + * + * @param collections list of all collection names to be exported. + * @return list of collection names. + */ + private List collections = new ArrayList<>(); + + /** + * Specifies a list of {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. + *

+ * If not specified, all repositories will be exported. + * + * @param repositories list of all repositories names to be exported. + * @return list of repositories names. + */ + private List repositories = new ArrayList<>(); + + /** + * Specifies a list of keyed {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. *

- * [icon="{@docRoot}/note.png"] - * NOTE: If empty, all collections will be exported. + * If not specified, all keyed repositories will be exported. * - * @param collections list of all collections to be exported. - * @return list of collections. + * @param keyedRepositories list of all keyed repositories names to be exported. + * @return list of keyed repositories names. */ - private List> collections = new ArrayList<>(); + private Map> keyedRepositories = new HashMap<>(); } diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java index e8c35e301..90385a798 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java @@ -25,9 +25,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.dizitart.no2.Nitrite; import org.dizitart.no2.exceptions.NitriteIOException; +import org.dizitart.no2.exceptions.ValidationException; import java.io.*; +import static org.dizitart.no2.common.util.ValidationUtils.notNull; + /** * Nitrite database export utility. It exports data to @@ -41,8 +44,6 @@ * @since 1.0 */ public class Exporter { - private Nitrite db; - private JsonFactory jsonFactory; private ExportOptions options; private Exporter() { @@ -51,46 +52,36 @@ private Exporter() { /** * Creates a new {@link Exporter} instance. * - * @param db the db + * @param exportOptions the exportOptions * @return the exporter instance */ - public static Exporter of(Nitrite db) { - return of(db, createObjectMapper()); - } - - public static Exporter of(Nitrite db, ObjectMapper objectMapper) { + public static Exporter withOptions(ExportOptions exportOptions) { Exporter exporter = new Exporter(); - exporter.db = db; - exporter.jsonFactory = objectMapper.getFactory(); - exporter.options = new ExportOptions(); + notNull(exportOptions, "exportOptions cannot be null"); + notNull(exportOptions.getNitriteFactory(), "nitriteFactory cannot be null"); + + if (exportOptions.getJsonFactory() == null) { + exportOptions.setJsonFactory(createObjectMapper().getFactory()); + } + exporter.options = exportOptions; + return exporter; } public static ObjectMapper createObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.setVisibility( objectMapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); - objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; } - /** - * Sets {@link ExportOptions} to customize data export. - * - * @param options the options - * @return the exporter - */ - public Exporter withOptions(ExportOptions options) { - this.options = options; - return this; - } - /** * Exports data to a file. * @@ -148,13 +139,13 @@ public void exportTo(OutputStream stream) throws IOException { public void exportTo(Writer writer) { JsonGenerator generator; try { - generator = jsonFactory.createGenerator(writer); + generator = options.getJsonFactory().createGenerator(writer); generator.setPrettyPrinter(new DefaultPrettyPrinter()); } catch (IOException ioe) { throw new NitriteIOException("I/O error while writing data with writer", ioe); } - NitriteJsonExporter jsonExporter = new NitriteJsonExporter(db); + NitriteJsonExporter jsonExporter = new NitriteJsonExporter(); jsonExporter.setGenerator(generator); jsonExporter.setOptions(options); try { diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java new file mode 100644 index 000000000..efea557b9 --- /dev/null +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java @@ -0,0 +1,41 @@ +package org.dizitart.no2.support; + +import com.fasterxml.jackson.core.JsonFactory; +import lombok.Getter; +import lombok.Setter; + +/** + * Represents import options. + * + * @author Anindya Chatterjee + * @see Importer + * @since 4.0 + */ +@Getter +@Setter +public class ImportOptions { + /** + * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This + * instance will be used to import the collections and data. + *

+ * This is a mandatory field. If not specified, the import operation will fail. + * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so + * the database must not be open elsewhere. Upon completion of the import operation, the + * {@link org.dizitart.no2.Nitrite} instance will be closed. + * + * @param nitriteFactory the nitriteFactory. + * @return the nitriteFactory. + */ + private NitriteFactory nitriteFactory; + + /** + * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. + * This instance will be used to read the exported data from a file. + *

+ * This is an optional field. If not specified, a default one will be created. + * + * @param jsonFactory the jsonFactory. + * @return the jsonFactory. + */ + private JsonFactory jsonFactory; +} diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java new file mode 100644 index 000000000..680f703e1 --- /dev/null +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java @@ -0,0 +1,21 @@ +package org.dizitart.no2.support; + +import org.dizitart.no2.Nitrite; + + +/** + * A factory interface to create a {@link Nitrite} instance. + * + * @since 4.0.0 + * @see Nitrite + * @author Anindya Chatterjee + * */ +@FunctionalInterface +public interface NitriteFactory { + /** + * Creates a {@link Nitrite} instance. + * + * @return the nitrite instance. + */ + Nitrite create(); +} diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 2ed1ff5f7..9bda82747 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -17,11 +17,13 @@ package org.dizitart.no2.support; import com.fasterxml.jackson.core.JsonGenerator; +import lombok.Setter; import org.apache.commons.codec.binary.Hex; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.DocumentCursor; import org.dizitart.no2.collection.NitriteCollection; +import org.dizitart.no2.collection.operation.IndexManager; import org.dizitart.no2.common.PersistentCollection; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.index.IndexDescriptor; @@ -31,28 +33,62 @@ import java.io.IOException; import java.io.ObjectOutputStream; import java.util.*; +import java.util.stream.Collectors; import static org.dizitart.no2.common.Constants.*; -import static org.dizitart.no2.common.util.ObjectUtils.getKeyName; -import static org.dizitart.no2.common.util.ObjectUtils.getKeyedRepositoryType; +import static org.dizitart.no2.common.util.ObjectUtils.*; /** * @author Anindya Chatterjee */ +@Setter class NitriteJsonExporter { - private final Nitrite db; private JsonGenerator generator; private ExportOptions options; - public NitriteJsonExporter(Nitrite db) { - this.db = db; - } + public void exportData() throws IOException, ClassNotFoundException { + Nitrite db = options.getNitriteFactory().create(); + Set collectionNames = db.listCollectionNames(); + Set repositoryNames = db.listRepositories(); + Map> keyedRepositoryNames = db.listKeyedRepositories(); + List indexDescriptors = new ArrayList<>(); + + if (!options.getCollections().isEmpty()) { + collectionNames = new HashSet<>(options.getCollections()); + } + + if (!options.getRepositories().isEmpty()) { + repositoryNames = new HashSet<>(options.getRepositories()); + } + + if (!options.getKeyedRepositories().isEmpty()) { + keyedRepositoryNames = options.getKeyedRepositories(); + } + + if (options.isExportIndices()) { + for (String collectionName : collectionNames) { + IndexManager indexManager = new IndexManager(collectionName, db.getConfig()); + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + + for (String repositoryName : repositoryNames) { + IndexManager indexManager = new IndexManager(repositoryName, db.getConfig()); + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + + for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { + String key = entry.getKey(); + Set enttityNameSet = entry.getValue(); + for (String entityName : enttityNameSet) { + String repositoryName = findRepositoryName(key, entityName); + IndexManager indexManager = new IndexManager(repositoryName, db.getConfig()); + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + } + } + - public void setGenerator(JsonGenerator generator) { - this.generator = generator; - } - public void exportData() throws IOException, ClassNotFoundException { List> collections = options.getCollections(); Set collectionNames; Set repositoryNames; @@ -208,10 +244,6 @@ private void writeContent(DocumentCursor cursor) throws IOException { generator.writeEndArray(); } - public void setOptions(ExportOptions options) { - this.options = options; - } - private String writeEncodedObject(Object object) { try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { try (ObjectOutputStream oos = new ObjectOutputStream(os)) { diff --git a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java index cd5a39fa1..8143e526d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java +++ b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java @@ -203,7 +203,7 @@ static NitriteBuilder builder() { * Gets the map of all key to the fully qualified class names corresponding * to all keyed-{@link ObjectRepository}s in the store. * - * @return the set of all registered classes' names. + * @return the map of all registered classes' names against the keys. */ Map> listKeyedRepositories(); From 1c61a24850951cd1de2cba58d1c3a7e95d983a0c Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Tue, 8 Aug 2023 21:27:50 +0530 Subject: [PATCH 02/18] work in progress --- nitrite-support/pom.xml | 4 + .../dizitart/no2/support/ExportOptions.java | 213 ++++---- .../org/dizitart/no2/support/Exporter.java | 283 +++++------ .../org/dizitart/no2/support/Importer.java | 214 ++++---- .../no2/support/NitriteJsonExporter.java | 434 ++++++++-------- .../no2/support/NitriteJsonImporter.java | 376 ++++++-------- .../no2/support/BaseExternalTest.java | 222 +++++---- .../support/ExporterImporterOptionTest.java | 157 +++--- .../no2/support/ExporterImporterTest.java | 149 +++--- .../dizitart/no2/support/GithubIssueTest.java | 41 +- .../collection/operation/IndexManager.java | 462 +++++++++--------- pom.xml | 6 + 12 files changed, 1270 insertions(+), 1291 deletions(-) diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index d29eda104..86dbee6a6 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -51,6 +51,10 @@ lombok provided + + de.undercouch + bson4jackson + junit diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java index 7f0d4b9fe..2a288e154 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java @@ -14,102 +14,119 @@ * limitations under the License. */ -package org.dizitart.no2.support; + package org.dizitart.no2.support; -import com.fasterxml.jackson.core.JsonFactory; -import lombok.Getter; -import lombok.Setter; - -import java.util.*; - -/** - * Represents export options. - * - * @author Anindya Chatterjee - * @see Exporter - * @since 1.0 - */ -@Getter -@Setter -public class ExportOptions { - /** - * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This - * instance will be used to export the collections and data. - *

- * This is a mandatory field. If not specified, the export operation will fail. - * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so - * the database must not be open elsewhere. Upon completion of the export operation, the - * {@link org.dizitart.no2.Nitrite} instance will be closed. - * - * @param nitriteFactory the nitriteFactory. - * @return the nitriteFactory. - */ - private NitriteFactory nitriteFactory; - - /** - * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. - * This instance will be used to write the export data to a file. - *

- * This is an optional field. If not specified, a default one will be created. - * - * @param jsonFactory the jsonFactory. - * @return the jsonFactory. - */ - private JsonFactory jsonFactory; - - /** - * Indicates if the export operation exports indices information. - *

- * If `true`, the export operation will export indices information. If `false`, the export - * operation will not export indices information. - *

- * This is an optional field. If not specified, it will be set to `true`. - * - * @param exportIndices a value indicating if indices information will be exported. - * @return `true` if indices information is exported; otherwise, `false`. - */ - private boolean exportIndices = true; - - /** - * Indicates if the export operation exports collection data. - *

- * If `true`, the export operation will export collection data. If `false`, the export - * operation will not export collection data. - *

- * This is an optional field. If not specified, it will be set to `true`. - * - * @param exportData a value indicating if collection data will be exported. - * @return `true` if collection data is exported; otherwise, `false`. - */ - private boolean exportData = true; - - /** - * Specifies a list of {@link org.dizitart.no2.collection.NitriteCollection} names to be exported. - *

- * If not specified, all collections will be exported. - * - * @param collections list of all collection names to be exported. - * @return list of collection names. - */ - private List collections = new ArrayList<>(); - - /** - * Specifies a list of {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. - *

- * If not specified, all repositories will be exported. - * - * @param repositories list of all repositories names to be exported. - * @return list of repositories names. - */ - private List repositories = new ArrayList<>(); - - /** - * Specifies a list of keyed {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. - *

- * If not specified, all keyed repositories will be exported. - * - * @param keyedRepositories list of all keyed repositories names to be exported. - * @return list of keyed repositories names. - */ - private Map> keyedRepositories = new HashMap<>(); -} + import com.fasterxml.jackson.core.JsonFactory; + import lombok.Getter; + import lombok.Setter; + + import java.util.*; + + /** + * Represents export options. + * + * @author Anindya Chatterjee + * @see Exporter + * @since 1.0 + */ + @Getter + @Setter + public class ExportOptions { + /** + * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This + * instance will be used to export the collections and data. + *

+ * This is a mandatory field. If not specified, the export operation will fail. + * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so + * the database must not be open elsewhere. Upon completion of the export operation, the + * {@link org.dizitart.no2.Nitrite} instance will be closed. + * + * @param nitriteFactory the nitriteFactory. + * @return the nitriteFactory. + */ + private NitriteFactory nitriteFactory; + + /** + * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. + * This instance will be used to write the export data to a file. + *

+ * This is an optional field. If not specified, a default one will be created. + * + * @param jsonFactory the jsonFactory. + * @return the jsonFactory. + */ + private JsonFactory jsonFactory; + + /** + * Indicates if the export operation exports indices information. + *

+ * If `true`, the export operation will export indices information. If `false`, the export + * operation will not export indices information. + *

+ * This is an optional field. If not specified, it will be set to `true`. + * + * @param exportIndices a value indicating if indices information will be exported. + * @return `true` if indices information is exported; otherwise, `false`. + */ + private boolean exportIndices = true; + + /** + * Indicates if the export operation exports collection data. + *

+ * If `true`, the export operation will export collection data. If `false`, the export + * operation will not export collection data. + *

+ * This is an optional field. If not specified, it will be set to `true`. + * + * @param exportData a value indicating if collection data will be exported. + * @return `true` if collection data is exported; otherwise, `false`. + */ + private boolean exportData = true; + + /** + * Specifies a list of {@link org.dizitart.no2.collection.NitriteCollection} names to be exported. + *

+ * + * Please see the rules for specifying the collections to be exported + *

+ * + * @param collections list of all collection names to be exported. + * @return list of collection names. + */ + private List collections; + + /** + * Specifies a list of {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. + *

+ * Please see the rules for specifying the repositories to be exported + *

+ * + * @param repositories list of all repositories names to be exported. + * @return list of repositories names. + */ + private List repositories; + + /** + * Specifies a list of keyed {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. + *

+ * Please see the rules for specifying the keyed-repositories to be exported + *

    + *
  • If null is specified, all keyed-repositories will be exported
  • + *
  • If an empty map is specified, no keyed-repositories will be exported
  • + *
  • If a non-empty map is specified, only the keyed-repositories in the map will be exported
  • + *
+ * + * @param keyedRepositories list of all keyed repositories names to be exported. + * @return list of keyed repositories names. + */ + private Map> keyedRepositories; + } + \ No newline at end of file diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java index 90385a798..5e1cc0ca0 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java @@ -14,144 +14,145 @@ * limitations under the License. */ -package org.dizitart.no2.support; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.dizitart.no2.Nitrite; -import org.dizitart.no2.exceptions.NitriteIOException; -import org.dizitart.no2.exceptions.ValidationException; - -import java.io.*; - -import static org.dizitart.no2.common.util.ValidationUtils.notNull; - - -/** - * Nitrite database export utility. It exports data to - * a json file. Contents of a Nitrite database can be exported - * using this tool. - *

- * [[app-listing]] - * include::/src/docs/asciidoc/tools/data-format.adoc[] - * - * @author Anindya Chatterjee - * @since 1.0 - */ -public class Exporter { - private ExportOptions options; - - private Exporter() { - } - - /** - * Creates a new {@link Exporter} instance. - * - * @param exportOptions the exportOptions - * @return the exporter instance - */ - public static Exporter withOptions(ExportOptions exportOptions) { - Exporter exporter = new Exporter(); - notNull(exportOptions, "exportOptions cannot be null"); - notNull(exportOptions.getNitriteFactory(), "nitriteFactory cannot be null"); - - if (exportOptions.getJsonFactory() == null) { - exportOptions.setJsonFactory(createObjectMapper().getFactory()); - } - exporter.options = exportOptions; - - return exporter; - } - - public static ObjectMapper createObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.setVisibility( - objectMapper.getSerializationConfig().getDefaultVisibilityChecker() - .withFieldVisibility(JsonAutoDetect.Visibility.ANY) - .withGetterVisibility(JsonAutoDetect.Visibility.NONE) - .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); - return objectMapper; - } - - /** - * Exports data to a file. - * - * @param file the file - */ - public void exportTo(String file) { - exportTo(new File(file)); - } - - /** - * Exports data to a {@link File}. - * - * @param file the file - * @throws NitriteIOException if there is any low-level I/O error. - */ - public void exportTo(File file) { - try { - if (file.isDirectory()) { - throw new IOException(file.getPath() + " is not a file"); - } - - File parent = file.getParentFile(); - // if parent dir does not exist, try to create it - if (!parent.exists()) { - boolean result = parent.mkdirs(); - if (!result) { - throw new IOException("Failed to create parent directory " + parent.getPath()); - } - } - try (FileOutputStream outputStream = new FileOutputStream(file)) { - exportTo(outputStream); - } - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while writing content to file " + file, ioe); - } - } - - /** - * Exports data to an {@link OutputStream}. - * - * @param stream the stream - */ - public void exportTo(OutputStream stream) throws IOException { - try(OutputStreamWriter writer = new OutputStreamWriter(stream)) { - exportTo(writer); - } - } - - /** - * Exports data to a {@link Writer}. - * - * @param writer the writer - * @throws NitriteIOException if there is any error while writing the data. - */ - public void exportTo(Writer writer) { - JsonGenerator generator; - try { - generator = options.getJsonFactory().createGenerator(writer); - generator.setPrettyPrinter(new DefaultPrettyPrinter()); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while writing data with writer", ioe); - } - - NitriteJsonExporter jsonExporter = new NitriteJsonExporter(); - jsonExporter.setGenerator(generator); - jsonExporter.setOptions(options); - try { - jsonExporter.exportData(); - } catch (IOException | ClassNotFoundException e) { - throw new NitriteIOException("Error while exporting data", e); - } - } -} + package org.dizitart.no2.support; + + import com.fasterxml.jackson.annotation.JsonAutoDetect; + import com.fasterxml.jackson.core.JsonFactory; + import com.fasterxml.jackson.core.JsonGenerator; + import com.fasterxml.jackson.core.JsonParser; + import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; + import com.fasterxml.jackson.databind.DeserializationFeature; + import com.fasterxml.jackson.databind.ObjectMapper; + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.exceptions.NitriteIOException; + import org.dizitart.no2.exceptions.ValidationException; + + import java.io.*; + + import static org.dizitart.no2.common.util.ValidationUtils.notNull; + + + /** + * Nitrite database export utility. It exports data to + * a json file. Contents of a Nitrite database can be exported + * using this tool. + *

+ * + * @author Anindya Chatterjee + * @since 1.0 + */ + public class Exporter { + private ExportOptions options; + + private Exporter() { + } + + /** + * Creates an Exporter instance with the specified export options. + * + * @param exportOptions the export options to be set + * (must not be null and must have a valid nitrite factory) + * + * @return the Exporter instance with the specified export options + */ + public static Exporter withOptions(ExportOptions exportOptions) { + Exporter exporter = new Exporter(); + notNull(exportOptions, "exportOptions cannot be null"); + notNull(exportOptions.getNitriteFactory(), "nitriteFactory cannot be null"); + + if (exportOptions.getJsonFactory() == null) { + exportOptions.setJsonFactory(createObjectMapper().getFactory()); + } + + exporter.options = exportOptions; + return exporter; + } + + public static ObjectMapper createObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.setVisibility( + objectMapper.getSerializationConfig().getDefaultVisibilityChecker() + .withFieldVisibility(JsonAutoDetect.Visibility.ANY) + .withGetterVisibility(JsonAutoDetect.Visibility.NONE) + .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); + return objectMapper; + } + + /** + * Exports data to a file. + * + * @param file the file + */ + public void exportTo(String file) { + exportTo(new File(file)); + } + + /** + * Exports data to a {@link File}. + * + * @param file the file + * @throws NitriteIOException if there is any low-level I/O error. + */ + public void exportTo(File file) { + try { + if (file.isDirectory()) { + throw new IOException(file.getPath() + " is not a file"); + } + + File parent = file.getParentFile(); + // if parent dir does not exist, try to create it + if (!parent.exists()) { + boolean result = parent.mkdirs(); + if (!result) { + throw new IOException("Failed to create parent directory " + parent.getPath()); + } + } + try (FileOutputStream outputStream = new FileOutputStream(file)) { + exportTo(outputStream); + } + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while writing content to file " + file, ioe); + } + } + + /** + * Exports data to an {@link OutputStream}. + * + * @param stream the stream + */ + public void exportTo(OutputStream stream) throws IOException { + try(OutputStreamWriter writer = new OutputStreamWriter(stream)) { + exportTo(writer); + } + } + + /** + * Exports data to a {@link Writer}. + * + * @param writer the writer + * @throws NitriteIOException if there is any error while writing the data. + */ + public void exportTo(Writer writer) { + JsonGenerator generator; + try { + generator = options.getJsonFactory().createGenerator(writer); + generator.setPrettyPrinter(new DefaultPrettyPrinter()); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while writing data with writer", ioe); + } + + NitriteJsonExporter jsonExporter = new NitriteJsonExporter(); + jsonExporter.setGenerator(generator); + jsonExporter.setOptions(options); + try { + jsonExporter.exportData(); + } catch (IOException | ClassNotFoundException e) { + throw new NitriteIOException("Error while exporting data", e); + } + } + } + \ No newline at end of file diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java b/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java index 20b8f52ef..e4dfed54b 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java @@ -14,110 +14,112 @@ * limitations under the License. */ -package org.dizitart.no2.support; + package org.dizitart.no2.support; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.dizitart.no2.Nitrite; -import org.dizitart.no2.exceptions.NitriteIOException; - -import java.io.*; - -import static org.dizitart.no2.support.Exporter.createObjectMapper; - - -/** - * Nitrite database import utility. It imports data from - * a json file. Contents of a Nitrite database can be imported - * using this tool. - *

- * [[app-listing]] - * include::/src/docs/asciidoc/tools/data-format.adoc[] - * - * @author Anindya Chatterjee - * @since 1.0 - */ -public class Importer { - private Nitrite db; - private JsonFactory jsonFactory; - - private Importer() { - } - - /** - * Creates a new {@link Importer} instance. - * - * @param db the db - * @return the importer instance - */ - public static Importer of(Nitrite db) { - return of(db, createObjectMapper()); - } - - public static Importer of(Nitrite db, ObjectMapper objectMapper) { - Importer importer = new Importer(); - importer.db = db; - importer.jsonFactory = objectMapper.getFactory(); - return importer; - } - - /** - * Imports data from a file path. - * - * @param file the file path - */ - public void importFrom(String file) { - importFrom(new File(file)); - } - - /** - * Imports data from a file. - * - * @param file the file - * @throws NitriteIOException if there is any low-level I/O error. - */ - public void importFrom(File file) { - try (FileInputStream stream = new FileInputStream(file)) { - importFrom(stream); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while reading content from file " + file, ioe); - } - } - - /** - * Imports data from an {@link InputStream}. - * - * @param stream the stream - */ - public void importFrom(InputStream stream) throws IOException { - try(InputStreamReader reader = new InputStreamReader(stream)) { - importFrom(reader); - } - } - - /** - * Imports data from a {@link Reader}. - * - * @param reader the reader - * @throws NitriteIOException if there is any error while reading the data. - */ - public void importFrom(Reader reader) { - JsonParser parser; - try { - parser = jsonFactory.createParser(reader); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while creating parser from reader", ioe); - } - - if (parser != null) { - NitriteJsonImporter jsonImporter = new NitriteJsonImporter(db); - jsonImporter.setParser(parser); - try { - jsonImporter.importData(); - } catch (IOException | ClassNotFoundException e) { - throw new NitriteIOException("Error while importing data", e); - } - } - } -} + import com.fasterxml.jackson.core.JsonFactory; + import com.fasterxml.jackson.core.JsonParser; + import com.fasterxml.jackson.databind.ObjectMapper; + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.exceptions.NitriteIOException; + + import java.io.*; + + import static org.dizitart.no2.common.util.ValidationUtils.notNull; + import static org.dizitart.no2.support.Exporter.createObjectMapper; + + + /** + * Nitrite database import utility. It imports data from + * a json file. Contents of a Nitrite database can be imported + * using this tool. + *

+ * + * @author Anindya Chatterjee + * @since 1.0 + */ + public class Importer { + private ImportOptions options; + + private Importer() { + } + + /** + * Creates a new Importer with specified ImportOptions. + * + * @param importOptions The ImportOptions to be used. + * @return A new Importer object. + */ + public static Importer withOptions(ImportOptions importOptions) { + Importer importer = new Importer(); + notNull(importOptions, "importOptions cannot be null"); + notNull(importOptions.getNitriteFactory(), "nitriteFactory cannot be null"); + + if (importOptions.getJsonFactory() == null) { + importOptions.setJsonFactory(createObjectMapper().getFactory()); + } + + importer.options = importOptions; + return importer; + } + + /** + * Imports data from a file path. + * + * @param file the file path + */ + public void importFrom(String file) { + importFrom(new File(file)); + } + + /** + * Imports data from a file. + * + * @param file the file + * @throws NitriteIOException if there is any low-level I/O error. + */ + public void importFrom(File file) { + try (FileInputStream stream = new FileInputStream(file)) { + importFrom(stream); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while reading content from file " + file, ioe); + } + } + + /** + * Imports data from an {@link InputStream}. + * + * @param stream the stream + */ + public void importFrom(InputStream stream) throws IOException { + try(InputStreamReader reader = new InputStreamReader(stream)) { + importFrom(reader); + } + } + + /** + * Imports data from a {@link Reader}. + * + * @param reader the reader + * @throws NitriteIOException if there is any error while reading the data. + */ + public void importFrom(Reader reader) { + JsonParser parser; + try { + parser = options.getJsonFactory().createParser(reader); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while creating parser from reader", ioe); + } + + if (parser != null) { + NitriteJsonImporter jsonImporter = new NitriteJsonImporter(); + jsonImporter.setParser(parser); + jsonImporter.setOptions(options); + try { + jsonImporter.importData(); + } catch (IOException | ClassNotFoundException e) { + throw new NitriteIOException("Error while importing data", e); + } + } + } + } + \ No newline at end of file diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 9bda82747..78760a9a7 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -14,245 +14,195 @@ * limitations under the License. */ -package org.dizitart.no2.support; - -import com.fasterxml.jackson.core.JsonGenerator; -import lombok.Setter; -import org.apache.commons.codec.binary.Hex; -import org.dizitart.no2.Nitrite; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.DocumentCursor; -import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.collection.operation.IndexManager; -import org.dizitart.no2.common.PersistentCollection; -import org.dizitart.no2.exceptions.NitriteIOException; -import org.dizitart.no2.index.IndexDescriptor; -import org.dizitart.no2.repository.ObjectRepository; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.*; -import java.util.stream.Collectors; - -import static org.dizitart.no2.common.Constants.*; -import static org.dizitart.no2.common.util.ObjectUtils.*; - -/** - * @author Anindya Chatterjee - */ -@Setter -class NitriteJsonExporter { - private JsonGenerator generator; - private ExportOptions options; - - public void exportData() throws IOException, ClassNotFoundException { - Nitrite db = options.getNitriteFactory().create(); - Set collectionNames = db.listCollectionNames(); - Set repositoryNames = db.listRepositories(); - Map> keyedRepositoryNames = db.listKeyedRepositories(); - List indexDescriptors = new ArrayList<>(); - - if (!options.getCollections().isEmpty()) { - collectionNames = new HashSet<>(options.getCollections()); - } - - if (!options.getRepositories().isEmpty()) { - repositoryNames = new HashSet<>(options.getRepositories()); - } - - if (!options.getKeyedRepositories().isEmpty()) { - keyedRepositoryNames = options.getKeyedRepositories(); - } - - if (options.isExportIndices()) { - for (String collectionName : collectionNames) { - IndexManager indexManager = new IndexManager(collectionName, db.getConfig()); - indexDescriptors.addAll(indexManager.getIndexDescriptors()); - } - - for (String repositoryName : repositoryNames) { - IndexManager indexManager = new IndexManager(repositoryName, db.getConfig()); - indexDescriptors.addAll(indexManager.getIndexDescriptors()); - } - - for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { - String key = entry.getKey(); - Set enttityNameSet = entry.getValue(); - for (String entityName : enttityNameSet) { - String repositoryName = findRepositoryName(key, entityName); - IndexManager indexManager = new IndexManager(repositoryName, db.getConfig()); - indexDescriptors.addAll(indexManager.getIndexDescriptors()); - } - } - } - - - - List> collections = options.getCollections(); - Set collectionNames; - Set repositoryNames; - Map> keyedRepositoryNames; - if (collections.isEmpty()) { - collectionNames = db.listCollectionNames(); - repositoryNames = db.listRepositories(); - keyedRepositoryNames = db.listKeyedRepositories(); - } else { - collectionNames = new HashSet<>(); - repositoryNames = new HashSet<>(); - keyedRepositoryNames = new HashMap<>(); - for (PersistentCollection collection : collections) { - String name; - if (collection instanceof NitriteCollection) { - NitriteCollection nitriteCollection = (NitriteCollection) collection; - name = nitriteCollection.getName(); - collectionNames.add(name); - } else if (collection instanceof ObjectRepository) { - ObjectRepository repository = (ObjectRepository) collection; - name = repository.getDocumentCollection().getName(); - if (name.contains(KEY_OBJ_SEPARATOR)) { - String key = getKeyName(name); - String type = getKeyedRepositoryType(name); - Set types; - if (keyedRepositoryNames.containsKey(key)) { - types = keyedRepositoryNames.get(key); - } else { - types = new LinkedHashSet<>(); - } - types.add(type); - keyedRepositoryNames.put(key, types); - } else { - repositoryNames.add(name); - } - } - } - } - exportData(collectionNames, repositoryNames, keyedRepositoryNames); - generator.close(); - } - - private void exportData(Set collectionNames, - Set repositoryNames, - Map> keyedRepositoryNames) throws IOException, ClassNotFoundException { - generator.writeStartObject(); - - generator.writeFieldName(TAG_COLLECTIONS); - generator.writeStartArray(); - for (String collectionName : collectionNames) { - NitriteCollection nitriteCollection = db.getCollection(collectionName); - writeCollection(nitriteCollection); - } - generator.writeEndArray(); - - generator.writeFieldName(TAG_REPOSITORIES); - generator.writeStartArray(); - for (String repoName : repositoryNames) { - Class type = Class.forName(repoName); - ObjectRepository repository = db.getRepository(type); - writeRepository(repository); - } - generator.writeEndArray(); - - generator.writeFieldName(TAG_KEYED_REPOSITORIES); - generator.writeStartArray(); - for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { - String key = entry.getKey(); - Set typeNames = entry.getValue(); - for (String typeName : typeNames) { - Class type = Class.forName(typeName); - ObjectRepository repository = db.getRepository(type, key); - writeKeyedRepository(key, repository); - } - } - generator.writeEndArray(); - - generator.writeEndObject(); - } - - - private void writeRepository(ObjectRepository repository) throws IOException { - generator.writeStartObject(); - generator.writeFieldName(TAG_TYPE); - generator.writeString(repository.getType().getName()); - - Collection indices = repository.listIndices(); - writeIndices(indices); - - DocumentCursor cursor = repository.getDocumentCollection().find(); - writeContent(cursor); - generator.writeEndObject(); - } - - private void writeKeyedRepository(String key, ObjectRepository repository) throws IOException { - generator.writeStartObject(); - - generator.writeFieldName(TAG_KEY); - generator.writeString(key); - - generator.writeFieldName(TAG_TYPE); - generator.writeString(repository.getType().getName()); - - Collection indices = repository.listIndices(); - writeIndices(indices); - - DocumentCursor cursor = repository.getDocumentCollection().find(); - writeContent(cursor); - generator.writeEndObject(); - } - - private void writeCollection(NitriteCollection nitriteCollection) throws IOException { - generator.writeStartObject(); - generator.writeFieldName(TAG_NAME); - generator.writeString(nitriteCollection.getName()); - - Collection indices = nitriteCollection.listIndices(); - writeIndices(indices); - - DocumentCursor cursor = nitriteCollection.find(); - writeContent(cursor); - generator.writeEndObject(); - } - - private void writeIndices(Collection indices) throws IOException { - generator.writeFieldName(TAG_INDICES); - generator.writeStartArray(); - if (options.isExportIndices()) { - for (IndexDescriptor index : indices) { - generator.writeStartObject(); - generator.writeFieldName(TAG_INDEX); - generator.writeObject(writeEncodedObject(index)); - generator.writeEndObject(); - } - } - generator.writeEndArray(); - } - - private void writeContent(DocumentCursor cursor) throws IOException { - generator.writeFieldName(TAG_DATA); - generator.writeStartArray(); - if (options.isExportData()) { - for (Document document : cursor) { - generator.writeStartObject(); - generator.writeFieldName(TAG_KEY); - generator.writeObject(writeEncodedObject(document.get(DOC_ID))); - - generator.writeFieldName(TAG_VALUE); - generator.writeObject(writeEncodedObject(document)); - generator.writeEndObject(); - } - } - generator.writeEndArray(); - } - - private String writeEncodedObject(Object object) { - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - try (ObjectOutputStream oos = new ObjectOutputStream(os)) { - oos.writeObject(object); - byte[] data = os.toByteArray(); - return Hex.encodeHexString(data); - } - } catch (IOException e) { - throw new NitriteIOException("Failed to write object", e); - } - } -} + package org.dizitart.no2.support; + + import com.fasterxml.jackson.core.JsonGenerator; + import lombok.Setter; + import org.apache.commons.codec.binary.Hex; + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.collection.Document; + import org.dizitart.no2.collection.DocumentCursor; + import org.dizitart.no2.collection.NitriteCollection; + import org.dizitart.no2.collection.NitriteId; + import org.dizitart.no2.collection.operation.IndexManager; + import org.dizitart.no2.common.tuples.Pair; + import org.dizitart.no2.exceptions.NitriteIOException; + import org.dizitart.no2.index.IndexDescriptor; + import org.dizitart.no2.repository.ObjectRepository; + import org.dizitart.no2.store.NitriteMap; + import org.dizitart.no2.store.NitriteStore; + + import java.io.ByteArrayOutputStream; + import java.io.IOException; + import java.io.ObjectOutputStream; + import java.util.*; + import java.util.stream.Collectors; + + import static org.dizitart.no2.common.Constants.*; + import static org.dizitart.no2.common.util.ObjectUtils.*; + + /** + * @author Anindya Chatterjee + */ + @Setter + class NitriteJsonExporter { + private JsonGenerator generator; + private ExportOptions options; + + public void exportData() throws IOException, ClassNotFoundException { + try(Nitrite db = options.getNitriteFactory().create()) { + Set collectionNames = options.getCollections() == null ? db.listCollectionNames() : Set.of(); + Set repositoryNames = options.getRepositories() == null ? db.listRepositories() : Set.of(); + Map> keyedRepositoryNames = options.getKeyedRepositories() == null + ? db.listKeyedRepositories() : Map.of(); + + List indexDescriptors = new ArrayList<>(); + if (options.getCollections() != null && !options.getCollections().isEmpty()) { + collectionNames = new HashSet<>(options.getCollections()); + } + + if (options.getRepositories() != null && !options.getRepositories().isEmpty()) { + repositoryNames = new HashSet<>(options.getRepositories()); + } + + if (options.getKeyedRepositories() != null && !options.getKeyedRepositories().isEmpty()) { + keyedRepositoryNames = options.getKeyedRepositories(); + } + + if (options.isExportIndices()) { + for (String collectionName : collectionNames) { + try(IndexManager indexManager = new IndexManager(collectionName, db.getConfig())) { + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + } + + for (String repositoryName : repositoryNames) { + try(IndexManager indexManager = new IndexManager(repositoryName, db.getConfig())) { + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + } + + for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { + String key = entry.getKey(); + Set enttityNameSet = entry.getValue(); + for (String entityName : enttityNameSet) { + String repositoryName = findRepositoryName(key, entityName); + try(IndexManager indexManager = new IndexManager(repositoryName, db.getConfig())) { + indexDescriptors.addAll(indexManager.getIndexDescriptors()); + } + } + } + } + + exportData(db, collectionNames, repositoryNames, keyedRepositoryNames, indexDescriptors); + generator.close(); + } + } + + private void exportData(Nitrite db, + Set collectionNames, + Set repositoryNames, + Map> keyedRepositoryNames, + List indexDescriptors) throws IOException { + NitriteStore nitriteStore = db.getStore(); + + generator.writeStartObject(); + + writeMaps(collectionNames, indexDescriptors, nitriteStore, TAG_COLLECTIONS); + + writeMaps(repositoryNames, indexDescriptors, nitriteStore, TAG_REPOSITORIES); + + writeKeyedMaps(keyedRepositoryNames, indexDescriptors, nitriteStore); + + generator.writeEndObject(); + } + + private void writeMaps(Set mapNames, List indexDescriptors, + NitriteStore nitriteStore, String tagName) throws IOException { + generator.writeFieldName(tagName); + generator.writeStartArray(); + for (String mapName : mapNames) { + try(NitriteMap nitriteMap + = nitriteStore.openMap(mapName, NitriteId.class, Document.class)) { + List indexes = indexDescriptors.stream().filter(d -> + mapName.equalsIgnoreCase(d.getCollectionName())).collect(Collectors.toList()); + writeNitriteMap(nitriteMap, indexes); + } + } + generator.writeEndArray(); + } + + private void writeKeyedMaps(Map> keyedMapNames, List indexDescriptors, + NitriteStore nitriteStore) throws IOException { + generator.writeFieldName(TAG_KEYED_REPOSITORIES); + generator.writeStartArray(); + for (Map.Entry> entry : keyedMapNames.entrySet()) { + String key = entry.getKey(); + Set typeNames = entry.getValue(); + for (String typeName : typeNames) { + String repoName = findRepositoryName(typeName, key); + try(NitriteMap nitriteMap + = nitriteStore.openMap(repoName, NitriteId.class, Document.class)) { + List indexes = indexDescriptors.stream().filter(d -> + repoName.equalsIgnoreCase(d.getCollectionName())).collect(Collectors.toList()); + writeNitriteMap(nitriteMap, indexes); + } + } + } + generator.writeEndArray(); + } + + private void writeNitriteMap(NitriteMap nitriteMap, + List indexes) throws IOException { + generator.writeStartObject(); + generator.writeFieldName(TAG_NAME); + generator.writeString(nitriteMap.getName()); + writeIndices(indexes); + writeContent(nitriteMap); + generator.writeEndObject(); + } + + private void writeIndices(Collection indices) throws IOException { + generator.writeFieldName(TAG_INDICES); + generator.writeStartArray(); + if (options.isExportIndices()) { + for (IndexDescriptor index : indices) { + generator.writeStartObject(); + generator.writeFieldName(TAG_INDEX); + generator.writeObject(writeEncodedObject(index)); + generator.writeEndObject(); + } + } + generator.writeEndArray(); + } + + private void writeContent(NitriteMap nitriteMap) throws IOException { + generator.writeFieldName(TAG_DATA); + generator.writeStartArray(); + if (options.isExportData()) { + for (Pair entry : nitriteMap.entries()) { + generator.writeStartObject(); + generator.writeFieldName(TAG_KEY); + generator.writeObject(writeEncodedObject(entry.getFirst())); + + generator.writeFieldName(TAG_VALUE); + generator.writeObject(writeEncodedObject(entry.getSecond())); + generator.writeEndObject(); + } + } + generator.writeEndArray(); + } + + private String writeEncodedObject(Object object) { + try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { + try (ObjectOutputStream oos = new ObjectOutputStream(os)) { + oos.writeObject(object); + byte[] data = os.toByteArray(); + return Hex.encodeHexString(data); + } + } catch (IOException e) { + throw new NitriteIOException("Failed to write object", e); + } + } + } + \ No newline at end of file diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java index 059b21c5c..1f83c83b2 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java @@ -14,220 +14,162 @@ * limitations under the License. */ -package org.dizitart.no2.support; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import org.apache.commons.codec.binary.Hex; -import org.dizitart.no2.Nitrite; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.PersistentCollection; -import org.dizitart.no2.exceptions.NitriteIOException; -import org.dizitart.no2.index.IndexDescriptor; -import org.dizitart.no2.repository.ObjectRepository; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import static org.dizitart.no2.common.Constants.*; -import static org.dizitart.no2.index.IndexOptions.indexOptions; - -/** - * @author Anindya Chatterjee. - */ -class NitriteJsonImporter { - private JsonParser parser; - private final Nitrite db; - - public NitriteJsonImporter(Nitrite db) { - this.db = db; - } - - public void setParser(JsonParser parser) { - this.parser = parser; - } - - public void importData() throws IOException, ClassNotFoundException { - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_COLLECTIONS.equals(fieldName)) { - readCollection(); - } - - if (TAG_REPOSITORIES.equals(fieldName)) { - readRepository(); - } - - if (TAG_KEYED_REPOSITORIES.equals(fieldName)) { - readKeyedRepository(); - } - } - } - - private void readRepository() throws IOException, ClassNotFoundException { - ObjectRepository repository = null; - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_TYPE.equals(fieldName)) { - // move to next token - parser.nextToken(); - - String typeId = parser.getText(); - Class type = Class.forName(typeId); - repository = db.getRepository(type); - } - - if (TAG_INDICES.equals(fieldName)) { - readIndices(repository); - } - - if (TAG_DATA.equals(fieldName) && repository != null) { - readCollectionData(repository.getDocumentCollection()); - } - } - } - } - - private void readKeyedRepository() throws IOException, ClassNotFoundException { - ObjectRepository repository = null; - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - String key = null; - - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_KEY.equals(fieldName)) { - parser.nextToken(); - key = parser.getText(); - } - - if (key != null && TAG_TYPE.equals(fieldName)) { - // move to next token - parser.nextToken(); - - String typeId = parser.getText(); - Class type = Class.forName(typeId); - repository = db.getRepository(type, key); - } - - if (TAG_INDICES.equals(fieldName)) { - readIndices(repository); - } - - if (TAG_DATA.equals(fieldName) && repository != null) { - readCollectionData(repository.getDocumentCollection()); - } - } - } - } - - private void readCollection() throws IOException { - NitriteCollection collection = null; - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_NAME.equals(fieldName)) { - // move to next token - parser.nextToken(); - - String collectionName = parser.getText(); - collection = db.getCollection(collectionName); - } - - if (TAG_INDICES.equals(fieldName)) { - readIndices(collection); - } - - if (TAG_DATA.equals(fieldName)) { - readCollectionData(collection); - } - } - } - } - - private void readIndices(PersistentCollection collection) throws IOException { - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_INDEX.equals(fieldName)) { - parser.nextToken(); - String data = parser.readValueAs(String.class); - IndexDescriptor index = (IndexDescriptor) readEncodedObject(data); - if (index != null) { - String[] fieldNames = index.getFields().getFieldNames().toArray(new String[0]); - if (collection != null && index.getFields() != null && !collection.hasIndex(fieldNames)) { - collection.createIndex(indexOptions(index.getIndexType()), fieldNames); - } - } - } - } - } - } - - private void readCollectionData(NitriteCollection collection) throws IOException { - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_KEY.equals(fieldName)) { - parser.nextToken(); - parser.readValueAs(String.class); - } - - if (TAG_VALUE.equals(fieldName)) { - parser.nextToken(); - String data = parser.readValueAs(String.class); - Document document = (Document) readEncodedObject(data); - if (collection != null) { - collection.insert(document); - } - } - } - } - } - - private Object readEncodedObject(String hexString) { - try { - byte[] data = Hex.decodeHex(hexString); - try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { - try (ObjectInputStream ois = new ObjectInputStream(is)) { - return ois.readObject(); - } - } - } catch (Exception e) { - throw new NitriteIOException("Error while reading data", e); - } - } -} + package org.dizitart.no2.support; + + import com.fasterxml.jackson.core.JsonParser; + import com.fasterxml.jackson.core.JsonToken; + import lombok.Setter; + import org.apache.commons.codec.binary.Hex; + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.collection.Document; + import org.dizitart.no2.collection.NitriteCollection; + import org.dizitart.no2.collection.NitriteId; + import org.dizitart.no2.collection.operation.IndexManager; + import org.dizitart.no2.common.PersistentCollection; + import org.dizitart.no2.exceptions.NitriteIOException; + import org.dizitart.no2.index.IndexDescriptor; + import org.dizitart.no2.repository.ObjectRepository; + import org.dizitart.no2.store.NitriteMap; + import org.dizitart.no2.store.NitriteStore; + + import java.io.ByteArrayInputStream; + import java.io.IOException; + import java.io.ObjectInputStream; + import java.util.ArrayList; + import java.util.List; + + import static org.dizitart.no2.common.Constants.*; + import static org.dizitart.no2.index.IndexOptions.indexOptions; + + /** + * @author Anindya Chatterjee. + */ + @Setter + class NitriteJsonImporter { + private JsonParser parser; + private ImportOptions options; + + public void importData() throws IOException, ClassNotFoundException { + try (Nitrite db = options.getNitriteFactory().create()) { + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_COLLECTIONS.equals(fieldName)) { + readNitriteMap(db); + } + + if (TAG_REPOSITORIES.equals(fieldName)) { + readNitriteMap(db); + } + + if (TAG_KEYED_REPOSITORIES.equals(fieldName)) { + readNitriteMap(db); + } + } + } + } + + private void readNitriteMap(Nitrite db) throws IOException { + // move to [ + parser.nextToken(); + NitriteStore nitriteStore = db.getStore(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + NitriteMap nitriteMap = null; + List indexDescriptors = new ArrayList<>(); + + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_NAME.equals(fieldName)) { + // move to next token + parser.nextToken(); + + String mapName = parser.getText(); + nitriteMap = nitriteStore.openMap(mapName, NitriteId.class, Document.class); + } + + if (TAG_INDICES.equals(fieldName)) { + indexDescriptors = readIndices(); + } + + if (TAG_DATA.equals(fieldName) && nitriteMap != null) { + readNitriteMapData(nitriteMap); + + // write index information + try(IndexManager indexManager = new IndexManager(nitriteMap.getName(), db.getConfig())) { + // during next data insertion, index will be rebuilt + indexDescriptors.forEach(indexManager::markIndexDirty); + } + } + } + } + } + + private List readIndices() throws IOException { + List indexDescriptors = new ArrayList<>(); + // move to [ + parser.nextToken(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_INDEX.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + IndexDescriptor index = (IndexDescriptor) readEncodedObject(data); + indexDescriptors.add(index); + } + } + } + return indexDescriptors; + } + + private void readNitriteMapData(NitriteMap nitriteMap) throws IOException { + // move to [ + parser.nextToken(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + NitriteId nitriteId = null; + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_KEY.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + nitriteId = (NitriteId) readEncodedObject(data); + } + + if (TAG_VALUE.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + Document document = (Document) readEncodedObject(data); + if (nitriteMap != null) { + nitriteMap.put(nitriteId, document); + } + } + } + } + } + + private Object readEncodedObject(String hexString) { + try { + byte[] data = Hex.decodeHex(hexString); + try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { + try (ObjectInputStream ois = new ObjectInputStream(is)) { + return ois.readObject(); + } + } + } catch (Exception e) { + throw new NitriteIOException("Error while reading data", e); + } + } + } + \ No newline at end of file diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java index 98a84d3a5..6733ec0ea 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java @@ -14,111 +14,117 @@ * limitations under the License. */ -package org.dizitart.no2.support; - -import org.dizitart.no2.Nitrite; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; -import org.dizitart.no2.mvstore.MVStoreModule; -import org.dizitart.no2.repository.ObjectRepository; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; -import java.util.UUID; - -import static org.dizitart.no2.common.Constants.*; -import static org.dizitart.no2.common.util.Iterables.setOf; -import static org.junit.Assert.assertTrue; - -/** - * @author Anindya Chatterjee. - */ -public abstract class BaseExternalTest { - protected ObjectRepository sourceEmpRepo; - protected ObjectRepository sourceKeyedEmpRepo; - protected ObjectRepository sourceCompRepo; - protected NitriteCollection sourceFirstColl; - protected NitriteCollection sourceSecondColl; - protected Nitrite sourceDb; - protected Nitrite destDb; - protected String schemaFile; - private String sourceDbFile; - private String destDbFile; - - @Rule - public Retry retry = new Retry(3); - - public static String getRandomTempDbFile() { - String dataDir = System.getProperty("java.io.tmpdir") + File.separator + "nitrite" + File.separator + "data"; - File file = new File(dataDir); - if (!file.exists()) { - assertTrue(file.mkdirs()); - } - return file.getPath() + File.separator + UUID.randomUUID() + ".db"; - } - - @Before - public void setUp() { - sourceDbFile = getRandomTempDbFile(); - destDbFile = getRandomTempDbFile(); - - sourceDb = createDb(sourceDbFile); - - destDb = createDb(destDbFile); - - sourceEmpRepo = sourceDb.getRepository(Employee.class); - sourceKeyedEmpRepo = sourceDb.getRepository(Employee.class, "key"); - sourceCompRepo = sourceDb.getRepository(Company.class); - - sourceFirstColl = sourceDb.getCollection("first"); - sourceSecondColl = sourceDb.getCollection("second"); - } - - @After - public void cleanUp() throws IOException { - sourceFirstColl.close(); - sourceSecondColl.close(); - sourceEmpRepo.close(); - sourceCompRepo.close(); - - sourceDb.close(); - destDb.close(); - - Files.delete(Paths.get(sourceDbFile)); - Files.delete(Paths.get(destDbFile)); - Files.delete(Paths.get(schemaFile)); - } - - protected List filter(List documents) { - for (Document document : documents) { - document.remove(DOC_REVISION); - document.remove(DOC_MODIFIED); - document.remove(DOC_SOURCE); - } - return documents; - } - - private Nitrite createDb(String filePath) { - MVStoreModule storeModule = MVStoreModule.withConfig() - .filePath(filePath) - .build(); - - SimpleDocumentMapper documentMapper = new SimpleDocumentMapper(); - documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); - documentMapper.registerEntityConverter(new Company.CompanyConverter()); - documentMapper.registerEntityConverter(new Note.NoteConverter()); - - return Nitrite.builder() - .loadModule(storeModule) - .loadModule(() -> setOf(documentMapper)) - .fieldSeparator(".") - .openOrCreate(); - } -} + package org.dizitart.no2.support; + + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.collection.Document; + import org.dizitart.no2.collection.NitriteCollection; + import org.dizitart.no2.common.mapper.SimpleDocumentMapper; + import org.dizitart.no2.mvstore.MVStoreModule; + import org.dizitart.no2.repository.ObjectRepository; + import org.junit.After; + import org.junit.Before; + import org.junit.Rule; + + import java.io.File; + import java.io.IOException; + import java.nio.file.Files; + import java.nio.file.Paths; + import java.util.List; + import java.util.UUID; + + import static org.dizitart.no2.common.Constants.*; + import static org.dizitart.no2.common.module.NitriteModule.module; + import static org.junit.Assert.assertTrue; + + /** + * @author Anindya Chatterjee. + */ + public abstract class BaseExternalTest { + protected ObjectRepository sourceEmpRepo; + protected ObjectRepository sourceKeyedEmpRepo; + protected ObjectRepository sourceCompRepo; + protected NitriteCollection sourceFirstColl; + protected NitriteCollection sourceSecondColl; + protected Nitrite sourceDb; + protected Nitrite destDb; + protected String schemaFile; + protected String sourceDbFile; + protected String destDbFile; + + @Rule + public Retry retry = new Retry(3); + + @Before + public void setUp() { + sourceDbFile = getRandomTempDbFile(); + destDbFile = getRandomTempDbFile(); + openDb(); + } + + @After + public void cleanUp() throws IOException { + closeDb(); + Files.delete(Paths.get(sourceDbFile)); + Files.delete(Paths.get(destDbFile)); + Files.delete(Paths.get(schemaFile)); + } + + public static String getRandomTempDbFile() { + String dataDir = System.getProperty("java.io.tmpdir") + File.separator + "nitrite" + File.separator + "data"; + File file = new File(dataDir); + if (!file.exists()) { + assertTrue(file.mkdirs()); + } + return file.getPath() + File.separator + UUID.randomUUID() + ".db"; + } + + protected void openDb() { + sourceDb = createDb(sourceDbFile); + destDb = createDb(destDbFile); + + sourceEmpRepo = sourceDb.getRepository(Employee.class); + sourceKeyedEmpRepo = sourceDb.getRepository(Employee.class, "key"); + sourceCompRepo = sourceDb.getRepository(Company.class); + + sourceFirstColl = sourceDb.getCollection("first"); + sourceSecondColl = sourceDb.getCollection("second"); + } + + protected void closeDb() { + sourceFirstColl.close(); + sourceSecondColl.close(); + sourceEmpRepo.close(); + sourceCompRepo.close(); + + sourceDb.close(); + destDb.close(); + } + + protected List filter(List documents) { + for (Document document : documents) { + document.remove(DOC_REVISION); + document.remove(DOC_MODIFIED); + document.remove(DOC_SOURCE); + } + return documents; + } + + protected Nitrite createDb(String filePath) { + MVStoreModule storeModule = MVStoreModule.withConfig() + .filePath(filePath) + .build(); + + SimpleDocumentMapper documentMapper = new SimpleDocumentMapper(); + documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); + documentMapper.registerEntityConverter(new Company.CompanyConverter()); + documentMapper.registerEntityConverter(new Note.NoteConverter()); + + return Nitrite.builder() + .loadModule(storeModule) + .loadModule(module(documentMapper)) + .fieldSeparator(".") + .openOrCreate(); + } + } + \ No newline at end of file diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java index 1523eff59..b7e9bf341 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java @@ -14,79 +14,84 @@ * limitations under the License. */ -package org.dizitart.no2.support; - -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.PersistentCollection; -import org.dizitart.no2.index.IndexDescriptor; -import org.dizitart.no2.repository.ObjectRepository; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.Random; - -import static org.dizitart.no2.collection.Document.createDocument; -import static org.junit.Assert.assertEquals; - -/** - * @author Anindya Chatterjee. - */ -public class ExporterImporterOptionTest extends BaseExternalTest { - - @Test - public void testImportExportSingle() { - schemaFile = System.getProperty("java.io.tmpdir") + File.separator - + "nitrite" + File.separator + "single-schema.json"; - - Random random = new Random(); - for (int i = 0; i < 5; i++) { - sourceEmpRepo.insert(DataGenerator.generateEmployee()); - sourceKeyedEmpRepo.insert(DataGenerator.generateEmployee()); - - Document document = createDocument("first-field", random.nextGaussian()); - sourceFirstColl.insert(document); - } - - Exporter exporter = Exporter.of(sourceDb); - exporter.withOptions(new ExportOptions() {{ - setCollections(new ArrayList>() {{ - add(sourceEmpRepo); - add(sourceKeyedEmpRepo); - add(sourceFirstColl); - }}); - }}); - exporter.exportTo(schemaFile); - - Importer importer = Importer.of(destDb); - importer.importFrom(schemaFile); - - ObjectRepository destEmpRepo = destDb.getRepository(Employee.class); - ObjectRepository destKeyedEmpRepo = destDb.getRepository(Employee.class, "key"); - NitriteCollection destFirstColl = destDb.getCollection("first"); - - assertEquals(filter(sourceFirstColl.find().toList()), - filter(destFirstColl.find().toList())); - assertEquals(sourceEmpRepo.find().toList(), - destEmpRepo.find().toList()); - assertEquals(sourceKeyedEmpRepo.find().toList(), - destKeyedEmpRepo.find().toList()); - - assertEquals(sourceEmpRepo.listIndices(), destEmpRepo.listIndices()); - assertEquals(sourceKeyedEmpRepo.listIndices(), destKeyedEmpRepo.listIndices()); - assertEquals(sourceFirstColl.listIndices(), destFirstColl.listIndices()); - - ObjectRepository destCompRepo = destDb.getRepository(Company.class); - NitriteCollection destSecondColl = destDb.getCollection("second"); - - assertEquals(filter(destSecondColl.find().toList()), - new ArrayList()); - assertEquals(destCompRepo.find().toList(), - new ArrayList()); - - assertEquals(destCompRepo.listIndices(), sourceCompRepo.listIndices()); - assertEquals(destSecondColl.listIndices(), new LinkedHashSet()); - } -} + package org.dizitart.no2.support; + + import org.dizitart.no2.Nitrite; + import org.dizitart.no2.collection.Document; + import org.dizitart.no2.collection.NitriteCollection; + import org.dizitart.no2.common.PersistentCollection; + import org.dizitart.no2.index.IndexDescriptor; + import org.dizitart.no2.repository.ObjectRepository; + import org.junit.Test; + + import java.io.File; + import java.util.*; + + import static org.dizitart.no2.collection.Document.createDocument; + import static org.junit.Assert.assertEquals; + + /** + * @author Anindya Chatterjee. + */ + public class ExporterImporterOptionTest extends BaseExternalTest { + + @Test + public void testImportExportSingle() { + schemaFile = System.getProperty("java.io.tmpdir") + File.separator + + "nitrite" + File.separator + "single-schema.json"; + + Random random = new Random(); + for (int i = 0; i < 5; i++) { + sourceEmpRepo.insert(DataGenerator.generateEmployee()); + sourceKeyedEmpRepo.insert(DataGenerator.generateEmployee()); + + Document document = createDocument("first-field", random.nextGaussian()); + sourceFirstColl.insert(document); + } + closeDb(); + + ExportOptions exportOptions = new ExportOptions(); + exportOptions.setNitriteFactory(() -> createDb(sourceDbFile)); + exportOptions.setCollections(List.of("first")); + exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee")); + exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee"))); + + Exporter exporter = Exporter.withOptions(exportOptions); + exporter.exportTo(schemaFile); + + ImportOptions importOptions = new ImportOptions(); + importOptions.setNitriteFactory(() -> createDb(destDbFile)); + + Importer importer = Importer.withOptions(importOptions); + importer.importFrom(schemaFile); + + openDb(); + + ObjectRepository destEmpRepo = destDb.getRepository(Employee.class); + ObjectRepository destKeyedEmpRepo = destDb.getRepository(Employee.class, "key"); + NitriteCollection destFirstColl = destDb.getCollection("first"); + + assertEquals(filter(sourceFirstColl.find().toList()), + filter(destFirstColl.find().toList())); + assertEquals(sourceEmpRepo.find().toList(), + destEmpRepo.find().toList()); + assertEquals(sourceKeyedEmpRepo.find().toList(), + destKeyedEmpRepo.find().toList()); + + assertEquals(sourceEmpRepo.listIndices(), destEmpRepo.listIndices()); + assertEquals(sourceKeyedEmpRepo.listIndices(), destKeyedEmpRepo.listIndices()); + assertEquals(sourceFirstColl.listIndices(), destFirstColl.listIndices()); + + ObjectRepository destCompRepo = destDb.getRepository(Company.class); + NitriteCollection destSecondColl = destDb.getCollection("second"); + + assertEquals(filter(destSecondColl.find().toList()), + new ArrayList()); + assertEquals(destCompRepo.find().toList(), + new ArrayList()); + + assertEquals(destCompRepo.listIndices(), sourceCompRepo.listIndices()); + assertEquals(destSecondColl.listIndices(), new LinkedHashSet()); + } + } + \ No newline at end of file diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java index 2f6dd5014..5bf5c9681 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java @@ -14,70 +14,87 @@ * limitations under the License. */ -package org.dizitart.no2.support; + package org.dizitart.no2.support; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.repository.ObjectRepository; -import org.junit.Test; - -import java.io.File; -import java.util.Random; - -import static org.dizitart.no2.collection.Document.createDocument; -import static org.junit.Assert.assertEquals; - -/** - * @author Anindya Chatterjee. - */ -public class ExporterImporterTest extends BaseExternalTest { - - @Test - public void testImportExport() { - schemaFile = System.getProperty("java.io.tmpdir") + File.separator - + "nitrite" + File.separator + "schema.json"; - - Random random = new Random(); - for (int i = 0; i < 5; i++) { - sourceEmpRepo.insert(DataGenerator.generateEmployee()); - sourceKeyedEmpRepo.insert(DataGenerator.generateEmployee()); - sourceCompRepo.insert(DataGenerator.generateCompanyRecord()); - - Document document = createDocument("first-field", random.nextGaussian()); - sourceFirstColl.insert(document); - - document = createDocument("second-field", random.nextLong()); - sourceSecondColl.insert(document); - } - - Exporter exporter = Exporter.of(sourceDb); - exporter.exportTo(schemaFile); - - Importer importer = Importer.of(destDb); - importer.importFrom(schemaFile); - - NitriteCollection destFirstColl = destDb.getCollection("first"); - NitriteCollection destSecondColl = destDb.getCollection("second"); - ObjectRepository destEmpRepo = destDb.getRepository(Employee.class); - ObjectRepository destKeyedEmpRepo = destDb.getRepository(Employee.class, "key"); - ObjectRepository destCompRepo = destDb.getRepository(Company.class); - - assertEquals(filter(sourceFirstColl.find().toList()), - filter(destFirstColl.find().toList())); - assertEquals(filter(sourceSecondColl.find().toList()), - filter(destSecondColl.find().toList())); - - assertEquals(sourceEmpRepo.find().toList(), - destEmpRepo.find().toList()); - assertEquals(sourceKeyedEmpRepo.find().toList(), - destKeyedEmpRepo.find().toList()); - assertEquals(sourceCompRepo.find().toList(), - destCompRepo.find().toList()); - - assertEquals(sourceEmpRepo.listIndices(), destEmpRepo.listIndices()); - assertEquals(sourceKeyedEmpRepo.listIndices(), destKeyedEmpRepo.listIndices()); - assertEquals(sourceCompRepo.listIndices(), destCompRepo.listIndices()); - assertEquals(sourceFirstColl.listIndices(), destFirstColl.listIndices()); - assertEquals(sourceSecondColl.listIndices(), destSecondColl.listIndices()); - } -} + import org.dizitart.no2.collection.Document; + import org.dizitart.no2.collection.NitriteCollection; + import org.dizitart.no2.repository.ObjectRepository; + import org.junit.Test; + + import java.io.File; + import java.util.List; + import java.util.Map; + import java.util.Random; + import java.util.Set; + + import static org.dizitart.no2.collection.Document.createDocument; + import static org.junit.Assert.*; + + /** + * @author Anindya Chatterjee. + */ + public class ExporterImporterTest extends BaseExternalTest { + + @Test + public void testImportExport() { + schemaFile = System.getProperty("java.io.tmpdir") + File.separator + + "nitrite" + File.separator + "schema.json"; + + Random random = new Random(); + for (int i = 0; i < 5; i++) { + sourceEmpRepo.insert(DataGenerator.generateEmployee()); + sourceKeyedEmpRepo.insert(DataGenerator.generateEmployee()); + sourceCompRepo.insert(DataGenerator.generateCompanyRecord()); + + Document document = createDocument("first-field", random.nextGaussian()); + sourceFirstColl.insert(document); + + document = createDocument("second-field", random.nextLong()); + sourceSecondColl.insert(document); + } + closeDb(); + + ExportOptions exportOptions = new ExportOptions(); + exportOptions.setNitriteFactory(() -> createDb(sourceDbFile)); + exportOptions.setCollections(List.of("first")); + exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee", "org.dizitart.no2.support.Company")); + exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee"))); + + Exporter exporter = Exporter.withOptions(exportOptions); + exporter.exportTo(schemaFile); + + ImportOptions importOptions = new ImportOptions(); + importOptions.setNitriteFactory(() -> createDb(destDbFile)); + + Importer importer = Importer.withOptions(importOptions); + importer.importFrom(schemaFile); + + openDb(); + + NitriteCollection destFirstColl = destDb.getCollection("first"); + NitriteCollection destSecondColl = destDb.getCollection("second"); + ObjectRepository destEmpRepo = destDb.getRepository(Employee.class); + ObjectRepository destKeyedEmpRepo = destDb.getRepository(Employee.class, "key"); + ObjectRepository destCompRepo = destDb.getRepository(Company.class); + + assertEquals(filter(sourceFirstColl.find().toList()), + filter(destFirstColl.find().toList())); + assertNotEquals(filter(sourceSecondColl.find().toList()), + filter(destSecondColl.find().toList())); + assertTrue(destSecondColl.find().isEmpty()); + + assertEquals(sourceEmpRepo.find().toList(), + destEmpRepo.find().toList()); + assertEquals(sourceKeyedEmpRepo.find().toList(), + destKeyedEmpRepo.find().toList()); + assertEquals(sourceCompRepo.find().toList(), + destCompRepo.find().toList()); + + assertEquals(sourceEmpRepo.listIndices(), destEmpRepo.listIndices()); + assertEquals(sourceKeyedEmpRepo.listIndices(), destKeyedEmpRepo.listIndices()); + assertEquals(sourceCompRepo.listIndices(), destCompRepo.listIndices()); + assertEquals(sourceFirstColl.listIndices(), destFirstColl.listIndices()); + assertEquals(0, destSecondColl.listIndices().size()); + } + } + \ No newline at end of file diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java index c819f3f20..dffdd36c0 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java @@ -14,6 +14,7 @@ import org.dizitart.no2.mvstore.MVStoreModule; import org.dizitart.no2.repository.Cursor; import org.dizitart.no2.repository.ObjectRepository; +import org.dizitart.no2.repository.annotations.Entity; import org.dizitart.no2.repository.annotations.Id; import org.junit.Test; @@ -23,6 +24,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDate; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.dizitart.no2.support.BaseExternalTest.getRandomTempDbFile; import static org.junit.Assert.assertNotNull; @@ -73,13 +77,22 @@ public void testIssue819() throws IOException { assertTrue(value instanceof Long); widgetRepo.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "localDateEpochDay"); - - // export the db - Exporter exporter = Exporter.of(db); - exporter.exportTo(exportFilePath); } + // export the db + ExportOptions exportOptions = new ExportOptions(); + exportOptions.setNitriteFactory(() -> createDb(initialDbPath)); + exportOptions.setRepositories(List.of("widget")); + Exporter exporter = Exporter.withOptions(exportOptions); + exporter.exportTo(exportFilePath); + // import the db + ImportOptions importOptions = new ImportOptions(); + importOptions.setNitriteFactory(() -> createDb(importedDbPath)); + Importer importer = Importer.withOptions(importOptions); + importer.importFrom(exportFilePath); + + // open the imported db storeModule = MVStoreModule.withConfig() .filePath(importedDbPath) .build(); @@ -89,8 +102,6 @@ public void testIssue819() throws IOException { .loadModule(new JacksonMapperModule()) .fieldSeparator(".") .openOrCreate()) { - Importer importer = Importer.of(db); - importer.importFrom(exportFilePath); // retrieve the widget as a Document to check the stored type ObjectRepository widgetRepo = db.getRepository(Widget.class); @@ -120,11 +131,23 @@ public void testIssue819() throws IOException { Files.deleteIfExists(path2); } + private Nitrite createDb(String path) { + MVStoreModule storeModule = MVStoreModule.withConfig() + .filePath(path) + .build(); + + return Nitrite.builder() + .loadModule(storeModule) + .loadModule(new JacksonMapperModule()) + .fieldSeparator(".") + .openOrCreate(); + } + @Data + @Entity(value = "widget") static class Widget { @Id - NitriteId id; - Long localDateEpochDay; + private NitriteId id; + private Long localDateEpochDay; } - } diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java index 96bee500b..5e78cd591 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java @@ -15,231 +15,237 @@ * */ -package org.dizitart.no2.collection.operation; - -import org.dizitart.no2.NitriteConfig; -import org.dizitart.no2.common.Fields; -import org.dizitart.no2.index.IndexDescriptor; -import org.dizitart.no2.index.IndexMeta; -import org.dizitart.no2.index.NitriteIndexer; -import org.dizitart.no2.store.NitriteMap; -import org.dizitart.no2.store.NitriteStore; - -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMapName; -import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMetaMapName; - -/** - * Represents the index manager for a collection. - * - * @author Anindya Chatterjee - * @since 4.0 - */ -public class IndexManager implements AutoCloseable { - private final NitriteConfig nitriteConfig; - private final NitriteStore nitriteStore; - private final String collectionName; - private final NitriteMap indexMetaMap; - private Collection indexDescriptorCache; - - /** - * Instantiates a new {@link IndexManager}. - * - * @param collectionName the collection name - * @param nitriteConfig the nitrite config - */ - public IndexManager(String collectionName, NitriteConfig nitriteConfig) { - this.collectionName = collectionName; - this.nitriteConfig = nitriteConfig; - this.nitriteStore = nitriteConfig.getNitriteStore(); - this.indexMetaMap = getIndexMetaMap(); - initialize(); - } - - /** - * Checks if an index descriptor already exists on the fields. - * - * @param fields the fields - * @return the boolean - */ - public boolean hasIndexDescriptor(Fields fields) { - return !findMatchingIndexDescriptors(fields).isEmpty(); - } - - /** - * Gets all defined index descriptors for the collection. - * - * @return the index descriptors - */ - public Collection getIndexDescriptors() { - if (indexDescriptorCache == null) { - indexDescriptorCache = listIndexDescriptors(); - } - return indexDescriptorCache; - } - - public Collection findMatchingIndexDescriptors(Fields fields) { - List indexDescriptors = new ArrayList<>(); - - for (IndexDescriptor indexDescriptor : getIndexDescriptors()) { - if (indexDescriptor.getFields().startsWith(fields)) { - indexDescriptors.add(indexDescriptor); - } - } - - return indexDescriptors; - } - - public IndexDescriptor findExactIndexDescriptor(Fields fields) { - IndexMeta meta = indexMetaMap.get(fields); - if (meta != null) { - return meta.getIndexDescriptor(); - } - return null; - } - - @Override - public void close() { - // close all index maps - if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) { - Iterable indexMetas = indexMetaMap.values(); - for (IndexMeta indexMeta : indexMetas) { - if (indexMeta != null && indexMeta.getIndexDescriptor() != null) { - String indexMapName = indexMeta.getIndexMap(); - NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); - indexMap.close(); - } - } - - // close index meta - indexMetaMap.close(); - } - } - - public void clearAll() { - // close all index maps - if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) { - Iterable indexMetas = indexMetaMap.values(); - for (IndexMeta indexMeta : indexMetas) { - if (indexMeta != null && indexMeta.getIndexDescriptor() != null) { - String indexMapName = indexMeta.getIndexMap(); - NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); - indexMap.clear(); - } - } - } - } - - /** - * Is dirty index boolean. - * - * @param fields the fields - * @return the boolean - */ - boolean isDirtyIndex(Fields fields) { - IndexMeta meta = indexMetaMap.get(fields); - return meta != null && meta.getIsDirty().get(); - } - - /** - * List index descriptors collection. - * - * @return the collection - */ - Collection listIndexDescriptors() { - Set indexSet = new LinkedHashSet<>(); - Iterable iterable = indexMetaMap.values(); - for (IndexMeta indexMeta : iterable) { - indexSet.add(indexMeta.getIndexDescriptor()); - } - return Collections.unmodifiableSet(indexSet); - } - - /** - * Create index descriptor index descriptor. - * - * @param fields the fields - * @param indexType the index type - * @return the index descriptor - */ - IndexDescriptor createIndexDescriptor(Fields fields, String indexType) { - validateIndexRequest(fields, indexType); - IndexDescriptor index = new IndexDescriptor(indexType, fields, collectionName); - - IndexMeta indexMeta = new IndexMeta(); - indexMeta.setIndexDescriptor(index); - indexMeta.setIsDirty(new AtomicBoolean(false)); - indexMeta.setIndexMap(deriveIndexMapName(index)); - - indexMetaMap.put(fields, indexMeta); - - updateIndexDescriptorCache(); - return index; - } - - /** - * Drop index descriptor. - * - * @param fields the fields - */ - void dropIndexDescriptor(Fields fields) { - IndexMeta meta = indexMetaMap.get(fields); - if (meta != null && meta.getIndexDescriptor() != null) { - String indexMapName = meta.getIndexMap(); - NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); - indexMap.drop(); - } - - indexMetaMap.remove(fields); - updateIndexDescriptorCache(); - } - - void dropIndexMeta() { - indexMetaMap.drop(); - } - - /** - * Begin indexing. - * - * @param fields the fields - */ - void beginIndexing(Fields fields) { - markDirty(fields, true); - } - - /** - * End indexing. - * - * @param fields the fields - */ - void endIndexing(Fields fields) { - markDirty(fields, false); - } - - private void initialize() { - updateIndexDescriptorCache(); - } - - private void markDirty(Fields fields, boolean dirty) { - IndexMeta meta = indexMetaMap.get(fields); - if (meta != null && meta.getIndexDescriptor() != null) { - meta.getIsDirty().set(dirty); - } - } - - private NitriteMap getIndexMetaMap() { - String mapName = deriveIndexMetaMapName(this.collectionName); - return this.nitriteStore.openMap(mapName, Fields.class, IndexMeta.class); - } - - private void updateIndexDescriptorCache() { - indexDescriptorCache = listIndexDescriptors(); - } - - private void validateIndexRequest(Fields fields, String indexType) { - NitriteIndexer indexer = nitriteConfig.findIndexer(indexType); - indexer.validateIndex(fields); - } -} + package org.dizitart.no2.collection.operation; + + import org.dizitart.no2.NitriteConfig; + import org.dizitart.no2.common.Fields; + import org.dizitart.no2.index.IndexDescriptor; + import org.dizitart.no2.index.IndexMeta; + import org.dizitart.no2.index.NitriteIndexer; + import org.dizitart.no2.store.NitriteMap; + import org.dizitart.no2.store.NitriteStore; + + import java.util.*; + import java.util.concurrent.atomic.AtomicBoolean; + + import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMapName; + import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMetaMapName; + + /** + * Represents the index manager for a collection. + * + * @author Anindya Chatterjee + * @since 4.0 + */ + public class IndexManager implements AutoCloseable { + private final NitriteConfig nitriteConfig; + private final NitriteStore nitriteStore; + private final String collectionName; + private final NitriteMap indexMetaMap; + private Collection indexDescriptorCache; + + /** + * Instantiates a new {@link IndexManager}. + * + * @param collectionName the collection name + * @param nitriteConfig the nitrite config + */ + public IndexManager(String collectionName, NitriteConfig nitriteConfig) { + this.collectionName = collectionName; + this.nitriteConfig = nitriteConfig; + this.nitriteStore = nitriteConfig.getNitriteStore(); + this.indexMetaMap = getIndexMetaMap(); + initialize(); + } + + /** + * Checks if an index descriptor already exists on the fields. + * + * @param fields the fields + * @return the boolean + */ + public boolean hasIndexDescriptor(Fields fields) { + return !findMatchingIndexDescriptors(fields).isEmpty(); + } + + /** + * Gets all defined index descriptors for the collection. + * + * @return the index descriptors + */ + public Collection getIndexDescriptors() { + if (indexDescriptorCache == null) { + indexDescriptorCache = listIndexDescriptors(); + } + return indexDescriptorCache; + } + + public Collection findMatchingIndexDescriptors(Fields fields) { + List indexDescriptors = new ArrayList<>(); + + for (IndexDescriptor indexDescriptor : getIndexDescriptors()) { + if (indexDescriptor.getFields().startsWith(fields)) { + indexDescriptors.add(indexDescriptor); + } + } + + return indexDescriptors; + } + + public IndexDescriptor findExactIndexDescriptor(Fields fields) { + IndexMeta meta = indexMetaMap.get(fields); + if (meta != null) { + return meta.getIndexDescriptor(); + } + return null; + } + + public void markIndexDirty(IndexDescriptor indexDescriptor) { + Fields fields = indexDescriptor.getFields(); + markDirty(fields, true); + } + + @Override + public void close() { + // close all index maps + if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) { + Iterable indexMetas = indexMetaMap.values(); + for (IndexMeta indexMeta : indexMetas) { + if (indexMeta != null && indexMeta.getIndexDescriptor() != null) { + String indexMapName = indexMeta.getIndexMap(); + NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); + indexMap.close(); + } + } + + // close index meta + indexMetaMap.close(); + } + } + + public void clearAll() { + // close all index maps + if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) { + Iterable indexMetas = indexMetaMap.values(); + for (IndexMeta indexMeta : indexMetas) { + if (indexMeta != null && indexMeta.getIndexDescriptor() != null) { + String indexMapName = indexMeta.getIndexMap(); + NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); + indexMap.clear(); + } + } + } + } + + /** + * Is dirty index boolean. + * + * @param fields the fields + * @return the boolean + */ + boolean isDirtyIndex(Fields fields) { + IndexMeta meta = indexMetaMap.get(fields); + return meta != null && meta.getIsDirty().get(); + } + + /** + * List index descriptors collection. + * + * @return the collection + */ + Collection listIndexDescriptors() { + Set indexSet = new LinkedHashSet<>(); + Iterable iterable = indexMetaMap.values(); + for (IndexMeta indexMeta : iterable) { + indexSet.add(indexMeta.getIndexDescriptor()); + } + return Collections.unmodifiableSet(indexSet); + } + + /** + * Create index descriptor index descriptor. + * + * @param fields the fields + * @param indexType the index type + * @return the index descriptor + */ + IndexDescriptor createIndexDescriptor(Fields fields, String indexType) { + validateIndexRequest(fields, indexType); + IndexDescriptor index = new IndexDescriptor(indexType, fields, collectionName); + + IndexMeta indexMeta = new IndexMeta(); + indexMeta.setIndexDescriptor(index); + indexMeta.setIsDirty(new AtomicBoolean(false)); + indexMeta.setIndexMap(deriveIndexMapName(index)); + + indexMetaMap.put(fields, indexMeta); + + updateIndexDescriptorCache(); + return index; + } + + /** + * Drop index descriptor. + * + * @param fields the fields + */ + void dropIndexDescriptor(Fields fields) { + IndexMeta meta = indexMetaMap.get(fields); + if (meta != null && meta.getIndexDescriptor() != null) { + String indexMapName = meta.getIndexMap(); + NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class); + indexMap.drop(); + } + + indexMetaMap.remove(fields); + updateIndexDescriptorCache(); + } + + void dropIndexMeta() { + indexMetaMap.drop(); + } + + /** + * Begin indexing. + * + * @param fields the fields + */ + void beginIndexing(Fields fields) { + markDirty(fields, true); + } + + /** + * End indexing. + * + * @param fields the fields + */ + void endIndexing(Fields fields) { + markDirty(fields, false); + } + + private void initialize() { + updateIndexDescriptorCache(); + } + + private void markDirty(Fields fields, boolean dirty) { + IndexMeta meta = indexMetaMap.get(fields); + if (meta != null && meta.getIndexDescriptor() != null) { + meta.getIsDirty().set(dirty); + } + } + + private NitriteMap getIndexMetaMap() { + String mapName = deriveIndexMetaMapName(this.collectionName); + return this.nitriteStore.openMap(mapName, Fields.class, IndexMeta.class); + } + + private void updateIndexDescriptorCache() { + indexDescriptorCache = listIndexDescriptors(); + } + + private void validateIndexRequest(Fields fields, String indexType) { + NitriteIndexer indexer = nitriteConfig.findIndexer(indexType); + indexer.validateIndex(fields); + } + } + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 42895013f..16643d6f5 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ 1.0.2 32.1.1-jre 1.6.8 + 2.13.1 2.20.0 0.8.10 @@ -151,6 +152,11 @@ ${lombok.version} provided + + de.undercouch + bson4jackson + ${bson-jackson.version} + From 902957b3c3e78ebcd16c68866caa99ad7e56b329 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Thu, 10 Aug 2023 11:55:58 +0530 Subject: [PATCH 03/18] Remove dependencies and instances of bson4jackson --- nitrite-support/pom.xml | 4 - .../no2/support/NitriteJsonExporter.java | 89 +++-- .../no2/support/NitriteJsonImporter.java | 313 +++++++++--------- .../no2/support/ExportOptionsTest.java | 7 - pom.xml | 6 - 5 files changed, 198 insertions(+), 221 deletions(-) diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index 86dbee6a6..d29eda104 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -51,10 +51,6 @@ lombok provided - - de.undercouch - bson4jackson - junit diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 78760a9a7..7737a3ed2 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -16,31 +16,28 @@ package org.dizitart.no2.support; - import com.fasterxml.jackson.core.JsonGenerator; - import lombok.Setter; - import org.apache.commons.codec.binary.Hex; - import org.dizitart.no2.Nitrite; - import org.dizitart.no2.collection.Document; - import org.dizitart.no2.collection.DocumentCursor; - import org.dizitart.no2.collection.NitriteCollection; - import org.dizitart.no2.collection.NitriteId; - import org.dizitart.no2.collection.operation.IndexManager; - import org.dizitart.no2.common.tuples.Pair; - import org.dizitart.no2.exceptions.NitriteIOException; - import org.dizitart.no2.index.IndexDescriptor; - import org.dizitart.no2.repository.ObjectRepository; - import org.dizitart.no2.store.NitriteMap; - import org.dizitart.no2.store.NitriteStore; - - import java.io.ByteArrayOutputStream; - import java.io.IOException; - import java.io.ObjectOutputStream; - import java.util.*; - import java.util.stream.Collectors; - - import static org.dizitart.no2.common.Constants.*; - import static org.dizitart.no2.common.util.ObjectUtils.*; - +import com.fasterxml.jackson.core.JsonGenerator; +import lombok.Setter; +import org.apache.commons.codec.binary.Hex; +import org.dizitart.no2.Nitrite; +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.collection.NitriteId; +import org.dizitart.no2.collection.operation.IndexManager; +import org.dizitart.no2.common.tuples.Pair; +import org.dizitart.no2.exceptions.NitriteIOException; +import org.dizitart.no2.index.IndexDescriptor; +import org.dizitart.no2.store.NitriteMap; +import org.dizitart.no2.store.NitriteStore; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.*; +import java.util.stream.Collectors; + +import static org.dizitart.no2.common.Constants.*; +import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName; + /** * @author Anindya Chatterjee */ @@ -48,40 +45,40 @@ class NitriteJsonExporter { private JsonGenerator generator; private ExportOptions options; - + public void exportData() throws IOException, ClassNotFoundException { try(Nitrite db = options.getNitriteFactory().create()) { Set collectionNames = options.getCollections() == null ? db.listCollectionNames() : Set.of(); Set repositoryNames = options.getRepositories() == null ? db.listRepositories() : Set.of(); Map> keyedRepositoryNames = options.getKeyedRepositories() == null ? db.listKeyedRepositories() : Map.of(); - + List indexDescriptors = new ArrayList<>(); if (options.getCollections() != null && !options.getCollections().isEmpty()) { collectionNames = new HashSet<>(options.getCollections()); } - + if (options.getRepositories() != null && !options.getRepositories().isEmpty()) { repositoryNames = new HashSet<>(options.getRepositories()); } - + if (options.getKeyedRepositories() != null && !options.getKeyedRepositories().isEmpty()) { keyedRepositoryNames = options.getKeyedRepositories(); } - + if (options.isExportIndices()) { for (String collectionName : collectionNames) { try(IndexManager indexManager = new IndexManager(collectionName, db.getConfig())) { indexDescriptors.addAll(indexManager.getIndexDescriptors()); } } - + for (String repositoryName : repositoryNames) { try(IndexManager indexManager = new IndexManager(repositoryName, db.getConfig())) { indexDescriptors.addAll(indexManager.getIndexDescriptors()); } } - + for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { String key = entry.getKey(); Set enttityNameSet = entry.getValue(); @@ -93,30 +90,30 @@ public void exportData() throws IOException, ClassNotFoundException { } } } - + exportData(db, collectionNames, repositoryNames, keyedRepositoryNames, indexDescriptors); generator.close(); } } - + private void exportData(Nitrite db, Set collectionNames, Set repositoryNames, Map> keyedRepositoryNames, List indexDescriptors) throws IOException { NitriteStore nitriteStore = db.getStore(); - + generator.writeStartObject(); - + writeMaps(collectionNames, indexDescriptors, nitriteStore, TAG_COLLECTIONS); - + writeMaps(repositoryNames, indexDescriptors, nitriteStore, TAG_REPOSITORIES); - + writeKeyedMaps(keyedRepositoryNames, indexDescriptors, nitriteStore); - + generator.writeEndObject(); } - + private void writeMaps(Set mapNames, List indexDescriptors, NitriteStore nitriteStore, String tagName) throws IOException { generator.writeFieldName(tagName); @@ -131,7 +128,7 @@ private void writeMaps(Set mapNames, List indexDescript } generator.writeEndArray(); } - + private void writeKeyedMaps(Map> keyedMapNames, List indexDescriptors, NitriteStore nitriteStore) throws IOException { generator.writeFieldName(TAG_KEYED_REPOSITORIES); @@ -151,7 +148,7 @@ private void writeKeyedMaps(Map> keyedMapNames, List nitriteMap, List indexes) throws IOException { generator.writeStartObject(); @@ -161,7 +158,7 @@ private void writeNitriteMap(NitriteMap nitriteMap, writeContent(nitriteMap); generator.writeEndObject(); } - + private void writeIndices(Collection indices) throws IOException { generator.writeFieldName(TAG_INDICES); generator.writeStartArray(); @@ -175,7 +172,7 @@ private void writeIndices(Collection indices) throws IOExceptio } generator.writeEndArray(); } - + private void writeContent(NitriteMap nitriteMap) throws IOException { generator.writeFieldName(TAG_DATA); generator.writeStartArray(); @@ -184,7 +181,7 @@ private void writeContent(NitriteMap nitriteMap) throws IOE generator.writeStartObject(); generator.writeFieldName(TAG_KEY); generator.writeObject(writeEncodedObject(entry.getFirst())); - + generator.writeFieldName(TAG_VALUE); generator.writeObject(writeEncodedObject(entry.getSecond())); generator.writeEndObject(); @@ -192,7 +189,7 @@ private void writeContent(NitriteMap nitriteMap) throws IOE } generator.writeEndArray(); } - + private String writeEncodedObject(Object object) { try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { try (ObjectOutputStream oos = new ObjectOutputStream(os)) { diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java index 1f83c83b2..cb90a6235 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java @@ -14,162 +14,159 @@ * limitations under the License. */ - package org.dizitart.no2.support; - - import com.fasterxml.jackson.core.JsonParser; - import com.fasterxml.jackson.core.JsonToken; - import lombok.Setter; - import org.apache.commons.codec.binary.Hex; - import org.dizitart.no2.Nitrite; - import org.dizitart.no2.collection.Document; - import org.dizitart.no2.collection.NitriteCollection; - import org.dizitart.no2.collection.NitriteId; - import org.dizitart.no2.collection.operation.IndexManager; - import org.dizitart.no2.common.PersistentCollection; - import org.dizitart.no2.exceptions.NitriteIOException; - import org.dizitart.no2.index.IndexDescriptor; - import org.dizitart.no2.repository.ObjectRepository; - import org.dizitart.no2.store.NitriteMap; - import org.dizitart.no2.store.NitriteStore; - - import java.io.ByteArrayInputStream; - import java.io.IOException; - import java.io.ObjectInputStream; - import java.util.ArrayList; - import java.util.List; - - import static org.dizitart.no2.common.Constants.*; - import static org.dizitart.no2.index.IndexOptions.indexOptions; - - /** - * @author Anindya Chatterjee. - */ - @Setter - class NitriteJsonImporter { - private JsonParser parser; - private ImportOptions options; - - public void importData() throws IOException, ClassNotFoundException { - try (Nitrite db = options.getNitriteFactory().create()) { - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_COLLECTIONS.equals(fieldName)) { - readNitriteMap(db); - } - - if (TAG_REPOSITORIES.equals(fieldName)) { - readNitriteMap(db); - } - - if (TAG_KEYED_REPOSITORIES.equals(fieldName)) { - readNitriteMap(db); - } - } - } - } - - private void readNitriteMap(Nitrite db) throws IOException { - // move to [ - parser.nextToken(); - NitriteStore nitriteStore = db.getStore(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - NitriteMap nitriteMap = null; - List indexDescriptors = new ArrayList<>(); - - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_NAME.equals(fieldName)) { - // move to next token - parser.nextToken(); - - String mapName = parser.getText(); - nitriteMap = nitriteStore.openMap(mapName, NitriteId.class, Document.class); - } - - if (TAG_INDICES.equals(fieldName)) { - indexDescriptors = readIndices(); - } - - if (TAG_DATA.equals(fieldName) && nitriteMap != null) { - readNitriteMapData(nitriteMap); - - // write index information - try(IndexManager indexManager = new IndexManager(nitriteMap.getName(), db.getConfig())) { - // during next data insertion, index will be rebuilt - indexDescriptors.forEach(indexManager::markIndexDirty); - } - } - } - } - } - - private List readIndices() throws IOException { - List indexDescriptors = new ArrayList<>(); - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_INDEX.equals(fieldName)) { - parser.nextToken(); - String data = parser.readValueAs(String.class); - IndexDescriptor index = (IndexDescriptor) readEncodedObject(data); - indexDescriptors.add(index); - } - } - } - return indexDescriptors; - } - - private void readNitriteMapData(NitriteMap nitriteMap) throws IOException { - // move to [ - parser.nextToken(); - - // loop till token equal to "]" - while (parser.nextToken() != JsonToken.END_ARRAY) { - // loop until end of collection object - NitriteId nitriteId = null; - while (parser.nextToken() != JsonToken.END_OBJECT) { - String fieldName = parser.getCurrentName(); - - if (TAG_KEY.equals(fieldName)) { - parser.nextToken(); - String data = parser.readValueAs(String.class); - nitriteId = (NitriteId) readEncodedObject(data); - } - - if (TAG_VALUE.equals(fieldName)) { - parser.nextToken(); - String data = parser.readValueAs(String.class); - Document document = (Document) readEncodedObject(data); - if (nitriteMap != null) { - nitriteMap.put(nitriteId, document); - } - } - } - } - } - - private Object readEncodedObject(String hexString) { - try { - byte[] data = Hex.decodeHex(hexString); - try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { - try (ObjectInputStream ois = new ObjectInputStream(is)) { - return ois.readObject(); - } - } - } catch (Exception e) { - throw new NitriteIOException("Error while reading data", e); - } - } - } +package org.dizitart.no2.support; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Setter; +import org.apache.commons.codec.binary.Hex; +import org.dizitart.no2.Nitrite; +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.collection.NitriteId; +import org.dizitart.no2.collection.operation.IndexManager; +import org.dizitart.no2.exceptions.NitriteIOException; +import org.dizitart.no2.index.IndexDescriptor; +import org.dizitart.no2.store.NitriteMap; +import org.dizitart.no2.store.NitriteStore; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.List; + +import static org.dizitart.no2.common.Constants.*; + +/** + * @author Anindya Chatterjee. + */ +@Setter +class NitriteJsonImporter { + private JsonParser parser; + private ImportOptions options; + + public void importData() throws IOException, ClassNotFoundException { + try (Nitrite db = options.getNitriteFactory().create()) { + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_COLLECTIONS.equals(fieldName)) { + readNitriteMap(db); + } + + if (TAG_REPOSITORIES.equals(fieldName)) { + readNitriteMap(db); + } + + if (TAG_KEYED_REPOSITORIES.equals(fieldName)) { + readNitriteMap(db); + } + } + } + } + + private void readNitriteMap(Nitrite db) throws IOException { + // move to [ + parser.nextToken(); + NitriteStore nitriteStore = db.getStore(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + NitriteMap nitriteMap = null; + List indexDescriptors = new ArrayList<>(); + + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_NAME.equals(fieldName)) { + // move to next token + parser.nextToken(); + + String mapName = parser.getText(); + nitriteMap = nitriteStore.openMap(mapName, NitriteId.class, Document.class); + } + + if (TAG_INDICES.equals(fieldName)) { + indexDescriptors = readIndices(); + } + + if (TAG_DATA.equals(fieldName) && nitriteMap != null) { + readNitriteMapData(nitriteMap); + + // write index information + try (IndexManager indexManager = new IndexManager(nitriteMap.getName(), db.getConfig())) { + // during next data insertion, index will be rebuilt + indexDescriptors.forEach(indexManager::markIndexDirty); + } + } + } + } + } + + private List readIndices() throws IOException { + List indexDescriptors = new ArrayList<>(); + // move to [ + parser.nextToken(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_INDEX.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + IndexDescriptor index = readEncodedObject(data, IndexDescriptor.class); + indexDescriptors.add(index); + } + } + } + return indexDescriptors; + } + + private void readNitriteMapData(NitriteMap nitriteMap) throws IOException { + // move to [ + parser.nextToken(); + + // loop till token equal to "]" + while (parser.nextToken() != JsonToken.END_ARRAY) { + // loop until end of collection object + NitriteId nitriteId = null; + while (parser.nextToken() != JsonToken.END_OBJECT) { + String fieldName = parser.getCurrentName(); + + if (TAG_KEY.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + nitriteId = readEncodedObject(data, NitriteId.class); + } + + if (TAG_VALUE.equals(fieldName)) { + parser.nextToken(); + String data = parser.readValueAs(String.class); + Document document = readEncodedObject(data, Document.class); + if (nitriteMap != null) { + nitriteMap.put(nitriteId, document); + } + } + } + } + } + + private T readEncodedObject(String hexString, Class type) { + try { + byte[] data = Hex.decodeHex(hexString); + try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { + try (ObjectInputStream ois = new ObjectInputStream(is)) { + return type.cast(ois.readObject()); + } + } + } catch (Exception e) { + throw new NitriteIOException("Error while reading data", e); + } + } +} \ No newline at end of file diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java index a286fb1d2..01cb019c7 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java @@ -9,13 +9,6 @@ import org.junit.Test; public class ExportOptionsTest { - @Test - public void testSetCollections() { - ExportOptions exportOptions = new ExportOptions(); - ArrayList> persistentCollectionList = new ArrayList>(); - exportOptions.setCollections(persistentCollectionList); - assertSame(persistentCollectionList, exportOptions.getCollections()); - } @Test public void testSetExportData() { diff --git a/pom.xml b/pom.xml index 16643d6f5..42895013f 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,6 @@ 1.0.2 32.1.1-jre 1.6.8 - 2.13.1 2.20.0 0.8.10 @@ -152,11 +151,6 @@ ${lombok.version} provided - - de.undercouch - bson4jackson - ${bson-jackson.version} - From ac076c90ae4d21e5a84464026b5983d36b1b270e Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Thu, 10 Aug 2023 21:46:59 +0530 Subject: [PATCH 04/18] Update NitriteJsonExporter.java --- .../java/org/dizitart/no2/support/NitriteJsonExporter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 7737a3ed2..50ab3cbf0 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -81,8 +81,8 @@ public void exportData() throws IOException, ClassNotFoundException { for (Map.Entry> entry : keyedRepositoryNames.entrySet()) { String key = entry.getKey(); - Set enttityNameSet = entry.getValue(); - for (String entityName : enttityNameSet) { + Set entityNameSet = entry.getValue(); + for (String entityName : entityNameSet) { String repositoryName = findRepositoryName(key, entityName); try(IndexManager indexManager = new IndexManager(repositoryName, db.getConfig())) { indexDescriptors.addAll(indexManager.getIndexDescriptors()); From 13f13334cbc2fdee64d11d02930a6ef7c13da269 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Thu, 10 Aug 2023 21:56:39 +0530 Subject: [PATCH 05/18] Refactor serialization package and replace Apache Commons Codec with Java Base64. --- nitrite-support/pom.xml | 4 ---- .../org/dizitart/no2/support/NitriteJsonExporter.java | 3 +-- .../org/dizitart/no2/support/NitriteJsonImporter.java | 7 +++---- pom.xml | 8 -------- potassium-nitrite/pom.xml | 4 ---- .../DocumentDecoder.kt | 2 +- .../DocumentEncoder.kt | 2 +- .../KotlinXSerializationMapper.kt | 4 ++-- .../org/dizitart/kno2/KotlinXSerializationMapperTest.kt | 2 +- 9 files changed, 9 insertions(+), 27 deletions(-) rename potassium-nitrite/src/main/kotlin/org/dizitart/kno2/{kotlinxserialization => serialization}/DocumentDecoder.kt (99%) rename potassium-nitrite/src/main/kotlin/org/dizitart/kno2/{kotlinxserialization => serialization}/DocumentEncoder.kt (99%) rename potassium-nitrite/src/main/kotlin/org/dizitart/kno2/{kotlinxserialization => serialization}/KotlinXSerializationMapper.kt (95%) diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index d29eda104..5b0981e70 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -42,10 +42,6 @@ com.fasterxml.jackson.core jackson-databind - - commons-codec - commons-codec - org.projectlombok lombok diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 50ab3cbf0..f2487edc7 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -18,7 +18,6 @@ import com.fasterxml.jackson.core.JsonGenerator; import lombok.Setter; -import org.apache.commons.codec.binary.Hex; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; @@ -195,7 +194,7 @@ private String writeEncodedObject(Object object) { try (ObjectOutputStream oos = new ObjectOutputStream(os)) { oos.writeObject(object); byte[] data = os.toByteArray(); - return Hex.encodeHexString(data); + return Base64.getEncoder().encodeToString(data); } } catch (IOException e) { throw new NitriteIOException("Failed to write object", e); diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java index cb90a6235..e1a820b1f 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java @@ -18,9 +18,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Setter; -import org.apache.commons.codec.binary.Hex; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; @@ -34,6 +32,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import static org.dizitart.no2.common.Constants.*; @@ -156,9 +155,9 @@ private void readNitriteMapData(NitriteMap nitriteMap) thro } } - private T readEncodedObject(String hexString, Class type) { + private T readEncodedObject(String encodedString, Class type) { try { - byte[] data = Hex.decodeHex(hexString); + byte[] data = Base64.getDecoder().decode(encodedString); try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { try (ObjectInputStream ois = new ObjectInputStream(is)) { return type.cast(ois.readObject()); diff --git a/pom.xml b/pom.xml index 42895013f..7b78cd2de 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,6 @@ 8.3.2 5.5.0 1.19.0 - 1.16.0 2.13.0 1.9.0 1.5.1 @@ -108,13 +107,6 @@ ${kotlinx-serialization.version} - - - commons-codec - commons-codec - ${commons-codec.version} - - com.h2database h2-mvstore diff --git a/potassium-nitrite/pom.xml b/potassium-nitrite/pom.xml index 78f06447c..560b84fa8 100644 --- a/potassium-nitrite/pom.xml +++ b/potassium-nitrite/pom.xml @@ -56,10 +56,6 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - - commons-codec - commons-codec - org.jetbrains.kotlin kotlin-stdlib diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentDecoder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt similarity index 99% rename from potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentDecoder.kt rename to potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt index 4cf9e4bd7..4dbc4ec59 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentDecoder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt @@ -1,4 +1,4 @@ -package org.dizitart.kno2.kotlinxserialization +package org.dizitart.kno2.serialization import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentEncoder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt similarity index 99% rename from potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentEncoder.kt rename to potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt index a05be94f0..7c03a61c7 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/DocumentEncoder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt @@ -1,4 +1,4 @@ -package org.dizitart.kno2.kotlinxserialization +package org.dizitart.kno2.serialization import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/KotlinXSerializationMapper.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt similarity index 95% rename from potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/KotlinXSerializationMapper.kt rename to potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt index ea600be08..44e25b26b 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/kotlinxserialization/KotlinXSerializationMapper.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.dizitart.kno2.kotlinxserialization +package org.dizitart.kno2.serialization import org.dizitart.no2.NitriteConfig import org.dizitart.no2.collection.Document @@ -26,7 +26,7 @@ import org.dizitart.no2.exceptions.ObjectMappingException import java.util.Date /** - * Mapper using kotlinx.serialization + * org.dizitart.no2.common.mapper.NitriteMapper implementation using using kotlinx.serialization * * @author Joris Jensen * @since 4.2.0 diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt index 49133f846..431d1b1bf 100644 --- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt +++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt @@ -19,7 +19,7 @@ package org.dizitart.kno2 import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertSame import kotlinx.serialization.Serializable -import org.dizitart.kno2.kotlinxserialization.KotlinXSerializationMapper +import org.dizitart.kno2.serialization.KotlinXSerializationMapper import org.dizitart.no2.collection.Document import org.dizitart.no2.mvstore.MVStoreModule import org.junit.Test From 00b69c9e2f9fddd6a1c98b355ca80148c66a9c6c Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Thu, 10 Aug 2023 22:45:56 +0530 Subject: [PATCH 06/18] fix android compatibility --- .../java/org/dizitart/no2/support/NitriteJsonExporter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index f2487edc7..4ae94cd14 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -47,10 +47,10 @@ class NitriteJsonExporter { public void exportData() throws IOException, ClassNotFoundException { try(Nitrite db = options.getNitriteFactory().create()) { - Set collectionNames = options.getCollections() == null ? db.listCollectionNames() : Set.of(); - Set repositoryNames = options.getRepositories() == null ? db.listRepositories() : Set.of(); + Set collectionNames = options.getCollections() == null ? db.listCollectionNames() : new HashSet<>(); + Set repositoryNames = options.getRepositories() == null ? db.listRepositories() : new HashSet<>(); Map> keyedRepositoryNames = options.getKeyedRepositories() == null - ? db.listKeyedRepositories() : Map.of(); + ? db.listKeyedRepositories() : new HashMap<>(); List indexDescriptors = new ArrayList<>(); if (options.getCollections() != null && !options.getCollections().isEmpty()) { From fa4e314a6e75eb508479fdd84dca0b3110b2f090 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Thu, 10 Aug 2023 23:05:08 +0530 Subject: [PATCH 07/18] Remove Base64 utility and related test --- .../no2/support/NitriteJsonExporter.java | 3 +- .../no2/support/NitriteJsonImporter.java | 4 +- nitrite/pom.xml | 4 + .../no2/common/crypto/AESEncryptor.java | 8 +- .../org/dizitart/no2/common/util/Base64.java | 587 ------------------ .../dizitart/no2/common/util/Base64Test.java | 209 ------- pom.xml | 8 + 7 files changed, 20 insertions(+), 803 deletions(-) delete mode 100644 nitrite/src/main/java/org/dizitart/no2/common/util/Base64.java delete mode 100644 nitrite/src/test/java/org/dizitart/no2/common/util/Base64Test.java diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java index 4ae94cd14..e448ccb6e 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import lombok.Setter; +import org.apache.commons.codec.binary.Base64; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; @@ -194,7 +195,7 @@ private String writeEncodedObject(Object object) { try (ObjectOutputStream oos = new ObjectOutputStream(os)) { oos.writeObject(object); byte[] data = os.toByteArray(); - return Base64.getEncoder().encodeToString(data); + return Base64.encodeBase64URLSafeString(data); } } catch (IOException e) { throw new NitriteIOException("Failed to write object", e); diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java index e1a820b1f..a30f330ee 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import lombok.Setter; +import org.apache.commons.codec.binary.Base64; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; @@ -32,7 +33,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import static org.dizitart.no2.common.Constants.*; @@ -157,7 +157,7 @@ private void readNitriteMapData(NitriteMap nitriteMap) thro private T readEncodedObject(String encodedString, Class type) { try { - byte[] data = Base64.getDecoder().decode(encodedString); + byte[] data = Base64.decodeBase64(encodedString); try (ByteArrayInputStream is = new ByteArrayInputStream(data)) { try (ObjectInputStream ois = new ObjectInputStream(is)) { return type.cast(ois.readObject()); diff --git a/nitrite/pom.xml b/nitrite/pom.xml index b4ffaeb52..f831cb189 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -43,6 +43,10 @@ lombok provided + + commons-codec + commons-codec + junit diff --git a/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java b/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java index f3ec0efdd..67825e787 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java @@ -17,7 +17,7 @@ package org.dizitart.no2.common.crypto; -import org.dizitart.no2.common.util.Base64; +import org.apache.commons.codec.binary.Base64; import org.dizitart.no2.common.util.CryptoUtils; import org.dizitart.no2.common.util.SecureString; import org.dizitart.no2.exceptions.NitriteSecurityException; @@ -33,7 +33,7 @@ * A password based AES string encryption utility. * *

- * NOTE: This is a derivative work of https://mkyong.com/java/java-symmetric-key-cryptography-example/ + * NOTE: This is a derivative work of ... *

* * @author Anindya Chatterjee @@ -115,7 +115,7 @@ public String encrypt(byte[] plainText) { .array(); // string representation, base64, send this string to other for decryption. - return Base64.encodeToString(cipherTextWithIvSalt, Base64.URL_SAFE); + return Base64.encodeBase64URLSafeString(cipherTextWithIvSalt); } catch (Exception e) { throw new NitriteSecurityException("Failed to encrypt data", e); } @@ -133,7 +133,7 @@ public String encrypt(byte[] plainText) { @Override public String decrypt(String encryptedText) { try { - byte[] decode = Base64.decode(encryptedText.getBytes(UTF_8), Base64.URL_SAFE); + byte[] decode = Base64.decodeBase64(encryptedText); // get back the iv and salt from the cipher text ByteBuffer bb = ByteBuffer.wrap(decode); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/Base64.java b/nitrite/src/main/java/org/dizitart/no2/common/util/Base64.java deleted file mode 100644 index 19989791f..000000000 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/Base64.java +++ /dev/null @@ -1,587 +0,0 @@ -package org.dizitart.no2.common.util; - -import java.nio.charset.StandardCharsets; - -/** - * Utilities for encoding and decoding the Base64 representation of - * binary data. - * - *

- * This is a derivative work of android.util.Base64 class - * from Android Open Source Project - *

- * - * @author The Android Open Source Project - * @author Anindya Chatterjee - * @since 4.0 - */ -public class Base64 { - /** - * Encoder flag bit to omit the padding '=' characters at the end - * of the output (if any). - */ - public static final int NO_PADDING = 1; - /** - * Encoder flag bit to omit all line terminators (i.e., the output - * will be on one long line). - */ - public static final int NO_WRAP = 2; - /** - * Encoder flag bit to indicate lines should be terminated with a - * CRLF pair instead of just an LF. Has no effect if {@code - * NO_WRAP}* is specified as well. - */ - public static final int CRLF = 4; - /** - * Encoder/decoder flag bit to indicate using the "URL and - * filename safe" variant of Base64 (see RFC 3548 section 4) where - * {@code -} and {@code _} are used in place of {@code +} and - * {@code /}. - */ - public static final int URL_SAFE = 8; - - /** - * The type Coder. - */ - static abstract class Coder { - /** - * The Output. - */ - public byte[] output; - /** - * The Op. - */ - public int op; - } - // -------------------------------------------------------- - // decoding - // -------------------------------------------------------- - - /** - * Decode the Base64-encoded data in input and return the data in - * a new byte array. - * - *

The padding '=' characters at the end are considered optional, but - * if any are present, there must be the correct number of them. - * - * @param input the input array to decode - * @param flags controls certain features of the decoded output. Pass {@code DEFAULT} to decode standard Base64. - * @return the byte [ ] - * @throws IllegalArgumentException if the input contains incorrect padding - */ - public static byte[] decode(byte[] input, int flags) { - return decode(input, 0, input.length, flags); - } - - /** - * Decode the Base64-encoded data in input and return the data in - * a new byte array. - * - *

The padding '=' characters at the end are considered optional, but - * if any are present, there must be the correct number of them. - * - * @param input the data to decode - * @param offset the position within the input array at which to start - * @param len the number of bytes of input to decode - * @param flags controls certain features of the decoded output. Pass {@code DEFAULT} to decode standard Base64. - * @return the byte [ ] - * @throws IllegalArgumentException if the input contains incorrect padding - */ - public static byte[] decode(byte[] input, int offset, int len, int flags) { - // Allocate space for the most data the input could represent. - // (It could contain less if it contains whitespace, etc.) - Decoder decoder = new Decoder(flags, new byte[len*3/4]); - if (!decoder.process(input, offset, len)) { - throw new IllegalArgumentException("Bad base-64 input"); - } - // Maybe we got lucky and allocated exactly enough output space. - if (decoder.op == decoder.output.length) { - return decoder.output; - } - // Need to shorten the array, so allocate a new one of the - // right size and copy. - byte[] temp = new byte[decoder.op]; - System.arraycopy(decoder.output, 0, temp, 0, decoder.op); - return temp; - } - - /** - * The type Decoder. - */ - /* package */ static class Decoder extends Coder { - /** - * Lookup table for turning bytes into their position in the - * Base64 alphabet. - */ - private static final int[] DECODE = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - }; - /** - * Decode lookup table for the "web safe" variant (RFC 3548 - * sec. 4) where - and _ replace + and /. - */ - private static final int[] DECODE_WEBSAFE = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - }; - /** Non-data values in the DECODE arrays. */ - private static final int SKIP = -1; - private static final int EQUALS = -2; - /** - * States 0-3 are reading through the next input tuple. - * State 4 is having read one '=' and expecting exactly - * one more. - * State 5 is expecting no more data or padding characters - * in the input. - * State 6 is the error state; an error has been detected - * in the input and no future input can "fix" it. - */ - private int state; // state number (0 to 6) - private final int value; - final private int[] alphabet; - - /** - * Instantiates a new Decoder. - * - * @param flags the flags - * @param output the output - */ - public Decoder(int flags, byte[] output) { - this.output = output; - alphabet = ((flags & URL_SAFE) == 0) ? DECODE : DECODE_WEBSAFE; - state = 0; - value = 0; - } - - /** - * Decode another block of input data. - * - * @return true if the state machine is still healthy. false if - * bad base-64 data has been detected in the input stream. - */ - private boolean process(byte[] input, int offset, int len) { - if (this.state == 6) return false; - int p = offset; - len += offset; - // Using local variables makes the decoder about 12% - // faster than if we manipulate the member variables in - // the loop. (Even alphabet makes a measurable - // difference, which is somewhat surprising to me since - // the member variable is final.) - int state = this.state; - int value = this.value; - int op = 0; - final byte[] output = this.output; - final int[] alphabet = this.alphabet; - while (p < len) { - // Try the fast path: we're starting a new tuple and the - // next four bytes of the input stream are all data - // bytes. This corresponds to going through states - // 0-1-2-3-0. We expect to use this method for most of - // the data. - // - // If any of the next four bytes of input are non-data - // (whitespace, etc.), value will end up negative. (All - // the non-data values in decode are small negative - // numbers, so shifting any of them up and or'ing them - // together will result in a value with its top bit set.) - // - // You can remove this whole block and the output should - // be the same, just slower. - if (state == 0) { - while (p+4 <= len && - (value = ((alphabet[input[p] & 0xff] << 18) | - (alphabet[input[p+1] & 0xff] << 12) | - (alphabet[input[p+2] & 0xff] << 6) | - (alphabet[input[p+3] & 0xff]))) >= 0) { - output[op+2] = (byte) value; - output[op+1] = (byte) (value >> 8); - output[op] = (byte) (value >> 16); - op += 3; - p += 4; - } - if (p >= len) break; - } - // The fast path isn't available -- either we've read a - // partial tuple, or the next four input bytes aren't all - // data, or whatever. Fall back to the slower state - // machine implementation. - int d = alphabet[input[p++] & 0xff]; - switch (state) { - case 0: - if (d >= 0) { - value = d; - ++state; - } else if (d != SKIP) { - this.state = 6; - return false; - } - break; - case 1: - if (d >= 0) { - value = (value << 6) | d; - ++state; - } else if (d != SKIP) { - this.state = 6; - return false; - } - break; - case 2: - if (d >= 0) { - value = (value << 6) | d; - ++state; - } else if (d == EQUALS) { - // Emit the last (partial) output tuple; - // expect exactly one more padding character. - output[op++] = (byte) (value >> 4); - state = 4; - } else if (d != SKIP) { - this.state = 6; - return false; - } - break; - case 3: - if (d >= 0) { - // Emit the output triple and return to state 0. - value = (value << 6) | d; - output[op+2] = (byte) value; - output[op+1] = (byte) (value >> 8); - output[op] = (byte) (value >> 16); - op += 3; - state = 0; - } else if (d == EQUALS) { - // Emit the last (partial) output tuple; - // expect no further data or padding characters. - output[op+1] = (byte) (value >> 2); - output[op] = (byte) (value >> 10); - op += 2; - state = 5; - } else if (d != SKIP) { - this.state = 6; - return false; - } - break; - case 4: - if (d == EQUALS) { - ++state; - } else if (d != SKIP) { - this.state = 6; - return false; - } - break; - case 5: - if (d != SKIP) { - this.state = 6; - return false; - } - break; - } - } - // Done reading input. Now figure out where we are left in - // the state machine and finish up. - switch (state) { - case 0: - // Output length is a multiple of three. Fine. - break; - case 1: - case 4: - // Read one padding '=' when we expected 2. Illegal. - // Read one extra input byte, which isn't enough to - // make another output byte. Illegal. - this.state = 6; - return false; - case 2: - // Read two extra input bytes, enough to emit 1 more - // output byte. Fine. - output[op++] = (byte) (value >> 4); - break; - case 3: - // Read three extra input bytes, enough to emit 2 more - // output bytes. Fine. - output[op++] = (byte) (value >> 10); - output[op++] = (byte) (value >> 2); - break; - case 5: - // Read all the padding '='s we expected and no more. - // Fine. - break; - } - this.state = state; - this.op = op; - return true; - } - } - // -------------------------------------------------------- - // encoding - // -------------------------------------------------------- - - /** - * Base64-encode the given data and return a newly allocated - * String with the result. - * - * @param input the data to encode - * @param flags controls certain features of the encoded output. Passing {@code DEFAULT} results in output that adheres to RFC 2045. - * @return the string - */ - public static String encodeToString(byte[] input, int flags) { - return new String(encode(input, flags), StandardCharsets.US_ASCII); - } - - /** - * Base64-encode the given data and return a newly allocated - * byte[] with the result. - * - * @param input the data to encode - * @param flags controls certain features of the encoded output. Passing {@code DEFAULT} results in output that adheres to RFC 2045. - * @return the byte [ ] - */ - public static byte[] encode(byte[] input, int flags) { - return encode(input, 0, input.length, flags); - } - - /** - * Base64-encode the given data and return a newly allocated - * byte[] with the result. - * - * @param input the data to encode - * @param offset the position within the input array at which to start - * @param len the number of bytes of input to encode - * @param flags controls certain features of the encoded output. Passing {@code DEFAULT} results in output that adheres to RFC 2045. - * @return the byte [ ] - */ - public static byte[] encode(byte[] input, int offset, int len, int flags) { - Encoder encoder = new Encoder(flags, null); - // Compute the exact length of the array we will produce. - int output_len = len / 3 * 4; - // Account for the tail of the data and the padding bytes, if any. - if (encoder.do_padding) { - if (len % 3 > 0) { - output_len += 4; - } - } else { - switch (len % 3) { - case 0: break; - case 1: output_len += 2; break; - case 2: output_len += 3; break; - } - } - // Account for the newlines, if any. - if (encoder.do_newline && len > 0) { - output_len += (((len-1) / (3 * Encoder.LINE_GROUPS)) + 1) * - (encoder.do_cr ? 2 : 1); - } - encoder.output = new byte[output_len]; - encoder.process(input, offset, len); - assert encoder.op == output_len; - return encoder.output; - } - - /** - * The type Encoder. - */ - static class Encoder extends Coder { - /** - * Emit a new line every this many output tuples. Corresponds to - * a 76-character line length (the maximum allowable according to - * RFC 2045). - */ - public static final int LINE_GROUPS = 19; - /** - * Lookup table for turning Base64 alphabet positions (6 bits) - * into output bytes. - */ - private static final byte[] ENCODE = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', - }; - /** - * Lookup table for turning Base64 alphabet positions (6 bits) - * into output bytes. - */ - private static final byte[] ENCODE_WEBSAFE = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', - }; - final private byte[] tail; - /** - * The Tail len. - */ - int tailLen; - private int count; - /** - * The Do padding. - */ - final public boolean do_padding; - /** - * The Do newline. - */ - final public boolean do_newline; - /** - * The Do cr. - */ - final public boolean do_cr; - final private byte[] alphabet; - - /** - * Instantiates a new Encoder. - * - * @param flags the flags - * @param output the output - */ - public Encoder(int flags, byte[] output) { - this.output = output; - do_padding = (flags & NO_PADDING) == 0; - do_newline = (flags & NO_WRAP) == 0; - do_cr = (flags & CRLF) != 0; - alphabet = ((flags & URL_SAFE) == 0) ? ENCODE : ENCODE_WEBSAFE; - tail = new byte[2]; - tailLen = 0; - count = do_newline ? LINE_GROUPS : -1; - } - - private void process(byte[] input, int offset, int len) { - // Using local variables makes the encoder about 9% faster. - final byte[] alphabet = this.alphabet; - final byte[] output = this.output; - int op = 0; - int count = this.count; - int p = offset; - len += offset; - int v = -1; - // First we need to concatenate the tail of the previous call - // with any input bytes available now and see if we can empty - // the tail. - switch (tailLen) { - case 0: - // There was no tail. - break; - case 1: - if (p+2 <= len) { - // A 1-byte tail with at least 2 bytes of - // input available now. - v = ((tail[0] & 0xff) << 16) | - ((input[p++] & 0xff) << 8) | - (input[p++] & 0xff); - tailLen = 0; - }; - break; - case 2: - if (p+1 <= len) { - // A 2-byte tail with at least 1 byte of input. - v = ((tail[0] & 0xff) << 16) | - ((tail[1] & 0xff) << 8) | - (input[p++] & 0xff); - tailLen = 0; - } - break; - } - if (v != -1) { - output[op++] = alphabet[(v >> 18) & 0x3f]; - output[op++] = alphabet[(v >> 12) & 0x3f]; - output[op++] = alphabet[(v >> 6) & 0x3f]; - output[op++] = alphabet[v & 0x3f]; - if (--count == 0) { - if (do_cr) output[op++] = '\r'; - output[op++] = '\n'; - count = LINE_GROUPS; - } - } - // At this point either there is no tail, or there are fewer - // than 3 bytes of input available. - // The main loop, turning 3 input bytes into 4 output bytes on - // each iteration. - while (p+3 <= len) { - v = ((input[p] & 0xff) << 16) | - ((input[p+1] & 0xff) << 8) | - (input[p+2] & 0xff); - output[op] = alphabet[(v >> 18) & 0x3f]; - output[op+1] = alphabet[(v >> 12) & 0x3f]; - output[op+2] = alphabet[(v >> 6) & 0x3f]; - output[op+3] = alphabet[v & 0x3f]; - p += 3; - op += 4; - if (--count == 0) { - if (do_cr) output[op++] = '\r'; - output[op++] = '\n'; - count = LINE_GROUPS; - } - } - // Finish up the tail of the input. Note that we need to - // consume any bytes in tail before any bytes - // remaining in input; there should be at most two bytes - // total. - if (p-tailLen == len-1) { - int t = 0; - v = ((tailLen > 0 ? tail[t++] : input[p++]) & 0xff) << 4; - tailLen -= t; - output[op++] = alphabet[(v >> 6) & 0x3f]; - output[op++] = alphabet[v & 0x3f]; - if (do_padding) { - output[op++] = '='; - output[op++] = '='; - } - if (do_newline) { - if (do_cr) output[op++] = '\r'; - output[op++] = '\n'; - } - } else if (p-tailLen == len-2) { - int t = 0; - v = (((tailLen > 1 ? tail[t++] : input[p++]) & 0xff) << 10) | - (((tailLen > 0 ? tail[t++] : input[p++]) & 0xff) << 2); - tailLen -= t; - output[op++] = alphabet[(v >> 12) & 0x3f]; - output[op++] = alphabet[(v >> 6) & 0x3f]; - output[op++] = alphabet[v & 0x3f]; - if (do_padding) { - output[op++] = '='; - } - if (do_newline) { - if (do_cr) output[op++] = '\r'; - output[op++] = '\n'; - } - } else if (do_newline && op > 0 && count != LINE_GROUPS) { - if (do_cr) output[op++] = '\r'; - output[op++] = '\n'; - } - assert tailLen == 0; - assert p == len; - this.op = op; - this.count = count; - } - } - - private Base64() { } // don't instantiate -} diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/Base64Test.java b/nitrite/src/test/java/org/dizitart/no2/common/util/Base64Test.java deleted file mode 100644 index dc5eafd89..000000000 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/Base64Test.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2017-2021 Nitrite author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.dizitart.no2.common.util; - -import org.junit.Test; - -import java.io.UnsupportedEncodingException; - -import static org.junit.Assert.*; - -public class Base64Test { - @Test - public void testDecode() throws UnsupportedEncodingException { - byte[] actualDecodeResult = Base64.decode("AAAAAAAA".getBytes("UTF-8"), 1); - assertEquals(6, actualDecodeResult.length); - assertEquals((byte) 0, actualDecodeResult[0]); - assertEquals((byte) 0, actualDecodeResult[1]); - assertEquals((byte) 0, actualDecodeResult[2]); - assertEquals((byte) 0, actualDecodeResult[3]); - assertEquals((byte) 0, actualDecodeResult[4]); - assertEquals((byte) 0, actualDecodeResult[5]); - } - - @Test - public void testDecode2() { - byte[] actualDecodeResult = Base64.decode(new byte[]{0, 'A', 'A', 'A', 'A', 'A', 'A', 'A'}, 1); - assertEquals(5, actualDecodeResult.length); - assertEquals((byte) 0, actualDecodeResult[0]); - assertEquals((byte) 0, actualDecodeResult[1]); - assertEquals((byte) 0, actualDecodeResult[2]); - assertEquals((byte) 0, actualDecodeResult[3]); - assertEquals((byte) 0, actualDecodeResult[4]); - } - - @Test - public void testDecode3() throws UnsupportedEncodingException { - byte[] actualDecodeResult = Base64.decode("AAAAAAAA".getBytes("UTF-8"), 2, 3, 1); - assertEquals(2, actualDecodeResult.length); - assertEquals((byte) 0, actualDecodeResult[0]); - assertEquals((byte) 0, actualDecodeResult[1]); - } - - @Test - public void testDecode4() { - assertThrows(IllegalArgumentException.class, - () -> Base64.decode(new byte[]{'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'}, 1, 1, 1)); - } - - @Test - public void testDecode5() { - byte[] actualDecodeResult = Base64.decode(new byte[]{'A', 'A', 0, 'A', 'A', 'A', 'A', 'A'}, 2, 3, 1); - assertEquals(1, actualDecodeResult.length); - assertEquals((byte) 0, actualDecodeResult[0]); - } - - @Test - public void testDecode7() { - assertThrows(NegativeArraySizeException.class, - () -> Base64.decode("AAAAAAAA".getBytes("UTF-8"), 2, Integer.MIN_VALUE, 1)); - } - - @Test - public void testDecoderConstructor() throws UnsupportedEncodingException { - assertEquals(24, (new Base64.Decoder(1, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8"))).output.length); - assertEquals(24, (new Base64.Decoder(8, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8"))).output.length); - } - - @Test - public void testEncodeToString() throws UnsupportedEncodingException { - assertEquals("QUFBQUFBQUE\n", Base64.encodeToString("AAAAAAAA".getBytes("UTF-8"), 1)); - assertEquals("", Base64.encodeToString(new byte[]{}, 1)); - assertEquals("QUFBQUFBQUFBQUFBQUFBQQ\n", Base64.encodeToString("AAAAAAAAAAAAAAAA".getBytes("UTF-8"), 1)); - assertEquals("QUFBQUFBQUE=\n", Base64.encodeToString("AAAAAAAA".getBytes("UTF-8"), 0)); - assertEquals("QUFBQUFBQUE=", Base64.encodeToString("AAAAAAAA".getBytes("UTF-8"), 2)); - assertEquals("QUFBQUFBQUE=\r\n", Base64.encodeToString("AAAAAAAA".getBytes("UTF-8"), 4)); - assertEquals("", Base64.encodeToString(new byte[]{}, 0)); - } - - @Test - public void testEncode() throws UnsupportedEncodingException { - assertEquals(12, Base64.encode("AAAAAAAA".getBytes("UTF-8"), 1).length); - assertEquals(0, Base64.encode(new byte[]{}, 1).length); - assertEquals(23, Base64.encode("AAAAAAAAAAAAAAAA".getBytes("UTF-8"), 1).length); - assertEquals(13, Base64.encode("AAAAAAAA".getBytes("UTF-8"), 0).length); - assertEquals(12, Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2).length); - assertEquals(14, Base64.encode("AAAAAAAA".getBytes("UTF-8"), 4).length); - assertEquals(0, Base64.encode(new byte[]{}, 0).length); - assertEquals(0, Base64.encode(new byte[]{'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'}, 1, 0, 1).length); - } - - @Test - public void testEncode2() throws UnsupportedEncodingException { - byte[] actualEncodeResult = Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2, 3, 1); - assertEquals(5, actualEncodeResult.length); - assertEquals('Q', actualEncodeResult[0]); - assertEquals('U', actualEncodeResult[1]); - assertEquals('F', actualEncodeResult[2]); - assertEquals('B', actualEncodeResult[3]); - assertEquals((byte) 10, actualEncodeResult[4]); - } - - @Test - public void testEncode4() throws UnsupportedEncodingException { - byte[] actualEncodeResult = Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2, 1, 1); - assertEquals(3, actualEncodeResult.length); - assertEquals('Q', actualEncodeResult[0]); - assertEquals('Q', actualEncodeResult[1]); - assertEquals((byte) 10, actualEncodeResult[2]); - } - - @Test - public void testEncode5() throws UnsupportedEncodingException { - byte[] actualEncodeResult = Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2, 2, 1); - assertEquals(4, actualEncodeResult.length); - assertEquals('Q', actualEncodeResult[0]); - assertEquals('U', actualEncodeResult[1]); - assertEquals('E', actualEncodeResult[2]); - assertEquals((byte) 10, actualEncodeResult[3]); - } - - @Test - public void testEncode6() throws UnsupportedEncodingException { - byte[] actualEncodeResult = Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2, 1, 0); - assertEquals(5, actualEncodeResult.length); - assertEquals('Q', actualEncodeResult[0]); - assertEquals('Q', actualEncodeResult[1]); - assertEquals('=', actualEncodeResult[2]); - assertEquals('=', actualEncodeResult[3]); - assertEquals((byte) 10, actualEncodeResult[4]); - } - - @Test - public void testEncode8() throws UnsupportedEncodingException { - byte[] actualEncodeResult = Base64.encode("AAAAAAAA".getBytes("UTF-8"), 2, 3, 4); - assertEquals(6, actualEncodeResult.length); - assertEquals('Q', actualEncodeResult[0]); - assertEquals('U', actualEncodeResult[1]); - assertEquals('F', actualEncodeResult[2]); - assertEquals('B', actualEncodeResult[3]); - assertEquals((byte) 13, actualEncodeResult[4]); - assertEquals((byte) 10, actualEncodeResult[5]); - } - - @Test - public void testEncoderConstructor() throws UnsupportedEncodingException { - Base64.Encoder actualEncoder = new Base64.Encoder(1, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8")); - assertFalse(actualEncoder.do_cr); - assertEquals(0, actualEncoder.tailLen); - assertEquals(24, actualEncoder.output.length); - assertFalse(actualEncoder.do_padding); - assertTrue(actualEncoder.do_newline); - } - - @Test - public void testEncoderConstructor2() throws UnsupportedEncodingException { - Base64.Encoder actualEncoder = new Base64.Encoder(0, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8")); - assertFalse(actualEncoder.do_cr); - assertEquals(0, actualEncoder.tailLen); - assertEquals(24, actualEncoder.output.length); - assertTrue(actualEncoder.do_padding); - assertTrue(actualEncoder.do_newline); - } - - @Test - public void testEncoderConstructor3() throws UnsupportedEncodingException { - Base64.Encoder actualEncoder = new Base64.Encoder(2, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8")); - assertFalse(actualEncoder.do_cr); - assertEquals(0, actualEncoder.tailLen); - assertEquals(24, actualEncoder.output.length); - assertTrue(actualEncoder.do_padding); - assertFalse(actualEncoder.do_newline); - } - - @Test - public void testEncoderConstructor4() throws UnsupportedEncodingException { - Base64.Encoder actualEncoder = new Base64.Encoder(4, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8")); - assertTrue(actualEncoder.do_cr); - assertEquals(0, actualEncoder.tailLen); - assertEquals(24, actualEncoder.output.length); - assertTrue(actualEncoder.do_padding); - assertTrue(actualEncoder.do_newline); - } - - @Test - public void testEncoderConstructor5() throws UnsupportedEncodingException { - Base64.Encoder actualEncoder = new Base64.Encoder(8, "AAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8")); - assertFalse(actualEncoder.do_cr); - assertEquals(0, actualEncoder.tailLen); - assertEquals(24, actualEncoder.output.length); - assertTrue(actualEncoder.do_padding); - assertTrue(actualEncoder.do_newline); - } -} - diff --git a/pom.xml b/pom.xml index 7b78cd2de..42895013f 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ 8.3.2 5.5.0 1.19.0 + 1.16.0 2.13.0 1.9.0 1.5.1 @@ -107,6 +108,13 @@ ${kotlinx-serialization.version} + + + commons-codec + commons-codec + ${commons-codec.version} + + com.h2database h2-mvstore From f60d571b129ab84b4e9b96cab83c785cc418da54 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Sat, 12 Aug 2023 16:29:55 +0530 Subject: [PATCH 08/18] readme updated --- README.md | 15 +++++++++++---- nitrite-support/README.md | 31 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d90df8c1a..02a5e0c11 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ ![Javadocs](https://javadoc.io/badge/org.dizitart/nitrite.svg) [![Discussion](https://img.shields.io/badge/chat-Discussion-blueviolet)](https://github.com/nitrite/nitrite-java/discussions) -

- nitrite logo +

+ nitrite logo

**NO**sql **O**bject (**NO2** a.k.a Nitrite) database is an open source nosql embedded -document store written in Java. It supports both in-memory and file based persistent store. +document store. It supports both in-memory and file based persistent store. Nitrite is an embedded database ideal for desktop, mobile or small web applications. @@ -37,6 +37,10 @@ Visit [here](https://github.com/nitrite/nitrite-java/tree/main/potassium-nitrite If you are looking for Nitrite for Flutter/Dart, head over to [nitrite-flutter](https://github.com/nitrite/nitrite-flutter). +## Deprecation Notice + +Nitrite DataGate and Nitrite Explorer is now deprecated and no longer maintained. + ## Getting Started with Nitrite **NOTE:** There are breaking api changes in version 4.x. So please exercise caution when upgrading from 3.x.x @@ -87,6 +91,9 @@ implementation 'org.dizitart:nitrite-mvstore-adapter' ``` +## Examples + +A Todo android application is available [here](https://github.com/nitrite/nitrite-android-demo) to demonstrate the usage of Nitrite in android. ### Quick Examples @@ -95,7 +102,7 @@ implementation 'org.dizitart:nitrite-mvstore-adapter' ```java // create a mvstore backed storage module MVStoreModule storeModule = MVStoreModule.withConfig() - .filePath("/tmp/test.db") // for android - .filePath(getFilesDir().getPath() + "/test.db") + .filePath("/tmp/test.db") .compress(true) .build(); diff --git a/nitrite-support/README.md b/nitrite-support/README.md index f56155013..ee759ae09 100644 --- a/nitrite-support/README.md +++ b/nitrite-support/README.md @@ -31,7 +31,22 @@ implementation 'org.dizitart:nitrite-support' ```java // export data to a json file -Exporter exporter = Exporter.of(sourceDb); +ExportOptions exportOptions = new ExportOptions(); +exportOptions.setNitriteFactory(() { + MVStoreModule storeModule = MVStoreModule.withConfig() + .filePath('/tmp/test-old.db') + .build(); + + return Nitrite.builder() + .compressed() + .loadModule(storeModule) + .openOrCreate(); +}); +exportOptions.setCollections(List.of("first")); +exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee")); +exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee"))); + +Exporter exporter = Exporter.withOptions(exportOptions); exporter.exportTo(schemaFile); ``` @@ -39,6 +54,18 @@ exporter.exportTo(schemaFile); ```java // import data from a json file -Importer importer = Importer.of(destDb); +ImportOptions importOptions = new ImportOptions(); +importOptions.setNitriteFactory(() { + MVStoreModule storeModule = MVStoreModule.withConfig() + .filePath('/tmp/test-old.db') + .build(); + + return Nitrite.builder() + .compressed() + .loadModule(storeModule) + .openOrCreate(); +}); + +Importer importer = Importer.withOptions(importOptions); importer.importFrom(schemaFile); ``` From bef0ae7cd6c463a9f173d0a87c1e3ccdd82f8fc8 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Mon, 14 Aug 2023 12:33:25 +0530 Subject: [PATCH 09/18] SimpleDocumentMapper renamed to EntityConverterMapper --- README.md | 4 +- .../java/org/dizitart/no2/NitriteTest.java | 6 +- .../no2/integration/NitriteBuilderTest.java | 4 +- .../no2/integration/NitriteStressTest.java | 6 +- .../dizitart/no2/integration/NitriteTest.java | 4 +- .../no2/integration/event/EventTest.java | 4 +- .../integration/migration/MigrationTest.java | 6 +- .../repository/BaseObjectRepositoryTest.java | 4 +- .../repository/CustomFieldSeparatorTest.java | 4 +- .../repository/NitriteIdAsIdTest.java | 4 +- .../ObjectRepositoryNegativeTest.java | 4 +- .../repository/ObjectRepositoryTest.java | 4 +- .../repository/RepositorySearchTest.java | 4 +- .../UniversalTextTokenizerTest.java | 4 +- .../java/org/dizitart/no2/NitriteTest.java | 10 +- .../no2/integration/NitriteBuilderTest.java | 4 +- .../no2/integration/NitriteStressTest.java | 4 +- .../dizitart/no2/integration/NitriteTest.java | 4 +- .../no2/integration/event/EventTest.java | 4 +- .../integration/migrate/MigrationTest.java | 6 +- .../repository/BaseObjectRepositoryTest.java | 4 +- .../repository/CustomFieldSeparatorTest.java | 4 +- .../repository/NitriteIdAsIdTest.java | 4 +- .../ObjectRepositoryNegativeTest.java | 4 +- .../repository/ObjectRepositoryTest.java | 4 +- .../repository/RepositorySearchTest.java | 4 +- .../UniversalTextTokenizerTest.java | 4 +- .../dizitart/no2/rocksdb/GithubIssues.java | 4 +- .../no2/support/BaseExternalTest.java | 4 +- .../java/org/dizitart/no2/NitriteConfig.java | 7 +- .../org/dizitart/no2/collection/Document.java | 25 ++++- .../no2/collection/DocumentCursor.java | 16 +--- .../dizitart/no2/collection/FindOptions.java | 18 +++- .../org/dizitart/no2/collection/FindPlan.java | 41 +++++++- .../no2/collection/NitriteCollection.java | 5 +- .../dizitart/no2/collection/NitriteId.java | 34 ++++--- .../no2/collection/SnowflakeIdGenerator.java | 10 +- .../no2/collection/UpdateOptions.java | 10 +- ...Mapper.java => EntityConverterMapper.java} | 10 +- .../no2/common/module/NitritePlugin.java | 3 + .../no2/common/module/PluginManager.java | 4 +- .../no2/common/processors/ProcessorChain.java | 4 +- .../org/dizitart/no2/filters/InFilter.java | 2 +- .../org/dizitart/no2/repository/EntityId.java | 8 +- .../no2/repository/ObjectIdField.java | 19 ++-- .../org/dizitart/no2/NitriteBuilderTest.java | 12 +-- .../org/dizitart/no2/NitriteConfigTest.java | 4 +- .../dizitart/no2/common/event/EventTest.java | 4 +- .../mapper/EntityConverterMapperTest.java | 96 +++++++++++++++++++ .../no2/common/mapper/MapperTest.java | 54 +++++------ .../mapper/SimpleDocumentMapperTest.java | 96 ------------------- .../no2/common/module/PluginManagerTest.java | 4 +- .../no2/common/util/DocumentUtilsTest.java | 8 +- .../no2/common/util/ObjectUtilsTest.java | 4 +- .../no2/common/util/ValidationUtilsTest.java | 6 +- .../no2/integration/NitriteStressTest.java | 4 +- .../dizitart/no2/integration/NitriteTest.java | 4 +- .../dizitart/no2/integration/StressTest.java | 4 +- .../repository/BaseObjectRepositoryTest.java | 4 +- .../repository/CustomFieldSeparatorTest.java | 4 +- .../repository/NitriteIdAsIdTest.java | 5 +- .../ObjectRepositoryNegativeTest.java | 4 +- .../repository/ObjectRepositoryTest.java | 4 +- .../repository/RepositoryJoinTest.java | 4 +- .../repository/RepositorySearchTest.java | 4 +- .../UniversalTextTokenizerTest.java | 4 +- .../EntityDecoratorScannerTest.java | 4 +- .../no2/repository/ObjectCursorTest.java | 4 +- 68 files changed, 373 insertions(+), 314 deletions(-) rename nitrite/src/main/java/org/dizitart/no2/common/mapper/{SimpleDocumentMapper.java => EntityConverterMapper.java} (93%) create mode 100644 nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java delete mode 100644 nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleDocumentMapperTest.java diff --git a/README.md b/README.md index 02a5e0c11..d2ec139ff 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ ![Javadocs](https://javadoc.io/badge/org.dizitart/nitrite.svg) [![Discussion](https://img.shields.io/badge/chat-Discussion-blueviolet)](https://github.com/nitrite/nitrite-java/discussions) -

- nitrite logo +

+ nitrite logo

**NO**sql **O**bject (**NO2** a.k.a Nitrite) database is an open source nosql embedded diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java index 2e1a0e15c..23906157d 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java @@ -29,7 +29,7 @@ import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexOptions; @@ -86,7 +86,7 @@ public class NitriteTest { public void setUp() throws ParseException { db = TestUtil.createDb(fileName, "test-user", "test-password"); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new CompatChild.Converter()); documentMapper.registerEntityConverter(new Receipt.Converter()); documentMapper.registerEntityConverter(new EmptyClass.Converter()); @@ -491,7 +491,7 @@ public void testReadCompatibility() throws IOException { String oldDbFile = System.getProperty("java.io.tmpdir") + File.separator + "old.db"; Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password"); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Receipt.Converter()); NitriteCollection collection = db.getCollection("test"); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java index 810ce1edd..2fcc73c9a 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java @@ -28,7 +28,7 @@ import org.dizitart.no2.common.Fields; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.InvalidOperationException; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.NitriteSecurityException; @@ -194,7 +194,7 @@ public void testPopulateRepositories() { .loadModule(module) .openOrCreate(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestObject.Converter()); documentMapper.registerEntityConverter(new TestObject2.Converter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java index f556c9c8c..7f19f75e6 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; @@ -67,7 +67,7 @@ public class NitriteStressTest { @Before public void before() { db = createDb(fileName); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestDto.Converter()); documentMapper.registerEntityConverter(new PerfTest.Converter()); documentMapper.registerEntityConverter(new PerfTestIndexed.Converter()); @@ -90,7 +90,7 @@ public void cleanUp() { @Test public void stressTest() { ObjectRepository testRepository = db.getRepository(TestDto.class); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestDto.Converter()); testRepository.createIndex(IndexOptions.indexOptions(IndexType.FULL_TEXT), "lastName"); testRepository.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "birthDate"); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java index 449b7ffe0..378e8192a 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.repository.data.ClassA; import org.dizitart.no2.integration.repository.data.ClassBConverter; import org.junit.After; @@ -39,7 +39,7 @@ public class NitriteTest { @Before public void setUp() { db = createDb(fileName); - SimpleDocumentMapper nitriteMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter()); nitriteMapper.registerEntityConverter(new ClassBConverter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java index d9b4e5816..5084dffa5 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.event; import org.dizitart.no2.collection.UpdateOptions; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Employee; import org.dizitart.no2.Nitrite; @@ -120,7 +120,7 @@ public void setUp() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); employeeRepository = db.getRepository(Employee.class); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java index 2843ba4c5..3e16c31c6 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.migration; import com.github.javafaker.Faker; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; @@ -58,7 +58,7 @@ public class MigrationTest { @Before public void setUp() { db = createDb(dbPath); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new OldClass.Converter()); documentMapper.registerEntityConverter(new OldClass.Literature.Converter()); documentMapper.registerEntityConverter(new NewClass.Converter()); @@ -128,7 +128,7 @@ public void migrate(InstructionSet instruction) { .addMigrations(migration) .openOrCreate("test-user", "test-password"); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new OldClass.Converter()); documentMapper.registerEntityConverter(new OldClass.Literature.Converter()); documentMapper.registerEntityConverter(new NewClass.Converter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java index f279620f0..7e90c07cd 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.integration.repository.decorator.ManufacturerConverter; @@ -142,7 +142,7 @@ protected void openDb() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new RepositoryJoinTest.Person.Converter()); documentMapper.registerEntityConverter(new RepositoryJoinTest.Address.Converter()); documentMapper.registerEntityConverter(new RepositoryJoinTest.PersonDetails.Converter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java index affd45598..bc4c0a903 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java @@ -22,7 +22,7 @@ import lombok.Setter; import lombok.ToString; import org.dizitart.no2.common.mapper.EntityConverter; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Company; import org.dizitart.no2.integration.repository.data.Note; @@ -72,7 +72,7 @@ public void setUp() { .fieldSeparator(":") .openOrCreate(); - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java index 4b776ea17..47b64f6b3 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2.integration.repository; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.WithNitriteId; import org.dizitart.no2.Nitrite; @@ -54,7 +54,7 @@ public class NitriteIdAsIdTest { @Before public void before() { db = TestUtil.createDb(fileName); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter()); repo = db.getRepository(WithNitriteId.class); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java index 66a816959..361ffc00f 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2.integration.repository; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.Nitrite; @@ -51,7 +51,7 @@ public class ObjectRepositoryNegativeTest { @Before public void setUp() { db = TestUtil.createDb(dbPath); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithPublicField.Converter()); documentMapper.registerEntityConverter(new WithObjectId.Converter()); documentMapper.registerEntityConverter(new WithOutId.Converter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java index d66ef2d9c..a4e0fecf6 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexType; @@ -70,7 +70,7 @@ public class ObjectRepositoryTest { @Before public void setUp() { - SimpleDocumentMapper mapper = new SimpleDocumentMapper(); + EntityConverterMapper mapper = new EntityConverterMapper(); mapper.registerEntityConverter(new InternalClass.Converter()); mapper.registerEntityConverter(new EmployeeEntity.Converter()); mapper.registerEntityConverter(new StressRecord.Converter()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java index 17c54b1e8..2b4454f11 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java @@ -20,7 +20,7 @@ import lombok.Getter; import org.dizitart.no2.common.WriteResult; import org.dizitart.no2.common.mapper.EntityConverter; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.SortOrder; @@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) { } } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Converter()); TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime()); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java index 59d6681ba..63d39a6f3 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java @@ -22,7 +22,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.index.NitriteTextIndexer; import org.dizitart.no2.index.fulltext.Languages; @@ -56,7 +56,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest { @Override public void setUp() { openDb(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TextData.Converter()); textRepository = db.getRepository(TextData.class); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java index 856d162e2..e4f938de0 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java @@ -29,7 +29,7 @@ import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexOptions; @@ -82,10 +82,10 @@ public class NitriteTest { public void setUp() throws ParseException { db = TestUtil.createDb(fileName, "test-user", "test-password"); - SimpleDocumentMapper simpleDocumentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); - simpleDocumentMapper.registerEntityConverter(new Receipt.Converter()); - simpleDocumentMapper.registerEntityConverter(new CompatChild.Converter()); - simpleDocumentMapper.registerEntityConverter(new EmptyClass.Converter()); + EntityConverterMapper entityConverterMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + entityConverterMapper.registerEntityConverter(new Receipt.Converter()); + entityConverterMapper.registerEntityConverter(new CompatChild.Converter()); + entityConverterMapper.registerEntityConverter(new EmptyClass.Converter()); simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java index 058e0b36b..c5b9fe1e2 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java @@ -29,7 +29,7 @@ import org.dizitart.no2.common.Fields; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.InvalidOperationException; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.NitriteSecurityException; @@ -175,7 +175,7 @@ public void testPopulateRepositories() { .fieldSeparator(".") .openOrCreate(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestObject.Converter()); documentMapper.registerEntityConverter(new TestObject2.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java index ff2d6dd9d..a061dfef7 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; @@ -67,7 +67,7 @@ public class NitriteStressTest { @Before public void before() { db = createDb(fileName); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestDto.Converter()); documentMapper.registerEntityConverter(new PerfTest.Converter()); documentMapper.registerEntityConverter(new PerfTestIndexed.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java index 20c06f02c..4ddc6ad38 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.repository.data.ClassA; import org.dizitart.no2.integration.repository.data.ClassBConverter; import org.junit.After; @@ -39,7 +39,7 @@ public class NitriteTest { @Before public void setUp() { db = createDb(fileName); - SimpleDocumentMapper nitriteMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter()); nitriteMapper.registerEntityConverter(new ClassBConverter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java index 9bbbcbdb1..e64133e9e 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.events.EventType; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Employee; import org.dizitart.no2.repository.ObjectRepository; @@ -88,7 +88,7 @@ public void setUp() { .openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); employeeRepository = db.getRepository(Employee.class); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java index cd31138bd..2969f330d 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.Constants; import org.dizitart.no2.common.Fields; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.MigrationException; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; @@ -58,7 +58,7 @@ public class MigrationTest { @Before public void setUp() { db = createDb(dbPath); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new OldClass.Converter()); documentMapper.registerEntityConverter(new OldClass.Literature.Converter()); documentMapper.registerEntityConverter(new NewClass.Converter()); @@ -127,7 +127,7 @@ public void migrate(InstructionSet instruction) { .addMigrations(migration) .openOrCreate("test-user", "test-password"); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new OldClass.Converter()); documentMapper.registerEntityConverter(new OldClass.Literature.Converter()); documentMapper.registerEntityConverter(new NewClass.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java index 0f34b6136..846926e7c 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.integration.repository.decorator.ManufacturerConverter; @@ -109,7 +109,7 @@ protected void openDb() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new RepositoryJoinTest.Person.Converter()); documentMapper.registerEntityConverter(new RepositoryJoinTest.Address.Converter()); documentMapper.registerEntityConverter(new RepositoryJoinTest.PersonDetails.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java index 792ac0426..f628f8a8f 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Company; @@ -71,7 +71,7 @@ public void setUp() { .fieldSeparator(":") .openOrCreate(); - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java index 4b776ea17..47b64f6b3 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2.integration.repository; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.WithNitriteId; import org.dizitart.no2.Nitrite; @@ -54,7 +54,7 @@ public class NitriteIdAsIdTest { @Before public void before() { db = TestUtil.createDb(fileName); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter()); repo = db.getRepository(WithNitriteId.class); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java index 6d7135ef5..860a4c46f 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2.integration.repository; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.Nitrite; @@ -51,7 +51,7 @@ public class ObjectRepositoryNegativeTest { @Before public void setUp() { db = TestUtil.createDb(dbPath); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithPublicField.Converter()); documentMapper.registerEntityConverter(new WithObjectId.Converter()); documentMapper.registerEntityConverter(new WithOutId.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java index 360ee228d..39d2f40a0 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.meta.Attributes; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexType; @@ -70,7 +70,7 @@ public class ObjectRepositoryTest { @Before public void setUp() { - SimpleDocumentMapper mapper = new SimpleDocumentMapper(); + EntityConverterMapper mapper = new EntityConverterMapper(); mapper.registerEntityConverter(new InternalClass.Converter()); mapper.registerEntityConverter(new EmployeeEntity.Converter()); mapper.registerEntityConverter(new StressRecord.Converter()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java index 066dd48af..0cfb86680 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.common.WriteResult; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.exceptions.InvalidIdException; import org.dizitart.no2.exceptions.NotIdentifiableException; @@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) { } } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Converter()); TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime()); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java index d509adc70..8ff352dc4 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java @@ -22,7 +22,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.index.NitriteTextIndexer; import org.dizitart.no2.index.fulltext.Languages; @@ -55,7 +55,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest { @Override public void setUp() { openDb(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TextData.Converter()); textRepository = db.getRepository(TextData.class); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java index f24145fd0..7174aea99 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java @@ -22,7 +22,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.repository.ObjectRepository; import org.junit.Test; @@ -42,7 +42,7 @@ public void testIssue412() { .loadModule(dbModule) .openOrCreate(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestData.Converter()); // Step 1 diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java index 6733ec0ea..1bd143ffe 100644 --- a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java +++ b/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteCollection; - import org.dizitart.no2.common.mapper.SimpleDocumentMapper; + import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.mvstore.MVStoreModule; import org.dizitart.no2.repository.ObjectRepository; import org.junit.After; @@ -115,7 +115,7 @@ protected Nitrite createDb(String filePath) { .filePath(filePath) .build(); - SimpleDocumentMapper documentMapper = new SimpleDocumentMapper(); + EntityConverterMapper documentMapper = new EntityConverterMapper(); documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); documentMapper.registerEntityConverter(new Company.CompanyConverter()); documentMapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java b/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java index 77ed5bfca..bc066bf98 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java @@ -107,7 +107,6 @@ public NitriteConfig loadModule(NitriteModule module) { * @param migration the migration * @return the nitrite config */ - @SuppressWarnings("Java8MapApi") public NitriteConfig addMigration(Migration migration) { if (configured) { throw new InvalidOperationException("Cannot add migration steps after database" + @@ -117,11 +116,7 @@ public NitriteConfig addMigration(Migration migration) { if (migration != null) { final int start = migration.getFromVersion(); final int end = migration.getToVersion(); - TreeMap targetMap = migrations.get(start); - if (targetMap == null) { - targetMap = new TreeMap<>(); - migrations.put(start, targetMap); - } + TreeMap targetMap = migrations.computeIfAbsent(start, k -> new TreeMap<>()); Migration existing = targetMap.get(end); if (existing != null) { log.warn("Overriding migration " + existing + " with " + migration); diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/Document.java b/nitrite/src/main/java/org/dizitart/no2/collection/Document.java index 9b47640c3..a93332d03 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/Document.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/Document.java @@ -16,6 +16,7 @@ package org.dizitart.no2.collection; +import org.dizitart.no2.NitriteConfig; import org.dizitart.no2.common.tuples.Pair; import java.io.Serializable; @@ -26,7 +27,27 @@ import static org.dizitart.no2.common.Constants.*; /** - * A representation of a nitrite document. + * Represents a document in Nitrite database. + *

+ * A document is a collection of key-value pairs. A key is always a {@link String} and value + * can be anything including null. + *

+ * Nitrite document supports nested documents as well. The key of a nested document is a {@link String} + * separated by {@link NitriteConfig#getFieldSeparator()}. By default, Nitrite uses `.` as field separator. + * This can be changed by setting {@link NitriteConfig#fieldSeparator(String)}. + *

+ * For example, if a document has a nested document + * { "a" : { "b" : 1 } }, then the value of inside the nested document can be retrieved by + * calling {@link #get(String)} with key a.b. + *

+ * Below fields are reserved and cannot be used as key in a document. + *

    + *
  • _id: The unique identifier of the document. If not provided, + * Nitrite will generate a unique {@link NitriteId} for the document during insertion.
  • + *
  • _revision: The revision number of the document.
  • + *
  • _source: The source of the document.
  • + *
  • _modified: The last modified time of the document in milliseconds since epoch.
  • + *
* * @since 1.0 * @author Anindya Chatterjee @@ -34,7 +55,7 @@ public interface Document extends Iterable>, Cloneable, Serializable { /** - * Creates a new empty document. + * Creates an empty document. * * @return the document */ diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java b/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java index ab87832ea..1ef6826f9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java @@ -20,26 +20,16 @@ import org.dizitart.no2.common.RecordStream; /** - * An interface to iterate over {@link NitriteCollection#find()} results. It provides a - * mechanism to iterate over all {@link NitriteId}s of the result. + * The DocumentCursor represents a cursor to iterate over {@link NitriteCollection#find()} results. + * It also provides methods for projection and perform left outer join with other DocumentCursor. + *

*

  * {@code
- *
- * // create/open a database
- * Nitrite db = Nitrite.builder()
- *  .openOrCreate("user", "password");
- *
- * // create a collection named - test
- * NitriteCollection collection = db.getCollection("test");
- *
- * // returns all ids un-filtered
  * DocumentCursor result = collection.find();
  *
  * for (Document doc : result) {
  *  // use your logic with the retrieved doc here
  * }
- *
- * }*
  * 
* * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/FindOptions.java b/nitrite/src/main/java/org/dizitart/no2/collection/FindOptions.java index 45469e068..b801ac3d3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/FindOptions.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/FindOptions.java @@ -36,16 +36,28 @@ @Accessors(fluent = true, chain = true) @Setter(AccessLevel.PACKAGE) public class FindOptions { + /** + * Gets the {@link SortableFields} for sorting the find results. + * */ private SortableFields orderBy; + + /** + * Gets the skip count. + * */ private Long skip; + + /** + * Gets the limit count. + * */ private Long limit; + + /** + * Indicates if the find operation should return distinct results. + * */ private boolean distinct = false; /** * Specifies the {@link Collator}. - * - * @param collator the collator - * @return the collator. */ @Setter(AccessLevel.PUBLIC) private Collator collator; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java b/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java index a2f86a27d..ce058de82 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java @@ -31,27 +31,66 @@ import java.util.Map; /** - * Represents an execution plan of a find operation after optimization. + * A plan for finding documents in a collection. * * @author Anindya Chatterjee * @since 4.0.0 */ @Data public class FindPlan { + /** + * Gets the {@link FieldBasedFilter} for byId search if any. + * */ private FieldBasedFilter byIdFilter; + + /** + * Gets the {@link IndexScanFilter} for index scan if any. + * */ private IndexScanFilter indexScanFilter; + + /** + * Gets the {@link Filter} for collection scan if any. + * */ private Filter collectionScanFilter; + /** + * Gets the {@link IndexDescriptor} for index scan if any. + * */ private IndexDescriptor indexDescriptor; + + /** + * Gets the index scan order. + * */ private Map indexScanOrder; + + /** + * Gets the blocking sort order. + * */ private List> blockingSortOrder; + /** + * Gets the skip count. + * */ private Long skip; + + /** + * Gets the limit count. + * */ private Long limit; + + /** + * Gets the distinct flag. + * */ private boolean distinct; + /** + * Gets the {@link Collator}. + * */ private Collator collator; + /** + * Gets the sub plans. + * */ private List subPlans; /** diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteCollection.java b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteCollection.java index 01a721198..1f6cdbdaf 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteCollection.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteCollection.java @@ -35,12 +35,13 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a named document collection stored in nitrite database. + * Represents a named document collection stored in Nitrite database. * It persists documents into the database. Each document is associated * with a unique {@link NitriteId} in a collection. *

* A nitrite collection supports indexing. Every nitrite collection is also - * observable. + * observable. It means, any change in a collection can be listened back via + * registering a {@link CollectionEventListener}. *

* Create a collection *
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java
index 302053861..ad9869f3b 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java
@@ -17,6 +17,7 @@
 package org.dizitart.no2.collection;
 
 import lombok.EqualsAndHashCode;
+import lombok.Getter;
 import org.dizitart.no2.exceptions.InvalidIdException;
 
 import java.io.IOException;
@@ -33,18 +34,24 @@
  * 

* During insertion if a unique object is supplied in the '_id' field * of the document, then the value of the '_id' field will be used to - * create a new {@link NitriteId}. If that is not supplied, then nitrite - * will auto generate one and supply it in the '_id' field of the document. + * create a new {@link NitriteId}. If the '_id' field is not supplied, then + * nitrite will generate a new [NitriteId] and will add it to the document. * * @author Anindya Chatterjee * @see NitriteCollection#getById(NitriteId) * @since 1.0 */ +@Getter @EqualsAndHashCode public final class NitriteId implements Comparable, Serializable { private static final long serialVersionUID = 1477462375L; private static final SnowflakeIdGenerator generator = new SnowflakeIdGenerator(); + /** + * Gets the underlying value of the NitriteId. + *

+ * The value is a string representation of a 64bit integer number. + */ private String idValue; private NitriteId() { @@ -56,7 +63,7 @@ private NitriteId(String value) { } /** - * Gets a new auto-generated {@link NitriteId}. + * Creates a new auto-generated {@link NitriteId}. * * @return a new auto-generated {@link NitriteId}. */ @@ -65,7 +72,9 @@ public static NitriteId newId() { } /** - * Creates a {@link NitriteId} from a long value. + * Creates a {@link NitriteId} from a value. + *

+ * The value must be a string representation of a 64bit integer number. * * @param value the value * @return the {@link NitriteId} @@ -75,6 +84,14 @@ public static NitriteId createId(String value) { return new NitriteId(value); } + /** + * Validates a value to be used as {@link NitriteId}. + *

+ * The value must be a string representation of a 64bit integer number. + * + * @param value the value + * @return `true` if the value is valid; otherwise `false`. + * */ public static boolean validId(Object value) { if (value == null) { throw new InvalidIdException("id cannot be null"); @@ -104,15 +121,6 @@ public String toString() { return ""; } - /** - * Gets the underlying id object. - * - * @return the underlying id object. - */ - public String getIdValue() { - return idValue; - } - private void writeObject(ObjectOutputStream stream) throws IOException { stream.writeUTF(idValue); } diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java b/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java index a7b56663c..d089e8e4b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java @@ -24,8 +24,8 @@ import java.util.UUID; /** - * Generate unique IDs using the Twitter Snowflake algorithm (see https://github.com/twitter/snowflake). Snowflake IDs - * are 64 bit positive longs composed of: + * Generate unique IDs using the Twitter Snowflake algorithm (see Snowflake). + * Snowflake IDs are 64 bit positive longs composed of: * *

    *
  • 41 bits time stamp
  • @@ -34,7 +34,8 @@ *
  • 1 unused sign bit, always set to 0
  • *
*

- * This is a derivative work of - https://github.com/apache/marmotta/blob/master/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java + * This is a derivative work of - + * Sebastian Schaffert *

* * @author Sebastian Schaffert (sschaffert@apache.org) @@ -46,12 +47,10 @@ public class SnowflakeIdGenerator { private final long nodeIdBits = 10L; private long nodeId; - private volatile long lastTimestamp = -1L; private volatile long sequence = 0L; private static final long no2epoch = 1288834974657L; - public SnowflakeIdGenerator() { random = new SecureRandom(); long maxNodeId = ~(-1L << nodeIdBits); @@ -79,7 +78,6 @@ protected long getNodeId() { return ((0x000000FF & (long) uuid[uuid.length - 1]) | (0x0000FF00 & (((long) rndByte) << 8))) >> 6; } - /** * Return the next unique id for the type with the given name using the generator's id generation strategy. * diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/UpdateOptions.java b/nitrite/src/main/java/org/dizitart/no2/collection/UpdateOptions.java index 54cba94b5..73319e67c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/UpdateOptions.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/UpdateOptions.java @@ -23,12 +23,13 @@ import org.dizitart.no2.filters.Filter; /** - * Settings to control update operation in {@link NitriteCollection}. + * Represents options to configure update operation. * * @author Anindya Chatterjee * @see NitriteCollection#update(Filter, Document, UpdateOptions) * @since 1.0 */ +@Getter @ToString @EqualsAndHashCode public class UpdateOptions { @@ -37,20 +38,13 @@ public class UpdateOptions { * Indicates if the update operation will insert a new document if it * does not find any existing document to update. * - * @param insertIfAbsent a value indicating, if a new document to insert in case the - * filter fails to find a document to update. - * @return `true` if a new document to insert; otherwise, `false`. * @see NitriteCollection#update(Filter, Document, UpdateOptions) */ - @Getter @Setter private boolean insertIfAbsent; /** * Indicates if only one document will be updated or all of them. - * - * @param justOnce a value indicating if only one document to update or all. - * @return `true` if only one document to update; otherwise, `false`. */ @Getter @Setter diff --git a/nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleDocumentMapper.java b/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java similarity index 93% rename from nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleDocumentMapper.java rename to nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java index ab40f0a97..e2e3591d3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleDocumentMapper.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java @@ -30,19 +30,23 @@ /** * A {@link NitriteMapper} based on {@link EntityConverter} implementation. * + *

+ * This mapper is used by default in nitrite. It uses {@link EntityConverter} to + * convert an object of type Source to an object of type Target. + * * @author Anindya Chatterjee. * @since 4.0 */ -public class SimpleDocumentMapper implements NitriteMapper { +public class EntityConverterMapper implements NitriteMapper { private final Set> valueTypes; private final Map, EntityConverter> converterRegistry; /** - * Instantiates a new {@link SimpleDocumentMapper}. + * Instantiates a new {@link EntityConverterMapper}. * * @param valueTypes the value types */ - public SimpleDocumentMapper(Class... valueTypes) { + public EntityConverterMapper(Class... valueTypes) { this.valueTypes = new HashSet<>(); this.converterRegistry = new HashMap<>(); init(listOf(valueTypes)); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java b/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java index b7a16d21d..806de1337 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java @@ -32,6 +32,9 @@ public interface NitritePlugin extends AutoCloseable { */ void initialize(NitriteConfig nitriteConfig); + /** + * Closes the plugin instance. + */ default void close() { // this is to make NitritePlugin a functional interface // and make close() not throw checked exception diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java index b724975d7..12d0da6aa 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java @@ -22,7 +22,7 @@ import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.PluginException; import org.dizitart.no2.index.*; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.store.NitriteStore; import org.dizitart.no2.store.memory.InMemoryStoreModule; @@ -188,7 +188,7 @@ protected void loadInternalPlugins() { if (nitriteMapper == null) { log.debug("Loading mappable mapper"); - NitritePlugin plugin = new SimpleDocumentMapper(); + NitritePlugin plugin = new EntityConverterMapper(); loadPlugin(plugin); } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java b/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java index 3d31ad18a..2ed6b0ad5 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java @@ -23,8 +23,8 @@ import java.util.List; /** - * Represents a {@link Processor} chain. It executes a - * list of processor on a document. + * Represents a {@link Processor} chain. The processors are executed in the order + * they are added to the chain. * * @author Anindya Chatterjee * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/InFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/InFilter.java index 79b4a3872..13d1b2fdf 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/InFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/InFilter.java @@ -27,8 +27,8 @@ /** * @author Anindya Chatterjee */ +@Getter class InFilter extends ComparableArrayFilter { - @Getter private final Set> comparableSet; InFilter(String field, Comparable... values) { diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java index 46748c69f..387ebc7c5 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java @@ -30,12 +30,10 @@ import static org.dizitart.no2.filters.FluentFilter.where; +@Getter public class EntityId { - @Getter - private String fieldName; - - @Getter - private String[] subFields; + private final String fieldName; + private final String[] subFields; private List embeddedFieldNames; diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java index 50d286a64..8a237fab1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java @@ -33,22 +33,18 @@ * @author Anindya Chatterjee */ @Getter +@Setter class ObjectIdField { - @Setter + // top level field name + private String idFieldName; + // child level field names private String[] fieldNames; - - @Getter - @Setter + // the id field of the entity class private Field field; - - @Getter - @Setter + // indicates if the id field is embedded private boolean isEmbedded; - @Getter - @Setter - private String idFieldName; - + // fully qualified field name with embedded field separator public String[] getEmbeddedFieldNames() { if (!isEmbedded) { return new String[]{ idFieldName }; @@ -63,6 +59,7 @@ public String[] getEmbeddedFieldNames() { return fieldNames; } + // creates a filter for the id field public Filter createUniqueFilter(Object value, NitriteMapper nitriteMapper) { if (getEmbeddedFieldNames().length == 1) { return where(idFieldName).eq(value); diff --git a/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java b/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java index 2bea9444b..62bacd76e 100644 --- a/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.common.FieldValues; import org.dizitart.no2.common.Fields; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.module.NitriteModule; import org.dizitart.no2.common.module.NitritePlugin; import org.dizitart.no2.common.module.PluginManager; @@ -139,7 +139,7 @@ public void testOpenOrCreate() { assertFalse(actualOpenOrCreateResult.isClosed()); assertFalse(store.isClosed()); assertSame(store, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); } @Test @@ -153,7 +153,7 @@ public void testOpenOrCreate2() { assertFalse(store.isClosed()); PluginManager pluginManager = config.getPluginManager(); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); assertTrue(store.getCatalog().getKeyedRepositoryNames().isEmpty()); assertSame(store, pluginManager.getNitriteStore()); assertTrue(((InMemoryConfig) store.getStoreConfig()).eventListeners().isEmpty()); @@ -170,7 +170,7 @@ public void testOpenOrCreate3() { assertFalse(store.isClosed()); PluginManager pluginManager = config.getPluginManager(); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); assertTrue(store.getCatalog().getKeyedRepositoryNames().isEmpty()); assertSame(store, pluginManager.getNitriteStore()); assertTrue(((InMemoryConfig) store.getStoreConfig()).eventListeners().isEmpty()); @@ -185,7 +185,7 @@ public void testOpenOrCreate4() { assertEquals(3, pluginManager.getIndexerMap().size()); NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); assertFalse(nitriteStore.isClosed()); assertTrue(((InMemoryConfig) nitriteStore.getStoreConfig()).eventListeners().isEmpty()); } @@ -199,7 +199,7 @@ public void testOpenOrCreate5() { NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertFalse(nitriteStore.isClosed()); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); } @Test diff --git a/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java b/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java index eb8bc3d55..dfbced302 100644 --- a/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.module.NitriteModule; import org.dizitart.no2.common.module.NitritePlugin; import org.dizitart.no2.common.module.PluginManager; @@ -115,7 +115,7 @@ public void testAutoConfigure() { assertEquals(3, pluginManager.getIndexerMap().size()); NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); assertFalse(nitriteStore.isClosed()); assertTrue(((InMemoryConfig) nitriteStore.getStoreConfig()).eventListeners().isEmpty()); } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java index cd274e7c1..4b8ddc781 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; import org.dizitart.no2.collection.UpdateOptions; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.collection.events.EventType; import org.dizitart.no2.repository.ObjectRepository; @@ -76,7 +76,7 @@ public void setUp() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); employeeRepository = db.getRepository(Employee.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java new file mode 100644 index 000000000..100ee29dc --- /dev/null +++ b/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java @@ -0,0 +1,96 @@ +package org.dizitart.no2.common.mapper; + +import org.dizitart.no2.integration.NitriteStressTest; +import org.dizitart.no2.integration.NitriteTest; +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.exceptions.ObjectMappingException; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class EntityConverterMapperTest { + @Test + public void testConvert() { + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(Integer.class); + assertEquals(0, ((Integer) entityConverterMapper.tryConvert(0, Object.class)).intValue()); + } + + @Test + public void testConvert2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + assertEquals("source", entityConverterMapper.tryConvert("source", Object.class)); + } + + @Test + public void testConvert3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + assertEquals(0, ((Integer) entityConverterMapper.tryConvert(0, Object.class)).intValue()); + } + + @Test + public void testConvertFromDocument() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + assertNull(entityConverterMapper.convertFromDocument(null, Object.class)); + } + + @Test + public void testConvertFromDocument2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + Class type = Object.class; + assertThrows(ObjectMappingException.class, + () -> entityConverterMapper.convertFromDocument(Document.createDocument(), type)); + } + + @Test + public void testConvertFromDocument3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + assertNull( + (new EntityConverterMapper(forNameResult, forNameResult1, Object.class)).convertFromDocument(null, null)); + } + + @Test + public void testConvertToDocument() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + assertThrows(ObjectMappingException.class, + () -> (new EntityConverterMapper(forNameResult, forNameResult1, Object.class)).convertToDocument("source")); + } + + @Test + public void testConvertToDocument2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + entityConverterMapper.registerEntityConverter(new NitriteTest.CompatChild.CompatChildConverter()); + assertEquals(2, entityConverterMapper.convertToDocument(new NitriteTest.CompatChild()).size()); + } + + @Test + public void testConvertToDocument3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + entityConverterMapper.registerEntityConverter(new NitriteStressTest.TestDto.Converter()); + assertEquals(7, entityConverterMapper.convertToDocument(new NitriteStressTest.TestDto()).size()); + } + + @Test + public void testConvertToDocument4() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + entityConverterMapper.registerEntityConverter(new Company.CompanyConverter()); + assertEquals(3, entityConverterMapper.convertToDocument(new Company()).size()); + } + +} + diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java index 918808de7..ee209e3af 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java @@ -31,15 +31,15 @@ * @author Anindya Chatterjee */ public class MapperTest { - private SimpleDocumentMapper simpleDocumentMapper; + private EntityConverterMapper entityConverterMapper; @Rule public Retry retry = new Retry(3); @Test public void testWithConverter() { - simpleDocumentMapper = new SimpleDocumentMapper(); - simpleDocumentMapper.registerEntityConverter(new Employee.Converter()); + entityConverterMapper = new EntityConverterMapper(); + entityConverterMapper.registerEntityConverter(new Employee.Converter()); Employee boss = new Employee(); boss.setEmpId("1"); @@ -53,12 +53,12 @@ public void testWithConverter() { emp1.setBoss(boss); long start = System.currentTimeMillis(); - Document document = (Document) simpleDocumentMapper.tryConvert(emp1, Document.class); + Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class); long diff = System.currentTimeMillis() - start; System.out.println(diff); start = System.currentTimeMillis(); - Employee employee = (Employee) simpleDocumentMapper.tryConvert(document, Employee.class); + Employee employee = (Employee) entityConverterMapper.tryConvert(document, Employee.class); diff = System.currentTimeMillis() - start; System.out.println(diff); assertEquals(emp1, employee); @@ -66,10 +66,10 @@ public void testWithConverter() { @Test public void testWithMappable() { - simpleDocumentMapper = new SimpleDocumentMapper(); - simpleDocumentMapper.registerEntityConverter(new Department.DepartmentConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableDepartment.Converter()); + entityConverterMapper = new EntityConverterMapper(); + entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); + entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -83,12 +83,12 @@ public void testWithMappable() { emp1.setBoss(boss); long start = System.currentTimeMillis(); - Document document = (Document) simpleDocumentMapper.tryConvert(emp1, Document.class); + Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class); long diff = System.currentTimeMillis() - start; System.out.println(diff); start = System.currentTimeMillis(); - MappableEmployee employee = (MappableEmployee) simpleDocumentMapper.tryConvert(document, MappableEmployee.class); + MappableEmployee employee = (MappableEmployee) entityConverterMapper.tryConvert(document, MappableEmployee.class); diff = System.currentTimeMillis() - start; System.out.println(diff); assertEquals(emp1, employee); @@ -96,10 +96,10 @@ public void testWithMappable() { @Test public void testWithConverterAndMappableMix() { - simpleDocumentMapper = new SimpleDocumentMapper(); - simpleDocumentMapper.registerEntityConverter(new Department.DepartmentConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableDepartment.Converter()); + entityConverterMapper = new EntityConverterMapper(); + entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); + entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); final MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -120,12 +120,12 @@ public void testWithConverterAndMappableMix() { }}); long start = System.currentTimeMillis(); - Document document = (Document) simpleDocumentMapper.tryConvert(department, Document.class); + Document document = (Document) entityConverterMapper.tryConvert(department, Document.class); long diff = System.currentTimeMillis() - start; System.out.println(diff); start = System.currentTimeMillis(); - Department dept = (Department) simpleDocumentMapper.tryConvert(document, Department.class); + Department dept = (Department) entityConverterMapper.tryConvert(document, Department.class); diff = System.currentTimeMillis() - start; System.out.println(diff); assertEquals(department, dept); @@ -133,10 +133,10 @@ public void testWithConverterAndMappableMix() { @Test public void testNested() { - simpleDocumentMapper = new SimpleDocumentMapper(); - simpleDocumentMapper.registerEntityConverter(new Department.DepartmentConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - simpleDocumentMapper.registerEntityConverter(new MappableDepartment.Converter()); + entityConverterMapper = new EntityConverterMapper(); + entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); + entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); final MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -157,12 +157,12 @@ public void testNested() { }}); long start = System.currentTimeMillis(); - Document document = (Document) simpleDocumentMapper.tryConvert(department, Document.class); + Document document = (Document) entityConverterMapper.tryConvert(department, Document.class); long diff = System.currentTimeMillis() - start; System.out.println(diff); start = System.currentTimeMillis(); - MappableDepartment dept = (MappableDepartment) simpleDocumentMapper.tryConvert(document, MappableDepartment.class); + MappableDepartment dept = (MappableDepartment) entityConverterMapper.tryConvert(document, MappableDepartment.class); diff = System.currentTimeMillis() - start; System.out.println(diff); assertEquals(department, dept); @@ -170,16 +170,16 @@ public void testNested() { @Test public void testWithValueType() { - simpleDocumentMapper = new SimpleDocumentMapper(); - simpleDocumentMapper.registerEntityConverter(new Company.CompanyConverter()); - simpleDocumentMapper.registerEntityConverter(new Company.CompanyId.CompanyIdConverter()); + entityConverterMapper = new EntityConverterMapper(); + entityConverterMapper.registerEntityConverter(new Company.CompanyConverter()); + entityConverterMapper.registerEntityConverter(new Company.CompanyId.CompanyIdConverter()); Company company = new Company(); company.setName("test"); company.setId(1L); company.setCompanyId(new Company.CompanyId(1L)); - Document document = (Document) simpleDocumentMapper.tryConvert(company, Document.class); + Document document = (Document) entityConverterMapper.tryConvert(company, Document.class); Object companyId = document.get("companyId"); assertTrue(companyId instanceof Document); } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleDocumentMapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleDocumentMapperTest.java deleted file mode 100644 index 27a1c8499..000000000 --- a/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleDocumentMapperTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.dizitart.no2.common.mapper; - -import org.dizitart.no2.integration.NitriteStressTest; -import org.dizitart.no2.integration.NitriteTest; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.exceptions.ObjectMappingException; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class SimpleDocumentMapperTest { - @Test - public void testConvert() { - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(Integer.class); - assertEquals(0, ((Integer) simpleDocumentMapper.tryConvert(0, Object.class)).intValue()); - } - - @Test - public void testConvert2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - assertEquals("source", simpleDocumentMapper.tryConvert("source", Object.class)); - } - - @Test - public void testConvert3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - assertEquals(0, ((Integer) simpleDocumentMapper.tryConvert(0, Object.class)).intValue()); - } - - @Test - public void testConvertFromDocument() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - assertNull(simpleDocumentMapper.convertFromDocument(null, Object.class)); - } - - @Test - public void testConvertFromDocument2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - Class type = Object.class; - assertThrows(ObjectMappingException.class, - () -> simpleDocumentMapper.convertFromDocument(Document.createDocument(), type)); - } - - @Test - public void testConvertFromDocument3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - assertNull( - (new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class)).convertFromDocument(null, null)); - } - - @Test - public void testConvertToDocument() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - assertThrows(ObjectMappingException.class, - () -> (new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class)).convertToDocument("source")); - } - - @Test - public void testConvertToDocument2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - simpleDocumentMapper.registerEntityConverter(new NitriteTest.CompatChild.CompatChildConverter()); - assertEquals(2, simpleDocumentMapper.convertToDocument(new NitriteTest.CompatChild()).size()); - } - - @Test - public void testConvertToDocument3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - simpleDocumentMapper.registerEntityConverter(new NitriteStressTest.TestDto.Converter()); - assertEquals(7, simpleDocumentMapper.convertToDocument(new NitriteStressTest.TestDto()).size()); - } - - @Test - public void testConvertToDocument4() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - SimpleDocumentMapper simpleDocumentMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); - simpleDocumentMapper.registerEntityConverter(new Company.CompanyConverter()); - assertEquals(3, simpleDocumentMapper.convertToDocument(new Company()).size()); - } - -} - diff --git a/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java b/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java index 459dd6a84..19ef3c7f2 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.common.module; import org.dizitart.no2.NitriteConfig; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.PluginException; import org.dizitart.no2.store.NitriteStore; import org.junit.Test; @@ -63,7 +63,7 @@ public void testFindAndLoadPlugins() { NitriteStore nitriteStore = pluginManager.getNitriteStore(); assertTrue(nitriteStore instanceof org.dizitart.no2.store.memory.InMemoryStore); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof SimpleDocumentMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); assertFalse(nitriteStore.isClosed()); } } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java index 7cca9f4f5..808c26a76 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java @@ -20,7 +20,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.filters.ComparableFilter; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.integration.Retry; @@ -83,13 +83,13 @@ public void testSkeletonDocument() { public void testSkeletonDocument2() { Class forNameResult = Object.class; Class forNameResult1 = Object.class; - SimpleDocumentMapper nitriteMapper = new SimpleDocumentMapper(forNameResult, forNameResult1, Object.class); + EntityConverterMapper nitriteMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); assertEquals(0, DocumentUtils.skeletonDocument(nitriteMapper, Object.class).size()); } @Test public void testSkeletonDocument3() { - SimpleDocumentMapper nitriteMapper = new SimpleDocumentMapper(); + EntityConverterMapper nitriteMapper = new EntityConverterMapper(); Document document = DocumentUtils.skeletonDocument(nitriteMapper, Integer.class); assertNull(document); } @@ -110,7 +110,7 @@ public void testIsSimilar2() { @Test public void testDummyDocument() { - SimpleDocumentMapper nitriteMapper = new SimpleDocumentMapper(); + EntityConverterMapper nitriteMapper = new EntityConverterMapper(); nitriteMapper.registerEntityConverter(new DummyTest.Converter()); Document document = skeletonDocument(nitriteMapper, DummyTest.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java index 54a614823..5481d03af 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java @@ -25,7 +25,7 @@ import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.ObjectMappingException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.integration.NitriteTest; @@ -125,7 +125,7 @@ public void testDeepEquals8() { @Test public void testNewInstance() { - SimpleDocumentMapper mapper = new SimpleDocumentMapper(); + EntityConverterMapper mapper = new EntityConverterMapper(); mapper.registerEntityConverter(new EnclosingType.Converter()); mapper.registerEntityConverter(new ChildClass.Converter()); mapper.registerEntityConverter(new FieldType.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java index 10c373a75..0c577f25b 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java @@ -16,7 +16,7 @@ package org.dizitart.no2.common.util; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.ClassA; @@ -79,7 +79,7 @@ public void testCharSequenceNotEmpty() { @Test public void testValidateProjectionType() { - SimpleDocumentMapper documentMapper = new SimpleDocumentMapper(); + EntityConverterMapper documentMapper = new EntityConverterMapper(); documentMapper.registerEntityConverter(new ClassA.ClassAConverter()); documentMapper.registerEntityConverter(new ClassBConverter()); documentMapper.registerEntityConverter(new EmptyClass.Converter()); @@ -96,7 +96,7 @@ public void testValidateProjectionType() { @Test public void testValidateRepositoryType() { - SimpleDocumentMapper documentMapper = new SimpleDocumentMapper(); + EntityConverterMapper documentMapper = new EntityConverterMapper(); documentMapper.registerEntityConverter(new ClassA.ClassAConverter()); documentMapper.registerEntityConverter(new ClassBConverter()); documentMapper.registerEntityConverter(new EmptyClass.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java index 7c2c22836..545e92dd2 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.repository.ObjectRepository; @@ -53,7 +53,7 @@ public class NitriteStressTest { @Test public void stressTest() { Nitrite database = createDb(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) database.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) database.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestDto.Converter()); ObjectRepository testRepository = database.getRepository(TestDto.class); testRepository.createIndex(IndexOptions.indexOptions(IndexType.FULL_TEXT), "lastName"); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java index b731efbd7..2a7f7dfcf 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -30,7 +30,7 @@ import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexOptions; @@ -76,7 +76,7 @@ public class NitriteTest { @Before public void setUp() throws ParseException { db = createDb("test-user", "test-password"); - SimpleDocumentMapper nitriteMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); nitriteMapper.registerEntityConverter(new Receipt.ReceiptConverter()); nitriteMapper.registerEntityConverter(new CompatChild.CompatChildConverter()); nitriteMapper.registerEntityConverter(new EmptyClass.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java index 437b293c9..d34936a7c 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; @@ -62,7 +62,7 @@ public void before() { .fieldSeparator(".") .openOrCreate(); - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new PerfTest.PerfTestConverter()); mapper.registerEntityConverter(new PerfTestIndexed.PerfTestIndexedConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java index 2b01b1b19..999b864d9 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.integration.repository.decorator.*; @@ -107,7 +107,7 @@ private void openDb() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new Employee.EmployeeConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java index b72b30105..3b7cd0933 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Company; @@ -62,7 +62,7 @@ public void setUp() { .fieldSeparator(":") .openOrCreate(); - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java index 53273f3dc..2130d4ca4 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.repository; import org.dizitart.no2.Nitrite; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.TestUtil; import org.dizitart.no2.collection.NitriteId; @@ -49,7 +49,7 @@ public class NitriteIdAsIdTest { @Before public void before() { db = TestUtil.createDb(); - SimpleDocumentMapper mapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter()); repo = db.getRepository(WithNitriteId.class); @@ -72,7 +72,6 @@ public void testNitriteIdField() { Cursor cursor = repo.find(); for (WithNitriteId withNitriteId : cursor) { - System.out.println(withNitriteId.name); assertNotNull(withNitriteId.idField); } diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java index a071dd90b..562b1b479 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.repository; import org.dizitart.no2.Nitrite; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.TestUtil; import org.dizitart.no2.collection.NitriteId; @@ -46,7 +46,7 @@ public class ObjectRepositoryNegativeTest { @Before public void setUp() { db = TestUtil.createDb(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithPublicField.Converter()); documentMapper.registerEntityConverter(new WithObjectId.Converter()); documentMapper.registerEntityConverter(new WithOutId.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java index 98759627e..752939810 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.exceptions.UniqueConstraintException; import org.dizitart.no2.exceptions.ValidationException; @@ -65,7 +65,7 @@ public class ObjectRepositoryTest { @Before public void setUp() { - SimpleDocumentMapper mapper = new SimpleDocumentMapper(); + EntityConverterMapper mapper = new EntityConverterMapper(); mapper.registerEntityConverter(new InternalClass.Converter()); mapper.registerEntityConverter(new EmployeeEntity.Converter()); mapper.registerEntityConverter(new StressRecord.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java index 9739e854f..d2fdfb633 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.common.RecordStream; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.InvalidOperationException; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.repository.ObjectRepository; @@ -105,7 +105,7 @@ private void openDb() { db = nitriteBuilder.openOrCreate(); } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Person.Converter()); documentMapper.registerEntityConverter(new Address.Converter()); documentMapper.registerEntityConverter(new PersonDetails.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java index 934a498ff..e2682f3eb 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.common.WriteResult; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.exceptions.InvalidIdException; import org.dizitart.no2.exceptions.NotIdentifiableException; @@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) { } } - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Converter()); TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java index c5524dfee..9277d4f4f 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java @@ -22,7 +22,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.index.NitriteTextIndexer; import org.dizitart.no2.index.fulltext.Languages; @@ -51,7 +51,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest { @Override public void setUp() { openDb(); - SimpleDocumentMapper documentMapper = (SimpleDocumentMapper) db.getConfig().nitriteMapper(); + EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TextData.Converter()); textRepository = db.getRepository(TextData.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java b/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java index 5d6b6ccc0..31a011297 100644 --- a/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java @@ -20,7 +20,7 @@ import lombok.Data; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.repository.data.ClassA; import org.dizitart.no2.integration.repository.data.ClassBConverter; @@ -40,7 +40,7 @@ public class EntityDecoratorScannerTest { @Before public void setUp() { - SimpleDocumentMapper nitriteMapper = new SimpleDocumentMapper(); + EntityConverterMapper nitriteMapper = new EntityConverterMapper(); nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter()); nitriteMapper.registerEntityConverter(new ClassBConverter()); collection = Nitrite.builder().fieldSeparator(".").openOrCreate().getCollection("test"); diff --git a/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java b/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java index 4ec228f17..439ac920d 100644 --- a/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.Lookup; import org.dizitart.no2.common.RecordStream; -import org.dizitart.no2.common.mapper.SimpleDocumentMapper; +import org.dizitart.no2.common.mapper.EntityConverterMapper; import org.dizitart.no2.common.processors.ProcessorChain; import org.dizitart.no2.common.streams.DocumentStream; import org.dizitart.no2.common.streams.MutatedObjectStream; @@ -81,7 +81,7 @@ public void testProject() { @Test public void testProject3() { - SimpleDocumentMapper nitriteMapper = new SimpleDocumentMapper(); + EntityConverterMapper nitriteMapper = new EntityConverterMapper(); RecordStream> recordStream = (RecordStream>) mock( RecordStream.class); DocumentStream cursor = new DocumentStream(recordStream, new ProcessorChain()); From b80675beba73c7495e67e26b37e5c499a78af54a Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Wed, 16 Aug 2023 21:20:04 +0530 Subject: [PATCH 10/18] documentation --- nitrite/pom.xml | 12 + .../no2/collection/CollectionFactory.java | 3 +- .../collection/DefaultNitriteCollection.java | 1 + .../org/dizitart/no2/collection/Document.java | 2 +- .../no2/collection/DocumentCursor.java | 2 +- .../org/dizitart/no2/collection/FindPlan.java | 2 +- .../no2/collection/NitriteDocument.java | 1 - .../events/CollectionEventListener.java | 5 +- .../no2/collection/events/EventAware.java | 18 +- .../operation/CollectionOperations.java | 115 ----- .../operation/DocumentIndexWriter.java | 1 - .../collection/operation/FindOptimizer.java | 2 - .../collection/operation/IndexManager.java | 448 +++++++++--------- .../collection/operation/IndexOperations.java | 1 + .../collection/operation/ReadOperations.java | 1 + .../collection/operation/WriteOperations.java | 1 + .../collection/operation/WriteResultImpl.java | 1 + 17 files changed, 238 insertions(+), 378 deletions(-) diff --git a/nitrite/pom.xml b/nitrite/pom.xml index f831cb189..1dd2c2640 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -142,6 +142,18 @@ org.apache.maven.plugins maven-javadoc-plugin + + + org.dizitart.no2.collection.operation, + org.dizitart.no2.common.concurrent, + org.dizitart.no2.common.crypto, + + + **/*CollectionFactory.java + **/*DefaultNitriteCollection.java + **/*SnowflakeIdGenerator.java + + org.apache.maven.plugins diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/CollectionFactory.java b/nitrite/src/main/java/org/dizitart/no2/collection/CollectionFactory.java index ea2973230..a4088a967 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/CollectionFactory.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/CollectionFactory.java @@ -33,9 +33,8 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * A factory class to create {@link NitriteCollection}. - *

NOTE: Internal API

* @author Anindya Chatterjee + * @since 4.0 */ public class CollectionFactory { private final Map collectionMap; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/DefaultNitriteCollection.java b/nitrite/src/main/java/org/dizitart/no2/collection/DefaultNitriteCollection.java index aedb15e49..df07fe291 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/DefaultNitriteCollection.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/DefaultNitriteCollection.java @@ -49,6 +49,7 @@ /** * @author Anindya Chatterjee. + * @since 1.0 */ class DefaultNitriteCollection implements NitriteCollection { private final String collectionName; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/Document.java b/nitrite/src/main/java/org/dizitart/no2/collection/Document.java index a93332d03..bf52fbec2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/Document.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/Document.java @@ -29,7 +29,7 @@ /** * Represents a document in Nitrite database. *

- * A document is a collection of key-value pairs. A key is always a {@link String} and value + * Nitrite document are composed of key-value pairs. A key is always a {@link String} and value * can be anything including null. *

* Nitrite document supports nested documents as well. The key of a nested document is a {@link String} diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java b/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java index 1ef6826f9..b2bfc01e8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/DocumentCursor.java @@ -20,7 +20,7 @@ import org.dizitart.no2.common.RecordStream; /** - * The DocumentCursor represents a cursor to iterate over {@link NitriteCollection#find()} results. + * The DocumentCursor represents a cursor as a stream of {@link Document} to iterate over {@link NitriteCollection#find()} results. * It also provides methods for projection and perform left outer join with other DocumentCursor. *

*

diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java b/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java
index ce058de82..b34a28a81 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/FindPlan.java
@@ -34,7 +34,7 @@
  * A plan for finding documents in a collection.
  *
  * @author Anindya Chatterjee
- * @since 4.0.0
+ * @since 4.0
  */
 @Data
 public class FindPlan {
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java
index 84e51e43d..6a9fd4041 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java
@@ -38,7 +38,6 @@
 import static org.dizitart.no2.common.util.ValidationUtils.notNull;
 
 /**
- * A default implementation of nitrite document.
  *
  * @since 4.0
  * @author Anindya Chatterjee
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventListener.java b/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventListener.java
index 290f1493f..ea62dcfe0 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventListener.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventListener.java
@@ -20,9 +20,8 @@
 import org.dizitart.no2.repository.ObjectRepository;
 
 /**
- * An interface when implemented makes an object be
- * able to listen to any changes in a {@link NitriteCollection}
- * or {@link ObjectRepository}.
+ * A listener which is able to listen to any changes in a
+ * in a {@link NitriteCollection} or {@link ObjectRepository}.
  *
  * @author Anindya Chatterjee.
  * @since 4.0
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/events/EventAware.java b/nitrite/src/main/java/org/dizitart/no2/collection/events/EventAware.java
index af2faa92b..4dbe3db52 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/events/EventAware.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/events/EventAware.java
@@ -17,26 +17,10 @@
 package org.dizitart.no2.collection.events;
 
 /**
- * Interface to be implemented by collections that wish to be aware
- * of any event.
- *
- * @author Anindya Chatterjee.
- * @see EventType
  * @since 4.0
+ * @author Anindya Chatterjee
  */
 public interface EventAware {
-    /**
-     * Subscribes an {@link CollectionEventListener} instance to listen to any
-     * collection events.
-     *
-     * @param listener the listener
-     */
     void subscribe(CollectionEventListener listener);
-
-    /**
-     * Unsubscribes an {@link CollectionEventListener} instance.
-     *
-     * @param listener the listener.
-     */
     void unsubscribe(CollectionEventListener listener);
 }
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/CollectionOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/CollectionOperations.java
index f0f6cb85f..fb57aa927 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/CollectionOperations.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/CollectionOperations.java
@@ -34,8 +34,6 @@
 import java.util.Collection;
 
 /**
- * The collection operations.
- *
  * @author Anindya Chatterjee
  * @since 1.0
  */
@@ -49,14 +47,6 @@ public class CollectionOperations implements AutoCloseable {
     private WriteOperations writeOperations;
     private ReadOperations readOperations;
 
-    /**
-     * Instantiates a new Collection operations.
-     *
-     * @param collectionName the collection name
-     * @param nitriteMap     the nitrite map
-     * @param nitriteConfig  the nitrite config
-     * @param eventBus       the event bus
-     */
     public CollectionOperations(String collectionName,
                                 NitriteMap nitriteMap,
                                 NitriteConfig nitriteConfig,
@@ -68,184 +58,79 @@ public CollectionOperations(String collectionName,
         initialize();
     }
 
-    /**
-     * Adds a document processor.
-     *
-     * @param processor the processor
-     */
     public void addProcessor(Processor processor) {
         processorChain.add(processor);
     }
 
-    /**
-     * Creates index.
-     *
-     * @param fields    the fields
-     * @param indexType the index type
-     */
     public void createIndex(Fields fields, String indexType) {
         indexOperations.createIndex(fields, indexType);
     }
 
-    /**
-     * Finds index descriptor.
-     *
-     * @param fields the fields
-     * @return the index descriptor
-     */
     public IndexDescriptor findIndex(Fields fields) {
         return indexOperations.findIndexDescriptor(fields);
     }
 
-    /**
-     * Rebuilds index.
-     *
-     * @param indexDescriptor the index descriptor
-     */
     public void rebuildIndex(IndexDescriptor indexDescriptor) {
         indexOperations.buildIndex(indexDescriptor, true);
     }
 
-    /**
-     * Lists all indexes.
-     *
-     * @return the collection
-     */
     public Collection listIndexes() {
         return indexOperations.listIndexes();
     }
 
-    /**
-     * Checks if an index exists on the fields.
-     *
-     * @param fields the fields
-     * @return the boolean
-     */
     public boolean hasIndex(Fields fields) {
         return indexOperations.hasIndexEntry(fields);
     }
 
-    /**
-     * Checks if indexing is going on the fields.
-     *
-     * @param fields the fields
-     * @return the boolean
-     */
     public boolean isIndexing(Fields fields) {
         return indexOperations.isIndexing(fields);
     }
 
-    /**
-     * Drops index.
-     *
-     * @param fields the fields
-     */
     public void dropIndex(Fields fields) {
         indexOperations.dropIndex(fields);
     }
 
-    /**
-     * Drops all indices.
-     */
     public void dropAllIndices() {
         indexOperations.dropAllIndices();
     }
 
-    /**
-     * Inserts documents to the collection.
-     *
-     * @param documents the documents
-     * @return the write result
-     */
     public WriteResult insert(Document[] documents) {
         return writeOperations.insert(documents);
     }
 
-    /**
-     * Updates documents in the collection.
-     *
-     * @param filter        the filter
-     * @param update        the update
-     * @param updateOptions the update options
-     * @return the write result
-     */
     public WriteResult update(Filter filter, Document update, UpdateOptions updateOptions) {
         return writeOperations.update(filter, update, updateOptions);
     }
 
-    /**
-     * Removes document from the collection.
-     *
-     * @param document the document
-     * @return the write result
-     */
     public WriteResult remove(Document document) {
         return writeOperations.remove(document);
     }
 
-    /**
-     * Removes document from collection.
-     *
-     * @param filter   the filter
-     * @param justOnce the just once
-     * @return the write result
-     */
     public WriteResult remove(Filter filter, boolean justOnce) {
         return writeOperations.remove(filter, justOnce);
     }
 
-    /**
-     * Finds documents using filter.
-     *
-     * @param filter      the filter
-     * @param findOptions the find options
-     * @return the document cursor
-     */
     public DocumentCursor find(Filter filter, FindOptions findOptions) {
         return readOperations.find(filter, findOptions);
     }
 
-    /**
-     * Gets document by id.
-     *
-     * @param nitriteId the nitrite id
-     * @return the by id
-     */
     public Document getById(NitriteId nitriteId) {
         return readOperations.getById(nitriteId);
     }
 
-    /**
-     * Drops the collection.
-     */
     public void dropCollection() {
         indexOperations.dropAllIndices();
         dropNitriteMap();
     }
 
-    /**
-     * Gets the size of the collection.
-     *
-     * @return the size
-     */
     public long getSize() {
         return nitriteMap.size();
     }
 
-    /**
-     * Gets the additional attributes for the collection.
-     *
-     * @return the attributes
-     */
     public Attributes getAttributes() {
         return nitriteMap != null ? nitriteMap.getAttributes() : null;
     }
 
-    /**
-     * Sets additional attributes in the collection.
-     *
-     * @param attributes the attributes
-     */
     public void setAttributes(Attributes attributes) {
         nitriteMap.setAttributes(attributes);
     }
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/DocumentIndexWriter.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/DocumentIndexWriter.java
index 85ec0ccc8..31fece0a9 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/DocumentIndexWriter.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/DocumentIndexWriter.java
@@ -27,7 +27,6 @@
 import java.util.Collection;
 
 /**
- *
  * @since 4.0
  * @author Anindya Chatterjee
  */
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/FindOptimizer.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/FindOptimizer.java
index 43a44b11a..919d5d36d 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/FindOptimizer.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/FindOptimizer.java
@@ -32,9 +32,7 @@
 import static org.dizitart.no2.filters.Filter.and;
 import static org.dizitart.no2.filters.Filter.or;
 
-
 /**
- *
  * @since 4.0
  * @author Anindya Chatterjee
  */
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java
index 5e78cd591..b8d6fc8c2 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexManager.java
@@ -15,237 +15,217 @@
  *
  */
 
- package org.dizitart.no2.collection.operation;
-
- import org.dizitart.no2.NitriteConfig;
- import org.dizitart.no2.common.Fields;
- import org.dizitart.no2.index.IndexDescriptor;
- import org.dizitart.no2.index.IndexMeta;
- import org.dizitart.no2.index.NitriteIndexer;
- import org.dizitart.no2.store.NitriteMap;
- import org.dizitart.no2.store.NitriteStore;
- 
- import java.util.*;
- import java.util.concurrent.atomic.AtomicBoolean;
- 
- import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMapName;
- import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMetaMapName;
- 
- /**
-  * Represents the index manager for a collection.
-  *
-  * @author Anindya Chatterjee
-  * @since 4.0
-  */
- public class IndexManager implements AutoCloseable {
-     private final NitriteConfig nitriteConfig;
-     private final NitriteStore nitriteStore;
-     private final String collectionName;
-     private final NitriteMap indexMetaMap;
-     private Collection indexDescriptorCache;
- 
-     /**
-      * Instantiates a new {@link IndexManager}.
-      *
-      * @param collectionName the collection name
-      * @param nitriteConfig  the nitrite config
-      */
-     public IndexManager(String collectionName, NitriteConfig nitriteConfig) {
-         this.collectionName = collectionName;
-         this.nitriteConfig = nitriteConfig;
-         this.nitriteStore = nitriteConfig.getNitriteStore();
-         this.indexMetaMap = getIndexMetaMap();
-         initialize();
-     }
- 
-     /**
-      * Checks if an index descriptor already exists on the fields.
-      *
-      * @param fields the fields
-      * @return the boolean
-      */
-     public boolean hasIndexDescriptor(Fields fields) {
-         return !findMatchingIndexDescriptors(fields).isEmpty();
-     }
- 
-     /**
-      * Gets all defined index descriptors for the collection.
-      *
-      * @return the index descriptors
-      */
-     public Collection getIndexDescriptors() {
-         if (indexDescriptorCache == null) {
-             indexDescriptorCache = listIndexDescriptors();
-         }
-         return indexDescriptorCache;
-     }
- 
-     public Collection findMatchingIndexDescriptors(Fields fields) {
-         List indexDescriptors = new ArrayList<>();
- 
-         for (IndexDescriptor indexDescriptor : getIndexDescriptors()) {
-             if (indexDescriptor.getFields().startsWith(fields)) {
-                 indexDescriptors.add(indexDescriptor);
-             }
-         }
- 
-         return indexDescriptors;
-     }
- 
-     public IndexDescriptor findExactIndexDescriptor(Fields fields) {
-         IndexMeta meta = indexMetaMap.get(fields);
-         if (meta != null) {
-             return meta.getIndexDescriptor();
-         }
-         return null;
-     }
- 
-     public void markIndexDirty(IndexDescriptor indexDescriptor) {
-         Fields fields = indexDescriptor.getFields();
-         markDirty(fields, true);
-     }
- 
-     @Override
-     public void close() {
-         // close all index maps
-         if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) {
-             Iterable indexMetas = indexMetaMap.values();
-             for (IndexMeta indexMeta : indexMetas) {
-                 if (indexMeta != null && indexMeta.getIndexDescriptor() != null) {
-                     String indexMapName = indexMeta.getIndexMap();
-                     NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
-                     indexMap.close();
-                 }
-             }
- 
-             // close index meta
-             indexMetaMap.close();
-         }
-     }
- 
-     public void clearAll() {
-         // close all index maps
-         if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) {
-             Iterable indexMetas = indexMetaMap.values();
-             for (IndexMeta indexMeta : indexMetas) {
-                 if (indexMeta != null && indexMeta.getIndexDescriptor() != null) {
-                     String indexMapName = indexMeta.getIndexMap();
-                     NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
-                     indexMap.clear();
-                 }
-             }
-         }
-     }
- 
-     /**
-      * Is dirty index boolean.
-      *
-      * @param fields the fields
-      * @return the boolean
-      */
-     boolean isDirtyIndex(Fields fields) {
-         IndexMeta meta = indexMetaMap.get(fields);
-         return meta != null && meta.getIsDirty().get();
-     }
- 
-     /**
-      * List index descriptors collection.
-      *
-      * @return the collection
-      */
-     Collection listIndexDescriptors() {
-         Set indexSet = new LinkedHashSet<>();
-         Iterable iterable = indexMetaMap.values();
-         for (IndexMeta indexMeta : iterable) {
-             indexSet.add(indexMeta.getIndexDescriptor());
-         }
-         return Collections.unmodifiableSet(indexSet);
-     }
- 
-     /**
-      * Create index descriptor index descriptor.
-      *
-      * @param fields    the fields
-      * @param indexType the index type
-      * @return the index descriptor
-      */
-     IndexDescriptor createIndexDescriptor(Fields fields, String indexType) {
-         validateIndexRequest(fields, indexType);
-         IndexDescriptor index = new IndexDescriptor(indexType, fields, collectionName);
- 
-         IndexMeta indexMeta = new IndexMeta();
-         indexMeta.setIndexDescriptor(index);
-         indexMeta.setIsDirty(new AtomicBoolean(false));
-         indexMeta.setIndexMap(deriveIndexMapName(index));
- 
-         indexMetaMap.put(fields, indexMeta);
- 
-         updateIndexDescriptorCache();
-         return index;
-     }
- 
-     /**
-      * Drop index descriptor.
-      *
-      * @param fields the fields
-      */
-     void dropIndexDescriptor(Fields fields) {
-         IndexMeta meta = indexMetaMap.get(fields);
-         if (meta != null && meta.getIndexDescriptor() != null) {
-             String indexMapName = meta.getIndexMap();
-             NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
-             indexMap.drop();
-         }
- 
-         indexMetaMap.remove(fields);
-         updateIndexDescriptorCache();
-     }
- 
-     void dropIndexMeta() {
-         indexMetaMap.drop();
-     }
- 
-     /**
-      * Begin indexing.
-      *
-      * @param fields the fields
-      */
-     void beginIndexing(Fields fields) {
-         markDirty(fields, true);
-     }
- 
-     /**
-      * End indexing.
-      *
-      * @param fields the fields
-      */
-     void endIndexing(Fields fields) {
-         markDirty(fields, false);
-     }
- 
-     private void initialize() {
-         updateIndexDescriptorCache();
-     }
- 
-     private void markDirty(Fields fields, boolean dirty) {
-         IndexMeta meta = indexMetaMap.get(fields);
-         if (meta != null && meta.getIndexDescriptor() != null) {
-             meta.getIsDirty().set(dirty);
-         }
-     }
- 
-     private NitriteMap getIndexMetaMap() {
-         String mapName = deriveIndexMetaMapName(this.collectionName);
-         return this.nitriteStore.openMap(mapName, Fields.class, IndexMeta.class);
-     }
- 
-     private void updateIndexDescriptorCache() {
-         indexDescriptorCache = listIndexDescriptors();
-     }
- 
-     private void validateIndexRequest(Fields fields, String indexType) {
-         NitriteIndexer indexer = nitriteConfig.findIndexer(indexType);
-         indexer.validateIndex(fields);
-     }
- }
- 
\ No newline at end of file
+package org.dizitart.no2.collection.operation;
+
+import org.dizitart.no2.NitriteConfig;
+import org.dizitart.no2.common.Fields;
+import org.dizitart.no2.index.IndexDescriptor;
+import org.dizitart.no2.index.IndexMeta;
+import org.dizitart.no2.index.NitriteIndexer;
+import org.dizitart.no2.store.NitriteMap;
+import org.dizitart.no2.store.NitriteStore;
+
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMapName;
+import static org.dizitart.no2.common.util.IndexUtils.deriveIndexMetaMapName;
+
+/**
+ * @since 4.0
+ * @author Anindya Chatterjee
+ */
+public class IndexManager implements AutoCloseable {
+    private final NitriteConfig nitriteConfig;
+    private final NitriteStore nitriteStore;
+    private final String collectionName;
+    private final NitriteMap indexMetaMap;
+    private Collection indexDescriptorCache;
+
+    public IndexManager(String collectionName, NitriteConfig nitriteConfig) {
+        this.collectionName = collectionName;
+        this.nitriteConfig = nitriteConfig;
+        this.nitriteStore = nitriteConfig.getNitriteStore();
+        this.indexMetaMap = getIndexMetaMap();
+        initialize();
+    }
+
+    public boolean hasIndexDescriptor(Fields fields) {
+        return !findMatchingIndexDescriptors(fields).isEmpty();
+    }
+
+    public Collection getIndexDescriptors() {
+        if (indexDescriptorCache == null) {
+            indexDescriptorCache = listIndexDescriptors();
+        }
+        return indexDescriptorCache;
+    }
+
+    public Collection findMatchingIndexDescriptors(Fields fields) {
+        List indexDescriptors = new ArrayList<>();
+
+        for (IndexDescriptor indexDescriptor : getIndexDescriptors()) {
+            if (indexDescriptor.getFields().startsWith(fields)) {
+                indexDescriptors.add(indexDescriptor);
+            }
+        }
+
+        return indexDescriptors;
+    }
+
+    public IndexDescriptor findExactIndexDescriptor(Fields fields) {
+        IndexMeta meta = indexMetaMap.get(fields);
+        if (meta != null) {
+            return meta.getIndexDescriptor();
+        }
+        return null;
+    }
+
+    public void markIndexDirty(IndexDescriptor indexDescriptor) {
+        Fields fields = indexDescriptor.getFields();
+        markDirty(fields, true);
+    }
+
+    @Override
+    public void close() {
+        // close all index maps
+        if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) {
+            Iterable indexMetas = indexMetaMap.values();
+            for (IndexMeta indexMeta : indexMetas) {
+                if (indexMeta != null && indexMeta.getIndexDescriptor() != null) {
+                    String indexMapName = indexMeta.getIndexMap();
+                    NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
+                    indexMap.close();
+                }
+            }
+
+            // close index meta
+            indexMetaMap.close();
+        }
+    }
+
+    public void clearAll() {
+        // close all index maps
+        if (!indexMetaMap.isClosed() && !indexMetaMap.isDropped()) {
+            Iterable indexMetas = indexMetaMap.values();
+            for (IndexMeta indexMeta : indexMetas) {
+                if (indexMeta != null && indexMeta.getIndexDescriptor() != null) {
+                    String indexMapName = indexMeta.getIndexMap();
+                    NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
+                    indexMap.clear();
+                }
+            }
+        }
+    }
+
+    /**
+     * Is dirty index boolean.
+     *
+     * @param fields the fields
+     * @return the boolean
+     */
+    boolean isDirtyIndex(Fields fields) {
+        IndexMeta meta = indexMetaMap.get(fields);
+        return meta != null && meta.getIsDirty().get();
+    }
+
+    /**
+     * List index descriptors collection.
+     *
+     * @return the collection
+     */
+    Collection listIndexDescriptors() {
+        Set indexSet = new LinkedHashSet<>();
+        Iterable iterable = indexMetaMap.values();
+        for (IndexMeta indexMeta : iterable) {
+            indexSet.add(indexMeta.getIndexDescriptor());
+        }
+        return Collections.unmodifiableSet(indexSet);
+    }
+
+    /**
+     * Create index descriptor index descriptor.
+     *
+     * @param fields    the fields
+     * @param indexType the index type
+     * @return the index descriptor
+     */
+    IndexDescriptor createIndexDescriptor(Fields fields, String indexType) {
+        validateIndexRequest(fields, indexType);
+        IndexDescriptor index = new IndexDescriptor(indexType, fields, collectionName);
+
+        IndexMeta indexMeta = new IndexMeta();
+        indexMeta.setIndexDescriptor(index);
+        indexMeta.setIsDirty(new AtomicBoolean(false));
+        indexMeta.setIndexMap(deriveIndexMapName(index));
+
+        indexMetaMap.put(fields, indexMeta);
+
+        updateIndexDescriptorCache();
+        return index;
+    }
+
+    /**
+     * Drop index descriptor.
+     *
+     * @param fields the fields
+     */
+    void dropIndexDescriptor(Fields fields) {
+        IndexMeta meta = indexMetaMap.get(fields);
+        if (meta != null && meta.getIndexDescriptor() != null) {
+            String indexMapName = meta.getIndexMap();
+            NitriteMap indexMap = nitriteStore.openMap(indexMapName, Object.class, Object.class);
+            indexMap.drop();
+        }
+
+        indexMetaMap.remove(fields);
+        updateIndexDescriptorCache();
+    }
+
+    void dropIndexMeta() {
+        indexMetaMap.drop();
+    }
+
+    /**
+     * Begin indexing.
+     *
+     * @param fields the fields
+     */
+    void beginIndexing(Fields fields) {
+        markDirty(fields, true);
+    }
+
+    /**
+     * End indexing.
+     *
+     * @param fields the fields
+     */
+    void endIndexing(Fields fields) {
+        markDirty(fields, false);
+    }
+
+    private void initialize() {
+        updateIndexDescriptorCache();
+    }
+
+    private void markDirty(Fields fields, boolean dirty) {
+        IndexMeta meta = indexMetaMap.get(fields);
+        if (meta != null && meta.getIndexDescriptor() != null) {
+            meta.getIsDirty().set(dirty);
+        }
+    }
+
+    private NitriteMap getIndexMetaMap() {
+        String mapName = deriveIndexMetaMapName(this.collectionName);
+        return this.nitriteStore.openMap(mapName, Fields.class, IndexMeta.class);
+    }
+
+    private void updateIndexDescriptorCache() {
+        indexDescriptorCache = listIndexDescriptors();
+    }
+
+    private void validateIndexRequest(Fields fields, String indexType) {
+        NitriteIndexer indexer = nitriteConfig.findIndexer(indexType);
+        indexer.validateIndex(fields);
+    }
+}
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java
index 6bba96ecb..3a6a6bc2d 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java
@@ -29,6 +29,7 @@
 
 /**
  * @author Anindya Chatterjee
+ * @since 1.0
  */
 class IndexOperations implements AutoCloseable {
     private final String collectionName;
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/ReadOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/ReadOperations.java
index e9ac800d3..807b47d98 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/ReadOperations.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/ReadOperations.java
@@ -36,6 +36,7 @@
 
 /**
  * @author Anindya Chatterjee
+ * @since 1.0
  */
 class ReadOperations {
     private final String collectionName;
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java
index 9f491055b..346079661 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java
@@ -39,6 +39,7 @@
 
 /**
  * @author Anindya Chatterjee
+ * @since 1.0
  */
 @Slf4j
 class WriteOperations {
diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteResultImpl.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteResultImpl.java
index 9e8a1d219..b210f20d6 100644
--- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteResultImpl.java
+++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteResultImpl.java
@@ -24,6 +24,7 @@
 
 /**
  * @author Anindya Chatterjee
+ * @since 1.0
  */
 @ToString
 class WriteResultImpl implements WriteResult {

From db456999b1de7e5e21687a0c121435bdf60aeb88 Mon Sep 17 00:00:00 2001
From: Anindya Chatterjee 
Date: Wed, 16 Aug 2023 22:50:11 +0530
Subject: [PATCH 11/18] field encryptor added to support

---
 .github/workflows/build.yml                   |  57 ++++-
 .../repository/FieldProcessorTest.java        | 194 ----------------
 .../collection/FieldProcessorTest.java        | 202 -----------------
 .../repository/FieldProcessorTest.java        | 194 ----------------
 .../collection/FieldProcessorTest.java        | 202 -----------------
 .../repository/FieldProcessorTest.java        | 194 ----------------
 nitrite-support/README.md                     |   4 +-
 .../no2/support}/crypto/AESEncryptor.java     |   2 +-
 .../no2/support}/crypto/Encryptor.java        |   2 +-
 .../support/{ => exchange}/ExportOptions.java |   2 +-
 .../no2/support/{ => exchange}/Exporter.java  |   7 +-
 .../support/{ => exchange}/ImportOptions.java |   2 +-
 .../no2/support/{ => exchange}/Importer.java  |   7 +-
 .../{ => exchange}/NitriteFactory.java        |   2 +-
 .../{ => exchange}/NitriteJsonExporter.java   |   2 +-
 .../{ => exchange}/NitriteJsonImporter.java   |   2 +-
 .../StringFieldEncryptionProcessor.java       |   7 +-
 .../org/dizitart/no2/support/TestUtil.java    | 212 ++++++++++++++++++
 .../no2/support}/crypto/AESEncryptorTest.java |   2 +-
 .../no2/support/{ => data}/Company.java       |   2 +-
 .../no2/support/{ => data}/DataGenerator.java |   2 +-
 .../no2/support/{ => data}/Employee.java      |   2 +-
 .../dizitart/no2/support/{ => data}/Note.java |   2 +-
 .../{ => exchange}/BaseExternalTest.java      |   6 +-
 .../{ => exchange}/ExportOptionsTest.java     |   6 +-
 .../ExporterImporterOptionTest.java           |  11 +-
 .../{ => exchange}/ExporterImporterTest.java  |   9 +-
 .../support/{ => exchange}/ExporterTest.java  |   3 +-
 .../{ => exchange}/GithubIssueTest.java       |   6 +-
 .../processors/BaseCollectionTest.java        | 168 ++++++++++++++
 .../processors}/FieldProcessorTest.java       |  18 +-
 .../collection/CollectionFindTest.java        |   6 -
 .../repository/FieldProcessorTest.java        | 194 ----------------
 33 files changed, 485 insertions(+), 1246 deletions(-)
 delete mode 100644 nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
 delete mode 100644 nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
 delete mode 100644 nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
 delete mode 100644 nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
 delete mode 100644 nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
 rename {nitrite/src/main/java/org/dizitart/no2/common => nitrite-support/src/main/java/org/dizitart/no2/support}/crypto/AESEncryptor.java (99%)
 rename {nitrite/src/main/java/org/dizitart/no2/common => nitrite-support/src/main/java/org/dizitart/no2/support}/crypto/Encryptor.java (96%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/ExportOptions.java (99%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/Exporter.java (96%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/ImportOptions.java (96%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/Importer.java (93%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/NitriteFactory.java (89%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/NitriteJsonExporter.java (99%)
 rename nitrite-support/src/main/java/org/dizitart/no2/support/{ => exchange}/NitriteJsonImporter.java (99%)
 rename {nitrite/src/main/java/org/dizitart/no2/common => nitrite-support/src/main/java/org/dizitart/no2/support}/processors/StringFieldEncryptionProcessor.java (94%)
 create mode 100644 nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
 rename {nitrite/src/test/java/org/dizitart/no2/common => nitrite-support/src/test/java/org/dizitart/no2/support}/crypto/AESEncryptorTest.java (96%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => data}/Company.java (98%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => data}/DataGenerator.java (98%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => data}/Employee.java (98%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => data}/Note.java (97%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/BaseExternalTest.java (95%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/ExportOptionsTest.java (83%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/ExporterImporterOptionTest.java (93%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/ExporterImporterTest.java (92%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/ExporterTest.java (97%)
 rename nitrite-support/src/test/java/org/dizitart/no2/support/{ => exchange}/GithubIssueTest.java (97%)
 create mode 100644 nitrite-support/src/test/java/org/dizitart/no2/support/processors/BaseCollectionTest.java
 rename {nitrite/src/test/java/org/dizitart/no2/integration/collection => nitrite-support/src/test/java/org/dizitart/no2/support/processors}/FieldProcessorTest.java (93%)
 delete mode 100644 nitrite/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6d501f379..869b6596e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -17,23 +17,22 @@ on:
       - "README.md"
 
 jobs:
-  build:
-    runs-on: ${{ matrix.os }}
+  build_linux:
+    runs-on: ubuntu-latest
     strategy:
       matrix:
         java: ['11', '17']
-        os: ['ubuntu-latest']
     env:
       JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
       MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
       MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
       PGP_KEY_ID: ${{ secrets.PGP_KEY_ID }}
       PGP_KEY_PASSWORD: ${{ secrets.PGP_KEY_PASSWORD }}
-    name: Build with Java ${{ matrix.java }} on ${{ matrix.os }}
 
+    name: Build with Java ${{ matrix.java }}
     steps:
       - uses: actions/checkout@v3
-      - name: Set up JDK ${{ matrix.java }} on ${{ matrix.os }}
+      - name: Set up JDK ${{ matrix.java }}
         uses: actions/setup-java@v3
         with:
           java-version: ${{ matrix.java }}
@@ -78,4 +77,50 @@ jobs:
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
           flags: unittests
-          name: codecov-umbrella
\ No newline at end of file
+          name: codecov-umbrella
+
+  build_macos:
+    runs-on: macos-latest
+    strategy:
+      matrix:
+        java: [ '11', '17' ]
+    env:
+      JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
+
+    name: Build with Java ${{ matrix.java }}
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up JDK ${{ matrix.java }}
+        uses: actions/setup-java@v3
+        with:
+          java-version: ${{ matrix.java }}
+          distribution: 'zulu'
+          java-package: jdk
+          architecture: x64
+          cache: 'maven'
+
+      - name: Build with Maven
+        run: mvn -B -ff -ntp clean install
+
+  build_windows:
+    runs-on: windows-latest
+    strategy:
+      matrix:
+        java: [ '11', '17' ]
+    env:
+      JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
+
+    name: Build with Java ${{ matrix.java }}
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up JDK ${{ matrix.java }}
+        uses: actions/setup-java@v3
+        with:
+          java-version: ${{ matrix.java }}
+          distribution: 'zulu'
+          java-package: jdk
+          architecture: x64
+          cache: 'maven'
+
+      - name: Build with Maven
+        run: mvn -B -ff -ntp clean install
\ No newline at end of file
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
deleted file mode 100644
index ad53f1c91..000000000
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.repository;
-
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.repository.ObjectRepository;
-import org.dizitart.no2.store.NitriteMap;
-import org.dizitart.no2.integration.repository.data.EncryptedPerson;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseObjectRepositoryTest {
-    private ObjectRepository persons;
-    private StringFieldEncryptionProcessor fieldProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-        persons = db.getRepository(EncryptedPerson.class);
-        fieldProcessor = new StringFieldEncryptionProcessor("s3k4e8");
-        fieldProcessor.addFields("creditCardNumber", "cvv");
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        persons.insert(person);
-
-        // process existing data
-        fieldProcessor.process(persons);
-
-        // add for further changes
-        persons.addProcessor(fieldProcessor);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        persons.insert(person);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = persons.getDocumentCollection().getStore()
-            .openMap(findRepositoryName(EncryptedPerson.class, null), NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        EncryptedPerson person = persons.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5500960345687452");
-        assertEquals(person.getCvv(), "008");
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5548960345687452");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        ObjectRepository testPersons = db.getRepository(EncryptedPerson.class, "test");
-
-        Encryptor encryptor = new AESEncryptor("secret");
-        Encryptor wrongEncryptor = new AESEncryptor("secret", "AES/GCM/NoPadding",
-            5, 5, 5);
-
-        testPersons.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        testPersons.insert(person);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        testPersons.insert(person);
-
-        testPersons.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("00000000000000");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        WriteResult writeResult = persons.update(where("name").eq("John Doe"), person);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "00000000000000");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        persons.createIndex("cvv");
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-}
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
deleted file mode 100644
index 08cf8fc9f..000000000
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.collection;
-
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.store.NitriteMap;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseCollectionTest {
-
-    private Encryptor encryptor;
-    private NitriteCollection collection;
-    private Processor cvvProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-
-        encryptor = new AESEncryptor("s3k4e8");
-        cvvProcessor = new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String cvv = document.get("cvv", String.class);
-                String encryptedCvv = encryptor.encrypt(cvv.getBytes(StandardCharsets.UTF_8));
-                document.put("cvv", encryptedCvv);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCvv = document.get("cvv", String.class);
-                String cvv = encryptor.decrypt(encryptedCvv);
-                document.put("cvv", cvv);
-                return document;
-            }
-        };
-        StringFieldEncryptionProcessor creditCardProcessor = new StringFieldEncryptionProcessor(encryptor);
-        creditCardProcessor.addFields("creditCardNumber");
-
-        collection = db.getCollection("encryption-test");
-        collection.addProcessor(creditCardProcessor);
-
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "5548960345687452")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        document = Document.createDocument("name", "Jane Doe")
-            .put("creditCardNumber", "5500960345687452")
-            .put("cvv", "008")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        cvvProcessor.process(collection);
-        collection.addProcessor(cvvProcessor);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = collection.getStore().openMap("encryption-test",
-            NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        Document document = collection.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "5500960345687452");
-        assertEquals(document.get("cvv", String.class), "008");
-
-        document = collection.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "5548960345687452");
-        assertEquals(document.get("cvv", String.class), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        Encryptor wrongEncryptor = new AESEncryptor("secret");
-
-        collection = db.getCollection("encryption-test");
-        collection.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "5548960345687452")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        document = Document.createDocument("name", "Jane Doe")
-            .put("creditCardNumber", "5500960345687452")
-            .put("cvv", "008")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        collection.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        Document document = collection.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(document);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "00000000000000")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-
-        WriteResult writeResult = collection.update(where("name").eq("John Doe"), document);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        document = collection.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "00000000000000");
-        assertEquals(document.get("cvv", String.class), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        collection.createIndex("cvv");
-        Document document = collection.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(document);
-    }
-}
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
deleted file mode 100644
index 8f31d6408..000000000
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.repository;
-
-import org.dizitart.no2.integration.repository.data.EncryptedPerson;
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.repository.ObjectRepository;
-import org.dizitart.no2.store.NitriteMap;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseObjectRepositoryTest {
-    private ObjectRepository persons;
-    private StringFieldEncryptionProcessor fieldProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-        persons = db.getRepository(EncryptedPerson.class);
-        fieldProcessor = new StringFieldEncryptionProcessor("s3k4e8");
-        fieldProcessor.addFields("creditCardNumber", "cvv");
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        persons.insert(person);
-
-        // process existing data
-        fieldProcessor.process(persons);
-
-        // add for further changes
-        persons.addProcessor(fieldProcessor);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        persons.insert(person);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = persons.getDocumentCollection().getStore()
-            .openMap(findRepositoryName(EncryptedPerson.class, null), NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        EncryptedPerson person = persons.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5500960345687452");
-        assertEquals(person.getCvv(), "008");
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5548960345687452");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        ObjectRepository testPersons = db.getRepository(EncryptedPerson.class, "test");
-
-        Encryptor encryptor = new AESEncryptor("secret");
-        Encryptor wrongEncryptor = new AESEncryptor("secret", "AES/GCM/NoPadding",
-            5, 5, 5);
-
-        testPersons.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        testPersons.insert(person);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        testPersons.insert(person);
-
-        testPersons.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("00000000000000");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        WriteResult writeResult = persons.update(where("name").eq("John Doe"), person);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "00000000000000");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        persons.createIndex("cvv");
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-}
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
deleted file mode 100644
index 08cf8fc9f..000000000
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.collection;
-
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.store.NitriteMap;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseCollectionTest {
-
-    private Encryptor encryptor;
-    private NitriteCollection collection;
-    private Processor cvvProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-
-        encryptor = new AESEncryptor("s3k4e8");
-        cvvProcessor = new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String cvv = document.get("cvv", String.class);
-                String encryptedCvv = encryptor.encrypt(cvv.getBytes(StandardCharsets.UTF_8));
-                document.put("cvv", encryptedCvv);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCvv = document.get("cvv", String.class);
-                String cvv = encryptor.decrypt(encryptedCvv);
-                document.put("cvv", cvv);
-                return document;
-            }
-        };
-        StringFieldEncryptionProcessor creditCardProcessor = new StringFieldEncryptionProcessor(encryptor);
-        creditCardProcessor.addFields("creditCardNumber");
-
-        collection = db.getCollection("encryption-test");
-        collection.addProcessor(creditCardProcessor);
-
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "5548960345687452")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        document = Document.createDocument("name", "Jane Doe")
-            .put("creditCardNumber", "5500960345687452")
-            .put("cvv", "008")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        cvvProcessor.process(collection);
-        collection.addProcessor(cvvProcessor);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = collection.getStore().openMap("encryption-test",
-            NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        Document document = collection.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "5500960345687452");
-        assertEquals(document.get("cvv", String.class), "008");
-
-        document = collection.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "5548960345687452");
-        assertEquals(document.get("cvv", String.class), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        Encryptor wrongEncryptor = new AESEncryptor("secret");
-
-        collection = db.getCollection("encryption-test");
-        collection.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "5548960345687452")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        document = Document.createDocument("name", "Jane Doe")
-            .put("creditCardNumber", "5500960345687452")
-            .put("cvv", "008")
-            .put("expiryDate", new Date());
-        collection.insert(document);
-
-        collection.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        Document document = collection.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(document);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        Document document = Document.createDocument("name", "John Doe")
-            .put("creditCardNumber", "00000000000000")
-            .put("cvv", "007")
-            .put("expiryDate", new Date());
-
-        WriteResult writeResult = collection.update(where("name").eq("John Doe"), document);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        document = collection.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(document);
-
-        assertEquals(document.get("creditCardNumber", String.class), "00000000000000");
-        assertEquals(document.get("cvv", String.class), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        collection.createIndex("cvv");
-        Document document = collection.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(document);
-    }
-}
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
deleted file mode 100644
index 8f31d6408..000000000
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.repository;
-
-import org.dizitart.no2.integration.repository.data.EncryptedPerson;
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.repository.ObjectRepository;
-import org.dizitart.no2.store.NitriteMap;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseObjectRepositoryTest {
-    private ObjectRepository persons;
-    private StringFieldEncryptionProcessor fieldProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-        persons = db.getRepository(EncryptedPerson.class);
-        fieldProcessor = new StringFieldEncryptionProcessor("s3k4e8");
-        fieldProcessor.addFields("creditCardNumber", "cvv");
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        persons.insert(person);
-
-        // process existing data
-        fieldProcessor.process(persons);
-
-        // add for further changes
-        persons.addProcessor(fieldProcessor);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        persons.insert(person);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = persons.getDocumentCollection().getStore()
-            .openMap(findRepositoryName(EncryptedPerson.class, null), NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        EncryptedPerson person = persons.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5500960345687452");
-        assertEquals(person.getCvv(), "008");
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5548960345687452");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        ObjectRepository testPersons = db.getRepository(EncryptedPerson.class, "test");
-
-        Encryptor encryptor = new AESEncryptor("secret");
-        Encryptor wrongEncryptor = new AESEncryptor("secret", "AES/GCM/NoPadding",
-            5, 5, 5);
-
-        testPersons.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        testPersons.insert(person);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        testPersons.insert(person);
-
-        testPersons.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("00000000000000");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        WriteResult writeResult = persons.update(where("name").eq("John Doe"), person);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "00000000000000");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        persons.createIndex("cvv");
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-}
diff --git a/nitrite-support/README.md b/nitrite-support/README.md
index ee759ae09..ba9cb29ee 100644
--- a/nitrite-support/README.md
+++ b/nitrite-support/README.md
@@ -43,8 +43,8 @@ exportOptions.setNitriteFactory(() {
         .openOrCreate();
 });
 exportOptions.setCollections(List.of("first"));
-exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee"));
-exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee")));
+exportOptions.setRepositories(List.of("org.dizitart.no2.support.data.Employee"));
+exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.data.Employee")));
 
 Exporter exporter = Exporter.withOptions(exportOptions);
 exporter.exportTo(schemaFile);
diff --git a/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java
similarity index 99%
rename from nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java
index 67825e787..4d8ba6975 100644
--- a/nitrite/src/main/java/org/dizitart/no2/common/crypto/AESEncryptor.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java
@@ -15,7 +15,7 @@
  *
  */
 
-package org.dizitart.no2.common.crypto;
+package org.dizitart.no2.support.crypto;
 
 import org.apache.commons.codec.binary.Base64;
 import org.dizitart.no2.common.util.CryptoUtils;
diff --git a/nitrite/src/main/java/org/dizitart/no2/common/crypto/Encryptor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java
similarity index 96%
rename from nitrite/src/main/java/org/dizitart/no2/common/crypto/Encryptor.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java
index 4d32637f5..01454a38f 100644
--- a/nitrite/src/main/java/org/dizitart/no2/common/crypto/Encryptor.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java
@@ -15,7 +15,7 @@
  *
  */
 
-package org.dizitart.no2.common.crypto;
+package org.dizitart.no2.support.crypto;
 
 /**
  * Represents a symmetric key string encryptor.
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java
similarity index 99%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java
index 2a288e154..9a663820b 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/ExportOptions.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
  import com.fasterxml.jackson.core.JsonFactory;
  import lombok.Getter;
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java
similarity index 96%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java
index 5e1cc0ca0..d26605873 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/Exporter.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java
@@ -14,19 +14,16 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
  import com.fasterxml.jackson.annotation.JsonAutoDetect;
- import com.fasterxml.jackson.core.JsonFactory;
  import com.fasterxml.jackson.core.JsonGenerator;
  import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
  import com.fasterxml.jackson.databind.DeserializationFeature;
  import com.fasterxml.jackson.databind.ObjectMapper;
- import org.dizitart.no2.Nitrite;
  import org.dizitart.no2.exceptions.NitriteIOException;
- import org.dizitart.no2.exceptions.ValidationException;
- 
+
  import java.io.*;
  
  import static org.dizitart.no2.common.util.ValidationUtils.notNull;
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java
similarity index 96%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java
index efea557b9..7ed1be5e9 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/ImportOptions.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java
@@ -1,4 +1,4 @@
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import com.fasterxml.jackson.core.JsonFactory;
 import lombok.Getter;
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java
similarity index 93%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java
index e4dfed54b..2255b31b4 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/Importer.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java
@@ -14,18 +14,15 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
- import com.fasterxml.jackson.core.JsonFactory;
  import com.fasterxml.jackson.core.JsonParser;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import org.dizitart.no2.Nitrite;
  import org.dizitart.no2.exceptions.NitriteIOException;
  
  import java.io.*;
  
  import static org.dizitart.no2.common.util.ValidationUtils.notNull;
- import static org.dizitart.no2.support.Exporter.createObjectMapper;
+ import static org.dizitart.no2.support.exchange.Exporter.createObjectMapper;
  
  
  /**
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java
similarity index 89%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java
index 680f703e1..788aea738 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteFactory.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java
@@ -1,4 +1,4 @@
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import org.dizitart.no2.Nitrite;
 
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonExporter.java
similarity index 99%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonExporter.java
index e448ccb6e..04cfd0e35 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonExporter.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonExporter.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
 import com.fasterxml.jackson.core.JsonGenerator;
 import lombok.Setter;
diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonImporter.java
similarity index 99%
rename from nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonImporter.java
index a30f330ee..32bc275d5 100644
--- a/nitrite-support/src/main/java/org/dizitart/no2/support/NitriteJsonImporter.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteJsonImporter.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonToken;
diff --git a/nitrite/src/main/java/org/dizitart/no2/common/processors/StringFieldEncryptionProcessor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java
similarity index 94%
rename from nitrite/src/main/java/org/dizitart/no2/common/processors/StringFieldEncryptionProcessor.java
rename to nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java
index ccf6a8a46..59fdc0deb 100644
--- a/nitrite/src/main/java/org/dizitart/no2/common/processors/StringFieldEncryptionProcessor.java
+++ b/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java
@@ -15,14 +15,15 @@
  *
  */
 
-package org.dizitart.no2.common.processors;
+package org.dizitart.no2.support.processors;
 
 import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
+import org.dizitart.no2.common.processors.Processor;
 import org.dizitart.no2.common.util.StringUtils;
 import org.dizitart.no2.exceptions.NitriteIOException;
+import org.dizitart.no2.support.crypto.AESEncryptor;
+import org.dizitart.no2.support.crypto.Encryptor;
 
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java b/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
new file mode 100644
index 000000000..a06ccae1a
--- /dev/null
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2017-2021 Nitrite author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.dizitart.no2.support;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.dizitart.no2.Nitrite;
+import org.dizitart.no2.collection.Document;
+import org.dizitart.no2.exceptions.ObjectMappingException;
+import org.dizitart.no2.mvstore.MVStoreModule;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Anindya Chatterjee
+ */
+@Slf4j
+public class TestUtil {
+
+    public static String getRandomTempDbFile() {
+        String dataDir = System.getProperty("java.io.tmpdir") + File.separator + "nitrite" + File.separator + "data";
+        File file = new File(dataDir);
+        if (!file.exists()) {
+            assertTrue(file.mkdirs());
+        }
+        return file.getPath() + File.separator + UUID.randomUUID() + ".db";
+    }
+
+    @SneakyThrows
+    public static void deleteDb(String filePath) {
+        Files.delete(Paths.get(filePath));
+    }
+
+    public static > boolean isSorted(Iterable iterable, boolean ascending) {
+        Iterator iterator = iterable.iterator();
+        if (!iterator.hasNext()) {
+            return true;
+        }
+        T t = iterator.next();
+        while (iterator.hasNext()) {
+            T t2 = iterator.next();
+            if (ascending) {
+                if (t.compareTo(t2) > 0) {
+                    return false;
+                }
+            } else {
+                if (t.compareTo(t2) < 0) {
+                    return false;
+                }
+            }
+            t = t2;
+        }
+        return true;
+    }
+
+    public static Nitrite createDb() {
+        MVStoreModule storeModule = MVStoreModule.withConfig()
+            .build();
+
+        return Nitrite.builder()
+            .loadModule(storeModule)
+            .fieldSeparator(".")
+            .openOrCreate();
+    }
+
+    public static Nitrite createDb(String user, String password) {
+        MVStoreModule storeModule = MVStoreModule.withConfig()
+            .build();
+
+        return Nitrite.builder()
+            .loadModule(storeModule)
+            .fieldSeparator(".")
+            .openOrCreate(user, password);
+    }
+
+    public static Nitrite createDb(String filePath) {
+        MVStoreModule storeModule = MVStoreModule.withConfig()
+            .filePath(filePath)
+            .compress(true)
+            .build();
+
+        return Nitrite.builder()
+            .loadModule(storeModule)
+            .fieldSeparator(".")
+            .openOrCreate();
+    }
+
+    public static Nitrite createDb(String filePath, String user, String password) {
+        MVStoreModule storeModule = MVStoreModule.withConfig()
+            .filePath(filePath)
+            .compress(true)
+            .build();
+
+        return Nitrite.builder()
+            .loadModule(storeModule)
+            .fieldSeparator(".")
+            .openOrCreate(user, password);
+    }
+
+    public static Document parse(String json) {
+        try {
+            ObjectMapper objectMapper = createObjectMapper();
+            JsonNode node = objectMapper.readValue(json, JsonNode.class);
+            return loadDocument(node);
+        } catch (IOException e) {
+            log.error("Error while parsing json", e);
+            throw new ObjectMappingException("failed to parse json " + json);
+        }
+    }
+
+    private static Document loadDocument(JsonNode node) {
+        Map objectMap = new LinkedHashMap<>();
+        Iterator> fields = node.fields();
+        while (fields.hasNext()) {
+            Map.Entry entry = fields.next();
+            String name = entry.getKey();
+            JsonNode value = entry.getValue();
+            Object object = loadObject(value);
+            objectMap.put(name, object);
+        }
+
+        return Document.createDocument(objectMap);
+    }
+
+    private static Object loadObject(JsonNode node) {
+        if (node == null)
+            return null;
+        try {
+            switch (node.getNodeType()) {
+                case ARRAY:
+                    return loadArray(node);
+                case BINARY:
+                    return node.binaryValue();
+                case BOOLEAN:
+                    return node.booleanValue();
+                case MISSING:
+                case NULL:
+                    return null;
+                case NUMBER:
+                    return node.numberValue();
+                case OBJECT:
+                case POJO:
+                    return loadDocument(node);
+                case STRING:
+                    return node.textValue();
+            }
+        } catch (IOException e) {
+            return null;
+        }
+        return null;
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    private static List loadArray(JsonNode array) {
+        if (array.isArray()) {
+            List list = new ArrayList();
+            Iterator iterator = array.elements();
+            while (iterator.hasNext()) {
+                Object element = iterator.next();
+                if (element instanceof JsonNode) {
+                    list.add(loadObject((JsonNode) element));
+                } else {
+                    list.add(element);
+                }
+            }
+            return list;
+        }
+        return null;
+    }
+
+    private static ObjectMapper createObjectMapper() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.setVisibility(
+            objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
+                .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
+                .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
+                .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
+        objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
+        objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
+        objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+        objectMapper.findAndRegisterModules();
+        return objectMapper;
+    }
+}
diff --git a/nitrite/src/test/java/org/dizitart/no2/common/crypto/AESEncryptorTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/crypto/AESEncryptorTest.java
similarity index 96%
rename from nitrite/src/test/java/org/dizitart/no2/common/crypto/AESEncryptorTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/crypto/AESEncryptorTest.java
index 854bff17b..79678a522 100644
--- a/nitrite/src/test/java/org/dizitart/no2/common/crypto/AESEncryptorTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/crypto/AESEncryptorTest.java
@@ -15,7 +15,7 @@
  *
  */
 
-package org.dizitart.no2.common.crypto;
+package org.dizitart.no2.support.crypto;
 
 import org.dizitart.no2.exceptions.NitriteSecurityException;
 import org.junit.Test;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/Company.java b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Company.java
similarity index 98%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/Company.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/data/Company.java
index d66f8254f..f49d93e55 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/Company.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Company.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.data;
 
 import lombok.Data;
 import org.dizitart.no2.collection.Document;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/DataGenerator.java b/nitrite-support/src/test/java/org/dizitart/no2/support/data/DataGenerator.java
similarity index 98%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/DataGenerator.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/data/DataGenerator.java
index acea54ef5..225a6a7b9 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/DataGenerator.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/data/DataGenerator.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.data;
 
 import com.github.javafaker.Faker;
 import lombok.experimental.UtilityClass;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/Employee.java b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Employee.java
similarity index 98%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/Employee.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/data/Employee.java
index f05767e09..5c7ed6d4d 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/Employee.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Employee.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.data;
 
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/Note.java b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Note.java
similarity index 97%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/Note.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/data/Note.java
index ee3435060..32e7dbe84 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/Note.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/data/Note.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.data;
 
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
similarity index 95%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
index 1bd143ffe..7a88d0db8 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/BaseExternalTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
  import org.dizitart.no2.Nitrite;
  import org.dizitart.no2.collection.Document;
@@ -22,6 +22,10 @@
  import org.dizitart.no2.common.mapper.EntityConverterMapper;
  import org.dizitart.no2.mvstore.MVStoreModule;
  import org.dizitart.no2.repository.ObjectRepository;
+ import org.dizitart.no2.support.Retry;
+ import org.dizitart.no2.support.data.Company;
+ import org.dizitart.no2.support.data.Employee;
+ import org.dizitart.no2.support.data.Note;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Rule;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExportOptionsTest.java
similarity index 83%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExportOptionsTest.java
index 01cb019c7..0cac9a283 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExportOptionsTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExportOptionsTest.java
@@ -1,11 +1,9 @@
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
-import java.util.ArrayList;
-
-import org.dizitart.no2.common.PersistentCollection;
+import org.dizitart.no2.support.exchange.ExportOptions;
 import org.junit.Test;
 
 public class ExportOptionsTest {
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterOptionTest.java
similarity index 93%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterOptionTest.java
index b7e9bf341..60996f47f 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterOptionTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterOptionTest.java
@@ -14,14 +14,15 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
- import org.dizitart.no2.Nitrite;
  import org.dizitart.no2.collection.Document;
  import org.dizitart.no2.collection.NitriteCollection;
- import org.dizitart.no2.common.PersistentCollection;
  import org.dizitart.no2.index.IndexDescriptor;
  import org.dizitart.no2.repository.ObjectRepository;
+ import org.dizitart.no2.support.data.Company;
+ import org.dizitart.no2.support.data.DataGenerator;
+ import org.dizitart.no2.support.data.Employee;
  import org.junit.Test;
  
  import java.io.File;
@@ -53,8 +54,8 @@ public void testImportExportSingle() {
          ExportOptions exportOptions = new ExportOptions();
          exportOptions.setNitriteFactory(() -> createDb(sourceDbFile));
          exportOptions.setCollections(List.of("first"));
-         exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee"));
-         exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee")));
+         exportOptions.setRepositories(List.of("org.dizitart.no2.support.data.Employee"));
+         exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.data.Employee")));
  
          Exporter exporter = Exporter.withOptions(exportOptions);
          exporter.exportTo(schemaFile);
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterTest.java
similarity index 92%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterTest.java
index 5bf5c9681..2805d5c1a 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterImporterTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterImporterTest.java
@@ -14,11 +14,14 @@
  * limitations under the License.
  */
 
- package org.dizitart.no2.support;
+ package org.dizitart.no2.support.exchange;
 
  import org.dizitart.no2.collection.Document;
  import org.dizitart.no2.collection.NitriteCollection;
  import org.dizitart.no2.repository.ObjectRepository;
+ import org.dizitart.no2.support.data.Company;
+ import org.dizitart.no2.support.data.DataGenerator;
+ import org.dizitart.no2.support.data.Employee;
  import org.junit.Test;
  
  import java.io.File;
@@ -57,8 +60,8 @@ public void testImportExport() {
          ExportOptions exportOptions = new ExportOptions();
          exportOptions.setNitriteFactory(() -> createDb(sourceDbFile));
          exportOptions.setCollections(List.of("first"));
-         exportOptions.setRepositories(List.of("org.dizitart.no2.support.Employee", "org.dizitart.no2.support.Company"));
-         exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.Employee")));
+         exportOptions.setRepositories(List.of("org.dizitart.no2.support.data.Employee", "org.dizitart.no2.support.data.Company"));
+         exportOptions.setKeyedRepositories(Map.of("key", Set.of("org.dizitart.no2.support.data.Employee")));
  
          Exporter exporter = Exporter.withOptions(exportOptions);
          exporter.exportTo(schemaFile);
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterTest.java
similarity index 97%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/ExporterTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterTest.java
index cd6b7c23e..e8a7b8e60 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/ExporterTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/ExporterTest.java
@@ -1,4 +1,4 @@
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import com.fasterxml.jackson.databind.DeserializationConfig;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -10,6 +10,7 @@
 import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.type.TypeFactory;
+import org.dizitart.no2.support.exchange.Exporter;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/GithubIssueTest.java
similarity index 97%
rename from nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/exchange/GithubIssueTest.java
index dffdd36c0..c94839374 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/GithubIssueTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/GithubIssueTest.java
@@ -1,4 +1,4 @@
-package org.dizitart.no2.support;
+package org.dizitart.no2.support.exchange;
 
 import lombok.Data;
 import org.dizitart.no2.Nitrite;
@@ -25,10 +25,8 @@
 import java.nio.file.Paths;
 import java.time.LocalDate;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
-import static org.dizitart.no2.support.BaseExternalTest.getRandomTempDbFile;
+import static org.dizitart.no2.support.exchange.BaseExternalTest.getRandomTempDbFile;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/processors/BaseCollectionTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/processors/BaseCollectionTest.java
new file mode 100644
index 000000000..867ff9808
--- /dev/null
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/processors/BaseCollectionTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2017-2021 Nitrite author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.dizitart.no2.support.processors;
+
+import lombok.extern.slf4j.Slf4j;
+import org.dizitart.no2.Nitrite;
+import org.dizitart.no2.NitriteBuilder;
+import org.dizitart.no2.collection.Document;
+import org.dizitart.no2.collection.NitriteCollection;
+import org.dizitart.no2.common.WriteResult;
+import org.dizitart.no2.mvstore.MVStoreModule;
+import org.dizitart.no2.mvstore.MVStoreModuleBuilder;
+import org.dizitart.no2.support.Retry;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Locale;
+
+import static org.dizitart.no2.collection.Document.createDocument;
+import static org.dizitart.no2.filters.Filter.ALL;
+import static org.dizitart.no2.support.TestUtil.deleteDb;
+import static org.dizitart.no2.support.TestUtil.getRandomTempDbFile;
+
+@Slf4j
+@RunWith(value = Parameterized.class)
+public abstract class BaseCollectionTest {
+    @Parameterized.Parameter
+    public boolean inMemory = false;
+    @Parameterized.Parameter(value = 1)
+    public boolean isSecured = false;
+    @Parameterized.Parameter(value = 2)
+    public boolean isCompressed = false;
+    @Parameterized.Parameter(value = 3)
+    public boolean isAutoCommit = false;
+
+    protected Nitrite db;
+    protected NitriteCollection collection;
+    protected Document doc1, doc2, doc3;
+    protected SimpleDateFormat simpleDateFormat;
+    private final String fileName = getRandomTempDbFile();
+
+    @Rule
+    public Retry retry = new Retry(3);
+
+    @Parameterized.Parameters(name = "InMemory = {0}, Secured = {1}, " +
+            "Compressed = {2}, AutoCommit = {3}, AutoCompact = {4}")
+    public static Collection data() {
+        return Arrays.asList(new Object[][]{
+                {false, false, false, false},
+                {false, false, false, true},
+                {false, false, true, false},
+                {false, false, true, true},
+                {false, true, false, false},
+                {false, true, false, true},
+                {false, true, true, false},
+                {false, true, true, true},
+                {true, false, false, false},
+                {true, false, false, true},
+                {true, false, true, false},
+                {true, false, true, true},
+                {true, true, false, false},
+                {true, true, false, true},
+                {true, true, true, false},
+                {true, true, true, true},
+        });
+    }
+
+    @Before
+    public void setUp() {
+        try {
+            openDb();
+
+            simpleDateFormat
+                    = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
+
+            doc1 = createDocument("firstName", "fn1")
+                    .put("lastName", "ln1")
+                    .put("birthDay", simpleDateFormat.parse("2012-07-01T16:02:48.440Z"))
+                    .put("data", new byte[]{1, 2, 3})
+                    .put("list", Arrays.asList("one", "two", "three"))
+                    .put("body", "a quick brown fox jump over the lazy dog");
+            doc2 = createDocument("firstName", "fn2")
+                    .put("lastName", "ln2")
+                    .put("birthDay", simpleDateFormat.parse("2010-06-12T16:02:48.440Z"))
+                    .put("data", new byte[]{3, 4, 3})
+                    .put("list", Arrays.asList("three", "four", "five"))
+                    .put("body", "quick hello world from nitrite");
+            doc3 = createDocument("firstName", "fn3")
+                    .put("lastName", "ln2")
+                    .put("birthDay", simpleDateFormat.parse("2014-04-17T16:02:48.440Z"))
+                    .put("data", new byte[]{9, 4, 8})
+                    .put("body", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
+                            "Sed nunc mi, mattis ullamcorper dignissim vitae, condimentum non lorem.");
+
+            collection = db.getCollection("test");
+            collection.remove(ALL);
+        } catch (Throwable t) {
+            log.error("Error while initializing test database", t);
+        }
+    }
+
+    @After
+    public void clear() {
+        try {
+            if (collection != null && !collection.isDropped()) {
+                collection.close();
+            }
+            if (db != null && !db.isClosed()) db.close();
+            if (!inMemory) {
+                deleteDb(fileName);
+            }
+        } catch (Throwable t) {
+            log.error("Error while clearing test database", t);
+        }
+    }
+
+    private void openDb() {
+        MVStoreModuleBuilder builder = MVStoreModule.withConfig();
+
+        if (isCompressed) {
+            builder.compress(true);
+        }
+
+        if (!isAutoCommit) {
+            builder.autoCommit(false);
+        }
+
+        if (!inMemory) {
+            builder.filePath(fileName);
+        }
+
+        MVStoreModule storeModule = builder.build();
+        NitriteBuilder nitriteBuilder = Nitrite.builder()
+                .fieldSeparator(".")
+                .loadModule(storeModule);
+
+        if (isSecured) {
+            db = nitriteBuilder.openOrCreate("test-user", "test-password");
+        } else {
+            db = nitriteBuilder.openOrCreate();
+        }
+    }
+
+    protected WriteResult insert() {
+        return collection.insert(doc1, doc2, doc3);
+    }
+}
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/processors/FieldProcessorTest.java
similarity index 93%
rename from nitrite/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
rename to nitrite-support/src/test/java/org/dizitart/no2/support/processors/FieldProcessorTest.java
index 08cf8fc9f..578fa7104 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/FieldProcessorTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/processors/FieldProcessorTest.java
@@ -15,18 +15,17 @@
  *
  */
 
-package org.dizitart.no2.integration.collection;
+package org.dizitart.no2.support.processors;
 
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.collection.NitriteId;
 import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
 import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
 import org.dizitart.no2.exceptions.NitriteSecurityException;
 import org.dizitart.no2.store.NitriteMap;
+import org.dizitart.no2.support.crypto.AESEncryptor;
+import org.dizitart.no2.support.crypto.Encryptor;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -46,14 +45,13 @@ public class FieldProcessorTest extends BaseCollectionTest {
 
     private Encryptor encryptor;
     private NitriteCollection collection;
-    private Processor cvvProcessor;
 
     @Before
     public void setUp() {
         super.setUp();
 
         encryptor = new AESEncryptor("s3k4e8");
-        cvvProcessor = new Processor() {
+        Processor cvvProcessor = new Processor() {
             @Override
             public Document processBeforeWrite(Document document) {
                 String cvv = document.get("cvv", String.class);
@@ -94,10 +92,12 @@ public Document processAfterRead(Document document) {
 
     @Test
     public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = collection.getStore().openMap("encryption-test",
-            NitriteId.class, Document.class);
+        List documents;
+        try (NitriteMap nitriteMap = collection.getStore().openMap("encryption-test",
+            NitriteId.class, Document.class)) {
 
-        List documents = toList(nitriteMap.values());
+            documents = toList(nitriteMap.values());
+        }
         for (Document document : documents) {
             if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
                 Assert.fail("unencrypted secret text found");
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
index 96c55ee3f..1d48a793a 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
@@ -23,7 +23,6 @@
 import org.dizitart.no2.collection.NitriteId;
 import org.dizitart.no2.common.RecordStream;
 import org.dizitart.no2.common.SortOrder;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
 import org.dizitart.no2.exceptions.IndexingException;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexOptions;
@@ -392,11 +391,6 @@ public void testProjection() {
         NitriteCollection collection = db.getCollection("person");
         collection.insert(doc1, doc2);
 
-        StringFieldEncryptionProcessor processor = new StringFieldEncryptionProcessor("pass");
-        processor.addFields("name");
-        processor.process(collection);
-        collection.addProcessor(processor);
-
         Document projection = Document.createDocument("name", null)
             .put("address.city", null)
             .put("address.state", null);
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
deleted file mode 100644
index 5f5297a50..000000000
--- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/FieldProcessorTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration.repository;
-
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.NitriteId;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.common.crypto.AESEncryptor;
-import org.dizitart.no2.common.crypto.Encryptor;
-import org.dizitart.no2.common.processors.Processor;
-import org.dizitart.no2.common.processors.StringFieldEncryptionProcessor;
-import org.dizitart.no2.exceptions.NitriteSecurityException;
-import org.dizitart.no2.integration.repository.data.EncryptedPerson;
-import org.dizitart.no2.repository.ObjectRepository;
-import org.dizitart.no2.store.NitriteMap;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.List;
-
-import static org.dizitart.no2.common.util.Iterables.toList;
-import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.*;
-
-/**
- * @author Anindya Chatterjee
- */
-public class FieldProcessorTest extends BaseObjectRepositoryTest {
-    private ObjectRepository persons;
-    private StringFieldEncryptionProcessor fieldProcessor;
-
-    @Before
-    public void setUp() {
-        super.setUp();
-        persons = db.getRepository(EncryptedPerson.class);
-        fieldProcessor = new StringFieldEncryptionProcessor("s3k4e8");
-        fieldProcessor.addFields("creditCardNumber", "cvv");
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        persons.insert(person);
-
-        // process existing data
-        fieldProcessor.process(persons);
-
-        // add for further changes
-        persons.addProcessor(fieldProcessor);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        persons.insert(person);
-    }
-
-    @Test
-    public void testFieldEncryptionInNitriteMap() {
-        NitriteMap nitriteMap = persons.getDocumentCollection().getStore()
-            .openMap(findRepositoryName(EncryptedPerson.class, null), NitriteId.class, Document.class);
-
-        List documents = toList(nitriteMap.values());
-        for (Document document : documents) {
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5548960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("creditCardNumber", String.class).equalsIgnoreCase("5500960345687452")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("008")) {
-                Assert.fail("unencrypted secret text found");
-            }
-
-            if (document.get("cvv", String.class).equalsIgnoreCase("007")) {
-                Assert.fail("unencrypted secret text found");
-            }
-        }
-    }
-
-    @Test
-    public void testSuccessfulDecryption() {
-        EncryptedPerson person = persons.find(where("name").eq("Jane Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5500960345687452");
-        assertEquals(person.getCvv(), "008");
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "5548960345687452");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test(expected = NitriteSecurityException.class)
-    public void testFailedDecryption() {
-        ObjectRepository testPersons = db.getRepository(EncryptedPerson.class, "test");
-
-        Encryptor encryptor = new AESEncryptor("secret");
-        Encryptor wrongEncryptor = new AESEncryptor("secret", "AES/GCM/NoPadding",
-            5, 5, 5);
-
-        testPersons.addProcessor(new Processor() {
-            @Override
-            public Document processBeforeWrite(Document document) {
-                String creditCardNumber = document.get("creditCardNumber", String.class);
-                String encryptedCreditCardNumber = encryptor.encrypt(creditCardNumber.getBytes(StandardCharsets.UTF_8));
-                document.put("creditCardNumber", encryptedCreditCardNumber);
-                return document;
-            }
-
-            @Override
-            public Document processAfterRead(Document document) {
-                String encryptedCreditCardNumber = document.get("creditCardNumber", String.class);
-                String creditCardNumber = wrongEncryptor.decrypt(encryptedCreditCardNumber);
-                document.put("creditCardNumber", creditCardNumber);
-                return document;
-            }
-        });
-
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("5548960345687452");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        testPersons.insert(person);
-
-        person = new EncryptedPerson();
-        person.setName("Jane Doe");
-        person.setCreditCardNumber("5500960345687452");
-        person.setCvv("008");
-        person.setExpiryDate(new Date());
-        testPersons.insert(person);
-
-        testPersons.find(where("name").eq("Jane Doe")).firstOrNull();
-    }
-
-    @Test
-    public void testSearchOnEncryptedField() {
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-
-    @Test
-    public void testUpdateEncryptedField() {
-        EncryptedPerson person = new EncryptedPerson();
-        person.setName("John Doe");
-        person.setCreditCardNumber("00000000000000");
-        person.setCvv("007");
-        person.setExpiryDate(new Date());
-
-        WriteResult writeResult = persons.update(where("name").eq("John Doe"), person);
-        assertEquals(writeResult.getAffectedCount(), 1);
-
-        person = persons.find(where("name").eq("John Doe")).firstOrNull();
-        assertNotNull(person);
-
-        assertEquals(person.getCreditCardNumber(), "00000000000000");
-        assertEquals(person.getCvv(), "007");
-    }
-
-    @Test
-    public void testIndexOnEncryptedField() {
-        persons.createIndex("cvv");
-        EncryptedPerson person = persons.find(where("cvv").eq("008")).firstOrNull();
-        assertNull(person);
-    }
-}

From a357ae6da21f209fb9e99c244cd408cce2974767 Mon Sep 17 00:00:00 2001
From: Anindya Chatterjee 
Date: Wed, 16 Aug 2023 22:53:11 +0530
Subject: [PATCH 12/18] build script modified

---
 .github/workflows/build.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 869b6596e..43e36215e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -29,7 +29,7 @@ jobs:
       PGP_KEY_ID: ${{ secrets.PGP_KEY_ID }}
       PGP_KEY_PASSWORD: ${{ secrets.PGP_KEY_PASSWORD }}
 
-    name: Build with Java ${{ matrix.java }}
+    name: Build with Java ${{ matrix.java }} in Ubuntu
     steps:
       - uses: actions/checkout@v3
       - name: Set up JDK ${{ matrix.java }}
@@ -87,7 +87,7 @@ jobs:
     env:
       JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
 
-    name: Build with Java ${{ matrix.java }}
+    name: Build with Java ${{ matrix.java }} in MacOS
     steps:
       - uses: actions/checkout@v3
       - name: Set up JDK ${{ matrix.java }}
@@ -110,7 +110,7 @@ jobs:
     env:
       JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
 
-    name: Build with Java ${{ matrix.java }}
+    name: Build with Java ${{ matrix.java }} in Windows
     steps:
       - uses: actions/checkout@v3
       - name: Set up JDK ${{ matrix.java }}

From 864512601236a13ff5ab567b06762b7e3ae0ab1a Mon Sep 17 00:00:00 2001
From: Anindya Chatterjee 
Date: Thu, 17 Aug 2023 10:19:18 +0530
Subject: [PATCH 13/18] test code refactoring

---
 .github/workflows/build.yml                   |   6 +-
 .../integration/migrate/MigrationTest.java    |  10 +-
 .../repository/BaseObjectRepositoryTest.java  |   4 +-
 .../repository/CustomFieldSeparatorTest.java  |  11 +-
 .../repository/JacksonModuleTest.java         |  12 +-
 .../repository/NitriteIdAsIdTest.java         |  11 +-
 .../repository/ObjectCursorTest.java          |   3 +-
 .../ObjectRepositoryNegativeTest.java         |   8 +-
 .../repository/ObjectRepositoryTest.java      |   9 +-
 .../repository/RepositoryJoinTest.java        |   6 +-
 .../repository/RepositorySearchTest.java      |   4 +-
 .../no2/integration/repository/Retry.java     |  10 +-
 .../no2/integration/repository/TestUtil.java  |  11 +
 .../repository/UnAnnotatedObjectTest.java     |  17 +-
 .../UniversalTextTokenizerTest.java           |   9 +-
 .../TransactionRepositoryTest.java            |  14 +-
 .../java/org/dizitart/no2/NitriteTest.java    |  19 +-
 .../no2/integration/MultiThreadedTest.java    |   8 +-
 .../no2/integration/NitriteBuilderTest.java   |  10 +-
 .../no2/integration/NitriteStressTest.java    |  34 +--
 .../org/dizitart/no2/integration/Retry.java   |  10 +-
 .../no2/integration/SerializabilityTest.java  |   8 +-
 .../dizitart/no2/integration/TestUtil.java    |   8 +-
 .../CollectionCompoundIndexTest.java          |   3 +-
 .../collection/CollectionIndexTest.java       |   1 -
 .../collection/CollectionJoinTest.java        |   1 -
 .../no2/integration/event/EventTest.java      |   1 -
 .../repository/NitriteIdAsIdTest.java         |   1 -
 .../repository/RepositorySearchTest.java      |   4 +-
 .../repository/UnAnnotatedObjectTest.java     |  17 +-
 .../UniversalTextTokenizerTest.java           |   4 -
 .../TransactionCollectionTest.java            |  22 +-
 .../TransactionRepositoryTest.java            |  14 +-
 .../java/org/dizitart/no2/NitriteTest.java    |  22 +-
 .../no2/integration/MultiThreadedTest.java    |   6 +-
 .../no2/integration/NitriteStressTest.java    |  34 +--
 .../org/dizitart/no2/integration/Retry.java   |  10 +-
 .../no2/integration/SerializabilityTest.java  |   8 +-
 .../dizitart/no2/integration/TestUtil.java    |  10 +-
 .../CollectionCompoundIndexTest.java          |   3 +-
 .../collection/CollectionIndexTest.java       |   1 -
 .../collection/CollectionJoinTest.java        |   1 -
 .../no2/integration/event/EventTest.java      |   1 -
 .../repository/BaseObjectRepositoryTest.java  |  20 --
 .../repository/NitriteIdAsIdTest.java         |   1 -
 .../repository/RepositorySearchTest.java      |   4 +-
 .../repository/UnAnnotatedObjectTest.java     |  17 +-
 .../UniversalTextTokenizerTest.java           |   4 -
 .../TransactionCollectionTest.java            |  22 +-
 .../TransactionRepositoryTest.java            |  14 +-
 .../dizitart/no2/rocksdb/GithubIssues.java    |   2 -
 .../org/dizitart/no2/rocksdb/RocksDBTest.java |  40 +---
 .../java/org/dizitart/no2/spatial/Retry.java  |  10 +-
 .../dizitart/no2/spatial/SpatialViewer.java   |   4 +-
 .../org/dizitart/no2/spatial/TestUtil.java    |  10 +-
 .../java/org/dizitart/no2/support/Retry.java  |  12 +-
 .../org/dizitart/no2/support/TestUtil.java    |   8 +-
 .../support/exchange/BaseExternalTest.java    |  53 +++--
 .../dizitart/no2/collection/DocumentTest.java |   4 +-
 .../dizitart/no2/common/event/EventTest.java  |   1 -
 .../no2/common/mapper/MapperTest.java         |  27 +--
 .../streams/ProjectedDocumentStreamTest.java  |   7 +-
 .../no2/integration/DbTestOperations.java     | 220 ------------------
 .../no2/integration/MultiThreadedTest.java    |   8 +-
 .../no2/integration/NitriteStressTest.java    |   4 +-
 .../dizitart/no2/integration/NitriteTest.java |  21 +-
 .../org/dizitart/no2/integration/Retry.java   |  10 +-
 .../no2/integration/SerializabilityTest.java  |   8 +-
 .../dizitart/no2/integration/StressTest.java  |  29 ---
 .../CollectionCompoundIndexTest.java          |   4 +-
 .../collection/CollectionFindTest.java        |   1 -
 .../collection/CollectionIndexTest.java       |   1 -
 .../collection/CollectionJoinTest.java        |   1 -
 .../repository/ObjectRepositoryTest.java      |   1 -
 .../repository/RepositorySearchTest.java      |   4 +-
 .../repository/UnAnnotatedObjectTest.java     |  14 +-
 .../UniversalTextTokenizerTest.java           |   4 -
 .../TransactionCollectionTest.java            |  22 +-
 .../TransactionRepositoryTest.java            |  14 +-
 .../org/dizitart/kno2/BackportJavaTimeTest.kt |  10 +-
 .../test/kotlin/org/dizitart/kno2/BaseTest.kt |   6 +-
 .../kno2/KotlinXSerializationMapperTest.kt    |   8 +-
 .../kotlin/org/dizitart/kno2/NitriteTest.kt   |   1 -
 .../org/dizitart/kno2/ObjectFilterTest.kt     |   6 +-
 .../org/dizitart/kno2/TransactionTest.kt      |  21 +-
 85 files changed, 347 insertions(+), 737 deletions(-)
 delete mode 100644 nitrite/src/test/java/org/dizitart/no2/integration/DbTestOperations.java

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 43e36215e..07ee48921 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -54,7 +54,7 @@ jobs:
         run: mvn -B -ff -ntp clean install
 
       - name: Deploy Snapshot
-        if: github.ref == 'refs/heads/develop'
+        if: github.ref == 'refs/heads/develop' && matrix.java == '11'
         run: mvn -B -ff -ntp deploy -DskipTests
         env:
           MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
@@ -63,7 +63,7 @@ jobs:
           PGP_KEY_PASSWORD: ${{ secrets.PGP_KEY_PASSWORD }}
 
       - name: Deploy Release
-        if: github.ref == 'refs/heads/release'
+        if: github.ref == 'refs/heads/release' && matrix.java == '11'
         run: mvn -B -ff -ntp release:clean release:prepare release:perform -DskipTests
         env:
           MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
@@ -72,7 +72,7 @@ jobs:
           PGP_KEY_PASSWORD: ${{ secrets.PGP_KEY_PASSWORD }}
 
       - name: Publish Code Coverage
-        if: github.ref == 'refs/heads/main'
+        if: github.ref == 'refs/heads/main' && matrix.java == '11'
         uses: codecov/codecov-action@v3
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
index f0920e5c6..9fe8f6b05 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
@@ -26,20 +26,18 @@
 import org.dizitart.no2.common.mapper.JacksonMapperModule;
 import org.dizitart.no2.exceptions.MigrationException;
 import org.dizitart.no2.index.IndexType;
+import org.dizitart.no2.integration.repository.Retry;
+import org.dizitart.no2.integration.repository.TestUtil;
 import org.dizitart.no2.migration.InstructionSet;
 import org.dizitart.no2.migration.Migration;
 import org.dizitart.no2.migration.TypeConverter;
 import org.dizitart.no2.mvstore.MVStoreModule;
 import org.dizitart.no2.repository.ObjectRepository;
-import org.dizitart.no2.integration.repository.Retry;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.UUID;
 
 import static org.dizitart.no2.filters.FluentFilter.where;
@@ -66,12 +64,12 @@ public void setUp() {
     }
 
     @After
-    public void cleanUp() throws IOException {
+    public void cleanUp() {
         if (!db.isClosed()) {
             db.close();
         }
 
-        Files.delete(Paths.get(dbPath));
+        TestUtil.deleteDb(dbPath);
     }
 
     @Test
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
index 607403048..0e9b2a14a 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
@@ -31,8 +31,6 @@
 import org.junit.runners.Parameterized;
 
 import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.UUID;
@@ -180,7 +178,7 @@ public void clear() throws Exception {
         }
 
         if (!inMemory) {
-            Files.delete(Paths.get(fileName));
+            TestUtil.deleteDb(fileName);
         }
     }
 }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
index 760b19067..888a31550 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
@@ -25,21 +25,18 @@
 import org.dizitart.no2.NitriteConfig;
 import org.dizitart.no2.common.mapper.JacksonMapperModule;
 import org.dizitart.no2.index.IndexType;
+import org.dizitart.no2.integration.repository.data.Company;
+import org.dizitart.no2.integration.repository.data.Note;
 import org.dizitart.no2.mvstore.MVStoreModule;
 import org.dizitart.no2.repository.ObjectRepository;
 import org.dizitart.no2.repository.annotations.Id;
 import org.dizitart.no2.repository.annotations.Index;
 import org.dizitart.no2.repository.annotations.Indices;
-import org.dizitart.no2.integration.repository.data.Company;
-import org.dizitart.no2.integration.repository.data.Note;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.IOException;
 import java.io.Serializable;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Date;
 
 import static org.dizitart.no2.filters.FluentFilter.where;
@@ -68,7 +65,7 @@ public void setUp() {
     }
 
     @After
-    public void reset() throws IOException {
+    public void reset() {
         (new NitriteConfig()).fieldSeparator(".");
         if (db != null && !db.isClosed()) {
             db.close();
@@ -79,7 +76,7 @@ public void reset() throws IOException {
             db.close();
         }
 
-        Files.delete(Paths.get(fileName));
+        TestUtil.deleteDb(fileName);
     }
 
     @Test
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/JacksonModuleTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/JacksonModuleTest.java
index b392f06e5..bad871a27 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/JacksonModuleTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/JacksonModuleTest.java
@@ -11,15 +11,13 @@
 import org.junit.After;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.UUID;
 
 import static org.dizitart.no2.integration.repository.BaseObjectRepositoryTest.getRandomTempDbFile;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * @author Anindya Chatterjee
@@ -29,11 +27,11 @@ public class JacksonModuleTest {
     private final String fileName = getRandomTempDbFile();
 
     @After
-    public void cleanUp() throws IOException {
+    public void cleanUp() {
         if (db != null && !db.isClosed()) {
             db.close();
         }
-        Files.delete(Paths.get(fileName));
+        TestUtil.deleteDb(fileName);
     }
 
     @Test(expected = ObjectMappingException.class)
@@ -60,7 +58,7 @@ public void testJavaTime() {
 
         assertEquals(repository.find().size(), 10);
         for (TestData testData : repository.find()) {
-            System.out.println(testData.localDateTime);
+            assertNotNull(testData.localDateTime);
         }
     }
 
@@ -88,7 +86,7 @@ public void testJavaTimeModule() {
 
         assertEquals(repository.find().size(), 10);
         for (TestData testData : repository.find()) {
-            System.out.println(testData.localDateTime);
+            assertNotNull(testData.localDateTime);
         }
     }
 
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
index 4296bcdcf..096e9a82b 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
@@ -21,9 +21,9 @@
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.NitriteId;
 import org.dizitart.no2.common.WriteResult;
+import org.dizitart.no2.common.mapper.JacksonMapper;
 import org.dizitart.no2.common.util.Iterables;
 import org.dizitart.no2.exceptions.InvalidIdException;
-import org.dizitart.no2.common.mapper.JacksonMapper;
 import org.dizitart.no2.repository.Cursor;
 import org.dizitart.no2.repository.ObjectRepository;
 import org.dizitart.no2.repository.annotations.Id;
@@ -32,10 +32,6 @@
 import org.junit.Rule;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
 import static org.dizitart.no2.common.module.NitriteModule.module;
 import static org.dizitart.no2.integration.repository.BaseObjectRepositoryTest.getRandomTempDbFile;
 import static org.dizitart.no2.integration.repository.TestUtil.createDb;
@@ -61,9 +57,9 @@ public void before() {
     }
 
     @After
-    public void after() throws IOException {
+    public void after() {
         db.close();
-        Files.delete(Paths.get(fileName));
+        TestUtil.deleteDb(fileName);
     }
 
     @Test
@@ -78,7 +74,6 @@ public void testNitriteIdField() {
 
         Cursor cursor = repo.find();
         for (WithNitriteId withNitriteId : cursor) {
-            System.out.println(withNitriteId.name);
             assertNotNull(withNitriteId.idField);
         }
 
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectCursorTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectCursorTest.java
index 4f9aa507c..bb8c8a728 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectCursorTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectCursorTest.java
@@ -21,6 +21,7 @@
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.integration.repository.data.Employee;
 import org.dizitart.no2.repository.Cursor;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.AbstractCollection;
@@ -59,6 +60,6 @@ public void testProjectForAbstractClass() {
     public void testProjectForValueType() {
         Cursor cursor = employeeRepository.find();
         RecordStream project = cursor.project(Date.class);
-        project.forEach(System.out::println);
+        project.forEach(Assert::assertNotNull);
     }
 }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
index 178d688ee..281c02d08 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
@@ -30,10 +30,6 @@
 import org.junit.Rule;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
 import static org.junit.Assert.*;
 
 /**
@@ -52,10 +48,10 @@ public void setUp() {
     }
 
     @After
-    public void close() throws IOException {
+    public void close() {
         db.close();
         db = null;
-        Files.delete(Paths.get(dbPath));
+        TestUtil.deleteDb(dbPath);
     }
 
     @Test(expected = ObjectMappingException.class)
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
index e0a510606..f829b4050 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
@@ -21,8 +21,8 @@
 import lombok.Data;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.common.meta.Attributes;
 import org.dizitart.no2.common.mapper.JacksonMapperModule;
+import org.dizitart.no2.common.meta.Attributes;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexType;
 import org.dizitart.no2.integration.repository.data.*;
@@ -36,9 +36,6 @@
 import org.junit.Rule;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Date;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
@@ -64,10 +61,10 @@ public void setUp() {
     }
 
     @After
-    public void close() throws IOException {
+    public void close() {
         db.close();
         db = null;
-        Files.delete(Paths.get(dbPath));
+        TestUtil.deleteDb(dbPath);
     }
 
     @Test
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java
index ccd66e1dd..6e1556eb4 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java
@@ -24,8 +24,8 @@
 import org.dizitart.no2.collection.NitriteId;
 import org.dizitart.no2.common.Lookup;
 import org.dizitart.no2.common.RecordStream;
-import org.dizitart.no2.exceptions.InvalidOperationException;
 import org.dizitart.no2.common.mapper.JacksonMapperModule;
+import org.dizitart.no2.exceptions.InvalidOperationException;
 import org.dizitart.no2.mvstore.MVStoreModule;
 import org.dizitart.no2.mvstore.MVStoreModuleBuilder;
 import org.dizitart.no2.repository.ObjectRepository;
@@ -38,8 +38,6 @@
 import org.junit.runners.Parameterized;
 
 import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
@@ -166,7 +164,7 @@ public void clear() throws IOException {
         }
 
         if (!inMemory) {
-            Files.delete(Paths.get(fileName));
+            TestUtil.deleteDb(fileName);
         }
     }
 
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index 47ef2fbb6..b582b49d2 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -61,8 +61,8 @@ public void testEmployeeProjection() {
         assertNotNull(employeeList);
         assertNotNull(subEmployeeList);
 
-        assertTrue(employeeList.size() > 0);
-        assertTrue(subEmployeeList.size() > 0);
+        assertFalse(employeeList.isEmpty());
+        assertFalse(subEmployeeList.isEmpty());
 
         assertEquals(employeeList.size(), subEmployeeList.size());
 
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/Retry.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/Retry.java
index 7c2c065bd..475106b6e 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/Retry.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/Retry.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration.repository;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -24,6 +25,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -48,11 +50,13 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.warn(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/TestUtil.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/TestUtil.java
index 6967e6289..264b53b6f 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/TestUtil.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/TestUtil.java
@@ -22,6 +22,9 @@
 import org.dizitart.no2.common.module.NitriteModule;
 import org.dizitart.no2.mvstore.MVStoreModule;
 
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
 /**
  * @author Anindya Chatterjee
  */
@@ -70,4 +73,12 @@ public static Nitrite createDb(String filePath, String user, String password, Ni
             .fieldSeparator(".")
             .openOrCreate(user, password);
     }
+
+    public static void deleteDb(String filePath) {
+        try {
+            Files.delete(Paths.get(filePath));
+        } catch (Exception e) {
+            log.error("Error while deleting db", e);
+        }
+    }
 }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
index 734a55e29..0306f8eca 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
@@ -25,8 +25,7 @@
 
 import static org.dizitart.no2.collection.FindOptions.orderBy;
 import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
 
 /**
  * @author Anindya Chatterjee.
@@ -44,33 +43,25 @@ public void testFind() {
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Ascending).skip(0).limit(10));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         Iterable findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Descending).skip(2).limit(7));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = cObjectRepository.find(where("id").gt(900),
             orderBy("id", SortOrder.Descending).skip(2).limit(7));
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
 
         Iterable findRecordC = cursor.project(ClassC.class);
         for (ClassC classC : findRecordC) {
-            System.out.println(classC);
+            assertNotNull(classC);
         }
     }
 }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index 566dc82b0..e92fa2848 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -34,9 +34,6 @@
 import org.junit.Before;
 import org.junit.Test;
 
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
 import static org.dizitart.no2.common.module.NitriteModule.module;
 import static org.dizitart.no2.filters.Filter.ALL;
 import static org.dizitart.no2.filters.FluentFilter.where;
@@ -93,7 +90,7 @@ public void clear() throws Exception {
         }
 
         if (!inMemory) {
-            Files.delete(Paths.get(fileName));
+            TestUtil.deleteDb(fileName);
         }
     }
 
@@ -139,7 +136,6 @@ public void testUniversalFullTextIndexing() {
         Cursor cursor = textRepository.find(where("text").text("Lorem"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for English text -> " + data.id);
             if (data.id % 2 == 0 || data.id % 3 == 0 || data.id % 5 == 0) {
                 fail();
             }
@@ -148,7 +144,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("শহর"));
         assertEquals(cursor.size(), 5);
         for (TextData data : cursor) {
-            System.out.println("Id for Bengali text -> " + data.id);
             if (data.id % 2 != 0) {
                 fail();
             }
@@ -159,7 +154,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("*転閉*"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for Chinese text -> " + data.id);
             if (data.id % 3 != 0) {
                 fail();
             }
@@ -169,7 +163,6 @@ public void testUniversalFullTextIndexing() {
         if (isCompressed) {
             assertEquals(cursor.size(), 1);
             for (TextData data : cursor) {
-                System.out.println("Id for Arabic text -> " + data.id);
                 if (data.id % 5 != 0) {
                     fail();
                 }
diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
index 4adab1075..7d3c1ff00 100644
--- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
+++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
@@ -45,6 +46,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionRepositoryTest extends BaseObjectRepositoryTest {
 
     @Test
@@ -588,7 +590,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +604,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -632,7 +634,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -646,7 +648,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -679,7 +681,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while updating", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -693,7 +695,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while updating", e);
                 }
             });
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
index 23906157d..2da3f5c24 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
@@ -20,16 +20,16 @@
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.FindOptions;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.collection.UpdateOptions;
 import org.dizitart.no2.common.SortOrder;
-import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.common.concurrent.ThreadPoolManager;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexOptions;
@@ -73,6 +73,7 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 public class NitriteTest {
     private Nitrite db;
     private NitriteCollection collection;
@@ -379,7 +380,7 @@ public void testIssue185() throws InterruptedException {
                     } catch (InterruptedException ignored) {
                     }
                 } catch (Throwable t) {
-                    t.printStackTrace();
+                    log.error("Error in thread", t);
                 }
             }
             latch.countDown();
@@ -537,7 +538,7 @@ public void testIssue212() {
             doc, UpdateOptions.updateOptions(true));
 
         for (Document document : collection.find()) {
-            System.out.println(document);
+            assertNotNull(document);
         }
     }
 
@@ -551,13 +552,8 @@ public void run() {
                     NitriteCollection collection = db.getCollection("testIssue245");
 
                     for (int i = 0; i < 5; i++) {
-
-                        System.out.println("Thread ID = " + id + " Inserting doc " + i);
                         Document doc = Document.createDocument(UUID.randomUUID().toString(), UUID.randomUUID().toString());
-
-                        WriteResult result = collection.insert(doc);//db.commit();
-                        System.out.println("Result of insert = " + result.getAffectedCount());
-                        System.out.println("Thread id = " + id + " --> count = " + collection.size());
+                        collection.insert(doc);//db.commit();
 
                         Thread.sleep(10);
 
@@ -566,7 +562,7 @@ public void run() {
                     collection.close();
 
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    log.error("Error in thread", e);
                 }
             }
         };
@@ -586,7 +582,6 @@ public void run() {
         t2.join();
 
         NitriteCollection collection = db.getCollection("testIssue245");
-        System.out.println("No of Documents = " + collection.size());
         collection.close();
         db.close();
     }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
index 11a7b35bf..a189a76a1 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
@@ -47,6 +48,7 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 @RunWith(Parameterized.class)
 public class MultiThreadedTest {
     private static final String fileName = TestUtil.getRandomTempDbFile();
@@ -112,9 +114,7 @@ public void testOperations() throws InterruptedException {
 
                         assertTrue(collection.hasIndex("unixTime"));
                     } catch (Throwable e) {
-                        System.out.println("Exception at thread " +
-                            Thread.currentThread().getName() + " with iteration " + j);
-                        e.printStackTrace();
+                        log.error("Error while executing test", e);
                     }
                 }
                 latch.countDown();
@@ -147,7 +147,7 @@ public void cleanUp() throws Exception {
             File dbFile = new File(fileName);
             long fileSize = dbFile.length();
             assertTrue(fileSize > 0);
-            dbFile.delete();
+            TestUtil.deleteDb(fileName);
         }
 
         if (executor != null && !executor.isShutdown()) {
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
index 2fcc73c9a..49ac8ef2f 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
@@ -80,7 +80,7 @@ public void startup() {
     }
 
     @After
-    public void cleanup() throws IOException {
+    public void cleanup() {
         (new NitriteConfig()).fieldSeparator(".");
 
         if (db != null && !db.isClosed()) {
@@ -88,7 +88,7 @@ public void cleanup() throws IOException {
         }
 
         if (Files.exists(Paths.get(filePath))) {
-            Files.delete(Paths.get(filePath));
+            TestUtil.deleteDb(filePath);
         }
 
         if (fakeDb != null && !fakeDb.isClosed()){
@@ -96,7 +96,7 @@ public void cleanup() throws IOException {
         }
 
         if (Files.exists(Paths.get(fakeFile))) {
-            Files.delete(Paths.get(fakeFile));
+            TestUtil.deleteDb(fakeFile);
         }
     }
 
@@ -137,7 +137,7 @@ public void testConfig() throws IOException {
         assertTrue(storeConfig.isReadOnly());
         db.close();
 
-        Files.delete(Paths.get(filePath));
+        TestUtil.deleteDb(filePath);
     }
 
     @Test
@@ -162,7 +162,7 @@ public void testConfigWithFile() {
         db.commit();
         db.close();
 
-        assertTrue(file.delete());
+        TestUtil.deleteDb(filePath);
     }
 
     @Test
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
index 7f19f75e6..ea65547b2 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
@@ -20,6 +20,7 @@
 import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlSchemaType;
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
@@ -54,6 +55,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class NitriteStressTest {
     private static final int TEST_SET_COUNT = 15000;
     private final PodamFactory podamFactory = new PodamFactoryImpl();
@@ -73,15 +75,12 @@ public void before() {
         documentMapper.registerEntityConverter(new PerfTestIndexed.Converter());
 
         collection = db.getCollection("test");
-        System.out.println(fileName);
     }
 
     @After
     public void cleanUp() {
         if (db != null && !db.isClosed()) {
-            long start = System.currentTimeMillis();
             db.close();
-            System.out.println("Time to compact and close - " + (System.currentTimeMillis() - start) / 1000 + " seconds");
         }
 
         deleteDb(fileName);
@@ -102,7 +101,7 @@ public void stressTest() {
                 counter++;
             }
         } catch (Throwable t) {
-            System.err.println("Crashed after " + counter + " records");
+            log.error("Error occurred", t);
             throw t;
         }
 
@@ -120,38 +119,23 @@ public void testIssue41() {
         AtomicLong counter = new AtomicLong(System.currentTimeMillis());
         PodamFactory factory = new PodamFactoryImpl();
 
-        long start = System.currentTimeMillis();
         for (int i = 0; i < 100000; i++) {
             Document doc = Document.createDocument();
             doc.put("number", random.nextDouble());
             doc.put("name", factory.manufacturePojo(String.class));
             doc.put("counter", counter.getAndIncrement());
             collection.insert(doc);
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries written");
-            }
         }
-        System.out.println("Records inserted in " + ((System.currentTimeMillis() - start) / (1000 * 60)) + " minutes");
 
         if (db.hasUnsavedChanges()) {
             db.commit();
         }
 
-        start = System.currentTimeMillis();
         DocumentCursor cursor = collection.find();
-        System.out.println("Size ->" + cursor.size());
-        System.out.println("Records size calculated in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
 
-        int i = 0;
-        start = System.currentTimeMillis();
         for (Document element : cursor) {
             assertNotNull(element);
-            i++;
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries processed");
-            }
         }
-        System.out.println("Iteration completed in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
     }
 
     @Test
@@ -168,17 +152,11 @@ public void testRepoPerformanceWithIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTestIndexed.class);
-        long start = System.currentTimeMillis();
         for (PerfTestIndexed item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 indexed items - " + diff + "ms");
     }
 
     @Test
@@ -195,17 +173,11 @@ public void testRepoPerformanceWithoutIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTest.class);
-        long start = System.currentTimeMillis();
         for (PerfTest item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 non-indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 non-indexed items - " + diff + "ms");
     }
 
     private List createTestSet() {
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/Retry.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
index 3d6a27d11..039a518c0 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -24,6 +25,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -48,11 +50,13 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.warn(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
index 09ca50080..9f0bf35a6 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration;
 
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
@@ -33,6 +34,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class SerializabilityTest {
     private NitriteCollection collection;
     private File dbFile;
@@ -69,9 +71,8 @@ public void testSerializabilityValidation() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
@@ -85,9 +86,8 @@ public void testSerializablity() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
index 4a0034399..f2f411019 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
@@ -22,7 +22,6 @@
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
@@ -52,9 +51,12 @@ public static String getRandomTempDbFile() {
         return file.getPath() + File.separator + UUID.randomUUID() + ".db";
     }
 
-    @SneakyThrows
     public static void deleteDb(String filePath) {
-        Files.delete(Paths.get(filePath));
+        try {
+            Files.delete(Paths.get(filePath));
+        } catch (Exception e) {
+            log.error("Error while deleting db", e);
+        }
     }
 
     public static > boolean isSorted(Iterable iterable, boolean ascending) {
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
index 8d37792ed..ffa990763 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
@@ -25,6 +25,7 @@
 import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.filters.Filter;
 import org.dizitart.no2.index.IndexType;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Date;
@@ -151,7 +152,7 @@ public void testDeleteWithIndex() {
     @Test
     public void testRebuildIndexOnRunningIndex() {
         insert();
-        db.getStore().subscribe(System.out::println);
+        db.getStore().subscribe(Assert::assertNotNull);
 
         collection.createIndex("firstName", "lastName");
         collection.rebuildIndex("firstName", "lastName");
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
index 4a45fa055..28a09d17d 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
@@ -278,7 +278,6 @@ public void testIndexEvent() {
                     break;
             }
             assertTrue(eventInfo.getItem() instanceof String);
-            System.out.println(eventInfo.getEventType() + " for field " + eventInfo.getItem());
         });
 
         collection.createIndex(indexOptions(IndexType.NON_UNIQUE), "first");
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
index caff44d61..3085b3625 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
@@ -100,7 +100,6 @@ public void testJoinAll() {
             } else if (document.get("firstName") == "fn3") {
                 assertNull(document.get("personalDetails"));
             }
-            System.out.println(document);
         }
     }
 }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
index 5084dffa5..dfed4ae8c 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
@@ -182,7 +182,6 @@ public void testDelete() {
         employeeRepository.remove(where("empId").eq(1L));
         await().atMost(1, TimeUnit.SECONDS).until(listenerPrepared(EventType.Remove));
 
-        System.out.println("Action - " + listener.getAction());
         assertEquals(listener.getAction(), EventType.Remove);
         assertNotNull(listener.getItem());
     }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
index 47b64f6b3..41db7a05c 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
@@ -78,7 +78,6 @@ public void testNitriteIdField() {
 
         Cursor cursor = repo.find();
         for (WithNitriteId withNitriteId : cursor) {
-            System.out.println(withNitriteId.name);
             assertNotNull(withNitriteId.idField);
         }
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index 2b4454f11..fe1acf6df 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -65,8 +65,8 @@ public void testEmployeeProjection() {
         assertNotNull(employeeList);
         assertNotNull(subEmployeeList);
 
-        assertTrue(employeeList.size() > 0);
-        assertTrue(subEmployeeList.size() > 0);
+        assertFalse(employeeList.isEmpty());
+        assertFalse(subEmployeeList.isEmpty());
 
         assertEquals(employeeList.size(), subEmployeeList.size());
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
index cf793fb10..defd452ac 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
@@ -26,8 +26,7 @@
 
 import static org.dizitart.no2.collection.FindOptions.orderBy;
 import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
 
 /**
  * @author Anindya Chatterjee.
@@ -45,33 +44,25 @@ public void testFind() {
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Ascending).skip(0).limit(10));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         Iterable findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Descending).skip(2).limit(7));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = cObjectRepository.find(where("id").gt(900),
             orderBy("id", SortOrder.Descending).skip(2).limit(7));
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
 
         Iterable findRecordC = cursor.project(ClassC.class);
         for (ClassC classC : findRecordC) {
-            System.out.println(classC);
+            assertNotNull(classC);
         }
     }
 }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index 63d39a6f3..377e1c09f 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -142,7 +142,6 @@ public void testUniversalFullTextIndexing() {
         Cursor cursor = textRepository.find(where("text").text("Lorem"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for English text -> " + data.id);
             if (data.id % 2 == 0 || data.id % 3 == 0 || data.id % 5 == 0) {
                 fail();
             }
@@ -151,7 +150,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("শহর"));
         assertEquals(cursor.size(), 5);
         for (TextData data : cursor) {
-            System.out.println("Id for Bengali text -> " + data.id);
             if (data.id % 2 != 0) {
                 fail();
             }
@@ -162,7 +160,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("*転閉*"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for Chinese text -> " + data.id);
             if (data.id % 3 != 0) {
                 fail();
             }
@@ -172,7 +169,6 @@ public void testUniversalFullTextIndexing() {
         if (isCompressed) {
             assertEquals(cursor.size(), 1);
             for (TextData data : cursor) {
-                System.out.println("Id for Arabic text -> " + data.id);
                 if (data.id % 5 != 0) {
                     fail();
                 }
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
index 6e3052aaa..b21bcf420 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
@@ -18,18 +18,21 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
-import org.dizitart.no2.integration.collection.BaseCollectionTest;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
-import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.TransactionException;
 import org.dizitart.no2.index.IndexType;
+import org.dizitart.no2.integration.collection.BaseCollectionTest;
 import org.dizitart.no2.transaction.Session;
 import org.dizitart.no2.transaction.Transaction;
 import org.junit.Test;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -44,6 +47,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionCollectionTest extends BaseCollectionTest {
 
     @Test
@@ -544,7 +548,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -558,7 +562,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -588,7 +592,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +606,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -637,7 +641,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -651,7 +655,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
index 4adab1075..e699c1b5e 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
@@ -45,6 +46,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionRepositoryTest extends BaseObjectRepositoryTest {
 
     @Test
@@ -588,7 +590,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in concurrent insert/remove", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +604,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in concurrent insert/remove", e);
                 }
             });
 
@@ -632,7 +634,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in concurrent insert", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -646,7 +648,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in concurrent insert", e);
                 }
             });
 
@@ -679,7 +681,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in concurrent update", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -693,7 +695,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in concurrent update", e);
                 }
             });
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
index e4f938de0..97486ddc8 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
@@ -20,16 +20,16 @@
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.FindOptions;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.collection.UpdateOptions;
 import org.dizitart.no2.common.SortOrder;
-import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.common.concurrent.ThreadPoolManager;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexOptions;
@@ -69,6 +69,7 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 public class NitriteTest {
     private Nitrite db;
     private NitriteCollection collection;
@@ -330,7 +331,7 @@ public void testIssue185() throws InterruptedException {
                     } catch (InterruptedException ignored) {
                     }
                 } catch (Throwable t) {
-                    t.printStackTrace();
+                    log.error("Error while updating", t);
                 }
             }
             latch.countDown();
@@ -364,7 +365,7 @@ public void testIssue193() throws InterruptedException {
                     receipt.setClientRef(refs[refIndex]);
                     repository.update(receipt, true);
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    log.error("Error while updating", e);
                     fail("Unhandled exception in thread - " + e.getMessage());
                 } finally {
                     latch.countDown();
@@ -396,7 +397,7 @@ public void testIssue212() {
             doc, UpdateOptions.updateOptions(true));
 
         for (Document document : collection.find()) {
-            System.out.println(document);
+            assertNotNull(document);
         }
     }
 
@@ -410,14 +411,8 @@ public void run() {
                     NitriteCollection collection = db.getCollection("testIssue245");
 
                     for (int i = 0; i < 5; i++) {
-
-                        System.out.println("Thread ID = " + id + " Inserting doc " + i);
                         Document doc = Document.createDocument(UUID.randomUUID().toString(), UUID.randomUUID().toString());
-
-                        WriteResult result = collection.insert(doc);//db.commit();
-                        System.out.println("Result of insert = " + result.getAffectedCount());
-                        System.out.println("Thread id = " + id + " --> count = " + collection.size());
-
+                        collection.insert(doc);//db.commit();
                         Thread.sleep(10);
 
                     }//for closing
@@ -425,7 +420,7 @@ public void run() {
                     collection.close();
 
                 } catch (Throwable e) {
-                    e.printStackTrace();
+                    log.error("Error while running thread", e);
                 }
             }
         };
@@ -445,7 +440,6 @@ public void run() {
         t2.join();
 
         NitriteCollection collection = db.getCollection("testIssue245");
-        System.out.println("No of Documents = " + collection.size());
         collection.close();
         db.close();
     }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
index 16dc19ca3..33b526136 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
@@ -46,6 +47,7 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 public class MultiThreadedTest {
     private static final String fileName = TestUtil.getRandomTempDbFile();
     private NitriteCollection collection;
@@ -99,9 +101,7 @@ public void testOperations() throws InterruptedException {
 
                         assertTrue(collection.hasIndex("unixTime"));
                     } catch (Throwable e) {
-                        System.out.println("Exception at thread " +
-                            Thread.currentThread().getName() + " with iteration " + j);
-                        e.printStackTrace();
+                        log.error("Error while executing test", e);
                     }
                 }
                 latch.countDown();
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
index a061dfef7..beaf04f7e 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
@@ -20,6 +20,7 @@
 import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlSchemaType;
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
@@ -54,6 +55,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class NitriteStressTest {
     private static final int TEST_SET_COUNT = 15000;
     private final PodamFactory podamFactory = new PodamFactoryImpl();
@@ -73,7 +75,6 @@ public void before() {
         documentMapper.registerEntityConverter(new PerfTestIndexed.Converter());
 
         collection = db.getCollection("test");
-        System.out.println(fileName);
     }
 
     @After
@@ -81,7 +82,6 @@ public void cleanUp() {
         if (db != null && !db.isClosed()) {
             long start = System.currentTimeMillis();
             db.close();
-            System.out.println("Time to compact and close - " + (System.currentTimeMillis() - start) / 1000 + " seconds");
         }
 
         deleteDb(fileName);
@@ -100,7 +100,7 @@ public void stressTest() {
                 counter++;
             }
         } catch (Throwable t) {
-            System.err.println("Crashed after " + counter + " records");
+            log.error("Error inserting record", t);
             throw t;
         }
 
@@ -118,38 +118,22 @@ public void testIssue41() {
         AtomicLong counter = new AtomicLong(System.currentTimeMillis());
         PodamFactory factory = new PodamFactoryImpl();
 
-        long start = System.currentTimeMillis();
         for (int i = 0; i < 100000; i++) {
             Document doc = Document.createDocument();
             doc.put("number", random.nextDouble());
             doc.put("name", factory.manufacturePojo(String.class));
             doc.put("counter", counter.getAndIncrement());
             collection.insert(doc);
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries written");
-            }
         }
-        System.out.println("Records inserted in " + ((System.currentTimeMillis() - start) / (1000 * 60)) + " minutes");
 
         if (db.hasUnsavedChanges()) {
             db.commit();
         }
 
-        start = System.currentTimeMillis();
         DocumentCursor cursor = collection.find();
-        System.out.println("Size ->" + cursor.size());
-        System.out.println("Records size calculated in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
-
-        int i = 0;
-        start = System.currentTimeMillis();
         for (Document element : cursor) {
             assertNotNull(element);
-            i++;
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries processed");
-            }
         }
-        System.out.println("Iteration completed in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
     }
 
     @Test
@@ -166,17 +150,11 @@ public void testRepoPerformanceWithIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTestIndexed.class);
-        long start = System.currentTimeMillis();
         for (PerfTestIndexed item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 indexed items - " + diff + "ms");
     }
 
     @Test
@@ -193,17 +171,11 @@ public void testRepoPerformanceWithoutIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTest.class);
-        long start = System.currentTimeMillis();
         for (PerfTest item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 non-indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 non-indexed items - " + diff + "ms");
     }
 
     private List createTestSet() {
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/Retry.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
index 3d6a27d11..a25ef04b1 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/Retry.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -24,6 +25,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -48,11 +50,13 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.error(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
index 09ca50080..9f0bf35a6 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration;
 
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
@@ -33,6 +34,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class SerializabilityTest {
     private NitriteCollection collection;
     private File dbFile;
@@ -69,9 +71,8 @@ public void testSerializabilityValidation() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
@@ -85,9 +86,8 @@ public void testSerializablity() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
index 5d1689ef4..e51892291 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java
@@ -22,7 +22,6 @@
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.dizitart.no2.Nitrite;
@@ -51,10 +50,13 @@ public static String getRandomTempDbFile() {
         return file.getPath() + File.separator + UUID.randomUUID() + ".db";
     }
 
-    @SneakyThrows
     public static void deleteDb(String fileName) {
-        File file = new File(fileName);
-        FileUtils.deleteDirectory(file);
+        try {
+            File file = new File(fileName);
+            FileUtils.deleteDirectory(file);
+        } catch (Exception e) {
+            log.error("Error while deleting db", e);
+        }
     }
 
     public static > boolean isSorted(Iterable iterable, boolean ascending) {
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
index 8d37792ed..ffa990763 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
@@ -25,6 +25,7 @@
 import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.filters.Filter;
 import org.dizitart.no2.index.IndexType;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Date;
@@ -151,7 +152,7 @@ public void testDeleteWithIndex() {
     @Test
     public void testRebuildIndexOnRunningIndex() {
         insert();
-        db.getStore().subscribe(System.out::println);
+        db.getStore().subscribe(Assert::assertNotNull);
 
         collection.createIndex("firstName", "lastName");
         collection.rebuildIndex("firstName", "lastName");
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
index 4a45fa055..28a09d17d 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
@@ -278,7 +278,6 @@ public void testIndexEvent() {
                     break;
             }
             assertTrue(eventInfo.getItem() instanceof String);
-            System.out.println(eventInfo.getEventType() + " for field " + eventInfo.getItem());
         });
 
         collection.createIndex(indexOptions(IndexType.NON_UNIQUE), "first");
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
index caff44d61..3085b3625 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
@@ -100,7 +100,6 @@ public void testJoinAll() {
             } else if (document.get("firstName") == "fn3") {
                 assertNull(document.get("personalDetails"));
             }
-            System.out.println(document);
         }
     }
 }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
index e64133e9e..179e567e4 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
@@ -150,7 +150,6 @@ public void testDelete() {
         employeeRepository.remove(where("empId").eq(1L));
         await().atMost(1, TimeUnit.SECONDS).until(listenerPrepared(EventType.Remove));
 
-        System.out.println("Action - " + listener.getAction());
         assertEquals(listener.getAction(), EventType.Remove);
         assertNotNull(listener.getItem());
     }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
index 846926e7c..022447b28 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
@@ -139,26 +139,6 @@ protected void openDb() {
 
     @After
     public void clear() throws Exception {
-        if (companyRepository != null && !companyRepository.isDropped()) {
-            companyRepository.remove(ALL);
-        }
-
-        if (employeeRepository != null && !employeeRepository.isDropped()) {
-            employeeRepository.remove(ALL);
-        }
-
-        if (aObjectRepository != null && !aObjectRepository.isDropped()) {
-            aObjectRepository.remove(ALL);
-        }
-
-        if (cObjectRepository != null && !cObjectRepository.isDropped()) {
-            cObjectRepository.remove(ALL);
-        }
-
-        if (bookRepository != null && !bookRepository.isDropped()) {
-            bookRepository.remove(ALL);
-        }
-
         if (db != null && !db.isClosed()) {
             db.commit();
             db.close();
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
index 47b64f6b3..41db7a05c 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
@@ -78,7 +78,6 @@ public void testNitriteIdField() {
 
         Cursor cursor = repo.find();
         for (WithNitriteId withNitriteId : cursor) {
-            System.out.println(withNitriteId.name);
             assertNotNull(withNitriteId.idField);
         }
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index 0cfb86680..b8db76d68 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -65,8 +65,8 @@ public void testEmployeeProjection() {
         assertNotNull(employeeList);
         assertNotNull(subEmployeeList);
 
-        assertTrue(employeeList.size() > 0);
-        assertTrue(subEmployeeList.size() > 0);
+        assertFalse(employeeList.isEmpty());
+        assertFalse(subEmployeeList.isEmpty());
 
         assertEquals(employeeList.size(), subEmployeeList.size());
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
index cf793fb10..defd452ac 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
@@ -26,8 +26,7 @@
 
 import static org.dizitart.no2.collection.FindOptions.orderBy;
 import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
 
 /**
  * @author Anindya Chatterjee.
@@ -45,33 +44,25 @@ public void testFind() {
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Ascending).skip(0).limit(10));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         Iterable findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Descending).skip(2).limit(7));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = cObjectRepository.find(where("id").gt(900),
             orderBy("id", SortOrder.Descending).skip(2).limit(7));
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
 
         Iterable findRecordC = cursor.project(ClassC.class);
         for (ClassC classC : findRecordC) {
-            System.out.println(classC);
+            assertNotNull(classC);
         }
     }
 }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index 8ff352dc4..d6f00b9d5 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -128,7 +128,6 @@ public void testUniversalFullTextIndexing() {
         Cursor cursor = textRepository.find(where("text").text("Lorem"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for English text -> " + data.id);
             if (data.id % 2 == 0 || data.id % 3 == 0 || data.id % 5 == 0) {
                 fail();
             }
@@ -137,7 +136,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("শহর"));
         assertEquals(cursor.size(), 5);
         for (TextData data : cursor) {
-            System.out.println("Id for Bengali text -> " + data.id);
             if (data.id % 2 != 0) {
                 fail();
             }
@@ -148,7 +146,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("*転閉*"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for Chinese text -> " + data.id);
             if (data.id % 3 != 0) {
                 fail();
             }
@@ -158,7 +155,6 @@ public void testUniversalFullTextIndexing() {
         if (isProtected) {
             assertEquals(cursor.size(), 1);
             for (TextData data : cursor) {
-                System.out.println("Id for Arabic text -> " + data.id);
                 if (data.id % 5 != 0) {
                     fail();
                 }
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
index 6e3052aaa..b21bcf420 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
@@ -18,18 +18,21 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
-import org.dizitart.no2.integration.collection.BaseCollectionTest;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
-import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.TransactionException;
 import org.dizitart.no2.index.IndexType;
+import org.dizitart.no2.integration.collection.BaseCollectionTest;
 import org.dizitart.no2.transaction.Session;
 import org.dizitart.no2.transaction.Transaction;
 import org.junit.Test;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -44,6 +47,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionCollectionTest extends BaseCollectionTest {
 
     @Test
@@ -544,7 +548,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -558,7 +562,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -588,7 +592,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +606,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -637,7 +641,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -651,7 +655,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
index 4adab1075..7d3c1ff00 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
@@ -45,6 +46,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionRepositoryTest extends BaseObjectRepositoryTest {
 
     @Test
@@ -588,7 +590,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +604,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -632,7 +634,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -646,7 +648,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -679,7 +681,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while updating", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -693,7 +695,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while updating", e);
                 }
             });
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
index 7174aea99..4bcd6e59f 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
@@ -49,7 +49,6 @@ public void testIssue412() {
 //        NitriteCollection collection = db.getCollection("test");
 //        Document document = Document.createDocument("a", 1).put("b", 2);
 //        collection.insert(document);
-//        System.out.println(collection.size());
 
         // Step 2
         ObjectRepository repository = db.getRepository(TestData.class);
@@ -57,7 +56,6 @@ public void testIssue412() {
         testData.setId(1);
         testData.setName("test");
         repository.insert(testData);
-        System.out.println(repository.size());
     }
 
     @Data
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/RocksDBTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/RocksDBTest.java
index 454b048ee..6d97f4875 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/RocksDBTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/RocksDBTest.java
@@ -22,13 +22,11 @@
 import com.esotericsoftware.kryo.kryo5.io.Input;
 import com.github.javafaker.Faker;
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.store.NitriteMap;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
 import org.rocksdb.*;
 
 import java.io.ByteArrayInputStream;
@@ -45,6 +43,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class RocksDBTest {
     private final String fileName = getRandomTempDbFile();
     private Nitrite db;
@@ -105,24 +104,19 @@ public void testRocksDBMap() {
         referenceMap.put(date3, 3L); // today + 5
         referenceMap.put(date4, 4L); // today
 
-        testLevelDBMap.entries().forEach(System.out::println);
-        System.out.println("*****************");
-        referenceMap.entrySet().forEach(System.out::println);
+        testLevelDBMap.entries().forEach(Assert::assertNotNull);
+        referenceMap.entrySet().forEach(Assert::assertNotNull);
 
         cal = Calendar.getInstance();
         cal.add(Calendar.DATE, 6);
         Date date5 = cal.getTime();
 
-        System.out.println("Floor Key " + referenceMap.floorKey(date5));
         assertEquals(testLevelDBMap.floorKey(date5), referenceMap.floorKey(date5));     // x <= date5 : date3
 
-        System.out.println("Lower Key " + referenceMap.lowerKey(date5));
         assertEquals(testLevelDBMap.lowerKey(date5), referenceMap.lowerKey(date5));     // x < date5 : date4
 
-        System.out.println("Higher Key " + referenceMap.higherKey(date5));
         assertEquals(testLevelDBMap.higherKey(date5), referenceMap.higherKey(date5));   // date5 >= x :
 
-        System.out.println("Ceiling Key " + referenceMap.ceilingKey(date5));
         assertEquals(testLevelDBMap.ceilingKey(date5), referenceMap.ceilingKey(date5));
     }
 
@@ -141,18 +135,14 @@ public void testRocksDBMapInteger() {
         referenceMap.put(3, 3); // today + 5
         referenceMap.put(4, 4); // today
 
-        testLevelDBMap.entries().forEach(System.out::println);
+        testLevelDBMap.entries().forEach(Assert::assertNotNull);
 
-        System.out.println("Floor Key " + referenceMap.floorKey(3));
         assertEquals(testLevelDBMap.floorKey(3), referenceMap.floorKey(3));     // x <= date5 : date3
 
-        System.out.println("Lower Key " + referenceMap.lowerKey(3));
         assertEquals(testLevelDBMap.lowerKey(3), referenceMap.lowerKey(3));     // x < date5 : date4
 
-        System.out.println("Higher Key " + referenceMap.higherKey(3));
         assertEquals(testLevelDBMap.higherKey(3), referenceMap.higherKey(3));   // date5 >= x :
 
-        System.out.println("Ceiling Key " + referenceMap.ceilingKey(3));
         assertEquals(testLevelDBMap.ceilingKey(3), referenceMap.ceilingKey(3));
     }
 
@@ -167,25 +157,13 @@ public void testNaturalSort() {
         map.put("A", 12);
         map.put("1", 11);
 
-        map.entries().forEach(System.out::println);
+        map.entries().forEach(Assert::assertNotNull);
 
         treeMap.put("z", 10);
         treeMap.put("Z", 14);
         treeMap.put("w", 13);
         treeMap.put("A", 12);
         treeMap.put("1", 11);
-
-        System.out.println(map.floorKey("w"));
-        System.out.println(map.higherKey("w"));
-        System.out.println(map.ceilingKey("w"));
-        System.out.println(map.lowerKey("w"));
-
-        System.out.println("***************");
-
-        System.out.println(treeMap.floorKey("w"));
-        System.out.println(treeMap.higherKey("w"));
-        System.out.println(treeMap.ceilingKey("w"));
-        System.out.println(treeMap.lowerKey("w"));
     }
 
     @Test
@@ -275,7 +253,6 @@ public void testPrev() {
                             byte[] key = iterator.key();
                             byte[] value = iterator.value();
 
-                            System.out.println("Key: Value = " + new String(key) + ": " + new String(value));
                             iterator.prev();
                         }
                     }
@@ -290,7 +267,7 @@ public void testPrev() {
                     }
                 } // frees the db and the db options
             } catch (RocksDBException e) {
-                e.printStackTrace();
+                log.error("Error while opening rocksdb", e);
             }
         } // frees the column family options
     }
@@ -306,7 +283,6 @@ public void testPrevNitriteMap() {
 
         Long floorKey = testLevelDBMap.floorKey(10L);
         while (floorKey != null) {
-            System.out.println("Key: Value = " + floorKey + ": " + testLevelDBMap.get(floorKey));
             floorKey = testLevelDBMap.lowerKey(floorKey);
         }
     }
diff --git a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/Retry.java b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/Retry.java
index 97691f917..d6df10c41 100644
--- a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/Retry.java
+++ b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/Retry.java
@@ -1,5 +1,6 @@
 package org.dizitart.no2.spatial;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -7,6 +8,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -31,11 +33,13 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.warn(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
diff --git a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java
index 0893b2180..1116a7752 100644
--- a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java
+++ b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.spatial;
 
+import lombok.extern.slf4j.Slf4j;
 import org.locationtech.jts.awt.ShapeWriter;
 import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.io.WKTReader;
@@ -27,6 +28,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class SpatialViewer {
     public static void main(String[] args) {
         JFrame f = new JFrame();
@@ -76,7 +78,7 @@ public void paint(Graphics g) {
                 g2d.draw(searchShape);
 
             } catch (Exception e) {
-                e.printStackTrace();
+                log.error("Error while drawing", e);
             }
         }
     }
diff --git a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/TestUtil.java b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/TestUtil.java
index b131e2f47..aecad83ef 100644
--- a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/TestUtil.java
+++ b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/TestUtil.java
@@ -17,7 +17,7 @@
 
 package org.dizitart.no2.spatial;
 
-import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.common.mapper.JacksonMapperModule;
 import org.dizitart.no2.mvstore.MVStoreModule;
@@ -33,6 +33,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TestUtil {
     public static String getRandomTempDbFile() {
         String dataDir = System.getProperty("java.io.tmpdir") + File.separator + "nitrite" + File.separator + "data";
@@ -56,8 +57,11 @@ public static Nitrite createDb(String fileName) {
             .openOrCreate();
     }
 
-    @SneakyThrows
     public static void deleteDb(String fileName) {
-        Files.delete(Paths.get(fileName));
+        try {
+            Files.delete(Paths.get(fileName));
+        } catch (Exception e) {
+            log.error("Error while deleting db", e);
+        }
     }
 }
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/Retry.java b/nitrite-support/src/test/java/org/dizitart/no2/support/Retry.java
index 98b478557..3d491a127 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/Retry.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/Retry.java
@@ -1,5 +1,6 @@
 package org.dizitart.no2.support;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -7,6 +8,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -31,12 +33,14 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.warn(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
-}
+}
\ No newline at end of file
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java b/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
index a06ccae1a..2aa2d3050 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/TestUtil.java
@@ -22,7 +22,6 @@
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
@@ -52,9 +51,12 @@ public static String getRandomTempDbFile() {
         return file.getPath() + File.separator + UUID.randomUUID() + ".db";
     }
 
-    @SneakyThrows
     public static void deleteDb(String filePath) {
-        Files.delete(Paths.get(filePath));
+        try {
+            Files.delete(Paths.get(filePath));
+        } catch (Exception e) {
+            log.error("Error while deleting db", e);
+        }
     }
 
     public static > boolean isSorted(Iterable iterable, boolean ascending) {
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
index 7a88d0db8..cab29361e 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
@@ -16,30 +16,29 @@
 
  package org.dizitart.no2.support.exchange;
 
- import org.dizitart.no2.Nitrite;
- import org.dizitart.no2.collection.Document;
- import org.dizitart.no2.collection.NitriteCollection;
- import org.dizitart.no2.common.mapper.EntityConverterMapper;
- import org.dizitart.no2.mvstore.MVStoreModule;
- import org.dizitart.no2.repository.ObjectRepository;
- import org.dizitart.no2.support.Retry;
- import org.dizitart.no2.support.data.Company;
- import org.dizitart.no2.support.data.Employee;
- import org.dizitart.no2.support.data.Note;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Rule;
- 
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.List;
- import java.util.UUID;
- 
- import static org.dizitart.no2.common.Constants.*;
- import static org.dizitart.no2.common.module.NitriteModule.module;
- import static org.junit.Assert.assertTrue;
+import org.dizitart.no2.Nitrite;
+import org.dizitart.no2.collection.Document;
+import org.dizitart.no2.collection.NitriteCollection;
+import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.mvstore.MVStoreModule;
+import org.dizitart.no2.repository.ObjectRepository;
+import org.dizitart.no2.support.Retry;
+import org.dizitart.no2.support.TestUtil;
+import org.dizitart.no2.support.data.Company;
+import org.dizitart.no2.support.data.Employee;
+import org.dizitart.no2.support.data.Note;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.UUID;
+
+import static org.dizitart.no2.common.Constants.*;
+import static org.dizitart.no2.common.module.NitriteModule.module;
+import static org.junit.Assert.assertTrue;
  
  /**
   * @author Anindya Chatterjee.
@@ -69,9 +68,9 @@ public void setUp() {
      @After
      public void cleanUp() throws IOException {
          closeDb();
-         Files.delete(Paths.get(sourceDbFile));
-         Files.delete(Paths.get(destDbFile));
-         Files.delete(Paths.get(schemaFile));
+         TestUtil.deleteDb(sourceDbFile);
+         TestUtil.deleteDb(destDbFile);
+         TestUtil.deleteDb(schemaFile);
      }
  
      public static String getRandomTempDbFile() {
diff --git a/nitrite/src/test/java/org/dizitart/no2/collection/DocumentTest.java b/nitrite/src/test/java/org/dizitart/no2/collection/DocumentTest.java
index 195621c25..616b83a46 100644
--- a/nitrite/src/test/java/org/dizitart/no2/collection/DocumentTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/collection/DocumentTest.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.collection;
 
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.NitriteConfig;
 import org.dizitart.no2.exceptions.InvalidIdException;
 import org.dizitart.no2.exceptions.ValidationException;
@@ -36,6 +37,7 @@
 import static org.dizitart.no2.integration.TestUtil.parse;
 import static org.junit.Assert.*;
 
+@Slf4j
 public class DocumentTest {
     private Document doc;
 
@@ -281,8 +283,6 @@ public void testSerializability() throws IOException, ClassNotFoundException {
                 oos.writeObject(doc);
                 byte[] data = bos.toByteArray();
 
-                System.out.println(data.length);
-
                 try (ByteArrayInputStream bis = new ByteArrayInputStream(data)) {
                     try (ObjectInputStream ois = new ObjectInputStream(bis)) {
                         Document otherDoc = (Document) ois.readObject();
diff --git a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java
index 4b8ddc781..6f5c0174b 100644
--- a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java
@@ -138,7 +138,6 @@ public void testDelete() {
         employeeRepository.remove(where("empId").eq(1L));
         await().atMost(1, TimeUnit.SECONDS).until(listenerPrepared(EventType.Remove));
 
-        System.out.println("Action - " + listener.getAction());
         assertEquals(listener.getAction(), EventType.Remove);
         assertNotNull(listener.getItem());
     }
diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java
index ee209e3af..130f20b7e 100644
--- a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java
@@ -52,15 +52,8 @@ public void testWithConverter() {
         emp1.setJoiningDate(new Date());
         emp1.setBoss(boss);
 
-        long start = System.currentTimeMillis();
         Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class);
-        long diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
-
-        start = System.currentTimeMillis();
         Employee employee = (Employee) entityConverterMapper.tryConvert(document, Employee.class);
-        diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
         assertEquals(emp1, employee);
     }
 
@@ -82,15 +75,9 @@ public void testWithMappable() {
         emp1.setJoiningDate(new Date());
         emp1.setBoss(boss);
 
-        long start = System.currentTimeMillis();
         Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class);
-        long diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
 
-        start = System.currentTimeMillis();
         MappableEmployee employee = (MappableEmployee) entityConverterMapper.tryConvert(document, MappableEmployee.class);
-        diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
         assertEquals(emp1, employee);
     }
 
@@ -119,15 +106,9 @@ public void testWithConverterAndMappableMix() {
             add(emp1);
         }});
 
-        long start = System.currentTimeMillis();
         Document document = (Document) entityConverterMapper.tryConvert(department, Document.class);
-        long diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
 
-        start = System.currentTimeMillis();
         Department dept = (Department) entityConverterMapper.tryConvert(document, Department.class);
-        diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
         assertEquals(department, dept);
     }
 
@@ -151,20 +132,14 @@ public void testNested() {
 
         MappableDepartment department = new MappableDepartment();
         department.setName("Dept");
-        department.setEmployeeList(new ArrayList() {{
+        department.setEmployeeList(new ArrayList<>() {{
             add(boss);
             add(emp1);
         }});
 
-        long start = System.currentTimeMillis();
         Document document = (Document) entityConverterMapper.tryConvert(department, Document.class);
-        long diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
 
-        start = System.currentTimeMillis();
         MappableDepartment dept = (MappableDepartment) entityConverterMapper.tryConvert(document, MappableDepartment.class);
-        diff = System.currentTimeMillis() - start;
-        System.out.println(diff);
         assertEquals(department, dept);
     }
 
diff --git a/nitrite/src/test/java/org/dizitart/no2/common/streams/ProjectedDocumentStreamTest.java b/nitrite/src/test/java/org/dizitart/no2/common/streams/ProjectedDocumentStreamTest.java
index 1e76c1c74..2e0cea9ab 100644
--- a/nitrite/src/test/java/org/dizitart/no2/common/streams/ProjectedDocumentStreamTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/common/streams/ProjectedDocumentStreamTest.java
@@ -24,10 +24,10 @@
 import org.dizitart.no2.common.RecordStream;
 import org.dizitart.no2.common.processors.ProcessorChain;
 import org.dizitart.no2.common.tuples.Pair;
+import org.junit.Assert;
 import org.junit.Test;
 
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
 @SuppressWarnings("unchecked")
@@ -66,6 +66,7 @@ public void testIterator2() {
         verify(recordStream).iterator();
         assertTrue(projectedDocumentStream.toList().isEmpty());
     }
+
     @Test
     public void test() {
         try(Nitrite db = Nitrite.builder().openOrCreate()) {
@@ -83,7 +84,7 @@ public void test() {
             db.getCollection("users")
                 .find()
                 .project(projection)
-                .forEach(System.out::println);
+                .forEach(Assert::assertNotNull);
         }
     }
 }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/DbTestOperations.java b/nitrite/src/test/java/org/dizitart/no2/integration/DbTestOperations.java
deleted file mode 100644
index 588ba57b7..000000000
--- a/nitrite/src/test/java/org/dizitart/no2/integration/DbTestOperations.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2017-2021 Nitrite author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.dizitart.no2.integration;
-
-import org.dizitart.no2.Nitrite;
-import org.dizitart.no2.collection.Document;
-import org.dizitart.no2.collection.DocumentCursor;
-import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.common.SortOrder;
-import org.dizitart.no2.common.WriteResult;
-import org.dizitart.no2.index.IndexType;
-import org.junit.Rule;
-
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import static org.dizitart.no2.integration.TestUtil.isSorted;
-import static org.dizitart.no2.collection.Document.createDocument;
-import static org.dizitart.no2.collection.FindOptions.orderBy;
-import static org.dizitart.no2.filters.Filter.*;
-import static org.dizitart.no2.filters.FluentFilter.where;
-import static org.dizitart.no2.index.IndexOptions.indexOptions;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author Anindya Chatterjee.
- */
-public class DbTestOperations {
-    private Nitrite db;
-
-    @Rule
-    public Retry retry = new Retry(3);
-
-    public static String getRandomTempDbFile() {
-        String dataDir = System.getProperty("java.io.tmpdir") + File.separator + "nitrite" + File.separator + "data";
-        File file = new File(dataDir);
-        if (!file.exists()) {
-            assertTrue(file.mkdirs());
-        }
-        return file.getPath() + File.separator + UUID.randomUUID().toString() + ".db";
-    }
-
-    void createDb() throws Exception {
-        db = TestUtil.createDb();
-        db.close();
-    }
-
-    void writeCollection() throws Exception {
-        NitriteCollection collection;
-
-        db = TestUtil.createDb();
-
-        collection = db.getCollection("test");
-        collection.remove(ALL);
-        db.close();
-    }
-
-    void writeIndex() throws Exception {
-        NitriteCollection collection;
-
-        db = TestUtil.createDb();
-
-        collection = db.getCollection("test");
-        collection.remove(ALL);
-        collection.createIndex(indexOptions(IndexType.FULL_TEXT), "body");
-        collection.createIndex("firstName");
-        collection.createIndex(indexOptions(IndexType.NON_UNIQUE), "lastName");
-        db.close();
-    }
-
-    void insertInCollection() throws Exception {
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
-
-        Document doc1 = createDocument("firstName", "fn1")
-            .put("lastName", "ln1")
-            .put("birthDay", simpleDateFormat.parse("2012-07-01T16:02:48.440Z"))
-            .put("data", new byte[]{1, 2, 3})
-            .put("body", "a quick brown fox jump over the lazy dog");
-        Document doc2 = createDocument("firstName", "fn2")
-            .put("lastName", "ln2")
-            .put("birthDay", simpleDateFormat.parse("2010-06-12T16:02:48.440Z"))
-            .put("data", new byte[]{3, 4, 3})
-            .put("body", "quick hello world from nitrite");
-        Document doc3 = createDocument("firstName", "fn3")
-            .put("lastName", "ln2")
-            .put("birthDay", simpleDateFormat.parse("2014-04-17T16:02:48.440Z"))
-            .put("data", new byte[]{9, 4, 8})
-            .put("body", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
-                "Sed nunc mi, mattis ullamcorper dignissim vitae, condimentum non lorem.");
-
-        NitriteCollection collection;
-
-        db = TestUtil.createDb();
-
-        collection = db.getCollection("test");
-
-        WriteResult result = collection.insert(doc1, doc2, doc3);
-        assertEquals(result.getAffectedCount(), 3);
-
-        db.commit();
-        db.close();
-    }
-
-    void readCollection() throws Exception {
-        NitriteCollection collection;
-
-        db = TestUtil.createDb();
-
-        collection = db.getCollection("test");
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
-
-        DocumentCursor cursor = collection.find();
-        assertEquals(cursor.size(), 3);
-
-        cursor = collection.find(where("birthDay").gt(simpleDateFormat.parse("2012-07-01T16:02:48.440Z")));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(where("birthDay").gte(simpleDateFormat.parse("2012-07-01T16:02:48.440Z")));
-        assertEquals(cursor.size(), 2);
-
-        cursor = collection.find(where("birthDay").lt(simpleDateFormat.parse("2012-07-01T16:02:48.440Z")));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(where("birthDay").lte(simpleDateFormat.parse("2012-07-01T16:02:48.440Z")));
-        assertEquals(cursor.size(), 2);
-
-        cursor = collection.find(where("birthDay").lte(new Date()));
-        assertEquals(cursor.size(), 3);
-
-        cursor = collection.find(where("birthDay").lt(new Date()));
-        assertEquals(cursor.size(), 3);
-
-        cursor = collection.find(where("birthDay").gt(new Date()));
-        assertEquals(cursor.size(), 0);
-
-        cursor = collection.find(where("birthDay").gte(new Date()));
-        assertEquals(cursor.size(), 0);
-
-        cursor = collection.find(where("birthDay").lte(new Date()).and(where("firstName").eq("fn1")));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(where("birthDay").lte(new Date()).or(where("firstName").eq("fn12")));
-        assertEquals(cursor.size(), 3);
-
-        cursor = collection.find(
-            and(
-                or(
-                    where("birthDay").lte(new Date()),
-                    where("firstName").eq("fn12")
-                ),
-                where("lastName").eq("ln1")
-            ));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(
-            and(
-                or(
-                    where("birthDay").lte(new Date()),
-                    where("firstName").eq("fn12")
-                ),
-                where("lastName").eq("ln1")
-            ).not());
-        assertEquals(cursor.size(), 2);
-
-        cursor = collection.find(where("data.1").eq((byte) 4));
-        assertEquals(cursor.size(), 2);
-
-        cursor = collection.find(where("data.1").lt(4));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(where("lastName").in("ln1", "ln2", "ln10"));
-        assertEquals(cursor.size(), 3);
-
-        cursor = collection.find(where("firstName").notIn("fn1", "fn2"));
-        assertEquals(cursor.size(), 1);
-
-        collection.createIndex("birthDay");
-        cursor = collection.find(orderBy("birthDay", SortOrder.Descending).skip(1).limit(2));
-        assertEquals(cursor.size(), 2);
-        List dateList = new ArrayList<>();
-        for (Document document : cursor) {
-            dateList.add(document.get("birthDay", Date.class));
-        }
-        assertTrue(isSorted(dateList, false));
-
-        cursor = collection.find(where("body").text("Lorem"));
-        assertEquals(cursor.size(), 1);
-
-        cursor = collection.find(where("body").text("quick"));
-        assertEquals(cursor.size(), 2);
-
-        cursor = collection.find(where("body").text("nosql"));
-        assertEquals(cursor.size(), 0);
-
-        db.close();
-    }
-
-    void deleteDb() throws Exception {
-        if (db != null && !db.isClosed()) {
-            db.close();
-        }
-    }
-}
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
index e2c3812e9..85fe9f0f3 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/MultiThreadedTest.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
@@ -36,7 +37,6 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import static org.dizitart.no2.integration.DbTestOperations.getRandomTempDbFile;
 import static org.dizitart.no2.integration.TestUtil.createDb;
 import static org.dizitart.no2.collection.Document.createDocument;
 import static org.dizitart.no2.filters.FluentFilter.where;
@@ -47,8 +47,8 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 public class MultiThreadedTest {
-    private static final String fileName = getRandomTempDbFile();
     private NitriteCollection collection;
     private final int threadCount = 20;
     private final CountDownLatch latch = new CountDownLatch(threadCount);
@@ -96,9 +96,7 @@ public void testOperations() throws Exception {
 
                         assertTrue(collection.hasIndex("unixTime"));
                     } catch (Throwable e) {
-                        System.out.println("Exception at thread " +
-                            Thread.currentThread().getName() + " with iteration " + j);
-                        e.printStackTrace();
+                        log.error("Error while inserting document", e);
                     }
                 }
                 latch.countDown();
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
index 545e92dd2..4ef9dfd08 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
@@ -20,6 +20,7 @@
 import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlSchemaType;
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.EntityConverter;
@@ -43,6 +44,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class NitriteStressTest {
     private static final int TEST_SET_COUNT = 15000;
     private final PodamFactory podamFactory = new PodamFactoryImpl();
@@ -66,7 +68,7 @@ public void stressTest() {
                 counter++;
             }
         } catch (Throwable t) {
-            System.err.println("Crashed after " + counter + " records");
+            log.error("Error occurred at " + counter, t);
             throw t;
         }
     }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java
index 2a7f7dfcf..c9e4eca01 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java
@@ -20,17 +20,17 @@
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.FindOptions;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.collection.UpdateOptions;
 import org.dizitart.no2.common.SortOrder;
-import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.common.concurrent.ThreadPoolManager;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexOptions;
@@ -67,6 +67,7 @@
 /**
  * @author Anindya Chatterjee.
  */
+@Slf4j
 public class NitriteTest {
     @Rule
     public Retry retry = new Retry(3);
@@ -282,7 +283,7 @@ public void testIssue185() throws InterruptedException {
                     } catch (InterruptedException ignored) {
                     }
                 } catch (Throwable t) {
-                    t.printStackTrace();
+                    log.error("Error while updating receipt", t);
                 }
             }
             latch.countDown();
@@ -317,7 +318,7 @@ public void testIssue193() throws InterruptedException {
                     repository.update(receipt, true);
                     latch.countDown();
                 } catch (Throwable t) {
-                    t.printStackTrace();
+                    log.error("Error while updating receipt", t);
                 }
             });
         }
@@ -346,7 +347,7 @@ public void testIssue212() {
             doc, UpdateOptions.updateOptions(true));
 
         for (Document document : collection.find()) {
-            System.out.println(document);
+            assertNotNull(document);
         }
     }
 
@@ -360,14 +361,9 @@ public void run() {
                     NitriteCollection collection = db.getCollection("testIssue245");
 
                     for (int i = 0; i < 5; i++) {
-
-                        System.out.println("Thread ID = " + id + " Inserting doc " + i);
                         Document doc = Document.createDocument(UUID.randomUUID().toString(), UUID.randomUUID().toString());
 
-                        WriteResult result = collection.insert(doc);//db.commit();
-                        System.out.println("Result of insert = " + result.getAffectedCount());
-                        System.out.println("Thread id = " + id + " --> count = " + collection.size());
-
+                        collection.insert(doc);//db.commit();
                         Thread.sleep(10);
 
                     }//for closing
@@ -375,7 +371,7 @@ public void run() {
                     collection.close();
 
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting document", e);
                 }
             }
         }
@@ -395,7 +391,6 @@ public void run() {
         t2.join();
 
         NitriteCollection collection = db.getCollection("testIssue245");
-        System.out.println("No of Documents = " + collection.size());
         collection.close();
         db.close();
     }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/Retry.java b/nitrite/src/test/java/org/dizitart/no2/integration/Retry.java
index 3d6a27d11..a25ef04b1 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/Retry.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/Retry.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration;
 
+import lombok.extern.slf4j.Slf4j;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -24,6 +25,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class Retry implements TestRule {
     private final int retryCount;
 
@@ -48,11 +50,13 @@ public void evaluate() throws Throwable {
                         return;
                     } catch (Throwable t) {
                         caughtThrowable = t;
-                        System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed");
+                        log.error(description.getDisplayName() + ": run " + (i + 1) + " failed");
                     }
                 }
-                System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
-                throw caughtThrowable;
+                log.error(description.getDisplayName() + ": giving up after " + retryCount + " failures");
+                if (caughtThrowable != null) {
+                    throw caughtThrowable;
+                }
             }
         };
     }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
index 7a759aeb3..6c716f2ac 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/SerializabilityTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration;
 
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
@@ -34,6 +35,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class SerializabilityTest {
     private NitriteCollection collection;
     private Nitrite db;
@@ -64,9 +66,8 @@ public void testSerializabilityValidation() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
@@ -80,9 +81,8 @@ public void testSerializablity() {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                log.error("Error while sleeping", e);
             }
-            System.out.println("Write " + i + " completed");
         }
     }
 
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java
index d34936a7c..f9274e4fb 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java
@@ -79,46 +79,29 @@ public void testIssue41() {
         AtomicLong counter = new AtomicLong(System.currentTimeMillis());
         PodamFactory factory = new PodamFactoryImpl();
 
-        long start = System.currentTimeMillis();
         for (int i = 0; i < 100000; i++) {
             Document doc = Document.createDocument();
             doc.put("number", random.nextDouble());
             doc.put("name", factory.manufacturePojo(String.class));
             doc.put("counter", counter.getAndIncrement());
             collection.insert(doc);
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries written");
-            }
         }
-        System.out.println("Records inserted in " + ((System.currentTimeMillis() - start) / (1000 * 60)) + " minutes");
 
         if (db.hasUnsavedChanges()) {
             db.commit();
         }
 
-        start = System.currentTimeMillis();
         DocumentCursor cursor = collection.find();
-        System.out.println("Size ->" + cursor.size());
-        System.out.println("Records size calculated in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
 
-        int i = 0;
-        start = System.currentTimeMillis();
         for (Document element : cursor) {
             assertNotNull(element);
-            i++;
-            if (i % 10000 == 0) {
-                System.out.println(i + " entries processed");
-            }
         }
-        System.out.println("Iteration completed in " + ((System.currentTimeMillis() - start) / (1000)) + " seconds");
     }
 
     @After
     public void clear() throws Exception {
         if (db != null && !db.isClosed()) {
-            long start = System.currentTimeMillis();
             db.close();
-            System.out.println("Time to compact and close - " + (System.currentTimeMillis() - start) / 1000 + " seconds");
         }
     }
 
@@ -136,17 +119,11 @@ public void testRepoPerformanceWithIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTestIndexed.class);
-        long start = System.currentTimeMillis();
         for (PerfTestIndexed item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 indexed items - " + diff + "ms");
     }
 
     @Test
@@ -163,17 +140,11 @@ public void testRepoPerformanceWithoutIndex() {
 
         // actual calculation
         repo = db.getRepository(PerfTest.class);
-        long start = System.currentTimeMillis();
         for (PerfTest item : items) {
             repo.insert(item);
         }
-        long diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to insert 10000 non-indexed items - " + diff + "ms");
 
-        start = System.currentTimeMillis();
         repo.remove(Filter.ALL);
-        diff = System.currentTimeMillis() - start;
-        System.out.println("Time take to remove 10000 non-indexed items - " + diff + "ms");
     }
 
     private  List getItems(Class type) {
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
index e2a4e4279..71c848c3a 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionCompoundIndexTest.java
@@ -17,6 +17,7 @@
 
 package org.dizitart.no2.integration.collection;
 
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.DocumentCursor;
 import org.dizitart.no2.collection.FindPlan;
@@ -41,6 +42,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class CollectionCompoundIndexTest extends BaseCollectionTest {
     @Test
     public void testCreateAndCheckIndex() {
@@ -151,7 +153,7 @@ public void testDeleteWithIndex() {
     @Test
     public void testRebuildIndexOnRunningIndex() {
         insert();
-        db.getStore().subscribe(System.out::println);
+        db.getStore().subscribe((m) -> log.info(m.getEvent().name()));
 
         collection.createIndex("firstName", "lastName");
         collection.rebuildIndex("firstName", "lastName");
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
index 1d48a793a..5fd707307 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindTest.java
@@ -402,7 +402,6 @@ public void testProjection() {
         assertEquals(recordStream.toList().stream().skip(1).findFirst().orElse(null),
             Document.createDocument("name", "Jane").put("address", Document.createDocument("city", "New Jersey")
                 .put("state", "NJ")));
-        System.out.println(recordStream.firstOrNull());
     }
 
     @Test
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
index 0fabd00c6..bb4ea47e7 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionIndexTest.java
@@ -216,7 +216,6 @@ public void testIndexEvent() {
                     break;
             }
             assertTrue(eventInfo.getItem() instanceof String);
-            System.out.println(eventInfo.getEventType() + " for field " + eventInfo.getItem());
         });
 
         collection.createIndex(indexOptions(IndexType.NON_UNIQUE), "first");
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
index caff44d61..3085b3625 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionJoinTest.java
@@ -100,7 +100,6 @@ public void testJoinAll() {
             } else if (document.get("firstName") == "fn3") {
                 assertNull(document.get("personalDetails"));
             }
-            System.out.println(document);
         }
     }
 }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
index 752939810..6f691f01c 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
@@ -186,7 +186,6 @@ public void testWriteThousandRecords() {
             repository.update(where("firstName").eq(record.getFirstName()), record);
         }
         sw.stop();
-        System.out.println("Sequential Time (s) - " + sw.getTime());
     }
 
     @Test
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index e2682f3eb..733bb03ec 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -65,8 +65,8 @@ public void testEmployeeProjection() {
         assertNotNull(employeeList);
         assertNotNull(subEmployeeList);
 
-        assertTrue(employeeList.size() > 0);
-        assertTrue(subEmployeeList.size() > 0);
+        assertFalse(employeeList.isEmpty());
+        assertFalse(subEmployeeList.isEmpty());
 
         assertEquals(employeeList.size(), subEmployeeList.size());
 
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
index c5c27490e..75f7f148a 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UnAnnotatedObjectTest.java
@@ -47,33 +47,25 @@ public void testFind() {
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Ascending).skip(0).limit(10));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         Iterable findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = aObjectRepository.find(where("b.number").eq(160).not(),
             orderBy("b.number", SortOrder.Descending).skip(2).limit(7));
 
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
-
         findRecord = cursor.project(ClassA.class);
         for (ClassA classA : findRecord) {
-            System.out.println(classA);
+            assertNotNull(classA);
         }
 
         cursor = cObjectRepository.find(where("id").gt(900),
             orderBy("id", SortOrder.Descending).skip(2).limit(7));
-        System.out.println("Available - " + !cursor.isEmpty());
-        System.out.println("Total Size - " + cursor.size());
 
         Iterable findRecordC = cursor.project(ClassC.class);
         for (ClassC classC : findRecordC) {
-            System.out.println(classC);
+            assertNotNull(classC);
         }
     }
 
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index 9277d4f4f..99f77c8ac 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -116,7 +116,6 @@ public void testUniversalFullTextIndexing() {
         Cursor cursor = textRepository.find(where("text").text("Lorem"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for English text -> " + data.id);
             if (data.id % 2 == 0 || data.id % 3 == 0 || data.id % 5 == 0) {
                 fail();
             }
@@ -125,7 +124,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("শহর"));
         assertEquals(cursor.size(), 5);
         for (TextData data : cursor) {
-            System.out.println("Id for Bengali text -> " + data.id);
             if (data.id % 2 != 0) {
                 fail();
             }
@@ -136,7 +134,6 @@ public void testUniversalFullTextIndexing() {
         cursor = textRepository.find(where("text").text("*転閉*"));
         assertEquals(cursor.size(), 2);
         for (TextData data : cursor) {
-            System.out.println("Id for Chinese text -> " + data.id);
             if (data.id % 3 != 0) {
                 fail();
             }
@@ -146,7 +143,6 @@ public void testUniversalFullTextIndexing() {
         if (isProtected) {
             assertEquals(cursor.size(), 1);
             for (TextData data : cursor) {
-                System.out.println("Id for Arabic text -> " + data.id);
                 if (data.id % 5 != 0) {
                     fail();
                 }
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
index 6e3052aaa..b21bcf420 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionCollectionTest.java
@@ -18,18 +18,21 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
-import org.dizitart.no2.integration.collection.BaseCollectionTest;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
-import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.TransactionException;
 import org.dizitart.no2.index.IndexType;
+import org.dizitart.no2.integration.collection.BaseCollectionTest;
 import org.dizitart.no2.transaction.Session;
 import org.dizitart.no2.transaction.Transaction;
 import org.junit.Test;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -44,6 +47,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionCollectionTest extends BaseCollectionTest {
 
     @Test
@@ -544,7 +548,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -558,7 +562,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -588,7 +592,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +606,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
@@ -637,7 +641,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error in transaction", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -651,7 +655,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error in transaction", e);
                 }
             });
 
diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
index 4adab1075..7d3c1ff00 100644
--- a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
+++ b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java
@@ -18,6 +18,7 @@
 package org.dizitart.no2.integration.transaction;
 
 import com.github.javafaker.Faker;
+import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.meta.Attributes;
@@ -45,6 +46,7 @@
 /**
  * @author Anindya Chatterjee
  */
+@Slf4j
 public class TransactionRepositoryTest extends BaseObjectRepositoryTest {
 
     @Test
@@ -588,7 +590,7 @@ public void testConcurrentInsertAndRemove() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -602,7 +604,7 @@ public void testConcurrentInsertAndRemove() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -632,7 +634,7 @@ public void testConcurrentInsert() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while inserting", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -646,7 +648,7 @@ public void testConcurrentInsert() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while inserting", e);
                 }
             });
 
@@ -679,7 +681,7 @@ public void testConcurrentUpdate() {
 
                         transaction.commit();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        log.error("Error while updating", e);
                         transaction.rollback();
                     } finally {
                         transaction.close();
@@ -693,7 +695,7 @@ public void testConcurrentUpdate() {
                 try {
                     future.get();
                 } catch (InterruptedException | ExecutionException e) {
-                    e.printStackTrace();
+                    log.error("Error while updating", e);
                 }
             });
 
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BackportJavaTimeTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BackportJavaTimeTest.kt
index 58c8888dd..e5dfafdf5 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BackportJavaTimeTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BackportJavaTimeTest.kt
@@ -20,11 +20,13 @@ import com.fasterxml.jackson.core.JsonGenerator
 import com.fasterxml.jackson.core.JsonParser
 import com.fasterxml.jackson.databind.*
 import com.fasterxml.jackson.databind.module.SimpleModule
+import lombok.extern.slf4j.Slf4j
 import org.dizitart.no2.index.IndexType
 import org.dizitart.no2.repository.annotations.Id
 import org.dizitart.no2.repository.annotations.Index
 import org.dizitart.no2.mvstore.MVStoreModule
 import org.junit.Test
+import org.slf4j.LoggerFactory
 import org.threeten.bp.LocalDateTime
 import org.threeten.bp.ZoneOffset
 import java.nio.file.Files
@@ -36,6 +38,7 @@ import java.util.*
  * @author Anindya Chatterjee
  */
 class BackportJavaTimeTest {
+    private val log = LoggerFactory.getLogger(BackportJavaTimeTest::class.java)
     private val dbPath = getRandomTempDbFile()
 
     @Index(fields = ["time"], type = IndexType.NON_UNIQUE)
@@ -79,8 +82,11 @@ class BackportJavaTimeTest {
         val repo = db.getRepository()
         val testData = TestData(time = LocalDateTime.now())
         repo.insert(testData)
-        println(repo.find().firstOrNull())
 
-        Files.delete(Paths.get(dbPath))
+        try {
+            Files.delete(Paths.get(dbPath))
+        } catch (e: Exception) {
+            log.error("Failed to delete db file", e)
+        }
     }
 }
\ No newline at end of file
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BaseTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BaseTest.kt
index 3dc629ae5..5accadf3b 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BaseTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BaseTest.kt
@@ -47,6 +47,10 @@ abstract class BaseTest {
             db?.close()
         }
         val file = File(fileName)
-        if (file.exists()) file.delete()
+        try {
+            if (file.exists()) file.delete()
+        } catch (e: Exception) {
+            // ignore
+        }
     }
 }
\ No newline at end of file
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt
index 431d1b1bf..daefb77c6 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt
@@ -23,6 +23,7 @@ import org.dizitart.kno2.serialization.KotlinXSerializationMapper
 import org.dizitart.no2.collection.Document
 import org.dizitart.no2.mvstore.MVStoreModule
 import org.junit.Test
+import org.slf4j.LoggerFactory
 import java.nio.file.Files
 import java.nio.file.Paths
 
@@ -31,6 +32,7 @@ import java.nio.file.Paths
  * @author Joris Jensen
  */
 class KotlinXSerializationMapperTest {
+    private val log = LoggerFactory.getLogger(KotlinXSerializationMapperTest::class.java)
     private val dbPath = getRandomTempDbFile()
 
     @Serializable
@@ -146,7 +148,11 @@ class KotlinXSerializationMapperTest {
             assertEquals(it, testData)
         }
         db.close()
-        Files.delete(Paths.get(dbPath))
+        try {
+            Files.delete(Paths.get(dbPath))
+        } catch (e: Exception) {
+            log.error("Failed to delete db file", e)
+        }
     }
 
     @Test
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/NitriteTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/NitriteTest.kt
index fc56686f5..a1ea45ba1 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/NitriteTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/NitriteTest.kt
@@ -153,7 +153,6 @@ class NitriteTest : BaseTest() {
         }
         latch.await()
         val cursor = repository.find()
-        println(cursor.toList())
         assertEquals(cursor.size(), 1)
     }
 
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ObjectFilterTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ObjectFilterTest.kt
index fabb10706..2afd8d548 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ObjectFilterTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ObjectFilterTest.kt
@@ -29,6 +29,7 @@ import org.junit.Test
 import org.locationtech.jts.geom.Geometry
 import org.locationtech.jts.geom.Point
 import org.locationtech.jts.io.WKTReader
+import org.slf4j.LoggerFactory
 import java.util.*
 import java.util.concurrent.CountDownLatch
 import java.util.concurrent.Executors
@@ -38,6 +39,7 @@ import java.util.concurrent.Executors
  * @author Anindya Chatterjee
  */
 class ObjectFilterTest : BaseTest() {
+    private val log = LoggerFactory.getLogger(ObjectFilterTest::class.java)
 
     @Before
     fun before() {
@@ -221,7 +223,7 @@ class ObjectFilterTest : BaseTest() {
                 val simpleObject = try {
                     repository.find(SimpleObject::id.name eq uuid).first()
                 } catch (t: Throwable) {
-                    t.printStackTrace()
+                    log.error("Error in test", t);
                     latch.countDown()
                     return@submit
                 }
@@ -236,7 +238,7 @@ class ObjectFilterTest : BaseTest() {
                             .find(SimpleObject::id.name eq uuid)
                         assertEquals(result.size(), 1)
                     } catch (t: Throwable) {
-                        t.printStackTrace()
+                        log.error("Error in test", t);
                     } finally {
                         latch.countDown()
                     }
diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/TransactionTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/TransactionTest.kt
index d7cefda4f..a2e43ae37 100644
--- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/TransactionTest.kt
+++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/TransactionTest.kt
@@ -31,6 +31,7 @@ import org.dizitart.no2.transaction.Transaction
 import org.junit.Assert
 import org.junit.Before
 import org.junit.Test
+import org.slf4j.LoggerFactory
 import java.util.concurrent.ExecutionException
 import java.util.concurrent.Executors
 import java.util.concurrent.Future
@@ -41,6 +42,8 @@ import java.util.function.Consumer
  * @author Anindya Chatterjee
  */
 class TransactionTest: BaseTest() {
+    private val log = LoggerFactory.getLogger(javaClass);
+
     @Before
     fun before() {
         db = nitrite {
@@ -624,7 +627,7 @@ class TransactionTest: BaseTest() {
                         txCol.remove(FluentFilter.where("id").eq(2 + fi * 10))
                         transaction.commit()
                     } catch (e: Exception) {
-                        e.printStackTrace()
+                        log.error("Error in transaction", e)
                         transaction.rollback()
                     } finally {
                         transaction.close()
@@ -636,9 +639,9 @@ class TransactionTest: BaseTest() {
                 try {
                     future.get()
                 } catch (e: InterruptedException) {
-                    e.printStackTrace()
+                    log.error("Error in transaction", e)
                 } catch (e: ExecutionException) {
-                    e.printStackTrace()
+                    log.error("Error in transaction", e)
                 }
             })
             Assert.assertEquals(90, collection.size())
@@ -665,7 +668,7 @@ class TransactionTest: BaseTest() {
                         }
                         transaction.commit()
                     } catch (e: Exception) {
-                        e.printStackTrace()
+                        log.error("Error in transaction", e)
                         transaction.rollback()
                     } finally {
                         transaction.close()
@@ -677,9 +680,9 @@ class TransactionTest: BaseTest() {
                 try {
                     future.get()
                 } catch (e: InterruptedException) {
-                    e.printStackTrace()
+                    log.error("Error in transaction", e)
                 } catch (e: ExecutionException) {
-                    e.printStackTrace()
+                   log.error("Error in transaction", e)
                 }
             })
             Assert.assertEquals(100, collection.size())
@@ -715,7 +718,7 @@ class TransactionTest: BaseTest() {
                         }
                         transaction.commit()
                     } catch (e: Exception) {
-                        e.printStackTrace()
+                        log.error("Error in transaction", e)
                         transaction.rollback()
                     } finally {
                         transaction.close()
@@ -727,9 +730,9 @@ class TransactionTest: BaseTest() {
                 try {
                     future.get()
                 } catch (e: InterruptedException) {
-                    e.printStackTrace()
+                    log.error("Error in transaction", e)
                 } catch (e: ExecutionException) {
-                    e.printStackTrace()
+                    log.error("Error in transaction", e)
                 }
             })
             Assert.assertEquals(10, collection.size())

From 08b60f7254ef21cf5dc0d748c988e1f9bfab6f2d Mon Sep 17 00:00:00 2001
From: Anindya Chatterjee 
Date: Thu, 17 Aug 2023 22:20:43 +0530
Subject: [PATCH 14/18] documentation

---
 .../no2/common/mapper/JacksonMapper.java      |  2 -
 .../java/org/dizitart/no2/NitriteTest.java    |  6 +-
 .../no2/integration/NitriteBuilderTest.java   |  4 +-
 .../no2/integration/NitriteStressTest.java    |  6 +-
 .../dizitart/no2/integration/NitriteTest.java |  4 +-
 .../no2/integration/event/EventTest.java      |  4 +-
 .../integration/migration/MigrationTest.java  |  6 +-
 .../repository/BaseObjectRepositoryTest.java  |  4 +-
 .../repository/CustomFieldSeparatorTest.java  |  4 +-
 .../repository/NitriteIdAsIdTest.java         |  4 +-
 .../ObjectRepositoryNegativeTest.java         |  4 +-
 .../repository/ObjectRepositoryTest.java      |  4 +-
 .../repository/RepositorySearchTest.java      |  4 +-
 .../UniversalTextTokenizerTest.java           |  4 +-
 .../java/org/dizitart/no2/NitriteTest.java    | 10 +-
 .../no2/integration/NitriteBuilderTest.java   |  4 +-
 .../no2/integration/NitriteStressTest.java    |  4 +-
 .../dizitart/no2/integration/NitriteTest.java |  4 +-
 .../no2/integration/event/EventTest.java      |  4 +-
 .../integration/migrate/MigrationTest.java    |  6 +-
 .../repository/BaseObjectRepositoryTest.java  |  5 +-
 .../repository/CustomFieldSeparatorTest.java  |  4 +-
 .../repository/NitriteIdAsIdTest.java         |  4 +-
 .../ObjectRepositoryNegativeTest.java         |  4 +-
 .../repository/ObjectRepositoryTest.java      |  4 +-
 .../repository/RepositorySearchTest.java      |  4 +-
 .../UniversalTextTokenizerTest.java           |  4 +-
 .../dizitart/no2/rocksdb/GithubIssues.java    |  4 +-
 .../support/exchange/BaseExternalTest.java    |  4 +-
 nitrite/pom.xml                               |  5 +-
 .../dizitart/no2/common/event/EventBus.java   | 26 -----
 .../no2/common/event/NitriteEventBus.java     | 17 ----
 .../no2/common/mapper/EntityConverter.java    |  5 +-
 .../no2/common/mapper/NitriteMapper.java      |  4 +-
 ...erMapper.java => SimpleNitriteMapper.java} |  8 +-
 .../dizitart/no2/common/meta/Attributes.java  | 25 +++--
 .../no2/common/meta/AttributesAware.java      | 13 ---
 .../no2/common/module/NitriteModule.java      |  5 +-
 .../no2/common/module/NitritePlugin.java      |  3 +-
 .../no2/common/module/PluginManager.java      |  9 +-
 .../no2/common/processors/Processor.java      | 11 ++-
 .../no2/common/processors/ProcessorChain.java | 16 ----
 .../org/dizitart/no2/NitriteBuilderTest.java  | 12 +--
 .../org/dizitart/no2/NitriteConfigTest.java   |  4 +-
 .../dizitart/no2/common/event/EventTest.java  |  4 +-
 .../mapper/EntityConverterMapperTest.java     | 96 -------------------
 .../no2/common/mapper/MapperTest.java         | 54 +++++------
 .../mapper/SimpleNitriteMapperTest.java       | 96 +++++++++++++++++++
 .../no2/common/module/PluginManagerTest.java  |  4 +-
 .../no2/common/util/DocumentUtilsTest.java    |  8 +-
 .../no2/common/util/ObjectUtilsTest.java      |  4 +-
 .../no2/common/util/ValidationUtilsTest.java  |  6 +-
 .../no2/integration/NitriteStressTest.java    |  4 +-
 .../dizitart/no2/integration/NitriteTest.java |  4 +-
 .../dizitart/no2/integration/StressTest.java  |  4 +-
 .../repository/BaseObjectRepositoryTest.java  |  4 +-
 .../repository/CustomFieldSeparatorTest.java  |  4 +-
 .../repository/NitriteIdAsIdTest.java         |  4 +-
 .../ObjectRepositoryNegativeTest.java         |  4 +-
 .../repository/ObjectRepositoryTest.java      |  4 +-
 .../repository/RepositoryJoinTest.java        |  4 +-
 .../repository/RepositorySearchTest.java      |  4 +-
 .../UniversalTextTokenizerTest.java           |  4 +-
 .../EntityDecoratorScannerTest.java           |  4 +-
 .../no2/repository/ObjectCursorTest.java      |  4 +-
 .../KotlinXSerializationMapper.kt             |  2 +-
 66 files changed, 275 insertions(+), 343 deletions(-)
 rename nitrite/src/main/java/org/dizitart/no2/common/mapper/{EntityConverterMapper.java => SimpleNitriteMapper.java} (95%)
 delete mode 100644 nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java
 create mode 100644 nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleNitriteMapperTest.java

diff --git a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java
index 282d83aaa..02a6e3a67 100644
--- a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java
+++ b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java
@@ -20,7 +20,6 @@
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.Module;
 import com.fasterxml.jackson.databind.*;
-import lombok.extern.slf4j.Slf4j;
 import org.dizitart.no2.NitriteConfig;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.modules.NitriteIdModule;
@@ -34,7 +33,6 @@
 /**
  * @author Anindya Chatterjee
  */
-@Slf4j
 public class JacksonMapper implements NitriteMapper {
     private ObjectMapper objectMapper;
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
index 2da3f5c24..6e27e27c8 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
@@ -28,7 +28,7 @@
 import org.dizitart.no2.common.SortOrder;
 import org.dizitart.no2.common.concurrent.ThreadPoolManager;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.ValidationException;
@@ -87,7 +87,7 @@ public class NitriteTest {
     public void setUp() throws ParseException {
         db = TestUtil.createDb(fileName, "test-user", "test-password");
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new CompatChild.Converter());
         documentMapper.registerEntityConverter(new Receipt.Converter());
         documentMapper.registerEntityConverter(new EmptyClass.Converter());
@@ -492,7 +492,7 @@ public void testReadCompatibility() throws IOException {
 
         String oldDbFile = System.getProperty("java.io.tmpdir") + File.separator + "old.db";
         Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password");
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new Receipt.Converter());
 
         NitriteCollection collection = db.getCollection("test");
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
index 49ac8ef2f..f49a6088f 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
@@ -28,7 +28,7 @@
 import org.dizitart.no2.common.Fields;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.exceptions.InvalidOperationException;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.NitriteSecurityException;
@@ -194,7 +194,7 @@ public void testPopulateRepositories() {
             .loadModule(module)
             .openOrCreate();
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestObject.Converter());
         documentMapper.registerEntityConverter(new TestObject2.Converter());
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
index ea65547b2..5fc8cc7f4 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
@@ -27,7 +27,7 @@
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.filters.Filter;
 import org.dizitart.no2.index.IndexOptions;
 import org.dizitart.no2.index.IndexType;
@@ -69,7 +69,7 @@ public class NitriteStressTest {
     @Before
     public void before() {
         db = createDb(fileName);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestDto.Converter());
         documentMapper.registerEntityConverter(new PerfTest.Converter());
         documentMapper.registerEntityConverter(new PerfTestIndexed.Converter());
@@ -89,7 +89,7 @@ public void cleanUp() {
     @Test
     public void stressTest() {
         ObjectRepository testRepository = db.getRepository(TestDto.class);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestDto.Converter());
         testRepository.createIndex(IndexOptions.indexOptions(IndexType.FULL_TEXT), "lastName");
         testRepository.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "birthDate");
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
index 378e8192a..02199d0b4 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
@@ -19,7 +19,7 @@
 
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.repository.data.ClassA;
 import org.dizitart.no2.integration.repository.data.ClassBConverter;
 import org.junit.After;
@@ -39,7 +39,7 @@ public class NitriteTest {
     @Before
     public void setUp() {
         db = createDb(fileName);
-        EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper nitriteMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter());
         nitriteMapper.registerEntityConverter(new ClassBConverter());
 
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
index dfed4ae8c..7bb8e8f47 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
@@ -18,7 +18,7 @@
 package org.dizitart.no2.integration.event;
 
 import org.dizitart.no2.collection.UpdateOptions;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.Employee;
 import org.dizitart.no2.Nitrite;
@@ -120,7 +120,7 @@ public void setUp() {
             db = nitriteBuilder.openOrCreate();
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new Employee.EmployeeConverter());
 
         employeeRepository = db.getRepository(Employee.class);
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java
index 3e16c31c6..887e95d01 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/migration/MigrationTest.java
@@ -18,7 +18,7 @@
 package org.dizitart.no2.integration.migration;
 
 import com.github.javafaker.Faker;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
@@ -58,7 +58,7 @@ public class MigrationTest {
     @Before
     public void setUp() {
         db = createDb(dbPath);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new OldClass.Converter());
         documentMapper.registerEntityConverter(new OldClass.Literature.Converter());
         documentMapper.registerEntityConverter(new NewClass.Converter());
@@ -128,7 +128,7 @@ public void migrate(InstructionSet instruction) {
             .addMigrations(migration)
             .openOrCreate("test-user", "test-password");
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new OldClass.Converter());
         documentMapper.registerEntityConverter(new OldClass.Literature.Converter());
         documentMapper.registerEntityConverter(new NewClass.Converter());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
index 7e90c07cd..1e08cac3e 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
@@ -19,7 +19,7 @@
 
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.NitriteBuilder;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.*;
 import org.dizitart.no2.integration.repository.decorator.ManufacturerConverter;
@@ -142,7 +142,7 @@ protected void openDb() {
             db = nitriteBuilder.openOrCreate();
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new RepositoryJoinTest.Person.Converter());
         documentMapper.registerEntityConverter(new RepositoryJoinTest.Address.Converter());
         documentMapper.registerEntityConverter(new RepositoryJoinTest.PersonDetails.Converter());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
index bc4c0a903..72886734b 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
@@ -22,7 +22,7 @@
 import lombok.Setter;
 import lombok.ToString;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.Company;
 import org.dizitart.no2.integration.repository.data.Note;
@@ -72,7 +72,7 @@ public void setUp() {
             .fieldSeparator(":")
             .openOrCreate();
 
-        EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         mapper.registerEntityConverter(new Company.CompanyConverter());
         mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter());
         mapper.registerEntityConverter(new Note.NoteConverter());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
index 41db7a05c..a2f83265e 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
@@ -17,7 +17,7 @@
 
 package org.dizitart.no2.integration.repository;
 
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.WithNitriteId;
 import org.dizitart.no2.Nitrite;
@@ -54,7 +54,7 @@ public class NitriteIdAsIdTest {
     @Before
     public void before() {
         db = TestUtil.createDb(fileName);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter());
 
         repo = db.getRepository(WithNitriteId.class);
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
index 361ffc00f..4f16c129e 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
@@ -17,7 +17,7 @@
 
 package org.dizitart.no2.integration.repository;
 
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.*;
 import org.dizitart.no2.Nitrite;
@@ -51,7 +51,7 @@ public class ObjectRepositoryNegativeTest {
     @Before
     public void setUp() {
         db = TestUtil.createDb(dbPath);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new WithPublicField.Converter());
         documentMapper.registerEntityConverter(new WithObjectId.Converter());
         documentMapper.registerEntityConverter(new WithOutId.Converter());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
index a4e0fecf6..314d46188 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
@@ -24,7 +24,7 @@
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.common.meta.Attributes;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexType;
@@ -70,7 +70,7 @@ public class ObjectRepositoryTest {
 
     @Before
     public void setUp() {
-        EntityConverterMapper mapper = new EntityConverterMapper();
+        SimpleNitriteMapper mapper = new SimpleNitriteMapper();
         mapper.registerEntityConverter(new InternalClass.Converter());
         mapper.registerEntityConverter(new EmployeeEntity.Converter());
         mapper.registerEntityConverter(new StressRecord.Converter());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index fe1acf6df..7257352d5 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -20,7 +20,7 @@
 import lombok.Getter;
 import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.repository.data.*;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.SortOrder;
@@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) {
             }
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new Converter());
 
         TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime());
diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index 377e1c09f..b49ebde04 100644
--- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -22,7 +22,7 @@
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.index.IndexType;
 import org.dizitart.no2.index.NitriteTextIndexer;
 import org.dizitart.no2.index.fulltext.Languages;
@@ -56,7 +56,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest {
     @Override
     public void setUp() {
         openDb();
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TextData.Converter());
 
         textRepository = db.getRepository(TextData.class);
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
index 97486ddc8..c2be82757 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/NitriteTest.java
@@ -28,7 +28,7 @@
 import org.dizitart.no2.common.SortOrder;
 import org.dizitart.no2.common.concurrent.ThreadPoolManager;
 import org.dizitart.no2.common.mapper.EntityConverter;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.ValidationException;
@@ -83,10 +83,10 @@ public class NitriteTest {
     public void setUp() throws ParseException {
         db = TestUtil.createDb(fileName, "test-user", "test-password");
 
-        EntityConverterMapper entityConverterMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
-        entityConverterMapper.registerEntityConverter(new Receipt.Converter());
-        entityConverterMapper.registerEntityConverter(new CompatChild.Converter());
-        entityConverterMapper.registerEntityConverter(new EmptyClass.Converter());
+        SimpleNitriteMapper simpleNitriteMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
+        simpleNitriteMapper.registerEntityConverter(new Receipt.Converter());
+        simpleNitriteMapper.registerEntityConverter(new CompatChild.Converter());
+        simpleNitriteMapper.registerEntityConverter(new EmptyClass.Converter());
 
         simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
index c5b9fe1e2..de615b29e 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteBuilderTest.java
@@ -29,7 +29,7 @@
 import org.dizitart.no2.common.Fields;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.exceptions.InvalidOperationException;
 import org.dizitart.no2.exceptions.NitriteIOException;
 import org.dizitart.no2.exceptions.NitriteSecurityException;
@@ -175,7 +175,7 @@ public void testPopulateRepositories() {
             .fieldSeparator(".")
             .openOrCreate();
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestObject.Converter());
         documentMapper.registerEntityConverter(new TestObject2.Converter());
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
index beaf04f7e..c1dca3c58 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java
@@ -27,7 +27,7 @@
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.filters.Filter;
 import org.dizitart.no2.index.IndexOptions;
 import org.dizitart.no2.index.IndexType;
@@ -69,7 +69,7 @@ public class NitriteStressTest {
     @Before
     public void before() {
         db = createDb(fileName);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestDto.Converter());
         documentMapper.registerEntityConverter(new PerfTest.Converter());
         documentMapper.registerEntityConverter(new PerfTestIndexed.Converter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
index 4ddc6ad38..317a43ce6 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/NitriteTest.java
@@ -19,7 +19,7 @@
 
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.repository.data.ClassA;
 import org.dizitart.no2.integration.repository.data.ClassBConverter;
 import org.junit.After;
@@ -39,7 +39,7 @@ public class NitriteTest {
     @Before
     public void setUp() {
         db = createDb(fileName);
-        EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper nitriteMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter());
         nitriteMapper.registerEntityConverter(new ClassBConverter());
 
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
index 179e567e4..1d977b58d 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/event/EventTest.java
@@ -19,7 +19,7 @@
 
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.events.EventType;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.Employee;
 import org.dizitart.no2.repository.ObjectRepository;
@@ -88,7 +88,7 @@ public void setUp() {
                     .openOrCreate();
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new Employee.EmployeeConverter());
 
         employeeRepository = db.getRepository(Employee.class);
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
index 2969f330d..1ea089de0 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/migrate/MigrationTest.java
@@ -23,7 +23,7 @@
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.Constants;
 import org.dizitart.no2.common.Fields;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.exceptions.MigrationException;
 import org.dizitart.no2.index.IndexOptions;
 import org.dizitart.no2.index.IndexType;
@@ -58,7 +58,7 @@ public class MigrationTest {
     @Before
     public void setUp() {
         db = createDb(dbPath);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new OldClass.Converter());
         documentMapper.registerEntityConverter(new OldClass.Literature.Converter());
         documentMapper.registerEntityConverter(new NewClass.Converter());
@@ -127,7 +127,7 @@ public void migrate(InstructionSet instruction) {
             .addMigrations(migration)
             .openOrCreate("test-user", "test-password");
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new OldClass.Converter());
         documentMapper.registerEntityConverter(new OldClass.Literature.Converter());
         documentMapper.registerEntityConverter(new NewClass.Converter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
index 022447b28..9e40324d7 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java
@@ -19,7 +19,7 @@
 
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.NitriteBuilder;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.*;
 import org.dizitart.no2.integration.repository.decorator.ManufacturerConverter;
@@ -38,7 +38,6 @@
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.dizitart.no2.filters.Filter.ALL;
 import static org.dizitart.no2.integration.TestUtil.deleteDb;
 import static org.dizitart.no2.integration.TestUtil.getRandomTempDbFile;
 
@@ -109,7 +108,7 @@ protected void openDb() {
             db = nitriteBuilder.openOrCreate();
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new RepositoryJoinTest.Person.Converter());
         documentMapper.registerEntityConverter(new RepositoryJoinTest.Address.Converter());
         documentMapper.registerEntityConverter(new RepositoryJoinTest.PersonDetails.Converter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
index f628f8a8f..80c1dd974 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java
@@ -26,7 +26,7 @@
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.index.IndexType;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.Company;
@@ -71,7 +71,7 @@ public void setUp() {
             .fieldSeparator(":")
             .openOrCreate();
 
-        EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         mapper.registerEntityConverter(new Company.CompanyConverter());
         mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter());
         mapper.registerEntityConverter(new Note.NoteConverter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
index 41db7a05c..a2f83265e 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java
@@ -17,7 +17,7 @@
 
 package org.dizitart.no2.integration.repository;
 
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.WithNitriteId;
 import org.dizitart.no2.Nitrite;
@@ -54,7 +54,7 @@ public class NitriteIdAsIdTest {
     @Before
     public void before() {
         db = TestUtil.createDb(fileName);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter());
 
         repo = db.getRepository(WithNitriteId.class);
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
index 860a4c46f..b26977b87 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java
@@ -17,7 +17,7 @@
 
 package org.dizitart.no2.integration.repository;
 
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.integration.Retry;
 import org.dizitart.no2.integration.repository.data.*;
 import org.dizitart.no2.Nitrite;
@@ -51,7 +51,7 @@ public class ObjectRepositoryNegativeTest {
     @Before
     public void setUp() {
         db = TestUtil.createDb(dbPath);
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new WithPublicField.Converter());
         documentMapper.registerEntityConverter(new WithObjectId.Converter());
         documentMapper.registerEntityConverter(new WithOutId.Converter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
index 39d2f40a0..c68b491f1 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java
@@ -24,7 +24,7 @@
 import org.dizitart.no2.collection.NitriteCollection;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.meta.Attributes;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.common.mapper.NitriteMapper;
 import org.dizitart.no2.exceptions.ValidationException;
 import org.dizitart.no2.index.IndexType;
@@ -70,7 +70,7 @@ public class ObjectRepositoryTest {
 
     @Before
     public void setUp() {
-        EntityConverterMapper mapper = new EntityConverterMapper();
+        SimpleNitriteMapper mapper = new SimpleNitriteMapper();
         mapper.registerEntityConverter(new InternalClass.Converter());
         mapper.registerEntityConverter(new EmployeeEntity.Converter());
         mapper.registerEntityConverter(new StressRecord.Converter());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
index b8db76d68..b3437533e 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java
@@ -23,7 +23,7 @@
 import org.dizitart.no2.common.WriteResult;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.exceptions.FilterException;
 import org.dizitart.no2.exceptions.InvalidIdException;
 import org.dizitart.no2.exceptions.NotIdentifiableException;
@@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) {
             }
         }
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new Converter());
 
         TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime());
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
index d6f00b9d5..c44e6ce63 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java
@@ -22,7 +22,7 @@
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.index.IndexType;
 import org.dizitart.no2.index.NitriteTextIndexer;
 import org.dizitart.no2.index.fulltext.Languages;
@@ -55,7 +55,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest {
     @Override
     public void setUp() {
         openDb();
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TextData.Converter());
 
         textRepository = db.getRepository(TextData.class);
diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
index 4bcd6e59f..08b3c4d9f 100644
--- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
+++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/rocksdb/GithubIssues.java
@@ -22,7 +22,7 @@
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.common.mapper.EntityConverter;
 import org.dizitart.no2.common.mapper.NitriteMapper;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.repository.ObjectRepository;
 import org.junit.Test;
 
@@ -42,7 +42,7 @@ public void testIssue412() {
             .loadModule(dbModule)
             .openOrCreate();
 
-        EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper();
+        SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper();
         documentMapper.registerEntityConverter(new TestData.Converter());
 
         // Step 1
diff --git a/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
index cab29361e..2fd3324fb 100644
--- a/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
+++ b/nitrite-support/src/test/java/org/dizitart/no2/support/exchange/BaseExternalTest.java
@@ -19,7 +19,7 @@
 import org.dizitart.no2.Nitrite;
 import org.dizitart.no2.collection.Document;
 import org.dizitart.no2.collection.NitriteCollection;
-import org.dizitart.no2.common.mapper.EntityConverterMapper;
+import org.dizitart.no2.common.mapper.SimpleNitriteMapper;
 import org.dizitart.no2.mvstore.MVStoreModule;
 import org.dizitart.no2.repository.ObjectRepository;
 import org.dizitart.no2.support.Retry;
@@ -118,7 +118,7 @@ protected Nitrite createDb(String filePath) {
              .filePath(filePath)
              .build();
  
-         EntityConverterMapper documentMapper = new EntityConverterMapper();
+         SimpleNitriteMapper documentMapper = new SimpleNitriteMapper();
          documentMapper.registerEntityConverter(new Employee.EmployeeConverter());
          documentMapper.registerEntityConverter(new Company.CompanyConverter());
          documentMapper.registerEntityConverter(new Note.NoteConverter());
diff --git a/nitrite/pom.xml b/nitrite/pom.xml
index 1dd2c2640..8e45274a7 100644
--- a/nitrite/pom.xml
+++ b/nitrite/pom.xml
@@ -146,12 +146,15 @@
                     
                         org.dizitart.no2.collection.operation,
                         org.dizitart.no2.common.concurrent,
-                        org.dizitart.no2.common.crypto,
+                        org.dizitart.no2.common.event,
                     
                     
                         **/*CollectionFactory.java
                         **/*DefaultNitriteCollection.java
                         **/*SnowflakeIdGenerator.java
+                        **/*AttributesAware.java
+                        **/*PluginManager.java
+                        **/*ProcessorChain.java
                     
                 
             
diff --git a/nitrite/src/main/java/org/dizitart/no2/common/event/EventBus.java b/nitrite/src/main/java/org/dizitart/no2/common/event/EventBus.java
index e9bc7538b..1cc3e68b6 100644
--- a/nitrite/src/main/java/org/dizitart/no2/common/event/EventBus.java
+++ b/nitrite/src/main/java/org/dizitart/no2/common/event/EventBus.java
@@ -17,41 +17,15 @@
 package org.dizitart.no2.common.event;
 
 /**
- * Represents a generic publish/subscribe event bus interface.
- *
- * @param      the event information type parameter
- * @param  the event listener type parameter
  * @author Anindya Chatterjee
  * @since 1.0
  */
 public interface EventBus extends AutoCloseable {
-    /**
-     * Registers an event listener to the event-bus.
-     *
-     * @param listener the event listener
-     */
     void register(EventListener listener);
 
-    /**
-     * De-registers an already registered event listener.
-     *
-     * @param listener the event listener
-     */
     void deregister(EventListener listener);
 
-    /**
-     * Posts an event to the event bus. All registered
-     * event listeners for this event will receive the `eventInfo`
-     * for further processing.
-     * 

- * Event processing is asynchronous. - * - * @param eventInfo the event related information - */ void post(EventInfo eventInfo); - /** - * Closes this {@link EventBus} instance. - * */ void close(); } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java b/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java index d5b0c3ecd..eb463bbed 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java @@ -23,10 +23,6 @@ import java.util.concurrent.ExecutorService; /** - * An abstract implementation of {@link EventBus}. - * - * @param the event information type parameter - * @param the event listener type parameter * @author Anindya Chatterjee. * @since 1.0 */ @@ -36,9 +32,6 @@ public abstract class NitriteEventBus private final Set listeners; private ExecutorService eventExecutor; - /** - * Instantiates a new Nitrite event bus. - */ public NitriteEventBus() { this.listeners = new CopyOnWriteArraySet<>(); } @@ -65,11 +58,6 @@ public void close() { } } - /** - * Gets the {@link ExecutorService} that executes listeners' code. - * - * @return the {@link ExecutorService}. - */ protected ExecutorService getEventExecutor() { if (eventExecutor == null || eventExecutor.isShutdown() @@ -79,11 +67,6 @@ protected ExecutorService getEventExecutor() { return eventExecutor; } - /** - * Gets a set of all event listeners. - * - * @return the event listeners - */ protected Set getListeners() { return listeners; } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverter.java b/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverter.java index f140cede0..e382f5cf9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverter.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverter.java @@ -20,8 +20,9 @@ import org.dizitart.no2.collection.Document; /** - * A class that implements this interface can be used to convert - * entity into a database {@link Document} and back again. + * The {@link EntityConverter} interface is used to convert + * an entity of type {@link T} into a database {@link Document} + * and vice versa. * * @since 4.0 * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/common/mapper/NitriteMapper.java b/nitrite/src/main/java/org/dizitart/no2/common/mapper/NitriteMapper.java index 7bd083966..5d32f7e26 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/mapper/NitriteMapper.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/mapper/NitriteMapper.java @@ -19,10 +19,10 @@ import org.dizitart.no2.common.module.NitritePlugin; /** - * Represents a mapper which will convert an object of one type to an object of another type. + * An interface that provides a method to try converting an object of one type to an object of another type. * * @author Anindya Chatterjee. - * @since 4.0 + * @since 1.0 */ public interface NitriteMapper extends NitritePlugin { /** diff --git a/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java b/nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleNitriteMapper.java similarity index 95% rename from nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java rename to nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleNitriteMapper.java index e2e3591d3..df218cfad 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/mapper/EntityConverterMapper.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/mapper/SimpleNitriteMapper.java @@ -32,21 +32,21 @@ * *

* This mapper is used by default in nitrite. It uses {@link EntityConverter} to - * convert an object of type Source to an object of type Target. + * convert an object and vice versa. * * @author Anindya Chatterjee. * @since 4.0 */ -public class EntityConverterMapper implements NitriteMapper { +public class SimpleNitriteMapper implements NitriteMapper { private final Set> valueTypes; private final Map, EntityConverter> converterRegistry; /** - * Instantiates a new {@link EntityConverterMapper}. + * Instantiates a new {@link SimpleNitriteMapper}. * * @param valueTypes the value types */ - public EntityConverterMapper(Class... valueTypes) { + public SimpleNitriteMapper(Class... valueTypes) { this.valueTypes = new HashSet<>(); this.converterRegistry = new HashMap<>(); init(listOf(valueTypes)); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/meta/Attributes.java b/nitrite/src/main/java/org/dizitart/no2/common/meta/Attributes.java index d338be0c3..ee4a32f27 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/meta/Attributes.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/meta/Attributes.java @@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Represents metadata attributes of a collection. + * Represents metadata attributes of a {@link NitriteMap}. * * @author Anindya Chatterjee * @since 1.0 @@ -125,12 +125,16 @@ public Attributes(String collection) { set(UNIQUE_ID, UUID.randomUUID().toString()); } + /** - * Set attributes. - * - * @param key the key - * @param value the value - * @return the attributes + * Adds a key-value pair to the attributes and returns the updated + * {@link Attributes} object. + * + * @param key The key is a string that represents the attribute name. It is used to identify the + * attribute in the attributes. + * @param value The value parameter is a string that represents the value to be associated with the + * given key in the attributes. + * @return The method is returning an instance of the Attributes class. */ public Attributes set(String key, String value) { attributes.put(LAST_MODIFIED_TIME, Long.toString(System.currentTimeMillis())); @@ -139,10 +143,11 @@ public Attributes set(String key, String value) { } /** - * Get string value of an attribute. - * - * @param key the key - * @return the string + * Retrieves the value associated with a given key from a {@link Attributes}. + * + * @param key The "key" parameter is a String that represents the key of the attribute that you + * want to retrieve from the attributes. + * @return The method is returning the value associated with the given key in the attributes. */ public String get(String key) { return attributes.get(key); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/meta/AttributesAware.java b/nitrite/src/main/java/org/dizitart/no2/common/meta/AttributesAware.java index 8ae092dd4..4a791bac9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/meta/AttributesAware.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/meta/AttributesAware.java @@ -18,24 +18,11 @@ package org.dizitart.no2.common.meta; /** - * Interface to be implemented by database objects that wish to be - * aware of their metadata attributes. - * * @author Anindya Chatterjee. * @since 1.0 */ public interface AttributesAware { - /** - * Returns the metadata attributes of an object. - * - * @return the meta data attributes. - */ Attributes getAttributes(); - /** - * Sets new meta data attributes. - * - * @param attributes new meta data attributes. - */ void setAttributes(Attributes attributes); } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/NitriteModule.java b/nitrite/src/main/java/org/dizitart/no2/common/module/NitriteModule.java index 4404d5ac7..ec2c2d12a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/NitriteModule.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/NitriteModule.java @@ -21,15 +21,14 @@ import static org.dizitart.no2.common.util.Iterables.setOf; /** - * Represents a nitrite plugin modules which may contains - * one or more nitrite plugins. + * Represents a module encapsulating a set of {@link NitritePlugin} objects. * * @author Anindya Chatterjee * @since 4.0 */ public interface NitriteModule { /** - * Creates a {@link NitriteModule} from a set of {@link NitritePlugin}s. + * Creates a {@link NitriteModule} with a set of {@link NitritePlugin}s. * * @param plugins the plugins * @return the nitrite module diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java b/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java index 806de1337..bc581d3ad 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/NitritePlugin.java @@ -19,7 +19,8 @@ import org.dizitart.no2.NitriteConfig; /** - * Represents a nitrite database plugin component. + * Represents a plugin for working with Nitrite + * database and provides methods for initializing and closing the plugin. * * @author Anindya Chatterjee. * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java index 12d0da6aa..2d92d6c98 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java @@ -22,7 +22,7 @@ import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.PluginException; import org.dizitart.no2.index.*; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.store.NitriteStore; import org.dizitart.no2.store.memory.InMemoryStoreModule; @@ -31,11 +31,6 @@ import java.util.Map; /** - * The nitrite database plugin manager. It loads the nitrite plugins - * before opening the database. - * - * @see NitriteModule - * @see NitritePlugin * @author Anindya Chatterjee. * @since 4.0 */ @@ -188,7 +183,7 @@ protected void loadInternalPlugins() { if (nitriteMapper == null) { log.debug("Loading mappable mapper"); - NitritePlugin plugin = new EntityConverterMapper(); + NitritePlugin plugin = new SimpleNitriteMapper(); loadPlugin(plugin); } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/processors/Processor.java b/nitrite/src/main/java/org/dizitart/no2/common/processors/Processor.java index 7c266efe8..ed6f9e381 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/processors/Processor.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/processors/Processor.java @@ -26,7 +26,8 @@ import static org.dizitart.no2.common.util.DocumentUtils.createUniqueFilter; /** - * Represents a document processor. + * An interface that provides methods to process a document before + * writing it into database or after reading from the database. * * @author Anindya Chatterjee * @since 4.0 @@ -50,9 +51,11 @@ public interface Processor { default Document processAfterRead(Document document) { return document; } /** - * Processes all documents of a {@link PersistentCollection}. - * - * @param collection the collection to process + * Processes documents in a persistent collection, updates them,and saves the changes + * back to the collection. + * + * @param collection the collection to process. It can either be a + * {@link NitriteCollection} or an {@link ObjectRepository}. */ default void process(PersistentCollection collection) { NitriteCollection nitriteCollection = null; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java b/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java index 2ed6b0ad5..ec8294d3f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/processors/ProcessorChain.java @@ -23,36 +23,20 @@ import java.util.List; /** - * Represents a {@link Processor} chain. The processors are executed in the order - * they are added to the chain. - * * @author Anindya Chatterjee * @since 4.0 */ public class ProcessorChain implements Processor { private final List processors; - /** - * Instantiates a new Processor chain. - */ public ProcessorChain() { processors = new ArrayList<>(); } - /** - * Adds a processor to the chain. - * - * @param processor the processor - */ public void add(Processor processor) { processors.add(processor); } - /** - * Removes a processor from the chain. - * - * @param processor the processor - */ public void remove(Processor processor) { processors.remove(processor); } diff --git a/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java b/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java index 62bacd76e..8092d9888 100644 --- a/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/NitriteBuilderTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.common.FieldValues; import org.dizitart.no2.common.Fields; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.module.NitriteModule; import org.dizitart.no2.common.module.NitritePlugin; import org.dizitart.no2.common.module.PluginManager; @@ -139,7 +139,7 @@ public void testOpenOrCreate() { assertFalse(actualOpenOrCreateResult.isClosed()); assertFalse(store.isClosed()); assertSame(store, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); } @Test @@ -153,7 +153,7 @@ public void testOpenOrCreate2() { assertFalse(store.isClosed()); PluginManager pluginManager = config.getPluginManager(); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); assertTrue(store.getCatalog().getKeyedRepositoryNames().isEmpty()); assertSame(store, pluginManager.getNitriteStore()); assertTrue(((InMemoryConfig) store.getStoreConfig()).eventListeners().isEmpty()); @@ -170,7 +170,7 @@ public void testOpenOrCreate3() { assertFalse(store.isClosed()); PluginManager pluginManager = config.getPluginManager(); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); assertTrue(store.getCatalog().getKeyedRepositoryNames().isEmpty()); assertSame(store, pluginManager.getNitriteStore()); assertTrue(((InMemoryConfig) store.getStoreConfig()).eventListeners().isEmpty()); @@ -185,7 +185,7 @@ public void testOpenOrCreate4() { assertEquals(3, pluginManager.getIndexerMap().size()); NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); assertFalse(nitriteStore.isClosed()); assertTrue(((InMemoryConfig) nitriteStore.getStoreConfig()).eventListeners().isEmpty()); } @@ -199,7 +199,7 @@ public void testOpenOrCreate5() { NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertFalse(nitriteStore.isClosed()); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); } @Test diff --git a/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java b/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java index dfbced302..639b43cf2 100644 --- a/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/NitriteConfigTest.java @@ -17,7 +17,7 @@ package org.dizitart.no2; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.module.NitriteModule; import org.dizitart.no2.common.module.NitritePlugin; import org.dizitart.no2.common.module.PluginManager; @@ -115,7 +115,7 @@ public void testAutoConfigure() { assertEquals(3, pluginManager.getIndexerMap().size()); NitriteStore nitriteStore = nitriteConfig.getNitriteStore(); assertSame(nitriteStore, pluginManager.getNitriteStore()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); assertFalse(nitriteStore.isClosed()); assertTrue(((InMemoryConfig) nitriteStore.getStoreConfig()).eventListeners().isEmpty()); } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java index 6f5c0174b..01d8d94b6 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/event/EventTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; import org.dizitart.no2.collection.UpdateOptions; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.collection.events.EventType; import org.dizitart.no2.repository.ObjectRepository; @@ -76,7 +76,7 @@ public void setUp() { db = nitriteBuilder.openOrCreate(); } - EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Employee.EmployeeConverter()); employeeRepository = db.getRepository(Employee.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java deleted file mode 100644 index 100ee29dc..000000000 --- a/nitrite/src/test/java/org/dizitart/no2/common/mapper/EntityConverterMapperTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.dizitart.no2.common.mapper; - -import org.dizitart.no2.integration.NitriteStressTest; -import org.dizitart.no2.integration.NitriteTest; -import org.dizitart.no2.collection.Document; -import org.dizitart.no2.exceptions.ObjectMappingException; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class EntityConverterMapperTest { - @Test - public void testConvert() { - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(Integer.class); - assertEquals(0, ((Integer) entityConverterMapper.tryConvert(0, Object.class)).intValue()); - } - - @Test - public void testConvert2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - assertEquals("source", entityConverterMapper.tryConvert("source", Object.class)); - } - - @Test - public void testConvert3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - assertEquals(0, ((Integer) entityConverterMapper.tryConvert(0, Object.class)).intValue()); - } - - @Test - public void testConvertFromDocument() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - assertNull(entityConverterMapper.convertFromDocument(null, Object.class)); - } - - @Test - public void testConvertFromDocument2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - Class type = Object.class; - assertThrows(ObjectMappingException.class, - () -> entityConverterMapper.convertFromDocument(Document.createDocument(), type)); - } - - @Test - public void testConvertFromDocument3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - assertNull( - (new EntityConverterMapper(forNameResult, forNameResult1, Object.class)).convertFromDocument(null, null)); - } - - @Test - public void testConvertToDocument() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - assertThrows(ObjectMappingException.class, - () -> (new EntityConverterMapper(forNameResult, forNameResult1, Object.class)).convertToDocument("source")); - } - - @Test - public void testConvertToDocument2() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - entityConverterMapper.registerEntityConverter(new NitriteTest.CompatChild.CompatChildConverter()); - assertEquals(2, entityConverterMapper.convertToDocument(new NitriteTest.CompatChild()).size()); - } - - @Test - public void testConvertToDocument3() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - entityConverterMapper.registerEntityConverter(new NitriteStressTest.TestDto.Converter()); - assertEquals(7, entityConverterMapper.convertToDocument(new NitriteStressTest.TestDto()).size()); - } - - @Test - public void testConvertToDocument4() { - Class forNameResult = Object.class; - Class forNameResult1 = Object.class; - EntityConverterMapper entityConverterMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); - entityConverterMapper.registerEntityConverter(new Company.CompanyConverter()); - assertEquals(3, entityConverterMapper.convertToDocument(new Company()).size()); - } - -} - diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java index 130f20b7e..f9a970d17 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/mapper/MapperTest.java @@ -31,15 +31,15 @@ * @author Anindya Chatterjee */ public class MapperTest { - private EntityConverterMapper entityConverterMapper; + private SimpleNitriteMapper simpleNitriteMapper; @Rule public Retry retry = new Retry(3); @Test public void testWithConverter() { - entityConverterMapper = new EntityConverterMapper(); - entityConverterMapper.registerEntityConverter(new Employee.Converter()); + simpleNitriteMapper = new SimpleNitriteMapper(); + simpleNitriteMapper.registerEntityConverter(new Employee.Converter()); Employee boss = new Employee(); boss.setEmpId("1"); @@ -52,17 +52,17 @@ public void testWithConverter() { emp1.setJoiningDate(new Date()); emp1.setBoss(boss); - Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class); - Employee employee = (Employee) entityConverterMapper.tryConvert(document, Employee.class); + Document document = (Document) simpleNitriteMapper.tryConvert(emp1, Document.class); + Employee employee = (Employee) simpleNitriteMapper.tryConvert(document, Employee.class); assertEquals(emp1, employee); } @Test public void testWithMappable() { - entityConverterMapper = new EntityConverterMapper(); - entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); - entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); + simpleNitriteMapper = new SimpleNitriteMapper(); + simpleNitriteMapper.registerEntityConverter(new Department.DepartmentConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableDepartment.Converter()); MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -75,18 +75,18 @@ public void testWithMappable() { emp1.setJoiningDate(new Date()); emp1.setBoss(boss); - Document document = (Document) entityConverterMapper.tryConvert(emp1, Document.class); + Document document = (Document) simpleNitriteMapper.tryConvert(emp1, Document.class); - MappableEmployee employee = (MappableEmployee) entityConverterMapper.tryConvert(document, MappableEmployee.class); + MappableEmployee employee = (MappableEmployee) simpleNitriteMapper.tryConvert(document, MappableEmployee.class); assertEquals(emp1, employee); } @Test public void testWithConverterAndMappableMix() { - entityConverterMapper = new EntityConverterMapper(); - entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); - entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); + simpleNitriteMapper = new SimpleNitriteMapper(); + simpleNitriteMapper.registerEntityConverter(new Department.DepartmentConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableDepartment.Converter()); final MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -106,18 +106,18 @@ public void testWithConverterAndMappableMix() { add(emp1); }}); - Document document = (Document) entityConverterMapper.tryConvert(department, Document.class); + Document document = (Document) simpleNitriteMapper.tryConvert(department, Document.class); - Department dept = (Department) entityConverterMapper.tryConvert(document, Department.class); + Department dept = (Department) simpleNitriteMapper.tryConvert(document, Department.class); assertEquals(department, dept); } @Test public void testNested() { - entityConverterMapper = new EntityConverterMapper(); - entityConverterMapper.registerEntityConverter(new Department.DepartmentConverter()); - entityConverterMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); - entityConverterMapper.registerEntityConverter(new MappableDepartment.Converter()); + simpleNitriteMapper = new SimpleNitriteMapper(); + simpleNitriteMapper.registerEntityConverter(new Department.DepartmentConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableEmployee.MappableEmployeeConverter()); + simpleNitriteMapper.registerEntityConverter(new MappableDepartment.Converter()); final MappableEmployee boss = new MappableEmployee(); boss.setEmpId("1"); @@ -137,24 +137,24 @@ public void testNested() { add(emp1); }}); - Document document = (Document) entityConverterMapper.tryConvert(department, Document.class); + Document document = (Document) simpleNitriteMapper.tryConvert(department, Document.class); - MappableDepartment dept = (MappableDepartment) entityConverterMapper.tryConvert(document, MappableDepartment.class); + MappableDepartment dept = (MappableDepartment) simpleNitriteMapper.tryConvert(document, MappableDepartment.class); assertEquals(department, dept); } @Test public void testWithValueType() { - entityConverterMapper = new EntityConverterMapper(); - entityConverterMapper.registerEntityConverter(new Company.CompanyConverter()); - entityConverterMapper.registerEntityConverter(new Company.CompanyId.CompanyIdConverter()); + simpleNitriteMapper = new SimpleNitriteMapper(); + simpleNitriteMapper.registerEntityConverter(new Company.CompanyConverter()); + simpleNitriteMapper.registerEntityConverter(new Company.CompanyId.CompanyIdConverter()); Company company = new Company(); company.setName("test"); company.setId(1L); company.setCompanyId(new Company.CompanyId(1L)); - Document document = (Document) entityConverterMapper.tryConvert(company, Document.class); + Document document = (Document) simpleNitriteMapper.tryConvert(company, Document.class); Object companyId = document.get("companyId"); assertTrue(companyId instanceof Document); } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleNitriteMapperTest.java b/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleNitriteMapperTest.java new file mode 100644 index 000000000..25a0a2c9a --- /dev/null +++ b/nitrite/src/test/java/org/dizitart/no2/common/mapper/SimpleNitriteMapperTest.java @@ -0,0 +1,96 @@ +package org.dizitart.no2.common.mapper; + +import org.dizitart.no2.integration.NitriteStressTest; +import org.dizitart.no2.integration.NitriteTest; +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.exceptions.ObjectMappingException; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SimpleNitriteMapperTest { + @Test + public void testConvert() { + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(Integer.class); + assertEquals(0, ((Integer) simpleNitriteMapper.tryConvert(0, Object.class)).intValue()); + } + + @Test + public void testConvert2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + assertEquals("source", simpleNitriteMapper.tryConvert("source", Object.class)); + } + + @Test + public void testConvert3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + assertEquals(0, ((Integer) simpleNitriteMapper.tryConvert(0, Object.class)).intValue()); + } + + @Test + public void testConvertFromDocument() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + assertNull(simpleNitriteMapper.convertFromDocument(null, Object.class)); + } + + @Test + public void testConvertFromDocument2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + Class type = Object.class; + assertThrows(ObjectMappingException.class, + () -> simpleNitriteMapper.convertFromDocument(Document.createDocument(), type)); + } + + @Test + public void testConvertFromDocument3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + assertNull( + (new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class)).convertFromDocument(null, null)); + } + + @Test + public void testConvertToDocument() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + assertThrows(ObjectMappingException.class, + () -> (new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class)).convertToDocument("source")); + } + + @Test + public void testConvertToDocument2() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + simpleNitriteMapper.registerEntityConverter(new NitriteTest.CompatChild.CompatChildConverter()); + assertEquals(2, simpleNitriteMapper.convertToDocument(new NitriteTest.CompatChild()).size()); + } + + @Test + public void testConvertToDocument3() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + simpleNitriteMapper.registerEntityConverter(new NitriteStressTest.TestDto.Converter()); + assertEquals(7, simpleNitriteMapper.convertToDocument(new NitriteStressTest.TestDto()).size()); + } + + @Test + public void testConvertToDocument4() { + Class forNameResult = Object.class; + Class forNameResult1 = Object.class; + SimpleNitriteMapper simpleNitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); + simpleNitriteMapper.registerEntityConverter(new Company.CompanyConverter()); + assertEquals(3, simpleNitriteMapper.convertToDocument(new Company()).size()); + } + +} + diff --git a/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java b/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java index 19ef3c7f2..247f93653 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/module/PluginManagerTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.common.module; import org.dizitart.no2.NitriteConfig; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.PluginException; import org.dizitart.no2.store.NitriteStore; import org.junit.Test; @@ -63,7 +63,7 @@ public void testFindAndLoadPlugins() { NitriteStore nitriteStore = pluginManager.getNitriteStore(); assertTrue(nitriteStore instanceof org.dizitart.no2.store.memory.InMemoryStore); assertEquals(3, pluginManager.getIndexerMap().size()); - assertTrue(pluginManager.getNitriteMapper() instanceof EntityConverterMapper); + assertTrue(pluginManager.getNitriteMapper() instanceof SimpleNitriteMapper); assertFalse(nitriteStore.isClosed()); } } diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java index 808c26a76..f2795d872 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/DocumentUtilsTest.java @@ -20,7 +20,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.filters.ComparableFilter; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.integration.Retry; @@ -83,13 +83,13 @@ public void testSkeletonDocument() { public void testSkeletonDocument2() { Class forNameResult = Object.class; Class forNameResult1 = Object.class; - EntityConverterMapper nitriteMapper = new EntityConverterMapper(forNameResult, forNameResult1, Object.class); + SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper(forNameResult, forNameResult1, Object.class); assertEquals(0, DocumentUtils.skeletonDocument(nitriteMapper, Object.class).size()); } @Test public void testSkeletonDocument3() { - EntityConverterMapper nitriteMapper = new EntityConverterMapper(); + SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper(); Document document = DocumentUtils.skeletonDocument(nitriteMapper, Integer.class); assertNull(document); } @@ -110,7 +110,7 @@ public void testIsSimilar2() { @Test public void testDummyDocument() { - EntityConverterMapper nitriteMapper = new EntityConverterMapper(); + SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper(); nitriteMapper.registerEntityConverter(new DummyTest.Converter()); Document document = skeletonDocument(nitriteMapper, DummyTest.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java index 5481d03af..ae4741c61 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/ObjectUtilsTest.java @@ -25,7 +25,7 @@ import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.ObjectMappingException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.integration.NitriteTest; @@ -125,7 +125,7 @@ public void testDeepEquals8() { @Test public void testNewInstance() { - EntityConverterMapper mapper = new EntityConverterMapper(); + SimpleNitriteMapper mapper = new SimpleNitriteMapper(); mapper.registerEntityConverter(new EnclosingType.Converter()); mapper.registerEntityConverter(new ChildClass.Converter()); mapper.registerEntityConverter(new FieldType.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java b/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java index 0c577f25b..5a8e0b17d 100644 --- a/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/common/util/ValidationUtilsTest.java @@ -16,7 +16,7 @@ package org.dizitart.no2.common.util; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.ClassA; @@ -79,7 +79,7 @@ public void testCharSequenceNotEmpty() { @Test public void testValidateProjectionType() { - EntityConverterMapper documentMapper = new EntityConverterMapper(); + SimpleNitriteMapper documentMapper = new SimpleNitriteMapper(); documentMapper.registerEntityConverter(new ClassA.ClassAConverter()); documentMapper.registerEntityConverter(new ClassBConverter()); documentMapper.registerEntityConverter(new EmptyClass.Converter()); @@ -96,7 +96,7 @@ public void testValidateProjectionType() { @Test public void testValidateRepositoryType() { - EntityConverterMapper documentMapper = new EntityConverterMapper(); + SimpleNitriteMapper documentMapper = new SimpleNitriteMapper(); documentMapper.registerEntityConverter(new ClassA.ClassAConverter()); documentMapper.registerEntityConverter(new ClassBConverter()); documentMapper.registerEntityConverter(new EmptyClass.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java index 4ef9dfd08..ced53550f 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java @@ -25,7 +25,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.repository.ObjectRepository; @@ -55,7 +55,7 @@ public class NitriteStressTest { @Test public void stressTest() { Nitrite database = createDb(); - EntityConverterMapper documentMapper = (EntityConverterMapper) database.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) database.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TestDto.Converter()); ObjectRepository testRepository = database.getRepository(TestDto.class); testRepository.createIndex(IndexOptions.indexOptions(IndexType.FULL_TEXT), "lastName"); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java index c9e4eca01..938e65a12 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -29,7 +29,7 @@ import org.dizitart.no2.common.SortOrder; import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.common.mapper.EntityConverter; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; @@ -77,7 +77,7 @@ public class NitriteTest { @Before public void setUp() throws ParseException { db = createDb("test-user", "test-password"); - EntityConverterMapper nitriteMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper nitriteMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); nitriteMapper.registerEntityConverter(new Receipt.ReceiptConverter()); nitriteMapper.registerEntityConverter(new CompatChild.CompatChildConverter()); nitriteMapper.registerEntityConverter(new EmptyClass.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java index f9274e4fb..f7817a1cb 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/StressTest.java @@ -24,7 +24,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.filters.Filter; import org.dizitart.no2.index.IndexOptions; import org.dizitart.no2.index.IndexType; @@ -62,7 +62,7 @@ public void before() { .fieldSeparator(".") .openOrCreate(); - EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new PerfTest.PerfTestConverter()); mapper.registerEntityConverter(new PerfTestIndexed.PerfTestIndexedConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java index 999b864d9..ede5f58d8 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/BaseObjectRepositoryTest.java @@ -19,7 +19,7 @@ import org.dizitart.no2.Nitrite; import org.dizitart.no2.NitriteBuilder; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.*; import org.dizitart.no2.integration.repository.decorator.*; @@ -107,7 +107,7 @@ private void openDb() { db = nitriteBuilder.openOrCreate(); } - EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new Employee.EmployeeConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java index 3b7cd0933..a562a1506 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/CustomFieldSeparatorTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.repository.data.Company; @@ -62,7 +62,7 @@ public void setUp() { .fieldSeparator(":") .openOrCreate(); - EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new Company.CompanyConverter()); mapper.registerEntityConverter(new EmployeeForCustomSeparator.EmployeeForCustomSeparatorConverter()); mapper.registerEntityConverter(new Note.NoteConverter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java index 2130d4ca4..35713996f 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/NitriteIdAsIdTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.repository; import org.dizitart.no2.Nitrite; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.TestUtil; import org.dizitart.no2.collection.NitriteId; @@ -49,7 +49,7 @@ public class NitriteIdAsIdTest { @Before public void before() { db = TestUtil.createDb(); - EntityConverterMapper mapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper mapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); mapper.registerEntityConverter(new WithNitriteId.WithNitriteIdConverter()); repo = db.getRepository(WithNitriteId.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java index 562b1b479..b94fd6304 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryNegativeTest.java @@ -18,7 +18,7 @@ package org.dizitart.no2.integration.repository; import org.dizitart.no2.Nitrite; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.integration.TestUtil; import org.dizitart.no2.collection.NitriteId; @@ -46,7 +46,7 @@ public class ObjectRepositoryNegativeTest { @Before public void setUp() { db = TestUtil.createDb(); - EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new WithPublicField.Converter()); documentMapper.registerEntityConverter(new WithObjectId.Converter()); documentMapper.registerEntityConverter(new WithOutId.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java index 6f691f01c..ef2007bdd 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/ObjectRepositoryTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.exceptions.UniqueConstraintException; import org.dizitart.no2.exceptions.ValidationException; @@ -65,7 +65,7 @@ public class ObjectRepositoryTest { @Before public void setUp() { - EntityConverterMapper mapper = new EntityConverterMapper(); + SimpleNitriteMapper mapper = new SimpleNitriteMapper(); mapper.registerEntityConverter(new InternalClass.Converter()); mapper.registerEntityConverter(new EmployeeEntity.Converter()); mapper.registerEntityConverter(new StressRecord.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java index d2fdfb633..38f626f95 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositoryJoinTest.java @@ -26,7 +26,7 @@ import org.dizitart.no2.common.RecordStream; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.InvalidOperationException; import org.dizitart.no2.integration.Retry; import org.dizitart.no2.repository.ObjectRepository; @@ -105,7 +105,7 @@ private void openDb() { db = nitriteBuilder.openOrCreate(); } - EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Person.Converter()); documentMapper.registerEntityConverter(new Address.Converter()); documentMapper.registerEntityConverter(new PersonDetails.Converter()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java index 733bb03ec..5561c5b35 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/RepositorySearchTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.common.WriteResult; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.exceptions.InvalidIdException; import org.dizitart.no2.exceptions.NotIdentifiableException; @@ -592,7 +592,7 @@ public TestData fromDocument(Document document, NitriteMapper nitriteMapper) { } } - EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new Converter()); TestData data1 = new TestData(new GregorianCalendar(2020, Calendar.JANUARY, 11).getTime()); diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java index 99f77c8ac..b05a998ea 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/repository/UniversalTextTokenizerTest.java @@ -22,7 +22,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.common.mapper.NitriteMapper; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.index.NitriteTextIndexer; import org.dizitart.no2.index.fulltext.Languages; @@ -51,7 +51,7 @@ public class UniversalTextTokenizerTest extends BaseObjectRepositoryTest { @Override public void setUp() { openDb(); - EntityConverterMapper documentMapper = (EntityConverterMapper) db.getConfig().nitriteMapper(); + SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); documentMapper.registerEntityConverter(new TextData.Converter()); textRepository = db.getRepository(TextData.class); diff --git a/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java b/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java index 31a011297..616e58e29 100644 --- a/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/repository/EntityDecoratorScannerTest.java @@ -20,7 +20,7 @@ import lombok.Data; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.NitriteCollection; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.repository.data.ClassA; import org.dizitart.no2.integration.repository.data.ClassBConverter; @@ -40,7 +40,7 @@ public class EntityDecoratorScannerTest { @Before public void setUp() { - EntityConverterMapper nitriteMapper = new EntityConverterMapper(); + SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper(); nitriteMapper.registerEntityConverter(new ClassA.ClassAConverter()); nitriteMapper.registerEntityConverter(new ClassBConverter()); collection = Nitrite.builder().fieldSeparator(".").openOrCreate().getCollection("test"); diff --git a/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java b/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java index 439ac920d..64d0370c8 100644 --- a/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/repository/ObjectCursorTest.java @@ -23,7 +23,7 @@ import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.Lookup; import org.dizitart.no2.common.RecordStream; -import org.dizitart.no2.common.mapper.EntityConverterMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.processors.ProcessorChain; import org.dizitart.no2.common.streams.DocumentStream; import org.dizitart.no2.common.streams.MutatedObjectStream; @@ -81,7 +81,7 @@ public void testProject() { @Test public void testProject3() { - EntityConverterMapper nitriteMapper = new EntityConverterMapper(); + SimpleNitriteMapper nitriteMapper = new SimpleNitriteMapper(); RecordStream> recordStream = (RecordStream>) mock( RecordStream.class); DocumentStream cursor = new DocumentStream(recordStream, new ProcessorChain()); diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt index 44e25b26b..86e0199be 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt @@ -26,7 +26,7 @@ import org.dizitart.no2.exceptions.ObjectMappingException import java.util.Date /** - * org.dizitart.no2.common.mapper.NitriteMapper implementation using using kotlinx.serialization + * org.dizitart.no2.common.mapper.NitriteMapper implementation using kotlinx.serialization * * @author Joris Jensen * @since 4.2.0 From 9f9de220601e2a923a907ac98e533c5f86d0f966 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Tue, 29 Aug 2023 12:34:44 +0530 Subject: [PATCH 15/18] documentation --- nitrite/pom.xml | 11 ++ .../java/org/dizitart/no2/common/DBNull.java | 2 - .../java/org/dizitart/no2/common/DBValue.java | 1 + .../org/dizitart/no2/common/FieldValues.java | 22 ++-- .../java/org/dizitart/no2/common/Fields.java | 16 +-- .../no2/common/PersistentCollection.java | 10 +- .../org/dizitart/no2/common/RecordStream.java | 6 +- .../org/dizitart/no2/common/SortOrder.java | 6 +- .../dizitart/no2/common/SortableFields.java | 6 +- .../org/dizitart/no2/common/UnknownType.java | 2 - .../org/dizitart/no2/common/WriteResult.java | 9 +- .../no2/common/streams/BoundedStream.java | 16 --- .../no2/common/streams/ConcatStream.java | 15 --- .../no2/common/streams/DistinctStream.java | 12 -- .../no2/common/streams/DocumentSorter.java | 12 -- .../no2/common/streams/DocumentStream.java | 14 --- .../no2/common/streams/FilteredStream.java | 17 --- .../no2/common/streams/IndexedStream.java | 17 --- .../common/streams/JoinedDocumentStream.java | 10 -- .../common/streams/MutatedObjectStream.java | 1 + .../streams/ProjectedDocumentStream.java | 15 --- .../common/streams/SortedDocumentStream.java | 2 - .../org/dizitart/no2/common/tuples/Pair.java | 7 +- .../dizitart/no2/common/tuples/Quartet.java | 10 +- .../dizitart/no2/common/tuples/Quintet.java | 13 +- .../dizitart/no2/common/tuples/Triplet.java | 9 +- .../dizitart/no2/common/util/Comparables.java | 7 -- .../dizitart/no2/common/util/CryptoUtils.java | 17 --- .../no2/common/util/DocumentUtils.java | 23 ---- .../dizitart/no2/common/util/IndexUtils.java | 14 --- .../dizitart/no2/common/util/Iterables.java | 32 ----- .../org/dizitart/no2/common/util/Numbers.java | 11 -- .../dizitart/no2/common/util/ObjectUtils.java | 21 ---- .../no2/common/util/SecureString.java | 26 ---- .../dizitart/no2/common/util/StringUtils.java | 24 ---- .../no2/common/util/ValidationUtils.java | 33 ----- .../no2/exceptions/FilterException.java | 2 +- .../no2/exceptions/IndexingException.java | 2 +- .../no2/exceptions/InvalidIdException.java | 4 +- .../exceptions/InvalidOperationException.java | 3 +- .../no2/exceptions/MigrationException.java | 2 +- .../no2/exceptions/NitriteException.java | 2 +- .../no2/exceptions/NitriteIOException.java | 3 +- .../exceptions/NitriteSecurityException.java | 2 +- .../exceptions/NotIdentifiableException.java | 2 +- .../exceptions/ObjectMappingException.java | 4 +- .../no2/exceptions/PluginException.java | 2 +- .../no2/exceptions/SyncException.java | 45 ------- .../no2/exceptions/TransactionException.java | 2 +- .../exceptions/UniqueConstraintException.java | 3 +- .../no2/exceptions/ValidationException.java | 2 +- .../org/dizitart/no2/filters/AndFilter.java | 7 -- .../dizitart/no2/filters/BetweenFilter.java | 1 + .../no2/filters/ComparableArrayFilter.java | 8 +- .../no2/filters/ElementMatchFilter.java | 1 + .../java/org/dizitart/no2/filters/Filter.java | 38 +++--- .../dizitart/no2/filters/FluentFilter.java | 114 ++++++++---------- 57 files changed, 166 insertions(+), 552 deletions(-) delete mode 100644 nitrite/src/main/java/org/dizitart/no2/exceptions/SyncException.java diff --git a/nitrite/pom.xml b/nitrite/pom.xml index 8e45274a7..078bf0e52 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -147,6 +147,8 @@ org.dizitart.no2.collection.operation, org.dizitart.no2.common.concurrent, org.dizitart.no2.common.event, + org.dizitart.no2.common.streams, + org.dizitart.no2.common.util, **/*CollectionFactory.java @@ -155,6 +157,15 @@ **/*AttributesAware.java **/*PluginManager.java **/*ProcessorChain.java + **/*Constants.java + **/*DBNull.java + **/*DBValue.java + **/*UnknownType.java + **/*AndFilter.java + **/*BetweenFilter.java + **/*ComparableArrayFilter.java + **/*ElementMatchFilter.java + **/*EqualsFilter.java diff --git a/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java b/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java index 93d6c143a..cbffce864 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java @@ -3,8 +3,6 @@ import java.io.Serializable; /** - * This class acts as a surrogate for null key. - * * @author Anindya Chatterjee * @since 1.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/DBValue.java b/nitrite/src/main/java/org/dizitart/no2/common/DBValue.java index a1f67cd87..6ee3c5014 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/DBValue.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/DBValue.java @@ -29,6 +29,7 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ @Data public class DBValue implements Comparable, Serializable { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/FieldValues.java b/nitrite/src/main/java/org/dizitart/no2/common/FieldValues.java index 56c300f98..32e020191 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/FieldValues.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/FieldValues.java @@ -9,8 +9,9 @@ import java.util.List; /** - * Represents a {@link Fields} and their corresponding values from a document. - * + * Represents a collection of field-value pairs, with methods to retrieve + * values by field name. + * * @author Anindya Chatterjee * @since 4.0 */ @@ -20,18 +21,15 @@ public class FieldValues { private Fields fields; private List> values; - /** - * Instantiates a new Field values. - */ public FieldValues() { values = new ArrayList<>(); } /** - * Get the value of the field. - * - * @param field the field - * @return the value + * Retrieves the value associated with a given field name. + * + * @param field the name of a field. + * @return the value. */ public Object get(String field) { if (fields.getFieldNames().contains(field)) { @@ -45,9 +43,9 @@ public Object get(String field) { } /** - * Gets the {@link Fields}. - * - * @return the fields + * Returns the {@link Fields} object associated with this instance. + * + * @return an instance of the Fields class. */ public Fields getFields() { if (fields != null) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/Fields.java b/nitrite/src/main/java/org/dizitart/no2/common/Fields.java index bc89affb2..9ae330676 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/Fields.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/Fields.java @@ -19,7 +19,8 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a list of document fields. + * Represents a collection of document field names and provides methods for + * manipulating and comparing them. * * @author Anindya Chatterjee * @since 4.0 @@ -29,7 +30,7 @@ public class Fields implements Comparable, Serializable { private static final long serialVersionUID = 1601646404L; /** - * The Field names. + * The names of the fields. */ @Setter(AccessLevel.PACKAGE) protected List fieldNames; @@ -56,9 +57,8 @@ public static Fields withNames(String... fields) { return f; } - /** - * Adds a new field name. + * Adds a field name to a list of field names and returns the updated list. * * @param field the field * @return the fields @@ -72,7 +72,7 @@ public Fields addField(String field) { } /** - * Gets the field names. + * Gets an unmodifiable list of field names. * * @return the field names */ @@ -92,7 +92,8 @@ public boolean startsWith(Fields other) { int length = Math.min(fieldNames.size(), other.fieldNames.size()); // if other is greater than it is not a prefix of this field - if (other.fieldNames.size() > length) return false; + if (other.fieldNames.size() > length) + return false; for (int i = 0; i < length; i++) { String thisField = fieldNames.get(i); @@ -120,7 +121,8 @@ public String toString() { @Override public int compareTo(Fields other) { - if (other == null) return 1; + if (other == null) + return 1; int fieldsSize = getFieldNames().size(); int otherFieldsSize = other.getFieldNames().size(); int result = Integer.compare(fieldsSize, otherFieldsSize); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java b/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java index deb52da92..70b3faffd 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java @@ -31,10 +31,11 @@ import java.util.Collection; + /** - * The interface Persistent collection. + * A persistent collection interface that provides methods to manage and manipulate data in a Nitrite database. * - * @param the type parameter + * @param the type of data stored in the collection. * @author Anindya Chatterjee. * @see NitriteCollection * @see ObjectRepository @@ -66,13 +67,14 @@ default void createIndex(String... fields) { * The default indexing option is - * *
    - *
  • {@code indexOptions.setIndexType(IndexType.Unique);}
  • + *
  • {@code indexOptions.setIndexType(IndexType.Unique);}
  • *
* *

* NOTE: *

    - *
  • _id value of the document is always indexed. But full-text indexing is not supported on _id value.
  • + *
  • _id field is always indexed.
  • + *
  • Full-text indexing is not supported on _id value.
  • *
  • Indexing on non-comparable value is not supported.
  • *
* diff --git a/nitrite/src/main/java/org/dizitart/no2/common/RecordStream.java b/nitrite/src/main/java/org/dizitart/no2/common/RecordStream.java index 2bfc34ea6..567f16b56 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/RecordStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/RecordStream.java @@ -21,9 +21,11 @@ import java.util.*; /** - * Represents a record stream which can be iterated in a for loop. + * An interface representing a stream of records of type T. + * Provides methods to create, manipulate and iterate over a + * stream of records. * - * @param the type parameter + * @param the type parameter for the records in the stream * @author Anindya Chatterjee. * @since 1.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/SortOrder.java b/nitrite/src/main/java/org/dizitart/no2/common/SortOrder.java index 8353a2621..2165e6fe8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/SortOrder.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/SortOrder.java @@ -17,18 +17,18 @@ package org.dizitart.no2.common; /** - * An enum to specify a sort order. + * An enum is used to specify the sort order for sorting operations. * * @author Anindya Chatterjee * @since 1.0 */ public enum SortOrder { /** - * Ascending sort order. + * Represents the ascending sort order. */ Ascending, /** - * Descending sort order. + * Represents the descending sort order. */ Descending } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/SortableFields.java b/nitrite/src/main/java/org/dizitart/no2/common/SortableFields.java index 7b2b67642..c268b0256 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/SortableFields.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/SortableFields.java @@ -29,8 +29,8 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a list of document field with - * sorting direction for find query. + * Represents a collection of fields that can be sorted, with each field + * having a specified sort order. * * @author Anindya Chatterjee * @since 4.0 @@ -65,7 +65,7 @@ public static SortableFields withNames(String... fields) { } /** - * Adds the sort order for a field. + * Adds a field and its corresponding sort order to a list of sortable fields. * * @param field the field * @param sortOrder the sort order diff --git a/nitrite/src/main/java/org/dizitart/no2/common/UnknownType.java b/nitrite/src/main/java/org/dizitart/no2/common/UnknownType.java index db54acd0b..35e650c5c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/UnknownType.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/UnknownType.java @@ -1,8 +1,6 @@ package org.dizitart.no2.common; /** - * Represents an unknown type. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/WriteResult.java b/nitrite/src/main/java/org/dizitart/no2/common/WriteResult.java index 737ad7025..f5e2488ae 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/WriteResult.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/WriteResult.java @@ -21,17 +21,16 @@ import org.dizitart.no2.common.util.Iterables; /** - * An interface to represent the result of a modification operation - * on {@link NitriteCollection}. It provides a means to iterate over - * all affected ids in the collection. + * An interface to represent the result of a write operation in Nitrite database. + * It is an iterable of {@link NitriteId}s of affected documents. * - * @author Anindya Chatterjee. + * @author Anindya Chatterjee * @since 1.0 */ public interface WriteResult extends Iterable { /** - * Gets the count of affected document in the collection. + * Gets the number of affected documents by the write operation. * * @return the affected document count. */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/BoundedStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/BoundedStream.java index cd876d937..0bc4a52d4 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/BoundedStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/BoundedStream.java @@ -26,8 +26,6 @@ import java.util.NoSuchElementException; /** - * Represents a bounded document stream. - * * @since 1.0 * @author Anindya Chatterjee. */ @@ -36,13 +34,6 @@ public class BoundedStream implements RecordStream> private final long skip; private final long limit; - /** - * Instantiates a new Bounded document stream. - * - * @param skip the skip - * @param limit the limit - * @param recordStream the record stream - */ public BoundedStream(Long skip, Long limit, RecordStream> recordStream) { this.skip = skip; this.limit = limit; @@ -70,13 +61,6 @@ private static class BoundedIterator implements Iterator { private final long limit; private long pos; - /** - * Instantiates a new Bounded iterator. - * - * @param iterator the iterator - * @param skip the skip - * @param limit the limit - */ public BoundedIterator(final Iterator iterator, final long skip, final long limit) { if (iterator == null) { throw new ValidationException("Iterator must not be null"); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/ConcatStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/ConcatStream.java index faf1e18c2..fbebe7aa1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/ConcatStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/ConcatStream.java @@ -25,19 +25,12 @@ import java.util.*; /** - * Represents an concatenation of multiple distinct nitrite document stream. - * * @author Anindya Chatterjee * @since 4.0 */ public class ConcatStream implements RecordStream> { private final Collection>> streams; - /** - * Instantiates a new Union stream. - * - * @param streams the streams - */ public ConcatStream(Collection>> streams) { this.streams = streams; } @@ -51,18 +44,10 @@ public Iterator> iterator() { return new UnionStreamIterator(iteratorQueue); } - /** - * The type Union stream iterator. - */ private static class UnionStreamIterator implements Iterator> { private final Queue>> iteratorQueue; private Iterator> currentIterator; - /** - * Instantiates a new Union stream iterator. - * - * @param iteratorQueue the iterator queue - */ public UnionStreamIterator(Queue>> iteratorQueue) { this.iteratorQueue = iteratorQueue; } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/DistinctStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/DistinctStream.java index 7e23b041f..e8e9a9a30 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/DistinctStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/DistinctStream.java @@ -25,19 +25,12 @@ import java.util.*; /** - * Represents a document stream of distinct elements - * * @author Anindya Chatterjee * @since 4.0 */ public class DistinctStream implements RecordStream> { private final RecordStream> rawStream; - /** - * Instantiates a new DistinctStream. - * - * @param rawStream the raw stream - */ public DistinctStream(RecordStream> rawStream) { this.rawStream = rawStream; } @@ -55,11 +48,6 @@ private static class DistinctStreamIterator implements Iterator nextPair; private boolean nextPairSet = false; - /** - * Instantiates a new DistinctStreamIterator. - * - * @param iterator the iterator - */ public DistinctStreamIterator(Iterator> iterator) { this.iterator = iterator; this.scannedIds = new HashSet<>(); // fastest lookup for ids - O(1) diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentSorter.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentSorter.java index 64b7dc8ce..c150976e9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentSorter.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentSorter.java @@ -29,12 +29,6 @@ import java.util.List; /** - * Sorts documents based on the sort order provided. - * - *

- * By default null is considered the lowest value. - *

- * * @author Anindya Chatterjee * @since 4.0 */ @@ -42,12 +36,6 @@ public class DocumentSorter implements Comparator> { private final Collator collator; private final List> sortOrder; - /** - * Instantiates a new Document sorter. - * - * @param collator the collator - * @param sortOrder the sort order - */ public DocumentSorter(Collator collator, List> sortOrder) { this.collator = collator; this.sortOrder = sortOrder; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentStream.java index 14aff3ddf..3a2b96e16 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/DocumentStream.java @@ -34,8 +34,6 @@ import java.util.Iterator; /** - * Represents a nitrite document stream. - * * @since 4.0 * @author Anindya Chatterjee. */ @@ -46,12 +44,6 @@ public class DocumentStream implements DocumentCursor { @Getter @Setter private FindPlan findPlan; - /** - * Instantiates a new Document stream. - * - * @param recordStream the record stream - * @param processorChain the processor chain - */ public DocumentStream(RecordStream> recordStream, ProcessorChain processorChain) { this.recordStream = recordStream; @@ -96,12 +88,6 @@ private static class DocumentCursorIterator implements Iterator { private final Iterator> iterator; private final ProcessorChain processorChain; - /** - * Instantiates a new Document cursor iterator. - * - * @param iterator the iterator - * @param processorChain the processor chain - */ DocumentCursorIterator(Iterator> iterator, ProcessorChain processorChain) { this.iterator = iterator; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/FilteredStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/FilteredStream.java index 058f31431..9ee59bf4e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/FilteredStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/FilteredStream.java @@ -29,8 +29,6 @@ import java.util.NoSuchElementException; /** - * Represents a filtered nitrite document stream. - * * @author Anindya Chatterjee. * @since 4.0 */ @@ -38,12 +36,6 @@ public class FilteredStream implements RecordStream> { private final RecordStream> recordStream; private final Filter filter; - /** - * Instantiates a new Filtered stream. - * - * @param recordStream the record stream - * @param filter the filter - */ public FilteredStream(RecordStream> recordStream, Filter filter) { this.recordStream = recordStream; this.filter = filter; @@ -61,21 +53,12 @@ public Iterator> iterator() { return new FilteredIterator(iterator, filter); } - /** - * The type Filtered iterator. - */ private static class FilteredIterator implements Iterator> { private final Iterator> iterator; private final Filter filter; private Pair nextPair; private boolean nextPairSet = false; - /** - * Instantiates a new Filtered iterator. - * - * @param iterator the iterator - * @param filter the filter - */ public FilteredIterator(Iterator> iterator, Filter filter) { this.iterator = iterator; this.filter = filter; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/IndexedStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/IndexedStream.java index d94368fb9..ab86c9fdd 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/IndexedStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/IndexedStream.java @@ -27,8 +27,6 @@ import java.util.Set; /** - * Represents a nitrite stream backed by an index. - * * @author Anindya Chatterjee * @since 4.0 */ @@ -36,12 +34,6 @@ public class IndexedStream implements RecordStream> { private final NitriteMap nitriteMap; private final Set nitriteIds; - /** - * Instantiates a new Indexed stream. - * - * @param nitriteIds the nitrite ids - * @param nitriteMap the nitrite map - */ public IndexedStream(Set nitriteIds, NitriteMap nitriteMap) { this.nitriteIds = nitriteIds; @@ -53,19 +45,10 @@ public Iterator> iterator() { return new IndexedStreamIterator(nitriteIds.iterator(), nitriteMap); } - /** - * The type Indexed stream iterator. - */ private static class IndexedStreamIterator implements Iterator> { private final Iterator iterator; private final NitriteMap nitriteMap; - /** - * Instantiates a new Indexed stream iterator. - * - * @param iterator the iterator - * @param nitriteMap the nitrite map - */ IndexedStreamIterator(Iterator iterator, NitriteMap nitriteMap) { this.iterator = iterator; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/JoinedDocumentStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/JoinedDocumentStream.java index aeb65ea11..0ebc52175 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/JoinedDocumentStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/JoinedDocumentStream.java @@ -34,8 +34,6 @@ import static org.dizitart.no2.common.util.ObjectUtils.deepEquals; /** - * Represents a joined document stream. - * * @author Anindya Chatterjee. * @since 1.0 */ @@ -45,14 +43,6 @@ public class JoinedDocumentStream implements RecordStream { private final Lookup lookup; private final ProcessorChain processorChain; - /** - * Instantiates a new Joined document stream. - * - * @param recordStream the record stream - * @param foreignCursor the foreign cursor - * @param lookup the lookup - * @param processorChain the processor chain - */ JoinedDocumentStream(RecordStream> recordStream, DocumentCursor foreignCursor, Lookup lookup, ProcessorChain processorChain) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/MutatedObjectStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/MutatedObjectStream.java index bbf211fb7..558bf81ba 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/MutatedObjectStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/MutatedObjectStream.java @@ -28,6 +28,7 @@ /** * @author Anindya Chatterjee. + * @since 4.0 */ public class MutatedObjectStream implements RecordStream { private final RecordStream recordIterable; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/ProjectedDocumentStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/ProjectedDocumentStream.java index fac78cbd4..a08e62b3e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/ProjectedDocumentStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/ProjectedDocumentStream.java @@ -28,8 +28,6 @@ import java.util.Iterator; /** - * Represents a projected nitrite document stream. - * * @author Anindya Chatterjee. * @since 1.0 */ @@ -38,13 +36,6 @@ public class ProjectedDocumentStream implements RecordStream { private final Document projection; private final ProcessorChain processorChain; - /** - * Instantiates a new Projected document stream. - * - * @param recordStream the record stream - * @param projection the projection - * @param processorChain the processor chain - */ public ProjectedDocumentStream(RecordStream> recordStream, Document projection, ProcessorChain processorChain) { this.recordStream = recordStream; @@ -70,12 +61,6 @@ private static class ProjectedDocumentIterator implements Iterator { private Document nextElement = null; private final Document projection; - /** - * Instantiates a new Projected document iterator. - * - * @param iterator the iterator - * @param processorChain the processor chain - */ ProjectedDocumentIterator(Iterator> iterator, ProcessorChain processorChain, Document projection) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/streams/SortedDocumentStream.java b/nitrite/src/main/java/org/dizitart/no2/common/streams/SortedDocumentStream.java index 8c89985c2..ed940bea3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/streams/SortedDocumentStream.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/streams/SortedDocumentStream.java @@ -29,8 +29,6 @@ import java.util.List; /** - * Represents a sorted nitrite document stream - * * @since 4.0 * @author Anindya Chatterjee. */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Pair.java b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Pair.java index cf2298ad9..18e733132 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Pair.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Pair.java @@ -25,11 +25,12 @@ import java.io.ObjectOutputStream; import java.io.Serializable; + /** - * Represents a pair. + * A simple generic class representing a pair of values. * - * @param the type parameter - * @param the type parameter + * @param the type of the first value in the pair + * @param the type of the second value in the pair * @author Anindya Chatterjee. * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quartet.java b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quartet.java index 6fb0cb6d7..a22becf4f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quartet.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quartet.java @@ -10,12 +10,12 @@ import java.io.Serializable; /** - * Represents a quartet. + * A tuple of four elements. * - * @param the type parameter - * @param the type parameter - * @param the type parameter - * @param the type parameter + * @param the type of the first element + * @param the type of the second element + * @param the type of the third element + * @param the type of the fourth element * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quintet.java b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quintet.java index be33599f4..f8a8c739a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quintet.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Quintet.java @@ -9,14 +9,15 @@ import java.io.ObjectOutputStream; import java.io.Serializable; + /** - * Represents a quintet. + * A tuple of five elements. * - * @param the type parameter - * @param the type parameter - * @param the type parameter - * @param the type parameter - * @param the type parameter + * @param the type of the first element + * @param the type of the second element + * @param the type of the third element + * @param the type of the fourth element + * @param the type of the fifth element * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Triplet.java b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Triplet.java index d0ce767c0..ddc236b99 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/tuples/Triplet.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/tuples/Triplet.java @@ -9,12 +9,13 @@ import java.io.ObjectOutputStream; import java.io.Serializable; + /** - * Represents a triplet. + * A generic class representing a tuple of three elements. * - * @param the type parameter - * @param the type parameter - * @param the type parameter + * @param the type of the first element + * @param the type of the second element + * @param the type of the third element * @author Anindya Chatterjee. * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/Comparables.java b/nitrite/src/main/java/org/dizitart/no2/common/util/Comparables.java index 3cf45de25..8b98f4612 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/Comparables.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/Comparables.java @@ -9,13 +9,6 @@ public class Comparables { private Comparables() {} - /** - * Compares two comparable objects. - * - * @param first the first - * @param second the second - * @return the int - */ @SuppressWarnings({"rawtypes", "unchecked"}) public static int compare(Comparable first, Comparable second) { if (first instanceof Number && second instanceof Number) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/CryptoUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/CryptoUtils.java index 5081e78d0..e93c37807 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/CryptoUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/CryptoUtils.java @@ -27,34 +27,17 @@ import java.security.spec.KeySpec; /** - * A utility class for cryptographic operations - * * @since 4.0 * @author Anindya Chatterjee */ public class CryptoUtils { - /** - * Gets random nonce. - * - * @param numBytes the number of bytes - * @return the byte [ ] - */ public static byte[] getRandomNonce(int numBytes) { byte[] nonce = new byte[numBytes]; new SecureRandom().nextBytes(nonce); return nonce; } - /** - * Gets password derived AES 256 bits secret key - * - * @param password the password - * @param salt the salt - * @return the aes key from password - * @throws NoSuchAlgorithmException the no such algorithm exception - * @throws InvalidKeySpecException the invalid key spec exception - */ public static SecretKey getAESKeyFromPassword(char[] password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/DocumentUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/DocumentUtils.java index 91c0fd3e1..6ad241682 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/DocumentUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/DocumentUtils.java @@ -29,21 +29,12 @@ import static org.dizitart.no2.common.util.ObjectUtils.newInstance; /** - * A utility class for {@link Document}. - * * @author Anindya Chatterjee * @since 1.0 */ public class DocumentUtils { private DocumentUtils(){} - /** - * Determines whether a document has recently been updated/created than the other. - * - * @param recent the recent document - * @param older the older document - * @return the boolean value - */ public static boolean isRecent(Document recent, Document older) { if (Objects.deepEquals(recent.getRevision(), older.getRevision())) { return recent.getLastModifiedSinceEpoch() >= older.getLastModifiedSinceEpoch(); @@ -51,24 +42,10 @@ public static boolean isRecent(Document recent, Document older) { return recent.getRevision() > older.getRevision(); } - /** - * Create unique filter to identify the `document`. - * - * @param document the document - * @return the unique filter - */ public static Filter createUniqueFilter(Document document) { return Filter.byId(document.getId()); } - /** - * Creates an empty document having all fields of a `type` set to `null`. - * - * @param the type parameter - * @param nitriteMapper the nitrite mapper - * @param type the type - * @return the document - */ public static Document skeletonDocument(NitriteMapper nitriteMapper, Class type) { Object dummy = newInstance(type, true, nitriteMapper); Document document = (Document) nitriteMapper.tryConvert(dummy, Document.class); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/IndexUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/IndexUtils.java index a304200d1..ab10b9617 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/IndexUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/IndexUtils.java @@ -22,20 +22,12 @@ import static org.dizitart.no2.common.Constants.*; /** - * A utility class for index. - * * @author Anindya Chatterjee * @since 1.0 */ public class IndexUtils { private IndexUtils() {} - /** - * Derives index map name. - * - * @param descriptor the descriptor - * @return the string - */ public static String deriveIndexMapName(IndexDescriptor descriptor) { return INDEX_PREFIX + INTERNAL_NAME_SEPARATOR + @@ -46,12 +38,6 @@ public static String deriveIndexMapName(IndexDescriptor descriptor) { descriptor.getIndexType(); } - /** - * Derives index meta map name. - * - * @param collectionName the collection name - * @return the string - */ public static String deriveIndexMetaMapName(String collectionName) { return INDEX_META_PREFIX + INTERNAL_NAME_SEPARATOR + collectionName; } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/Iterables.java b/nitrite/src/main/java/org/dizitart/no2/common/util/Iterables.java index 27f745b54..5ac7f2c42 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/Iterables.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/Iterables.java @@ -20,22 +20,12 @@ import java.util.*; /** - * A utility class for {@link Iterable}. - * * @author Anindya Chatterjee. * @since 1.0 */ public class Iterables { private Iterables() {} - /** - * Gets the first element of an {@link Iterable} or - * `null` if it is empty. - * - * @param the type parameter - * @param iterable the iterable - * @return the first element or `null`. - */ public static T firstOrNull(Iterable iterable) { if (iterable == null) return null; @@ -46,13 +36,6 @@ public static T firstOrNull(Iterable iterable) { return null; } - /** - * Converts an {@link Iterable} into a {@link List}. - * - * @param the type parameter - * @param iterable the iterable - * @return the list containing all elements of the `iterable`. - */ public static List toList(Iterable iterable) { if (iterable instanceof List) return (List) iterable; List list = new ArrayList<>(); @@ -62,13 +45,6 @@ public static List toList(Iterable iterable) { return list; } - /** - * Converts an {@link Iterable} into a {@link Set}. - * - * @param the type parameter - * @param iterable the iterable - * @return the list containing all elements of the `iterable`. - */ public static Set toSet(Iterable iterable) { if (iterable instanceof Set) return (Set) iterable; Set set = new LinkedHashSet<>(); @@ -78,14 +54,6 @@ public static Set toSet(Iterable iterable) { return set; } - /** - * Converts an {@link Iterable} of type `T` into an array of type `T`. - * - * @param the type parameter - * @param iterable the iterable - * @param type the type - * @return the array of type `T`. - */ @SuppressWarnings("unchecked") public static T[] toArray(Iterable iterable, Class type) { T[] dummy = (T[]) Array.newInstance(type, 0); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/Numbers.java b/nitrite/src/main/java/org/dizitart/no2/common/util/Numbers.java index fb5cee5ad..a5e52d3e3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/Numbers.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/Numbers.java @@ -22,8 +22,6 @@ import java.math.BigInteger; /** - * A utility class for {@link Number}s. - * * @author Anindya Chatterjee * @since 1.0 */ @@ -31,15 +29,6 @@ public class Numbers { private Numbers() { } - /** - * Compare two numbers. - * - * @param x first number. - * @param y second number. - * @return `0` if `x` and `y` are numerically equal. A value less - * than `0` if `x` is numerically less than `y`. A value greater - * than `0` if `x` is numerically greater than `y`. - */ public static int compare(Number x, Number y) { if (isSpecial(x) || isSpecial(y)) { return Double.compare(x.doubleValue(), y.doubleValue()); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java index 0865b12eb..ce27d3166 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java @@ -41,8 +41,6 @@ import static org.dizitart.no2.common.util.Iterables.toArray; /** - * A utility class. - * * @author Anindya Chatterjee. * @since 1.0 */ @@ -102,12 +100,6 @@ public static String findRepositoryNameByDecorator(EntityDecorator entity return findRepositoryName(entityName, key); } - /** - * Gets the key name of a keyed-{@link ObjectRepository} - * - * @param collectionName name of the collection - * @return the key - */ public static String getKeyName(String collectionName) { if (collectionName.contains(KEY_OBJ_SEPARATOR)) { String[] split = collectionName.split("\\" + KEY_OBJ_SEPARATOR); @@ -116,12 +108,6 @@ public static String getKeyName(String collectionName) { throw new ValidationException(collectionName + " is not a valid keyed object repository"); } - /** - * Gets the type name of a keyed-{@link ObjectRepository} - * - * @param collectionName name of the collection - * @return the type name - */ public static String getKeyedRepositoryType(String collectionName) { if (collectionName.contains(KEY_OBJ_SEPARATOR)) { String[] split = collectionName.split("\\" + KEY_OBJ_SEPARATOR); @@ -130,13 +116,6 @@ public static String getKeyedRepositoryType(String collectionName) { throw new ValidationException(collectionName + " is not a valid keyed object repository"); } - /** - * Computes equality of two objects. - * - * @param o1 the first object - * @param o2 the other object - * @return `true` if two objects are equal. - */ @SuppressWarnings("rawtypes") public static boolean deepEquals(Object o1, Object o2) { if (o1 == null && o2 == null) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/SecureString.java b/nitrite/src/main/java/org/dizitart/no2/common/util/SecureString.java index 679278265..e267d3fbe 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/SecureString.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/SecureString.java @@ -20,11 +20,6 @@ import java.util.Arrays; /** - * This is not a string but a CharSequence that can be cleared of its memory. - * Important for handling passwords. Represents text that should be kept - * confidential, such as by deleting it from computer memory when no longer - * needed or garbage collected. - * * @since 4.0 * @author Anindya Chatterjee */ @@ -59,12 +54,6 @@ public CharSequence subSequence(final int start, final int end) { return new SecureString(start, end, this); } - /** - * Convert array back to String but not using toString(). See toString() docs - * below. - * - * @return the string - */ public String asString() { final char[] value = new char[chars.length]; for (int i = 0; i < value.length; i++) { @@ -73,31 +62,16 @@ public String asString() { return new String(value); } - /** - * Manually clear the underlying array holding the characters - */ public void clear() { Arrays.fill(chars, '0'); Arrays.fill(pad, 0); } - /** - * Protect against using this class in log statements. - *

- * {@inheritDoc} - */ @Override public String toString() { return "Secure:XXXXX"; } - /** - * Randomly pad the characters to not store the real character in memory. - * - * @param start start of the {@code CharSequence} - * @param length length of the {@code CharSequence} - * @param characters the {@code CharSequence} to scramble - */ private void scramble(final int start, final int length, final CharSequence characters) { final SecureRandom random = new SecureRandom(); for (int i = start; i < length; i++) { diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/StringUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/StringUtils.java index 0659cdf00..9847a3fe3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/StringUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/StringUtils.java @@ -20,44 +20,20 @@ import java.util.StringTokenizer; /** - * A utility class for {@link String}. - * * @author Anindya Chatterjee * @since 1.0 */ public class StringUtils { private StringUtils() {} - /** - * Checks if a string is `null` or empty string. - * - * @param value the string value - * @return `true` if `null` or empty string. - */ public static boolean isNullOrEmpty(String value) { return value == null || "".equalsIgnoreCase(value); } - /** - * Checks if a {@link CharSequence} is `null` or empty. - * - * @param value the {@link CharSequence} - * @return `true` if `null` or empty. - */ public static boolean isNullOrEmpty(CharSequence value) { return value == null || value.length() == 0; } - /** - * Returns a new String composed of copies of the `strings` - * joined together with a copy of the specified `separator`. - * - * @param separator the delimiter that separates each element - * @param strings the elements to join together. - * @return a new {@code String} that is composed of the `strings` - * separated by the `separator` - * @since 4.0.0 - */ public static String join(String separator, String[] strings) { return join(separator, Arrays.asList(strings)); } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/ValidationUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/ValidationUtils.java index 839f06692..6adfcb860 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/ValidationUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/ValidationUtils.java @@ -29,8 +29,6 @@ import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; /** - * A validation utility class. - * * @author Anindya Chatterjee * @since 1.0 */ @@ -38,36 +36,18 @@ public class ValidationUtils { private ValidationUtils() { } - /** - * Validates if a string is empty or `null`. - * - * @param value the string value - * @param message the error message - */ public static void notEmpty(String value, String message) { if (isNullOrEmpty(value)) { throw new ValidationException(message); } } - /** - * Validates if a {@link CharSequence} is empty or `null`. - * - * @param value the value - * @param message the message - */ public static void notEmpty(CharSequence value, String message) { if (isNullOrEmpty(value)) { throw new ValidationException(message); } } - /** - * Validates if a {@link CharSequence} is empty or `null`. - * - * @param value the value - * @param message the message - */ public static void notEmpty(Collection value, String message) { if (value.isEmpty()) { throw new ValidationException(message); @@ -80,25 +60,12 @@ public static void notEmpty(T[] value, String message) { } } - /** - * Validates if an object is `null`. - * - * @param value the object - * @param message the message - */ public static void notNull(Object value, String message) { if (value == null) { throw new ValidationException(message); } } - /** - * Validates if an array contains `null` item. - * - * @param the type parameter - * @param array the array to check for `null` object - * @param message the message - */ public static void containsNull(T[] array, String message) { for (T element : array) { if (element == null) { diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/FilterException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/FilterException.java index abbd544b8..8b36f6474 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/FilterException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/FilterException.java @@ -18,7 +18,7 @@ /** * Exception thrown during find operations due to - * invalid filter configuration. + * invalid filter expression. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/IndexingException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/IndexingException.java index 91afbf1f4..cfcf3d81b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/IndexingException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/IndexingException.java @@ -17,7 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown while handling with nitrite database index. + * Exception thrown when there is an error with indexing in Nitrite. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidIdException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidIdException.java index 2055673f3..fbe0295e6 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidIdException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidIdException.java @@ -20,9 +20,7 @@ import org.dizitart.no2.collection.NitriteId; /** - * Exception thrown when a {@link Document} - * does not have any {@link NitriteId} associated - * with it or it has invalid/incompatible {@link NitriteId}. + * Exception thrown when an invalid ID is encountered. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidOperationException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidOperationException.java index 3c4f2b2d8..7b3abcbc2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidOperationException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/InvalidOperationException.java @@ -17,8 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a requested operation is not - * allowed to be executed. + * Exception thrown when an invalid operation is performed. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/MigrationException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/MigrationException.java index d74aa030f..fd5492993 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/MigrationException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/MigrationException.java @@ -1,7 +1,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a migration step fails. + * Exception thrown when there is an error during database migration. * * @author Anindya Chatterjee * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteException.java index 47ca02552..d37206a38 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteException.java @@ -19,7 +19,7 @@ import lombok.Getter; /** - * Represents a generic nitrite database runtime error. + * Base class for all Nitrite exceptions. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteIOException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteIOException.java index 5e09c4c52..2868cfc72 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteIOException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteIOException.java @@ -17,7 +17,8 @@ package org.dizitart.no2.exceptions; /** - * Represents a generic database I/O error. + * Exception thrown when there is an IO error while performing an operation + * in Nitrite database. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteSecurityException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteSecurityException.java index df5a7b173..ba53af365 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteSecurityException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/NitriteSecurityException.java @@ -17,7 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a database security error occurs. + * Exception thrown when a security violation occurs in Nitrite. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/NotIdentifiableException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/NotIdentifiableException.java index 9d218d85f..4ec4c8702 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/NotIdentifiableException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/NotIdentifiableException.java @@ -17,7 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when an object is not uniquely identifiable. + * Exception thrown when an object cannot be identified. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/ObjectMappingException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/ObjectMappingException.java index bce2531d3..144db91d8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/ObjectMappingException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/ObjectMappingException.java @@ -19,8 +19,8 @@ import org.dizitart.no2.collection.Document; /** - * Exception thrown while mapping of {@link Document} from - * objects fails or vice versa. + * Exception thrown when there is an error mapping an object to a + * document or vice versa. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/PluginException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/PluginException.java index 6363b7cac..de6573140 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/PluginException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/PluginException.java @@ -17,7 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a nitrite plugin fails to load properly. + * Exception thrown when a Nitrite plugin encounters an error. * * @author Anindya Chatterjee. * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/SyncException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/SyncException.java deleted file mode 100644 index 2f8e869f8..000000000 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/SyncException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017-2020. Nitrite author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.dizitart.no2.exceptions; - -/** - * Exception thrown when a problem encountered during replication. - * - * @author Anindya Chatterjee. - * @since 1.0 - */ -public class SyncException extends NitriteException { - - /** - * Instantiates a new {@link SyncException}. - * - * @param errorMessage the error message - */ - public SyncException(String errorMessage) { - super(errorMessage); - } - - /** - * Instantiates a new {@link SyncException}. - * - * @param errorMessage the error message - * @param cause the cause - */ - public SyncException(String errorMessage, Throwable cause) { - super(errorMessage, cause); - } -} diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/TransactionException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/TransactionException.java index ac4757488..3d754b1a1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/TransactionException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/TransactionException.java @@ -1,7 +1,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a transaction fails. + * Exception thrown when an error occurs during a transaction. * * @author Anindya Chatterjee * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/UniqueConstraintException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/UniqueConstraintException.java index fc5f0a870..bda276958 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/UniqueConstraintException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/UniqueConstraintException.java @@ -17,8 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when any modification in a collection - * violates unique constraint. + * Exception thrown when a unique constraint is violated. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/exceptions/ValidationException.java b/nitrite/src/main/java/org/dizitart/no2/exceptions/ValidationException.java index b7079b519..3ccd5e298 100644 --- a/nitrite/src/main/java/org/dizitart/no2/exceptions/ValidationException.java +++ b/nitrite/src/main/java/org/dizitart/no2/exceptions/ValidationException.java @@ -17,7 +17,7 @@ package org.dizitart.no2.exceptions; /** - * Exception thrown when a validation fails. + * Exception thrown when a validation error occurs. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/AndFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/AndFilter.java index 4a345de20..d971a50ab 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/AndFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/AndFilter.java @@ -23,19 +23,12 @@ import org.dizitart.no2.exceptions.FilterException; /** - * Represents an And filter. - * * @author Anindya Chatterjee * @since 1.0 */ @Getter public class AndFilter extends LogicalFilter { - /** - * Instantiates a new And filter. - * - * @param filters the filters - */ AndFilter(Filter... filters) { super(filters); diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/BetweenFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/BetweenFilter.java index 903b32121..f155bb18b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/BetweenFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/BetweenFilter.java @@ -21,6 +21,7 @@ /** * @author Anindya Chatterjee + * @since 1.0 */ class BetweenFilter extends AndFilter { diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java index 0ceb2b4e4..24135a4e6 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java @@ -23,14 +23,10 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ abstract class ComparableArrayFilter extends FieldBasedFilter { - /** - * Instantiates a new Comparable filter. - * - * @param field the field - * @param value the value - */ + public ComparableArrayFilter(String field, Object value) { super(field, value); } diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java index 64709e8b9..c37f9aabf 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java @@ -33,6 +33,7 @@ /** * @author Anindya Chatterjee + * @since 1.0 */ class ElementMatchFilter extends NitriteFilter { private final String field; diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java b/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java index b816c6209..a08fecf4b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java @@ -48,8 +48,12 @@ public interface Filter { Filter ALL = element -> true; /** - * Filter by id. - * + * Returns a filter that matches documents with the specified NitriteId. + *

+ * The returned filter matches documents where the value of the _id field + * is equal to the specified NitriteId's idValue. + * + * * @param nitriteId the nitrite id * @return the filter */ @@ -58,10 +62,12 @@ static Filter byId(NitriteId nitriteId) { } /** - * And filter. - * - * @param filters the filters - * @return the filter + * Creates a filter that performs a logical AND operation on two or more filters. + * The returned filter accepts a document if all filters in the list accept the document. + * + * @param filters the filters to AND together + * @return the new filter + * @throws FilterException if less than two filters are specified */ static Filter and(Filter... filters) { notEmpty(filters, "At least two filters must be specified"); @@ -73,10 +79,12 @@ static Filter and(Filter... filters) { } /** - * Or filter. - * - * @param filters the filters - * @return the filter + * Creates a filter that performs a logical OR operation on two or more filters. + * The returned filter selects all documents that satisfy at least one of the filters in the list. + * + * @param filters the filters to be combined using the OR operation + * @return the filter that performs the OR operation on the specified filters + * @throws FilterException if less than two filters are specified */ static Filter or(Filter... filters) { notEmpty(filters, "At least two filters must be specified"); @@ -88,18 +96,18 @@ static Filter or(Filter... filters) { } /** - * Filters a document map and returns true if the criteria matches. + * Applies the filter to the given element. * - * @param element the entry to check. - * @return boolean value to indicate if the filtering criteria matches the document. + * @param element the element to apply the filter to. + * @return {@code true} if the element matches the filter, {@code false} otherwise. */ boolean apply(Pair element); /** * Creates a not filter which performs a logical NOT operation on a filter and selects - * the documents that do not satisfy the criteria. This also includes documents - * that do not contain the value. + * the documents that do not satisfy the criteria. *

+ * NOTE: This also includes documents that do not contain the value. * * @return the not filter */ diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java index f222d7e05..155c6f77a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java @@ -34,10 +34,10 @@ private FluentFilter() { } /** - * Where clause for fluent filter api. + * Creates a new {@link FluentFilter} instance with the specified field name. * - * @param field the field - * @return the fluent filter + * @param field the name of the field to filter on + * @return a new {@link FluentFilter} instance with the specified field name */ public static FluentFilter where(String field) { FluentFilter filter = new FluentFilter(); @@ -46,123 +46,109 @@ public static FluentFilter where(String field) { } /** - * Creates an equality filter which matches documents where the value - * of a field equals the specified value. + * Creates an equality filter that matches documents where the value of a + * field equals the specified value. * - * - * @param value the value - * @return the equality filter. + * @param value the value to match against. + * @return a {@link NitriteFilter} instance representing the equality filter. */ public NitriteFilter eq(Object value) { return new EqualsFilter(field, value); } /** - * Creates an equality filter which matches documents where the value - * of a field not equals the specified value. + * Creates a filter that matches all documents where the value of + * the specified field is not equal to the given value. * - * @param value the value - * @return the filter + * @param value the value to compare against. + * @return a {@link NitriteFilter} instance. */ public NitriteFilter notEq(Object value) { return new NotEqualsFilter(field, value); } /** - * Creates a greater than filter which matches those documents where the value - * of the field is greater than (i.e. >) the specified value. + * Creates a filter that matches all documents where the value of + * the specified field is greater than the given value. * - * @param value the value - * @return the greater than filter + * @param value the value to compare against. + * @return the NitriteFilter instance representing the greater than filter. */ public NitriteFilter gt(Comparable value) { return new GreaterThanFilter(field, value); } /** - * Creates a greater equal filter which matches those documents where the value - * of the field is greater than or equals to (i.e. ≥) the specified value. + * Creates a filter that matches documents where the value of the + * field is greater than or equal to the specified value. * - * @param value the value - * @return the greater or equal filter + * @param value the value to compare against. + * @return a filter that matches documents where the value of the field is greater than or equal to the specified value. */ public NitriteFilter gte(Comparable value) { return new GreaterEqualFilter(field, value); } /** - * Creates a lesser than filter which matches those documents where the value - * of the field is less than (i.e. <) the specified value. + * Creates a filter that matches documents where the value of the + * field is less than the specified value. * - * @param value the value - * @return the lesser than filter + * @param value the value to compare against. + * @return a filter that matches documents where the value of the field is less than the specified value. */ public NitriteFilter lt(Comparable value) { return new LesserThanFilter(field, value); } /** - * Creates a lesser equal filter which matches those documents where the value - * of the field is lesser than or equals to (i.e. ≤) the specified value. + * Creates a filter that matches documents where the value of the + * field is less than or equal to the specified value. * - * @param value the value - * @return the lesser equal filter + * @param value the value to compare against. + * @return a filter that matches documents where the value of the field is less than or equal to the specified value. */ public NitriteFilter lte(Comparable value) { return new LesserEqualFilter(field, value); } /** - * Creates a between filter which matches those documents where the value - * of the field is within the specified bound including the end values. - *

 {@code
-     * // matches all documents where 'age' field is between 30 and 40
-     * collection.find(where("age").between(40, 30));
-     * }*
-     * 
+ * Creates a filter that matches documents where the value of the field is + * between the specified lower and upper bounds. * - * @param lowerBound the lower value - * @param upperBound the upper value - * @return the between filter + * @param lowerBound the lower bound (inclusive) of the range to match. + * @param upperBound the upper bound (inclusive) of the range to match. + * @return a filter that matches documents where the value of the field is + * between the specified lower and upper bounds. */ public NitriteFilter between(Comparable lowerBound, Comparable upperBound) { return new BetweenFilter<>(field, new BetweenFilter.Bound<>(lowerBound, upperBound)); } /** - * Creates a between filter which matches those documents where the value - * of the field is within the specified bound. - *
 {@code
-     * // matches all documents where 'age' field is
-     * // between 30 and 40, excluding 30 and 40
-     * collection.find(where("age").between(40, 30, false));
-     * }*
-     * 
+ * Creates a filter that matches documents where the value of the field is + * between the given lower and upper bounds. * - * @param lowerBound the lower value - * @param upperBound the upper value - * @param inclusive indicates whether to include end values - * @return the between filter + * @param lowerBound the lower bound of the range (inclusive). + * @param upperBound the upper bound of the range (inclusive). + * @param inclusive whether the bounds are inclusive or not. + * @return a filter that matches documents where the value of the field is + * between the given lower and upper bounds. */ public NitriteFilter between(Comparable lowerBound, Comparable upperBound, boolean inclusive) { return new BetweenFilter<>(field, new BetweenFilter.Bound<>(lowerBound, upperBound, inclusive)); } + /** - * Creates a between filter which matches those documents where the value - * of the field is within the specified bound. - *
 {@code
-     * // matches all documents where 'age' field is
-     * // between 30 and 40, including 40 and excluding 30
-     * collection.find(where("age").between(40, 30, true, false));
-     * }*
-     * 
+ * Creates a filter that matches documents where the value of a field is + * between two specified values. * - * @param lowerBound the lower value - * @param upperBound the upper value - * @param lowerInclusive indicates whether to include lower end value - * @param upperInclusive indicates whether to include upper end value - * @return the between filter + * @param lowerBound the lower bound (inclusive) of the range + * @param upperBound the upper bound (inclusive) of the range + * @param lowerInclusive true if the lower bound is inclusive, false otherwise + * @param upperInclusive true if the upper bound is inclusive, false otherwise + * @return a filter that matches documents where the value of a field is + * between two specified values */ public NitriteFilter between(Comparable lowerBound, Comparable upperBound, boolean lowerInclusive, boolean upperInclusive) { @@ -172,7 +158,7 @@ public NitriteFilter between(Comparable lowerBound, Comparable upperBound, } /** - * Creates a text filter which performs a text search on the content of the fields + * Creates a filter which performs a text search on the content of the fields * indexed with a full-text index. * * @param value the text value From 1923d5ddf1343eb5f309264390046a199bad7b56 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Sun, 1 Oct 2023 15:17:05 +0530 Subject: [PATCH 16/18] code refactoring and test case fixes --- nitrite-jackson-mapper/pom.xml | 5 + .../no2/common/mapper/JacksonMapper.java | 71 ++++- .../common/mapper/JacksonMapperModule.java | 15 + .../mapper/modules/NitriteIdDeserializer.java | 1 + .../mapper/modules/NitriteIdSerializer.java | 1 + nitrite-mvstore-adapter/pom.xml | 13 + .../dizitart/no2/mvstore/MVSpatialKey.java | 1 + .../dizitart/no2/mvstore/MVStoreConfig.java | 55 +++- .../dizitart/no2/mvstore/MVStoreModule.java | 26 +- .../no2/mvstore/MVStoreModuleBuilder.java | 91 ++++++ .../dizitart/no2/mvstore/MVStoreUtils.java | 5 +- .../org/dizitart/no2/mvstore/Recovery.java | 8 +- .../dizitart/no2/mvstore/ReverseIterator.java | 1 + .../no2/mvstore/compat/v1/Compat.java | 36 +-- .../no2/mvstore/compat/v1/MVMapBuilder.java | 11 +- .../mvstore/compat/v1/NitriteDataType.java | 5 +- .../compat/v1/NitriteObjectInputStream.java | 6 +- .../no2/mvstore/compat/v1/UpgradeUtil.java | 3 +- .../v1/mvstore/compress/CompressLZF.java | 4 - nitrite-rocksdb-adapter/pom.xml | 13 + .../dizitart/no2/rocksdb/CleaningAction.java | 4 + .../org/dizitart/no2/rocksdb/Constants.java | 1 + .../org/dizitart/no2/rocksdb/EntrySet.java | 4 + .../java/org/dizitart/no2/rocksdb/KeySet.java | 4 + .../dizitart/no2/rocksdb/RocksDBConfig.java | 56 +++- .../org/dizitart/no2/rocksdb/RocksDBMap.java | 6 +- .../dizitart/no2/rocksdb/RocksDBModule.java | 31 ++ .../no2/rocksdb/RocksDBModuleBuilder.java | 45 +++ .../dizitart/no2/rocksdb/RocksDBRTree.java | 1 + .../no2/rocksdb/RocksDBReference.java | 3 +- .../dizitart/no2/rocksdb/RocksDBStore.java | 6 +- .../no2/rocksdb/RocksDBStoreUtils.java | 6 +- .../dizitart/no2/rocksdb/StoreFactory.java | 3 +- .../org/dizitart/no2/rocksdb/ValueSet.java | 4 + .../formatter/ComparableKeySerializer.java | 1 + .../formatter/DefaultJavaSerializers.java | 1 + .../formatter/DefaultTimeKeySerializers.java | 1 + .../rocksdb/formatter/KryoKeySerializer.java | 1 + .../formatter/KryoObjectFormatter.java | 3 +- .../rocksdb/formatter/NitriteSerializers.java | 1 + .../rocksdb/formatter/ObjectFormatter.java | 37 +++ nitrite-spatial/pom.xml | 8 + .../dizitart/no2/spatial/FluentFilter.java | 33 +- .../dizitart/no2/spatial/GeometryUtils.java | 4 + .../no2/spatial/NitriteBoundingBox.java | 1 - .../dizitart/no2/spatial/SpatialFilter.java | 16 +- .../dizitart/no2/spatial/SpatialIndex.java | 2 +- .../dizitart/no2/spatial/SpatialIndexer.java | 15 +- .../dizitart/no2/spatial/SpatialModule.java | 14 +- .../spatial/mapper/GeometryDeserializer.java | 3 +- .../no2/spatial/mapper/GeometryModule.java | 4 +- .../spatial/mapper/GeometrySerializer.java | 1 + .../dizitart/no2/spatial/SpatialViewer.java | 2 +- nitrite-support/pom.xml | 5 + .../no2/support/crypto/AESEncryptor.java | 44 +-- .../no2/support/crypto/Encryptor.java | 16 +- .../no2/support/exchange/ExportOptions.java | 249 ++++++++------- .../no2/support/exchange/Exporter.java | 283 +++++++++--------- .../no2/support/exchange/ImportOptions.java | 24 +- .../no2/support/exchange/Importer.java | 211 ++++++------- .../no2/support/exchange/NitriteFactory.java | 13 +- .../StringFieldEncryptionProcessor.java | 30 +- nitrite/pom.xml | 31 +- .../main/java/org/dizitart/no2/Nitrite.java | 153 ++++++---- .../java/org/dizitart/no2/NitriteBuilder.java | 93 +++--- .../java/org/dizitart/no2/NitriteConfig.java | 86 ++++-- .../org/dizitart/no2/NitriteDatabase.java | 2 +- .../no2/collection/SnowflakeIdGenerator.java | 2 +- .../events/CollectionEventInfo.java | 2 +- .../collection/operation/WriteOperations.java | 2 +- .../org/dizitart/no2/common/Constants.java | 2 +- .../java/org/dizitart/no2/common/DBNull.java | 4 +- .../no2/common/PersistentCollection.java | 1 - .../concurrent/ErrorAwareThreadFactory.java | 2 +- .../common/concurrent/ThreadPoolManager.java | 2 +- .../no2/common/event/NitriteEventBus.java | 2 +- .../no2/common/module/PluginManager.java | 2 +- .../dizitart/no2/common/util/ObjectUtils.java | 3 - .../no2/filters/ComparableArrayFilter.java | 4 +- .../no2/filters/ComparableFilter.java | 2 +- .../no2/filters/FieldBasedFilter.java | 12 +- .../java/org/dizitart/no2/filters/Filter.java | 2 +- .../dizitart/no2/filters/FluentFilter.java | 32 +- .../dizitart/no2/filters/IndexOnlyFilter.java | 5 +- .../dizitart/no2/filters/NitriteFilter.java | 2 +- .../dizitart/no2/filters/StringFilter.java | 2 +- .../org/dizitart/no2/filters/TextFilter.java | 2 - .../org/dizitart/no2/index/BoundingBox.java | 16 +- .../dizitart/no2/index/ComparableIndexer.java | 2 - .../org/dizitart/no2/index/CompoundIndex.java | 2 - .../dizitart/no2/index/IndexDescriptor.java | 2 +- .../java/org/dizitart/no2/index/IndexMap.java | 2 - .../org/dizitart/no2/index/IndexMeta.java | 2 - .../org/dizitart/no2/index/IndexOptions.java | 2 +- .../org/dizitart/no2/index/IndexScanner.java | 14 - .../org/dizitart/no2/index/IndexType.java | 10 +- .../org/dizitart/no2/index/NitriteIndex.java | 41 +-- .../dizitart/no2/index/NitriteIndexer.java | 40 +-- .../no2/index/NitriteTextIndexer.java | 2 - .../dizitart/no2/index/NonUniqueIndexer.java | 2 - .../dizitart/no2/index/SingleFieldIndex.java | 2 - .../org/dizitart/no2/index/TextIndex.java | 2 - .../org/dizitart/no2/index/UniqueIndexer.java | 2 - .../no2/index/fulltext/Languages.java | 2 +- .../no2/index/fulltext/TextTokenizer.java | 2 +- .../fulltext/UniversalTextTokenizer.java | 2 +- .../org/dizitart/no2/migration/Generator.java | 2 +- .../org/dizitart/no2/migration/Migration.java | 16 +- .../no2/migration/MigrationManager.java | 2 - .../dizitart/no2/migration/MigrationStep.java | 11 +- .../no2/migration/NitriteInstructionSet.java | 2 - .../no2/migration/commands/AddField.java | 2 +- .../migration/commands/ChangeDataType.java | 2 +- .../no2/migration/commands/ChangeIdField.java | 2 +- .../no2/migration/commands/Command.java | 7 - .../no2/migration/commands/CreateIndex.java | 2 +- .../no2/migration/commands/DeleteField.java | 2 +- .../dizitart/no2/migration/commands/Drop.java | 2 +- .../no2/migration/commands/DropIndex.java | 2 +- .../no2/migration/commands/Rename.java | 4 +- .../no2/migration/commands/RenameField.java | 2 +- .../repository/DefaultObjectRepository.java | 1 - .../no2/repository/EntityDecorator.java | 8 +- .../repository/EntityDecoratorScanner.java | 1 + .../org/dizitart/no2/repository/EntityId.java | 34 +++ .../dizitart/no2/repository/EntityIndex.java | 8 +- .../no2/repository/IndexValidator.java | 8 +- .../dizitart/no2/repository/ObjectCursor.java | 1 + .../no2/repository/ObjectIdField.java | 1 + .../dizitart/no2/repository/Reflector.java | 1 + .../no2/repository/RepositoryFactory.java | 28 -- .../no2/repository/RepositoryOperations.java | 68 ----- .../no2/repository/annotations/Entity.java | 5 +- .../no2/repository/annotations/Id.java | 2 +- .../no2/repository/annotations/Index.java | 2 +- .../no2/repository/annotations/Indices.java | 2 +- .../annotations/InheritIndices.java | 2 +- .../no2/store/AbstractNitriteStore.java | 24 +- .../org/dizitart/no2/store/MapMetaData.java | 2 - .../java/org/dizitart/no2/store/MetaData.java | 2 - .../org/dizitart/no2/store/NitriteStore.java | 66 ++-- .../org/dizitart/no2/store/StoreCatalog.java | 28 +- .../org/dizitart/no2/store/StoreConfig.java | 19 +- .../org/dizitart/no2/store/StoreMetaData.java | 12 - .../no2/store/UserAuthenticationService.java | 22 -- .../dizitart/no2/store/UserCredential.java | 2 - .../dizitart/no2/store/events/EventInfo.java | 6 +- .../no2/store/events/StoreEventBus.java | 5 +- .../no2/store/events/StoreEventListener.java | 6 +- .../no2/store/events/StoreEvents.java | 12 +- .../no2/store/memory/InMemoryConfig.java | 2 - .../no2/store/memory/InMemoryMap.java | 4 - .../store/memory/InMemoryModuleBuilder.java | 2 - .../no2/store/memory/InMemoryRTree.java | 4 - .../no2/store/memory/InMemoryStore.java | 4 - .../no2/store/memory/InMemoryStoreModule.java | 2 - .../dizitart/no2/transaction/ChangeType.java | 41 --- .../org/dizitart/no2/transaction/Command.java | 5 - .../DefaultTransactionalRepository.java | 1 - .../no2/transaction/JournalEntry.java | 2 - .../no2/transaction/NitriteTransaction.java | 2 +- .../org/dizitart/no2/transaction/Session.java | 12 +- .../dizitart/no2/transaction/Transaction.java | 58 +++- .../no2/transaction/TransactionConfig.java | 2 - .../no2/transaction/TransactionState.java | 6 +- .../no2/exceptions/SyncExceptionTest.java | 26 -- .../main/kotlin/org/dizitart/kno2/Builder.kt | 34 ++- .../kotlin/org/dizitart/kno2/Documents.kt | 27 +- .../org/dizitart/kno2/KNO2JacksonMapper.kt | 5 +- .../kotlin/org/dizitart/kno2/KNO2Module.kt | 3 + .../main/kotlin/org/dizitart/kno2/Nitrite.kt | 59 ++-- .../kotlin/org/dizitart/kno2/Transaction.kt | 15 +- .../kno2/serialization/DocumentDecoder.kt | 2 + .../kno2/serialization/DocumentEncoder.kt | 1 + .../KotlinXSerializationMapper.kt | 5 +- 175 files changed, 1704 insertions(+), 1227 deletions(-) delete mode 100644 nitrite/src/test/java/org/dizitart/no2/exceptions/SyncExceptionTest.java diff --git a/nitrite-jackson-mapper/pom.xml b/nitrite-jackson-mapper/pom.xml index b03f4eb08..2fb2c3507 100644 --- a/nitrite-jackson-mapper/pom.xml +++ b/nitrite-jackson-mapper/pom.xml @@ -117,6 +117,11 @@ org.apache.maven.plugins maven-javadoc-plugin + + + org.dizitart.no2.common.mapper.modules, + + org.apache.maven.plugins diff --git a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java index 02a6e3a67..951eae0f3 100644 --- a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java +++ b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapper.java @@ -24,6 +24,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.modules.NitriteIdModule; import org.dizitart.no2.exceptions.ObjectMappingException; +import org.dizitart.no2.exceptions.ValidationException; import java.io.IOException; import java.util.*; @@ -31,19 +32,29 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** + * A {@link NitriteMapper} implementation that uses Jackson ObjectMapper to + * convert objects to and from Nitrite document. + * + * @since 4.0 + * @see NitriteMapper * @author Anindya Chatterjee */ public class JacksonMapper implements NitriteMapper { private ObjectMapper objectMapper; + /** + * Returns the object mapper instance used for document conversion. + * + * @return the object mapper instance used for document conversion + */ protected ObjectMapper getObjectMapper() { if (objectMapper == null) { objectMapper = new ObjectMapper(); objectMapper.setVisibility( - objectMapper.getSerializationConfig().getDefaultVisibilityChecker() - .withFieldVisibility(JsonAutoDetect.Visibility.ANY) - .withGetterVisibility(JsonAutoDetect.Visibility.NONE) - .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); + objectMapper.getSerializationConfig().getDefaultVisibilityChecker() + .withFieldVisibility(JsonAutoDetect.Visibility.ANY) + .withGetterVisibility(JsonAutoDetect.Visibility.NONE) + .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); @@ -53,11 +64,34 @@ protected ObjectMapper getObjectMapper() { return objectMapper; } + /** + * Registers a Jackson module with the object mapper. + * + * @param module the Jackson module to register + * @throws ValidationException if the module is null + */ public void registerJacksonModule(Module module) { notNull(module, "module cannot be null"); getObjectMapper().registerModule(module); } + /** + * Tries to convert the given source object to the target type using Jackson + * ObjectMapper. + *

+ * If the source object is null, returns null. If the source + * object is a value node, returns the node value. If the target type is + * Document, converts the source object to a Document. If the source object is + * already a Document, converts it to the target type. If the conversion fails, + * throws an ObjectMappingException. + * + * @param source the source object to convert + * @param type the target type to convert to + * @param the type of the source object + * @param the type of the target object + * @return the converted object of the target type + * @throws ObjectMappingException if the conversion fails + */ @Override public Object tryConvert(Source source, Class type) { if (source == null) { @@ -66,7 +100,8 @@ public Object tryConvert(Source source, Class type) { try { JsonNode node = getObjectMapper().convertValue(source, JsonNode.class); - if (node == null) return null; + if (node == null) + return null; if (node.isValueNode()) { return getNodeValue(node); @@ -79,18 +114,28 @@ public Object tryConvert(Source source, Class type) { } } catch (Exception e) { throw new ObjectMappingException("Failed to convert object of type " - + source.getClass() + " to type " + type, e); + + source.getClass() + " to type " + type, e); } throw new ObjectMappingException("Can't convert object to type " + type - + ", try registering a jackson Module for it."); + + ", try registering a jackson Module for it."); } - @Override public void initialize(NitriteConfig nitriteConfig) { } + /** + * Converts a Nitrite Document to an object of the specified class type using + * Jackson ObjectMapper. + * + * @param source the Nitrite Document to be converted + * @param type the class type of the object to be converted to + * @param the type of the object to be converted to + * @return the converted object of the specified class type + * @throws ObjectMappingException if there is an error in the object mapping + * process + */ protected Target convertFromDocument(Document source, Class type) { try { return getObjectMapper().convertValue(source, type); @@ -105,6 +150,14 @@ protected Target convertFromDocument(Document source, Class typ } } + /** + * Converts the given source object to a Nitrite {@link Document} using + * Jackson's {@link ObjectMapper}. + * + * @param source the source object to convert + * @param the type of the source object + * @return the converted Nitrite {@link Document} + */ protected Document convertToDocument(Source source) { JsonNode node = getObjectMapper().convertValue(source, JsonNode.class); return readDocument(node); @@ -166,7 +219,7 @@ private Object readObject(JsonNode node) { return null; } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) private List readArray(JsonNode array) { if (array.isArray()) { List list = new ArrayList(); diff --git a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapperModule.java b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapperModule.java index 7b7d6d55d..47edf3429 100644 --- a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapperModule.java +++ b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/JacksonMapperModule.java @@ -25,15 +25,30 @@ import static org.dizitart.no2.common.util.Iterables.setOf; /** + * A Nitrite module that provides a jackson based {@link NitriteMapper} + * implementation for object to document conversion. + * + * @since 4.0 + * @see NitriteMapper + * @see JacksonMapper * @author Anindya Chatterjee */ public class JacksonMapperModule implements NitriteModule { private final JacksonMapper jacksonMapper; + /** + * Instantiates a new {@link JacksonMapperModule}. + */ public JacksonMapperModule() { jacksonMapper = new JacksonMapper(); } + /** + * Instantiates a new {@link JacksonMapperModule} with custom + * jackson modules. + * + * @param jacksonModules the jackson modules + */ public JacksonMapperModule(Module... jacksonModules) { jacksonMapper = new JacksonMapper(); for (Module jacksonModule : jacksonModules) { diff --git a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdDeserializer.java b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdDeserializer.java index ca07c4c6f..701996982 100644 --- a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdDeserializer.java +++ b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdDeserializer.java @@ -24,6 +24,7 @@ import java.io.IOException; /** + * @since 4.0 * @author Anindya Chatterjee */ class NitriteIdDeserializer extends StdScalarDeserializer { diff --git a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdSerializer.java b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdSerializer.java index 1b6b34e2b..e2402e1d1 100644 --- a/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdSerializer.java +++ b/nitrite-jackson-mapper/src/main/java/org/dizitart/no2/common/mapper/modules/NitriteIdSerializer.java @@ -24,6 +24,7 @@ import java.io.IOException; /** + * @since 4.0 * @author Anindya Chatterjee */ class NitriteIdSerializer extends StdScalarSerializer { diff --git a/nitrite-mvstore-adapter/pom.xml b/nitrite-mvstore-adapter/pom.xml index 4b060ed73..0a9d0a21a 100644 --- a/nitrite-mvstore-adapter/pom.xml +++ b/nitrite-mvstore-adapter/pom.xml @@ -151,6 +151,19 @@ org.apache.maven.plugins maven-javadoc-plugin + + + org.dizitart.no2.mvstore.compat.v1, + + + **/*MVSpatialKey.java + **/*MVStoreUtils.java + **/*NitriteMVMap.java + **/*NitriteMVRTreeMap.java + **/*NitriteMVStore.java + **/*ReverseIterator.java + + org.apache.maven.plugins diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java index c7fc552b1..f41490173 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java @@ -23,6 +23,7 @@ import java.util.Arrays; /** + * @since 4.0 * @author Anindya Chatterjee */ public class MVSpatialKey extends SpatialKey implements Spatial { diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreConfig.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreConfig.java index a51bfab7c..cbfc94d9a 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreConfig.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreConfig.java @@ -16,7 +16,6 @@ package org.dizitart.no2.mvstore; - import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -29,54 +28,97 @@ import java.util.Set; /** - * Represents MV store configuration - * - * @since 4.0.0 + * Configuration class for MVStore. + * + * @since 4.0 * @author Anindya Chatterjee */ @Getter @Accessors(fluent = true) public class MVStoreConfig implements StoreConfig { @Setter(AccessLevel.PACKAGE) + /** + * The set of event listeners for the MVStore. + */ private Set eventListeners; @Setter(AccessLevel.PACKAGE) + /** + * The file path of the MVStore file. + */ private String filePath; @Setter(AccessLevel.PACKAGE) + /** + * The size of the buffer used for auto-commit operations. + */ private int autoCommitBufferSize; @Setter(AccessLevel.PACKAGE) + /** + * The encryption key to be used for encrypting and decrypting the data. + */ private char[] encryptionKey; @Setter(AccessLevel.PACKAGE) + /** + * A flag indicating whether the MVStore should be opened in read-only mode. + */ private Boolean isReadOnly = false; @Setter(AccessLevel.PACKAGE) + /** + * Indicates whether the MVStore should compress data or not. + */ private boolean compress; @Setter(AccessLevel.PACKAGE) + /** + * Indicates whether to use high compression for data blocks. + */ private boolean compressHigh; @Setter(AccessLevel.PACKAGE) + /** + * Indicates whether auto-commit mode is enabled for the MVStore. + */ private boolean autoCommit; @Setter(AccessLevel.PACKAGE) + /** + * Sets a value indicating whether the MVStore should automatically compact + * itself when it is closed. + */ private boolean autoCompact; @Setter(AccessLevel.PACKAGE) + /** + * Indicates whether the MVStore should be opened in recovery mode or not. + */ private boolean recoveryMode; @Setter(AccessLevel.PACKAGE) + /** + * The size of the cache (in KB) used by the MVStore. + */ private int cacheSize; @Setter(AccessLevel.PACKAGE) + /** + * The number of threads that can concurrently access the MVStore cache. + */ private int cacheConcurrency; + /** + * Sets the page split size for the MVStore. + */ @Setter(AccessLevel.PACKAGE) private int pageSplitSize; @Setter(AccessLevel.PACKAGE) + /** + * The file store used by the MVStore. + */ private FileStore fileStore; MVStoreConfig() { @@ -88,6 +130,11 @@ public void addStoreEventListener(StoreEventListener listener) { eventListeners.add(listener); } + /** + * Creates and returns a copy of this object. + * + * @return a clone of this instance. + */ public MVStoreConfig clone() { MVStoreConfig config = new MVStoreConfig(); config.eventListeners(new HashSet<>(eventListeners)); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModule.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModule.java index dc72c0d22..d716f36ed 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModule.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModule.java @@ -18,7 +18,6 @@ import lombok.AccessLevel; import lombok.Setter; -import org.dizitart.no2.common.module.NitriteModule; import org.dizitart.no2.common.module.NitritePlugin; import org.dizitart.no2.store.NitriteStore; import org.dizitart.no2.store.StoreModule; @@ -28,15 +27,24 @@ import static org.dizitart.no2.common.util.Iterables.setOf; /** - * A {@link NitriteModule} which provides h2's mvstore as a storage engine. - * - * @since 4.0.0 + * A Nitrite module that provides a Nitrite store implementation using H2 MVStore. + * + * @since 4.0 + * @see NitriteStore * @author Anindya Chatterjee */ public class MVStoreModule implements StoreModule { @Setter(AccessLevel.PACKAGE) + /** + * The configuration object for the MVStore. + */ private MVStoreConfig storeConfig; + /** + * Constructs a new instance of {@link MVStoreModule} with the specified file path. + * + * @param path the file path for the MVStore database. + */ public MVStoreModule(String path) { this.storeConfig = new MVStoreConfig(); this.storeConfig.filePath(path); @@ -47,10 +55,20 @@ public Set plugins() { return setOf(getStore()); } + /** + * Returns a new instance of {@link MVStoreModuleBuilder} to configure the MVStore module. + * + * @return a new instance of {@link MVStoreModuleBuilder}. + */ public static MVStoreModuleBuilder withConfig() { return new MVStoreModuleBuilder(); } + /** + * Returns a new instance of {@link NitriteStore} with the configured {@link StoreConfig}. + * + * @return a new instance of {@link NitriteStore}. + */ public NitriteStore getStore() { NitriteMVStore store = new NitriteMVStore(); store.setStoreConfig(storeConfig); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModuleBuilder.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModuleBuilder.java index 2fab152cf..215ffbe2c 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModuleBuilder.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreModuleBuilder.java @@ -28,27 +28,95 @@ import java.util.Set; /** + * The MVStoreModuleBuilder class is responsible for building an instance of + * {@link MVStoreModule}. It provides methods to set various configuration + * options for the MVStore database. + * + * @since 4.0 + * @see MVStoreModule * @author Anindya Chatterjee */ @Getter @Setter @Accessors(fluent = true) public class MVStoreModuleBuilder { + /** + * The file path of the MVStore file. + */ private String filePath; + + /** + * The size of the buffer used for auto-commit. When the buffer is full, + * the changes are automatically committed to the database. The default + * buffer size is 1024. + */ private int autoCommitBufferSize = 1024; + + /** + * The encryption key to be used for encrypting the MVStore. + */ private char[] encryptionKey; + + /** + * Indicates whether the MVStore instance should be opened in read-only mode. + */ private boolean readOnly; + + /** + * Flag to enable/disable compression of data in MVStore. + */ private boolean compress; + + /** + * Flag to enable high compression for the MVStore. If set to true, the MVStore + * will use a higher compression level, which may result in slower read and + * write performance but smaller file size on disk. + */ private boolean compressHigh; + + /** + * Flag to enable/disable auto-commit mode. If set to true, all changes + * will be committed immediately. If set to false, changes will be buffered + * and committed when {@link org.dizitart.no2.Nitrite#commit()} is called. + */ private boolean autoCommit = true; + + /** + * Indicates whether the MVStore should be opened in recovery mode or not. + */ private boolean recoveryMode = false; + + /** + * The size of the read cache in MB used by the MVStore. The default value is + * 16MB. + */ private int cacheSize = 16; + + /** + * The read cache concurrency used by MVStore. Default is 16 segments. + */ private int cacheConcurrency = 16; + + /** + * The amount of memory a MVStore page should contain at most, in bytes, + * before it is split. The default is 16 KB. + */ private int pageSplitSize = 16; + + /** + * The file store used by the MVStore. + */ private FileStore fileStore; + + /** + * The configuration for the MVStore. + */ private MVStoreConfig dbConfig; @Setter(AccessLevel.NONE) + /** + * Set of event listeners to be registered with the MVStore. + */ private final Set eventListeners; MVStoreModuleBuilder() { @@ -56,6 +124,12 @@ public class MVStoreModuleBuilder { eventListeners = new HashSet<>(); } + /** + * Sets the file path for the MVStore. + * + * @param file the file path for the MVStore. + * @return the MVStoreModuleBuilder instance. + */ public MVStoreModuleBuilder filePath(File file) { if (file != null) { this.filePath = file.getPath(); @@ -63,16 +137,33 @@ public MVStoreModuleBuilder filePath(File file) { return this; } + /** + * Sets the file path for the MVStore. + * + * @param path the file path for the MVStore. + * @return the MVStoreModuleBuilder instance. + */ public MVStoreModuleBuilder filePath(String path) { this.filePath = path; return this; } + /** + * Adds a {@link StoreEventListener} to the module builder. + * + * @param listener the listener to be added + * @return the module builder instance + */ public MVStoreModuleBuilder addStoreEventListener(StoreEventListener listener) { eventListeners.add(listener); return this; } + /** + * Builds an instance of {@link MVStoreModule} with the configured parameters. + * + * @return an instance of {@link MVStoreModule}. + */ public MVStoreModule build() { MVStoreModule module = new MVStoreModule(filePath()); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java index 025e1f373..4388cb221 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java @@ -33,9 +33,9 @@ /** * @author Anindya Chatterjee. - * @since 4.0.0 + * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite-mvstore") @SuppressWarnings("ALL") class MVStoreUtils { private MVStoreUtils() { @@ -98,7 +98,6 @@ static MVStore openOrCreate(MVStoreConfig storeConfig) { if (store != null) { store.setRetentionTime(0); store.setVersionsToKeep(0); -// store.setReuseSpace(true); } } diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/Recovery.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/Recovery.java index 591b4a6c0..a79273435 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/Recovery.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/Recovery.java @@ -16,13 +16,9 @@ package org.dizitart.no2.mvstore; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.exceptions.NitriteIOException; -import org.h2.mvstore.MVStoreTool; import org.h2.store.fs.FilePath; -import java.io.IOException; -import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; @@ -30,12 +26,12 @@ import static org.h2.mvstore.MVStoreTool.rollback; /** - * The nitrite database recovery utility. + * The Recovery class provides methods to attempt a MVStore file recovery + * by rolling back to the newest good version. * * @author Anindya Chatterjee * @since 1.0 */ -@Slf4j public class Recovery { /** diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/ReverseIterator.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/ReverseIterator.java index f98c0fae0..033b2e847 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/ReverseIterator.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/ReverseIterator.java @@ -7,6 +7,7 @@ import java.util.NoSuchElementException; /** + * @since 4.0 * @author Anindya Chatterjee */ public class ReverseIterator implements Iterator> { diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/Compat.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/Compat.java index 4f8576621..4ccb102fc 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/Compat.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/Compat.java @@ -23,48 +23,25 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Nitrite v3 compatible classes used in data migration. - * * @author Anindya Chatterjee - * @since 4.0.0 + * @since 4.0 */ class Compat { - /** - * The enum Index type. - */ enum IndexType { - /** - * Unique index type. - */ Unique, - /** - * Non unique index type. - */ NonUnique, - /** - * Fulltext index type. - */ Fulltext } - /** - * The type User credential. - */ @Data static class UserCredential implements Serializable { private byte[] passwordHash; private byte[] passwordSalt; } - /** - * The type Document. - */ - static class Document extends LinkedHashMap implements Serializable { + static class Document extends LinkedHashMap { } - /** - * The type Index. - */ @Data static class Index implements Serializable { private IndexType indexType; @@ -72,9 +49,6 @@ static class Index implements Serializable { private String collectionName; } - /** - * The type Index meta. - */ @Data static class IndexMeta implements Serializable { private Index index; @@ -82,9 +56,6 @@ static class IndexMeta implements Serializable { private AtomicBoolean isDirty; } - /** - * The type Attributes. - */ @Data static class Attributes implements Serializable { private long createdTime; @@ -96,9 +67,6 @@ static class Attributes implements Serializable { private String uuid; } - /** - * The type Nitrite id. - */ @Data static class NitriteId implements Serializable, Comparable { private Long idValue; diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/MVMapBuilder.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/MVMapBuilder.java index 8f376e7d5..e5ef709c4 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/MVMapBuilder.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/MVMapBuilder.java @@ -20,18 +20,11 @@ import org.dizitart.no2.mvstore.compat.v1.mvstore.MVMap; /** - * The type Mv map builder. - * - * @param the type parameter - * @param the type parameter - * - * @since 4.0.0 + * @since 4.0 * @author Anindya Chatterjee. */ class MVMapBuilder extends MVMap.Builder { - /** - * Instantiates a new Mv map builder. - */ + public MVMapBuilder() { setKeyType(new NitriteDataType()); setValueType(new NitriteDataType()); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteDataType.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteDataType.java index b4932cd05..bf05c3199 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteDataType.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteDataType.java @@ -37,10 +37,7 @@ import java.util.UUID; /** - * The type Nitrite data type. - * - * NOTE: This code is a modification of h2 mvstore's {@link ObjectDataType} - * @since 4.0.0 + * @since 4.0 * @author H2 Group * @author Anindya Chatterjee */ diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteObjectInputStream.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteObjectInputStream.java index d04a328f3..86313cecc 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteObjectInputStream.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteObjectInputStream.java @@ -26,12 +26,10 @@ import java.util.Map; /** - * A specialized version of {@link ObjectInputStream} for nitrite. - * - * @since 4.0.0 + * @since 4.0 * @author Anindya Chatterjee. */ -@Slf4j +@Slf4j(topic = "nitrite-mvstore") class NitriteObjectInputStream extends ObjectInputStream { private static final Map> migrationMap = new HashMap<>(); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java index 3d3db1743..f43687e0c 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java @@ -44,9 +44,10 @@ import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; /** + * @since 4.0 * @author Anindya Chatterjee */ -@Slf4j +@Slf4j(topic = "nitrite-mvstore") public class UpgradeUtil { private UpgradeUtil() { } diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/compress/CompressLZF.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/compress/CompressLZF.java index 62d0adae7..b66ddd25d 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/compress/CompressLZF.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/compress/CompressLZF.java @@ -9,10 +9,6 @@ import java.nio.ByteBuffer; public final class CompressLZF implements Compressor { - private static final int HASH_SIZE = 16384; - private static final int MAX_LITERAL = 32; - private static final int MAX_OFF = 8192; - private static final int MAX_REF = 264; private int[] cachedHashTable; public CompressLZF() { diff --git a/nitrite-rocksdb-adapter/pom.xml b/nitrite-rocksdb-adapter/pom.xml index 68187b12f..accead5d0 100644 --- a/nitrite-rocksdb-adapter/pom.xml +++ b/nitrite-rocksdb-adapter/pom.xml @@ -149,6 +149,19 @@ org.apache.maven.plugins maven-javadoc-plugin + + + **/*Serializer.java + **/*Serializers.java + **/*KryoObjectFormatter.java + **/*CleaningAction.java + **/*Constants.java + **/*RocksDBMap.java + **/*RocksDBReference.java + **/*RocksDBRTree.java + **/*RocksDBStore.java + + org.apache.maven.plugins diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/CleaningAction.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/CleaningAction.java index acc30479a..128dc241b 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/CleaningAction.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/CleaningAction.java @@ -1,5 +1,9 @@ package org.dizitart.no2.rocksdb; +/** + * @since 4.0 + * @author Anindya Chatterjee + */ class CleaningAction implements Runnable { private final AutoCloseable resource; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/Constants.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/Constants.java index acd13e6c6..d3a495b0f 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/Constants.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/Constants.java @@ -19,6 +19,7 @@ import java.lang.ref.Cleaner; /** + * @since 4.0 * @author Anindya Chatterjee */ public class Constants { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/EntrySet.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/EntrySet.java index 4b22bb002..b00e7898b 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/EntrySet.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/EntrySet.java @@ -6,6 +6,10 @@ import java.util.Iterator; +/** + * @since 4.0 + * @author Anindya Chatterjee + */ class EntrySet implements Iterable> { private final ObjectFormatter objectFormatter; private final RocksDB rocksDB; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/KeySet.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/KeySet.java index a39ff3621..9c891e6ff 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/KeySet.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/KeySet.java @@ -10,6 +10,10 @@ import static org.dizitart.no2.rocksdb.Constants.CLEANER; +/** + * @since 4.0 + * @author Anindya Chatterjee + */ class KeySet implements Iterable { private final ObjectFormatter objectFormatter; private final RocksDB rocksDB; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBConfig.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBConfig.java index 6c2652170..94a830835 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBConfig.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBConfig.java @@ -15,24 +15,58 @@ import java.util.HashSet; import java.util.Set; +/** + * Configuration class for RocksDB store. It implements the {@link StoreConfig} + * interface. + * + * @since 4.0 + * @see StoreConfig + * @see RocksDBModule + * @see RocksDBModuleBuilder + * @author Anindya Chatterjee + */ @Accessors(fluent = true) public class RocksDBConfig implements StoreConfig { - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The set of event listeners registered with this configuration. + */ private Set eventListeners; - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The RocksDB {@link Options} used to configure the database instance. + */ private Options options; - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The RocksDB {@link DBOptions} used to configure the database instance. + */ private DBOptions dbOptions; - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The RocksDB {@link ColumnFamilyOptions} used to configure the database instance. + */ private ColumnFamilyOptions columnFamilyOptions; - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The file path of the RocksDB data store. + */ private String filePath; - @Getter @Setter(AccessLevel.PACKAGE) + @Getter + @Setter(AccessLevel.PACKAGE) + /** + * The object formatter used to serialize and deserialize objects. + */ private ObjectFormatter objectFormatter; RocksDBConfig() { @@ -40,11 +74,21 @@ public class RocksDBConfig implements StoreConfig { objectFormatter = new KryoObjectFormatter(); } + /** + * Adds a store event listener to the configuration. + * + * @param listener the store event listener to add + */ @Override public void addStoreEventListener(StoreEventListener listener) { eventListeners.add(listener); } + /** + * Returns whether the RocksDB instance is in memory or not. + * + * @return {@code true} if the RocksDB instance is in memory; {@code false} otherwise. + */ @Override public final boolean isInMemory() { return false; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java index 6beb12ba0..55ebf109f 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java @@ -20,7 +20,11 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; -@Slf4j +/** + * @since 4.0 + * @author Anindya Chatterjee + */ +@Slf4j(topic = "nitrite-rocksdb") public class RocksDBMap implements NitriteMap { private final String mapName; private final RocksDBReference reference; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModule.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModule.java index acca1b5c3..cb6d8934e 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModule.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModule.java @@ -10,24 +10,55 @@ import static org.dizitart.no2.common.util.Iterables.setOf; +/** + * A Nitrite store module that provides a RocksDB implementation of the + * NitriteStore interface. + * + * @since 4.0 + * @see NitriteStore + * @see StoreModule + * @author Anindya Chatterjee + */ public class RocksDBModule implements StoreModule { @Setter(AccessLevel.PACKAGE) + /** + * The RocksDB configuration for the Nitrite database store. + */ private RocksDBConfig storeConfig; + /** + * Instantiates a new RocksDB module. + */ public RocksDBModule(String path) { this.storeConfig = new RocksDBConfig(); this.storeConfig.filePath(path); } + /** + * Returns a set of Nitrite plugins. + * + * @return a set of Nitrite plugins. + */ @Override public Set plugins() { return setOf(getStore()); } + /** + * Returns a new instance of {@link RocksDBModuleBuilder} to build a + * {@link RocksDBModule} with custom configuration. + * + * @return a new instance of {@link RocksDBModuleBuilder}. + */ public static RocksDBModuleBuilder withConfig() { return new RocksDBModuleBuilder(); } + /** + * Returns a new instance of {@link NitriteStore} backed by RocksDB. + * + * @return a new instance of {@link NitriteStore} backed by RocksDB. + */ public NitriteStore getStore() { RocksDBStore store = new RocksDBStore(); store.setStoreConfig(storeConfig); diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModuleBuilder.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModuleBuilder.java index 8de08a377..20f9def6b 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModuleBuilder.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBModuleBuilder.java @@ -31,17 +31,39 @@ import java.util.Set; /** + * A builder class to create a RocksDBModule instance with the desired configuration. + * + * @since 4.0 + * @see RocksDBModule * @author Anindya Chatterjee */ @Getter @Setter @Accessors(fluent = true) public class RocksDBModuleBuilder { + /** + * The file path of the RocksDB data store. + */ private String filePath; + /** + * The RocksDB {@link Options} used by the module builder. + */ private Options options; + /** + * The RocksDB {@link DBOptions} used by the module builder. + */ private DBOptions dbOptions; + /** + * The RocksDB {@link ColumnFamilyOptions} used by the module builder. + */ private ColumnFamilyOptions columnFamilyOptions; + /** + * The object formatter used to serialize and deserialize objects. + */ private ObjectFormatter objectFormatter; + /** + * The RocksDB configuration for the module. + */ private RocksDBConfig dbConfig; @Setter(AccessLevel.NONE) @@ -52,6 +74,12 @@ public class RocksDBModuleBuilder { eventListeners = new HashSet<>(); } + /** + * Sets the file path for the RocksDB data store. + * + * @param file the file path for the RocksDB data store. + * @return the {@link RocksDBModuleBuilder} instance. + */ public RocksDBModuleBuilder filePath(File file) { if (file != null) { this.filePath = file.getPath(); @@ -59,16 +87,33 @@ public RocksDBModuleBuilder filePath(File file) { return this; } + /** + * Sets the file path for the RocksDB data store. + * + * @param path the file path for the RocksDB data store. + * @return the current {@link RocksDBModuleBuilder} instance. + */ public RocksDBModuleBuilder filePath(String path) { this.filePath = path; return this; } + /** + * Adds a {@link StoreEventListener} to the module builder. + * + * @param listener the listener to add + * @return the {@link RocksDBModuleBuilder} instance + */ public RocksDBModuleBuilder addStoreEventListener(StoreEventListener listener) { eventListeners.add(listener); return this; } + /** + * Builds a {@link RocksDBModule} with the specified configuration. + * + * @return the {@link RocksDBModule} instance. + */ public RocksDBModule build() { RocksDBModule module = new RocksDBModule(filePath()); diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBRTree.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBRTree.java index 0c2534059..0f760ca83 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBRTree.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBRTree.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** + * @since 4.0 * @author Anindya Chatterjee */ public class RocksDBRTree implements NitriteRTree { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBReference.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBReference.java index 3bdd886e2..66414c6f6 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBReference.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBReference.java @@ -30,9 +30,10 @@ import java.util.concurrent.ConcurrentHashMap; /** + * @since 4.0 * @author Anindya Chatterjee */ -@Slf4j +@Slf4j(topic = "nitrite-rocksdb") @Getter @Setter public class RocksDBReference implements AutoCloseable { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStore.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStore.java index 7cb929c91..15f823a43 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStore.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStore.java @@ -18,7 +18,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -@Slf4j +/** + * @since 4.0 + * @author Anindya Chatterjee + */ +@Slf4j(topic = "nitrite-rocksdb") public class RocksDBStore extends AbstractNitriteStore { private final AtomicBoolean closed; private final Map> nitriteMapRegistry; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStoreUtils.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStoreUtils.java index 7b071c64c..62b7aa950 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStoreUtils.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBStoreUtils.java @@ -1,11 +1,13 @@ package org.dizitart.no2.rocksdb; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.exceptions.InvalidOperationException; import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; -@Slf4j +/** + * @since 4.0 + * @author Anindya Chatterjee + */ class RocksDBStoreUtils { private RocksDBStoreUtils() { } diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/StoreFactory.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/StoreFactory.java index a7f86e175..0a4a5ad5a 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/StoreFactory.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/StoreFactory.java @@ -28,9 +28,10 @@ import java.util.concurrent.ConcurrentHashMap; /** + * @since 4.0 * @author Anindya Chatterjee */ -@Slf4j(topic = "no2-rocksdb") +@Slf4j(topic = "nitrite-rocksdb") class StoreFactory { private StoreFactory() { } diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/ValueSet.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/ValueSet.java index 3916a5e1d..50a316937 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/ValueSet.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/ValueSet.java @@ -10,6 +10,10 @@ import static org.dizitart.no2.rocksdb.Constants.CLEANER; +/** + * @since 4.0 + * @author Anindya Chatterjee + */ class ValueSet implements Iterable { private final ObjectFormatter objectFormatter; private final RocksDB rocksDB; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ComparableKeySerializer.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ComparableKeySerializer.java index 747571769..c24c6c751 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ComparableKeySerializer.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ComparableKeySerializer.java @@ -6,6 +6,7 @@ import com.esotericsoftware.kryo.kryo5.io.Output; /** + * @since 4.0 * @author Anindya Chatterjee */ public abstract class ComparableKeySerializer> extends KryoKeySerializer { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultJavaSerializers.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultJavaSerializers.java index 6dc8ca5bd..3091d0092 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultJavaSerializers.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultJavaSerializers.java @@ -8,6 +8,7 @@ import java.util.UUID; /** + * @since 4.0 * @author Anindya Chatterjee */ public class DefaultJavaSerializers { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultTimeKeySerializers.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultTimeKeySerializers.java index 097817233..172d413fc 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultTimeKeySerializers.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/DefaultTimeKeySerializers.java @@ -13,6 +13,7 @@ import java.util.Locale; /** + * @since 4.0 * @author Anindya Chatterjee */ class DefaultTimeKeySerializers { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoKeySerializer.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoKeySerializer.java index a9a594f3a..5d9c34b54 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoKeySerializer.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoKeySerializer.java @@ -7,6 +7,7 @@ import com.esotericsoftware.kryo.kryo5.io.Output; /** + * @since 4.0 * @author Anindya Chatterjee */ public abstract class KryoKeySerializer extends Serializer { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoObjectFormatter.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoObjectFormatter.java index 29d1a392c..58b33ca1b 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoObjectFormatter.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/KryoObjectFormatter.java @@ -34,9 +34,10 @@ import static org.dizitart.no2.rocksdb.Constants.DB_NULL; /** + * @since 4.0 * @author Anindya Chatterjee */ -@Slf4j +@Slf4j(topic = "nitrite-rocksdb") public class KryoObjectFormatter implements ObjectFormatter { private static final Kryo kryo = new Kryo(); private final Map, KryoKeySerializer> keySerializerRegistry; diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/NitriteSerializers.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/NitriteSerializers.java index d570520a8..acc1cdc73 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/NitriteSerializers.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/NitriteSerializers.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** + * @since 4.0 * @author Anindya Chatterjee */ public class NitriteSerializers { diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ObjectFormatter.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ObjectFormatter.java index 8f6a8cd30..82863e498 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ObjectFormatter.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/formatter/ObjectFormatter.java @@ -16,13 +16,50 @@ package org.dizitart.no2.rocksdb.formatter; + /** + * An interface to define methods for encoding and decoding objects and their + * keys. + * + * @since 4.0 * @author Anindya Chatterjee */ public interface ObjectFormatter { + /** + * Encodes an object into a byte array. + * + * @param object the object to encode + * @param the type of the object + * @return the byte array representing the encoded object + */ byte[] encode(T object); + + /** + * Encodes an object's key into a byte array. + * + * @param object the object whose key to encode + * @param the type of the object + * @return the byte array representing the encoded key + */ byte[] encodeKey(T object); + /** + * Decodes a byte array into an object of the specified type. + * + * @param bytes the byte array to decode + * @param type the type of the object to decode + * @param the type of the object + * @return the decoded object + */ T decode(byte[] bytes, Class type); + + /** + * Decodes a byte array into an object's key of the specified type. + * + * @param bytes the byte array to decode + * @param type the type of the object's key to decode + * @param the type of the object's key + * @return the decoded object's key + */ T decodeKey(byte[] bytes, Class type); } diff --git a/nitrite-spatial/pom.xml b/nitrite-spatial/pom.xml index d269889f7..f2cbe47fc 100644 --- a/nitrite-spatial/pom.xml +++ b/nitrite-spatial/pom.xml @@ -85,6 +85,14 @@ org.apache.maven.plugins maven-javadoc-plugin + + + org.dizitart.no2.spatial.mapper, + + + **/*GeometryUtils.java + + org.apache.maven.plugins diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/FluentFilter.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/FluentFilter.java index bf6a2bf11..5d5833ff7 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/FluentFilter.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/FluentFilter.java @@ -21,11 +21,12 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Point; + /** - * Fluent filter api for spatial data - * + * A fluent filter api for spatial queries. + * + * @since 4.0 * @author Anindya Chatterjee - * @since 4.0.0 */ public class FluentFilter { private String field; @@ -34,10 +35,10 @@ private FluentFilter() { } /** - * Where clause for fluent filter. + * Creates a new {@link FluentFilter} instance with the specified field. * - * @param field the field - * @return the fluent filter + * @param field the field to filter on + * @return the new {@link FluentFilter} instance */ public static FluentFilter where(String field) { FluentFilter filter = new FluentFilter(); @@ -49,8 +50,8 @@ public static FluentFilter where(String field) { * Creates a spatial filter which matches documents where the spatial data * of a field intersects the specified {@link Geometry} value. * - * @param geometry the geometry - * @return the filter + * @param geometry the geometry to intersect with + * @return the new {@link Filter} instance */ public Filter intersects(Geometry geometry) { return new IntersectsFilter(field, geometry); @@ -60,8 +61,8 @@ public Filter intersects(Geometry geometry) { * Creates a spatial filter which matches documents where the spatial data * of a field is within the specified {@link Geometry} value. * - * @param geometry the geometry - * @return the filter + * @param geometry the geometry to check for containment within + * @return the new {@link Filter} instance */ public Filter within(Geometry geometry) { return new WithinFilter(field, geometry); @@ -71,9 +72,9 @@ public Filter within(Geometry geometry) { * Creates a spatial filter which matches documents where the spatial data * of a field is near the specified coordinate. * - * @param point the point - * @param distance the distance - * @return the filter + * @param point the coordinate to check proximity to + * @param distance the maximum distance to consider + * @return the new {@link Filter} instance */ public Filter near(Coordinate point, Double distance) { return new NearFilter(field, point, distance); @@ -83,9 +84,9 @@ public Filter near(Coordinate point, Double distance) { * Creates a spatial filter which matches documents where the spatial data * of a field is near the specified point. * - * @param point the point - * @param distance the distance - * @return the filter + * @param point the point to check proximity to + * @param distance the maximum distance to consider + * @return the new {@link Filter} instance */ public Filter near(Point point, Double distance) { return new NearFilter(field, point, distance); diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/GeometryUtils.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/GeometryUtils.java index 0ec577d71..f414ca8c7 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/GeometryUtils.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/GeometryUtils.java @@ -23,6 +23,10 @@ import org.locationtech.jts.io.WKTReader; import org.locationtech.jts.io.WKTWriter; +/** + * @since 4.0 + * @author Anindya Chatterjee + */ public class GeometryUtils { private static final String GEOMETRY_ID = "geometry:"; private static WKTWriter writer; diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/NitriteBoundingBox.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/NitriteBoundingBox.java index f8249b568..77acc4a52 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/NitriteBoundingBox.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/NitriteBoundingBox.java @@ -26,7 +26,6 @@ import java.io.ObjectOutputStream; /** - * * @since 4.0 * @author Anindya Chatterjee */ diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialFilter.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialFilter.java index d42853e52..c437f36c0 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialFilter.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialFilter.java @@ -23,9 +23,14 @@ import org.locationtech.jts.geom.Geometry; /** - * Represents a spatial filter. - * - * @since 4.0.0 + * The abstract base class for all spatial filters in Nitrite. + *

+ * A spatial filter is used to query Nitrite database for documents that have a specific spatial relationship + * with a given geometry. It extends {@link IndexOnlyFilter} and provides an implementation for the + * {@link #supportedIndexType()} method. + *

+ * + * @since 4.0 * @author Anindya Chatterjee */ public abstract class SpatialFilter extends IndexOnlyFilter { @@ -42,6 +47,11 @@ protected SpatialFilter(String field, Geometry geometry) { this.geometry = geometry; } + /** + * Returns the geometry value of this filter. + * + * @return the geometry value of this filter. + */ @Override public Geometry getValue() { return geometry; diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndex.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndex.java index 303155ae8..eec76b6f9 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndex.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndex.java @@ -43,7 +43,7 @@ /** * Represents a spatial index in nitrite. * - * @since 4.0.0 + * @since 4.0 * @author Anindya Chatterjee */ public class SpatialIndex implements NitriteIndex { diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndexer.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndexer.java index f39c50a1f..9f45b440c 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndexer.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialIndexer.java @@ -30,14 +30,18 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Represents a spatial data indexer. - * + * The {@code SpatialIndexer} class implements the {@link NitriteIndexer} + * interface and provides support for creating and managing spatial + * indexes in Nitrite database. It uses the {@link SpatialIndex} class to create + * and manage the indexes. + * + * @since 4.0 * @author Anindya Chatterjee - * @since 4.0.0 */ public class SpatialIndexer implements NitriteIndexer { /** - * Spatial index type. + * The name of the spatial index type. To be used while creating a spatial + * index. */ public static final String SPATIAL_INDEX = "Spatial"; private final Map indexRegistry; @@ -74,7 +78,8 @@ public void writeIndexEntry(FieldValues fieldValues, IndexDescriptor indexDescri } @Override - public void removeIndexEntry(FieldValues fieldValues, IndexDescriptor indexDescriptor, NitriteConfig nitriteConfig) { + public void removeIndexEntry(FieldValues fieldValues, IndexDescriptor indexDescriptor, + NitriteConfig nitriteConfig) { SpatialIndex spatialIndex = findSpatialIndex(indexDescriptor, nitriteConfig); spatialIndex.remove(fieldValues); } diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialModule.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialModule.java index aa07b5f33..f91f3c185 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialModule.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/SpatialModule.java @@ -23,15 +23,23 @@ import static org.dizitart.no2.common.util.Iterables.setOf; + /** - * A nitrite module to enable spatial data indexing. - * - * @since 4.0.0 + * A Nitrite module for spatial indexing. This module provides a + * {@link SpatialIndexer} plugin for Nitrite database. + * + * @since 4.0 * @author Anindya Chatterjee */ public class SpatialModule implements NitriteModule { private SpatialIndexer spatialIndexer; + /** + * {@inheritDoc} + * Returns a set of Nitrite plugins, which includes the SpatialIndexer. + * + * @return a set of Nitrite plugins, which includes the SpatialIndexer. + */ @Override public Set plugins() { if (spatialIndexer == null) { diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryDeserializer.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryDeserializer.java index e9288f867..105b9791b 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryDeserializer.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryDeserializer.java @@ -19,16 +19,15 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.spatial.GeometryUtils; import org.locationtech.jts.geom.Geometry; import java.io.IOException; /** + * @since 4.0 * @author Anindya Chatterjee */ -@Slf4j class GeometryDeserializer extends StdScalarDeserializer { protected GeometryDeserializer() { diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryModule.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryModule.java index 74ffac9be..c6870681f 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryModule.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometryModule.java @@ -20,10 +20,8 @@ import org.locationtech.jts.geom.Geometry; /** - * Class that registers capability of serializing {@link Geometry} objects with the Jackson core. - * * @author Anindya Chatterjee - * @since 4.0.0 + * @since 4.0 */ public class GeometryModule extends SimpleModule { diff --git a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometrySerializer.java b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometrySerializer.java index dbb9c7b44..a959d6047 100644 --- a/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometrySerializer.java +++ b/nitrite-spatial/src/main/java/org/dizitart/no2/spatial/mapper/GeometrySerializer.java @@ -25,6 +25,7 @@ import java.io.IOException; /** + * @since 4.0 * @author Anindya Chatterjee */ class GeometrySerializer extends StdScalarSerializer { diff --git a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java index 1116a7752..cf3946800 100644 --- a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java +++ b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialViewer.java @@ -28,7 +28,7 @@ /** * @author Anindya Chatterjee */ -@Slf4j +@Slf4j(topic = "nitrite-spatial") public class SpatialViewer { public static void main(String[] args) { JFrame f = new JFrame(); diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index 5b0981e70..13257affc 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -91,6 +91,11 @@ org.apache.maven.plugins maven-javadoc-plugin + + + **/*Exporter.java + + org.apache.maven.plugins diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java index 4d8ba6975..81e575e37 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/AESEncryptor.java @@ -30,12 +30,19 @@ import java.nio.charset.StandardCharsets; /** - * A password based AES string encryption utility. - * + * The {@code AESEncryptor} class provides AES encryption and decryption + * functionality. *
- * + * It uses AES/GCM/NoPadding encryption algorithm with a 128-bit tag length, + * 12-byte IV length, and 16-byte salt length by default. + *

+ * The class provides methods to encrypt and decrypt byte arrays and strings + * using the specified password and encryption parameters. + *

+ * + * NOTE: This is a derivative work of this. + * * @author Anindya Chatterjee * @since 4.0 */ @@ -50,12 +57,12 @@ public class AESEncryptor implements Encryptor { /** * Instantiates a new {@link AESEncryptor} with these default values - *

    - *
  • Encryption Algo - AES/GCM/NoPadding
  • - *
  • Tag Length (bit) - 128
  • - *
  • IV Length (byte) - 12
  • - *
  • Salt Length (byte) - 16
  • - *
+ *
    + *
  • Encryption Algo - AES/GCM/NoPadding
  • + *
  • Tag Length (bit) - 128
  • + *
  • IV Length (byte) - 12
  • + *
  • Salt Length (byte) - 16
  • + *
* * @param password the password */ @@ -73,8 +80,8 @@ public AESEncryptor(String password) { * @param saltLengthByte the salt length byte */ public AESEncryptor(String password, String encryptionAlgo, - Integer tagLengthBit, Integer ivLengthByte, - Integer saltLengthByte) { + Integer tagLengthBit, Integer ivLengthByte, + Integer saltLengthByte) { this.password = new SecureString(password); this.encryptAlgo = encryptionAlgo; this.tagLengthBit = tagLengthBit; @@ -109,10 +116,10 @@ public String encrypt(byte[] plainText) { // prefix IV and Salt to cipher text byte[] cipherTextWithIvSalt = ByteBuffer.allocate(iv.length + salt.length + cipherText.length) - .put(iv) - .put(salt) - .put(cipherText) - .array(); + .put(iv) + .put(salt) + .put(cipherText) + .array(); // string representation, base64, send this string to other for decryption. return Base64.encodeBase64URLSafeString(cipherTextWithIvSalt); @@ -125,8 +132,9 @@ public String encrypt(byte[] plainText) { * Returns the decrypted string encoded by AES. * *

- * NOTE: The same password, salt and iv are needed to decrypt it. + * NOTE: The same password, salt and iv are needed to decrypt it. *

+ * * @param encryptedText the encrypted text * @return the plain text decrypted string */ diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java index 01454a38f..7c39d6490 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/crypto/Encryptor.java @@ -18,25 +18,25 @@ package org.dizitart.no2.support.crypto; /** - * Represents a symmetric key string encryptor. - * + * The Encryptor interface provides methods to encrypt and decrypt plain text. + * * @author Anindya Chatterjee * @since 4.0 */ public interface Encryptor { /** - * Returns a base64 encoded encrypted string. + * Encrypts the given plain text using the encryption algorithm. * - * @param plainText the plain text - * @return the encrypted string + * @param plainText the plain text to be encrypted + * @return the encrypted text */ String encrypt(byte[] plainText); /** - * Returns the decrypted string, encoded by this encryptor. + * Decrypts the given encrypted text. * - * @param encryptedText the encrypted text - * @return the string + * @param encryptedText the encrypted text to decrypt + * @return the decrypted text */ String decrypt(String encryptedText); } diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java index 9a663820b..ede9cab64 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ExportOptions.java @@ -14,119 +14,138 @@ * limitations under the License. */ - package org.dizitart.no2.support.exchange; +package org.dizitart.no2.support.exchange; - import com.fasterxml.jackson.core.JsonFactory; - import lombok.Getter; - import lombok.Setter; - - import java.util.*; - - /** - * Represents export options. - * - * @author Anindya Chatterjee - * @see Exporter - * @since 1.0 - */ - @Getter - @Setter - public class ExportOptions { - /** - * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This - * instance will be used to export the collections and data. - *

- * This is a mandatory field. If not specified, the export operation will fail. - * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so - * the database must not be open elsewhere. Upon completion of the export operation, the - * {@link org.dizitart.no2.Nitrite} instance will be closed. - * - * @param nitriteFactory the nitriteFactory. - * @return the nitriteFactory. - */ - private NitriteFactory nitriteFactory; - - /** - * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. - * This instance will be used to write the export data to a file. - *

- * This is an optional field. If not specified, a default one will be created. - * - * @param jsonFactory the jsonFactory. - * @return the jsonFactory. - */ - private JsonFactory jsonFactory; - - /** - * Indicates if the export operation exports indices information. - *

- * If `true`, the export operation will export indices information. If `false`, the export - * operation will not export indices information. - *

- * This is an optional field. If not specified, it will be set to `true`. - * - * @param exportIndices a value indicating if indices information will be exported. - * @return `true` if indices information is exported; otherwise, `false`. - */ - private boolean exportIndices = true; - - /** - * Indicates if the export operation exports collection data. - *

- * If `true`, the export operation will export collection data. If `false`, the export - * operation will not export collection data. - *

- * This is an optional field. If not specified, it will be set to `true`. - * - * @param exportData a value indicating if collection data will be exported. - * @return `true` if collection data is exported; otherwise, `false`. - */ - private boolean exportData = true; - - /** - * Specifies a list of {@link org.dizitart.no2.collection.NitriteCollection} names to be exported. - *

- * - * Please see the rules for specifying the collections to be exported - *

    - *
  • If null is specified, all collections will be exported
  • - *
  • If an empty list is specified, no collection will be exported
  • - *
  • If a non-empty list is specified, only the collections in the list will be exported
  • - *
- * - * @param collections list of all collection names to be exported. - * @return list of collection names. - */ - private List collections; - - /** - * Specifies a list of {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. - *

- * Please see the rules for specifying the repositories to be exported - *

    - *
  • If null is specified, all repositories will be exported
  • - *
  • If an empty list is specified, no repositories will be exported
  • - *
  • If a non-empty list is specified, only the repositories in the list will be exported
  • - *
- * - * @param repositories list of all repositories names to be exported. - * @return list of repositories names. - */ - private List repositories; - - /** - * Specifies a list of keyed {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. - *

- * Please see the rules for specifying the keyed-repositories to be exported - *

    - *
  • If null is specified, all keyed-repositories will be exported
  • - *
  • If an empty map is specified, no keyed-repositories will be exported
  • - *
  • If a non-empty map is specified, only the keyed-repositories in the map will be exported
  • - *
- * - * @param keyedRepositories list of all keyed repositories names to be exported. - * @return list of keyed repositories names. - */ - private Map> keyedRepositories; - } - \ No newline at end of file +import com.fasterxml.jackson.core.JsonFactory; +import lombok.Getter; +import lombok.Setter; + +import java.util.*; + +/** + * The options used for exporting Nitrite database collections and data. + * + * @author Anindya Chatterjee + * @see Exporter + * @since 1.0 + */ +@Getter +@Setter +public class ExportOptions { + /** + * Specifies a {@link NitriteFactory} to create a + * {@link org.dizitart.no2.Nitrite} instance. This instance will be used to + * export the collections and data. + *

+ * The {@link NitriteFactory} instance must be able to create a + * {@link org.dizitart.no2.Nitrite}, so the database must not be open elsewhere. + * Upon completion of the export operation, the {@link org.dizitart.no2.Nitrite} + * instance will be closed. + * + *

+ * NOTE: This is a mandatory field. If not specified, the export operation will + * fail. + * + * @param nitriteFactory the nitriteFactory. + * @return the nitriteFactory. + */ + private NitriteFactory nitriteFactory; + + /** + * Specifies a {@link JsonFactory} to create a + * {@link com.fasterxml.jackson.core.JsonGenerator} instance. + * This instance will be used to write the export data to a file. + *

+ * NOTE: This is an optional field. If not specified, a default one will be + * created. + * + * @param jsonFactory the jsonFactory. + * @return the jsonFactory. + */ + private JsonFactory jsonFactory; + + /** + * Indicates if the export operation exports indices information. + *

+ * If true, the export operation will export indices information. + * If false, the export operation will not export indices + * information. + *

+ * This is an optional field. If not specified, it will be set to + * true. + * + * @param exportIndices a value indicating if indices information will be + * exported. + * @return true if indices information is exported; otherwise, + * false. + */ + private boolean exportIndices = true; + + /** + * Indicates if the export operation exports collection data. + *

+ * If true, the export operation will export collection data. If + * false, the export operation will not export collection data. + *

+ * This is an optional field. If not specified, it will be set to + * true. + * + * @param exportData a value indicating if collection data will be exported. + * @return true if collection data is exported; otherwise, + * false. + */ + private boolean exportData = true; + + /** + * Specifies a list of {@link org.dizitart.no2.collection.NitriteCollection} + * names to be exported. + *

+ * + * The rules for specifying the collections to be exported as follows: + *

    + *
  • If null is specified, all collections will be exported
  • + *
  • If an empty list is specified, no collection will be exported
  • + *
  • If a non-empty list is specified, only the collections in the list will + * be exported
  • + *
+ * + * @param collections list of all collection names to be exported. + * @return list of collection names. + */ + private List collections; + + /** + * Specifies a list of {@link org.dizitart.no2.repository.ObjectRepository} + * names to be exported. + *

+ * The rules for specifying the repositories to be exported as follows: + *

    + *
  • If null is specified, all repositories will be exported
  • + *
  • If an empty list is specified, no repositories will be exported
  • + *
  • If a non-empty list is specified, only the repositories in the list will + * be exported
  • + *
+ * + * @param repositories list of all repositories names to be exported. + * @return list of repositories names. + */ + private List repositories; + + /** + * Specifies a list of keyed + * {@link org.dizitart.no2.repository.ObjectRepository} names to be exported. + *

+ * The rules for specifying the keyed-repositories to be exported as + * follows: + *

    + *
  • If null is specified, all keyed-repositories will be exported
  • + *
  • If an empty map is specified, no keyed-repositories will be exported
  • + *
  • If a non-empty map is specified, only the keyed-repositories in the map + * will be exported
  • + *
+ * + * @param keyedRepositories list of all keyed repositories names to be exported. + * @return list of keyed repositories names. + */ + private Map> keyedRepositories; +} diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java index d26605873..12ca97db3 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Exporter.java @@ -14,142 +14,147 @@ * limitations under the License. */ - package org.dizitart.no2.support.exchange; - - import com.fasterxml.jackson.annotation.JsonAutoDetect; - import com.fasterxml.jackson.core.JsonGenerator; - import com.fasterxml.jackson.core.JsonParser; - import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; - import com.fasterxml.jackson.databind.DeserializationFeature; - import com.fasterxml.jackson.databind.ObjectMapper; - import org.dizitart.no2.exceptions.NitriteIOException; - - import java.io.*; - - import static org.dizitart.no2.common.util.ValidationUtils.notNull; - - - /** - * Nitrite database export utility. It exports data to - * a json file. Contents of a Nitrite database can be exported - * using this tool. - *

- * - * @author Anindya Chatterjee - * @since 1.0 - */ - public class Exporter { - private ExportOptions options; - - private Exporter() { - } - - /** - * Creates an Exporter instance with the specified export options. - * - * @param exportOptions the export options to be set - * (must not be null and must have a valid nitrite factory) - * - * @return the Exporter instance with the specified export options - */ - public static Exporter withOptions(ExportOptions exportOptions) { - Exporter exporter = new Exporter(); - notNull(exportOptions, "exportOptions cannot be null"); - notNull(exportOptions.getNitriteFactory(), "nitriteFactory cannot be null"); - - if (exportOptions.getJsonFactory() == null) { - exportOptions.setJsonFactory(createObjectMapper().getFactory()); - } - - exporter.options = exportOptions; - return exporter; - } - - public static ObjectMapper createObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.setVisibility( - objectMapper.getSerializationConfig().getDefaultVisibilityChecker() - .withFieldVisibility(JsonAutoDetect.Visibility.ANY) - .withGetterVisibility(JsonAutoDetect.Visibility.NONE) - .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); - return objectMapper; - } - - /** - * Exports data to a file. - * - * @param file the file - */ - public void exportTo(String file) { - exportTo(new File(file)); - } - - /** - * Exports data to a {@link File}. - * - * @param file the file - * @throws NitriteIOException if there is any low-level I/O error. - */ - public void exportTo(File file) { - try { - if (file.isDirectory()) { - throw new IOException(file.getPath() + " is not a file"); - } - - File parent = file.getParentFile(); - // if parent dir does not exist, try to create it - if (!parent.exists()) { - boolean result = parent.mkdirs(); - if (!result) { - throw new IOException("Failed to create parent directory " + parent.getPath()); - } - } - try (FileOutputStream outputStream = new FileOutputStream(file)) { - exportTo(outputStream); - } - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while writing content to file " + file, ioe); - } - } - - /** - * Exports data to an {@link OutputStream}. - * - * @param stream the stream - */ - public void exportTo(OutputStream stream) throws IOException { - try(OutputStreamWriter writer = new OutputStreamWriter(stream)) { - exportTo(writer); - } - } - - /** - * Exports data to a {@link Writer}. - * - * @param writer the writer - * @throws NitriteIOException if there is any error while writing the data. - */ - public void exportTo(Writer writer) { - JsonGenerator generator; - try { - generator = options.getJsonFactory().createGenerator(writer); - generator.setPrettyPrinter(new DefaultPrettyPrinter()); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while writing data with writer", ioe); - } - - NitriteJsonExporter jsonExporter = new NitriteJsonExporter(); - jsonExporter.setGenerator(generator); - jsonExporter.setOptions(options); - try { - jsonExporter.exportData(); - } catch (IOException | ClassNotFoundException e) { - throw new NitriteIOException("Error while exporting data", e); - } - } - } - \ No newline at end of file +package org.dizitart.no2.support.exchange; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.dizitart.no2.exceptions.NitriteIOException; + +import java.io.*; + +import static org.dizitart.no2.common.util.ValidationUtils.notNull; + +/** + * The Exporter class provides methods to export Nitrite database data to a file + * or an output stream in JSON format. + *

+ * It uses the provided ExportOptions to configure the export process. + * + * @author Anindya Chatterjee + * @since 1.0 + */ +public class Exporter { + private ExportOptions options; + + private Exporter() { + } + + /** + * Creates an Exporter instance with the specified export options. + * + * @param exportOptions the export options to be set + * (must not be null and must have a valid nitrite factory) + * + * @return the Exporter instance with the specified export options + */ + public static Exporter withOptions(ExportOptions exportOptions) { + Exporter exporter = new Exporter(); + notNull(exportOptions, "exportOptions cannot be null"); + notNull(exportOptions.getNitriteFactory(), "nitriteFactory cannot be null"); + + if (exportOptions.getJsonFactory() == null) { + exportOptions.setJsonFactory(createObjectMapper().getFactory()); + } + + exporter.options = exportOptions; + return exporter; + } + + /** + * Creates and returns an instance of ObjectMapper with custom configurations. + * + * @return an instance of ObjectMapper with custom configurations. + */ + public static ObjectMapper createObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.setVisibility( + objectMapper.getSerializationConfig().getDefaultVisibilityChecker() + .withFieldVisibility(JsonAutoDetect.Visibility.ANY) + .withGetterVisibility(JsonAutoDetect.Visibility.NONE) + .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); + return objectMapper; + } + + /** + * Exports the data to the specified file. + * + * @param file the file to export the data to + */ + public void exportTo(String file) { + exportTo(new File(file)); + } + + /** + * Exports the content to the specified file. + * + * @param file the file to export the content to + * @throws NitriteIOException if there is an I/O error while writing content to the file + */ + public void exportTo(File file) { + try { + if (file.isDirectory()) { + throw new IOException(file.getPath() + " is not a file"); + } + + File parent = file.getParentFile(); + // if parent dir does not exist, try to create it + if (!parent.exists()) { + boolean result = parent.mkdirs(); + if (!result) { + throw new IOException("Failed to create parent directory " + parent.getPath()); + } + } + try (FileOutputStream outputStream = new FileOutputStream(file)) { + exportTo(outputStream); + } + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while writing content to file " + file, ioe); + } + } + + /** + * Exports the data to the specified output stream. + * + * @param stream the output stream to export the data to + * @throws IOException if an I/O error occurs + */ + public void exportTo(OutputStream stream) throws IOException { + try (OutputStreamWriter writer = new OutputStreamWriter(stream)) { + exportTo(writer); + } + } + + /** + * Exports the data to the specified writer using JSON format. + * + * @param writer the writer to export the data to + * @throws NitriteIOException if there is an I/O error while writing data with writer + * @throws NitriteIOException if there is an error while exporting data + */ + public void exportTo(Writer writer) { + JsonGenerator generator; + try { + generator = options.getJsonFactory().createGenerator(writer); + generator.setPrettyPrinter(new DefaultPrettyPrinter()); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while writing data with writer", ioe); + } + + NitriteJsonExporter jsonExporter = new NitriteJsonExporter(); + jsonExporter.setGenerator(generator); + jsonExporter.setOptions(options); + try { + jsonExporter.exportData(); + } catch (IOException | ClassNotFoundException e) { + throw new NitriteIOException("Error while exporting data", e); + } + } +} diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java index 7ed1be5e9..c05f67f0f 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/ImportOptions.java @@ -5,8 +5,8 @@ import lombok.Setter; /** - * Represents import options. - * + * The options for importing collections and data into a Nitrite database. + * * @author Anindya Chatterjee * @see Importer * @since 4.0 @@ -15,13 +15,18 @@ @Setter public class ImportOptions { /** - * Specifies a {@link NitriteFactory} to create a {@link org.dizitart.no2.Nitrite} instance. This - * instance will be used to import the collections and data. + * Specifies a {@link NitriteFactory} to create a + * {@link org.dizitart.no2.Nitrite} instance. This instance will be used to + * export the collections and data. *

- * This is a mandatory field. If not specified, the import operation will fail. - * The {@link NitriteFactory} instance must be able to create a {@link org.dizitart.no2.Nitrite}, so - * the database must not be open elsewhere. Upon completion of the import operation, the - * {@link org.dizitart.no2.Nitrite} instance will be closed. + * The {@link NitriteFactory} instance must be able to create a + * {@link org.dizitart.no2.Nitrite}, so the database must not be open elsewhere. + * Upon completion of the import operation, the {@link org.dizitart.no2.Nitrite} + * instance will be closed. + * + *

+ * NOTE: This is a mandatory field. If not specified, the import operation will + * fail. * * @param nitriteFactory the nitriteFactory. * @return the nitriteFactory. @@ -29,7 +34,8 @@ public class ImportOptions { private NitriteFactory nitriteFactory; /** - * Specifies a {@link JsonFactory} to create a {@link com.fasterxml.jackson.core.JsonGenerator} instance. + * Specifies a {@link JsonFactory} to create a + * {@link com.fasterxml.jackson.core.JsonGenerator} instance. * This instance will be used to read the exported data from a file. *

* This is an optional field. If not specified, a default one will be created. diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java index 2255b31b4..d2bd2ff11 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/Importer.java @@ -14,109 +14,110 @@ * limitations under the License. */ - package org.dizitart.no2.support.exchange; +package org.dizitart.no2.support.exchange; - import com.fasterxml.jackson.core.JsonParser; - import org.dizitart.no2.exceptions.NitriteIOException; - - import java.io.*; - - import static org.dizitart.no2.common.util.ValidationUtils.notNull; - import static org.dizitart.no2.support.exchange.Exporter.createObjectMapper; - - - /** - * Nitrite database import utility. It imports data from - * a json file. Contents of a Nitrite database can be imported - * using this tool. - *

- * - * @author Anindya Chatterjee - * @since 1.0 - */ - public class Importer { - private ImportOptions options; - - private Importer() { - } - - /** - * Creates a new Importer with specified ImportOptions. - * - * @param importOptions The ImportOptions to be used. - * @return A new Importer object. - */ - public static Importer withOptions(ImportOptions importOptions) { - Importer importer = new Importer(); - notNull(importOptions, "importOptions cannot be null"); - notNull(importOptions.getNitriteFactory(), "nitriteFactory cannot be null"); - - if (importOptions.getJsonFactory() == null) { - importOptions.setJsonFactory(createObjectMapper().getFactory()); - } - - importer.options = importOptions; - return importer; - } - - /** - * Imports data from a file path. - * - * @param file the file path - */ - public void importFrom(String file) { - importFrom(new File(file)); - } - - /** - * Imports data from a file. - * - * @param file the file - * @throws NitriteIOException if there is any low-level I/O error. - */ - public void importFrom(File file) { - try (FileInputStream stream = new FileInputStream(file)) { - importFrom(stream); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while reading content from file " + file, ioe); - } - } - - /** - * Imports data from an {@link InputStream}. - * - * @param stream the stream - */ - public void importFrom(InputStream stream) throws IOException { - try(InputStreamReader reader = new InputStreamReader(stream)) { - importFrom(reader); - } - } - - /** - * Imports data from a {@link Reader}. - * - * @param reader the reader - * @throws NitriteIOException if there is any error while reading the data. - */ - public void importFrom(Reader reader) { - JsonParser parser; - try { - parser = options.getJsonFactory().createParser(reader); - } catch (IOException ioe) { - throw new NitriteIOException("I/O error while creating parser from reader", ioe); - } - - if (parser != null) { - NitriteJsonImporter jsonImporter = new NitriteJsonImporter(); - jsonImporter.setParser(parser); - jsonImporter.setOptions(options); - try { - jsonImporter.importData(); - } catch (IOException | ClassNotFoundException e) { - throw new NitriteIOException("Error while importing data", e); - } - } - } - } - \ No newline at end of file +import com.fasterxml.jackson.core.JsonParser; +import org.dizitart.no2.exceptions.NitriteIOException; +import org.dizitart.no2.exceptions.ValidationException; + +import java.io.*; + +import static org.dizitart.no2.common.util.ValidationUtils.notNull; +import static org.dizitart.no2.support.exchange.Exporter.createObjectMapper; + +/** + * The Importer class provides methods to import data from a file or stream into + * Nitrite database. + *

+ * It uses the provided ImportOptions to configure the import process. + * + * @author Anindya Chatterjee + * @since 1.0 + */ +public class Importer { + private ImportOptions options; + + private Importer() { + } + + /** + * Creates a new instance of {@link Importer} with the specified import options. + * + * @param importOptions the import options to use + * @return a new instance of {@link Importer} with the specified import options + * @throws ValidationException if the import options or nitrite factory is null + */ + public static Importer withOptions(ImportOptions importOptions) { + Importer importer = new Importer(); + notNull(importOptions, "importOptions cannot be null"); + notNull(importOptions.getNitriteFactory(), "nitriteFactory cannot be null"); + + if (importOptions.getJsonFactory() == null) { + importOptions.setJsonFactory(createObjectMapper().getFactory()); + } + + importer.options = importOptions; + return importer; + } + + /** + * Imports data from the specified file. + * + * @param file the file to import data from + */ + public void importFrom(String file) { + importFrom(new File(file)); + } + + /** + * Imports data from a file. + * + * @param file the file to import data from + * @throws NitriteIOException if there is an I/O error while reading content from the file + */ + public void importFrom(File file) { + try (FileInputStream stream = new FileInputStream(file)) { + importFrom(stream); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while reading content from file " + file, ioe); + } + } + + /** + * Imports data from the specified input stream. + * + * @param stream the input stream to import data from + * @throws IOException if an I/O error occurs + */ + public void importFrom(InputStream stream) throws IOException { + try (InputStreamReader reader = new InputStreamReader(stream)) { + importFrom(reader); + } + } + + /** + * Imports data from a Reader object using a JSON parser. + * + * @param reader the Reader object to import data from + * @throws NitriteIOException if there is an I/O error while creating the parser from the reader or while importing data + */ + public void importFrom(Reader reader) { + JsonParser parser; + try { + parser = options.getJsonFactory().createParser(reader); + } catch (IOException ioe) { + throw new NitriteIOException("I/O error while creating parser from reader", ioe); + } + + if (parser != null) { + NitriteJsonImporter jsonImporter = new NitriteJsonImporter(); + jsonImporter.setParser(parser); + jsonImporter.setOptions(options); + try { + jsonImporter.importData(); + } catch (IOException | ClassNotFoundException e) { + throw new NitriteIOException("Error while importing data", e); + } + } + } +} diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java index 788aea738..4bf1b5efb 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/exchange/NitriteFactory.java @@ -2,20 +2,19 @@ import org.dizitart.no2.Nitrite; - /** - * A factory interface to create a {@link Nitrite} instance. - * - * @since 4.0.0 + * A functional interface for creating a {@link Nitrite} instance. + * + * @since 4.0 * @see Nitrite * @author Anindya Chatterjee - * */ + */ @FunctionalInterface public interface NitriteFactory { /** - * Creates a {@link Nitrite} instance. + * Creates a new instance of Nitrite database. * - * @return the nitrite instance. + * @return a new instance of Nitrite database. */ Nitrite create(); } diff --git a/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java b/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java index 59fdc0deb..78f74434e 100644 --- a/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java +++ b/nitrite-support/src/main/java/org/dizitart/no2/support/processors/StringFieldEncryptionProcessor.java @@ -31,13 +31,13 @@ import java.util.List; /** - * A string field encryption processor. It encrypts the field value - * of type {@link String} in a nitrite document using the provided {@link Encryptor}. - * + * A processor class which is responsible for encrypting and + * decrypting string fields in a Nitrite database document. + * * @author Anindya Chatterjee * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite-support") public class StringFieldEncryptionProcessor implements Processor { private final Encryptor encryptor; private final List fields; @@ -62,14 +62,22 @@ public StringFieldEncryptionProcessor(Encryptor encryptor) { } /** - * Adds fields for encryption. + * Adds one or more field names to the list of fields that should be encrypted. * - * @param fields the fields + * @param fields the names of the fields to be encrypted */ - public void addFields(String... fields){ + public void addFields(String... fields) { this.fields.addAll(Arrays.asList(fields)); } + /** + * Processes the document before writing to the database. Encrypts the values of the specified fields + * using the provided encryptor. + * + * @param document the document to be processed + * @return a new document with encrypted values for the specified fields + * @throws NitriteIOException if there is an error while processing the document + */ @Override public Document processBeforeWrite(Document document) { try { @@ -93,6 +101,14 @@ public Document processBeforeWrite(Document document) { } } + /** + * Processes the document after reading from the database. Decrypts the encrypted fields + * and returns a new document with decrypted values. + * + * @param document the document to be processed + * @return a new document with decrypted values + * @throws NitriteIOException if there is an error while processing the document + */ @Override public Document processAfterRead(Document document) { try { diff --git a/nitrite/pom.xml b/nitrite/pom.xml index 078bf0e52..0515d8a25 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -138,6 +138,11 @@ org.jacoco jacoco-maven-plugin + + + **/index/fulltext/languages/* + + org.apache.maven.plugins @@ -149,9 +154,12 @@ org.dizitart.no2.common.event, org.dizitart.no2.common.streams, org.dizitart.no2.common.util, + org.dizitart.no2.index.fulltext.languages, + org.dizitart.no2.migration.commands, + org.dizitart.no2.store.memory, - **/*CollectionFactory.java + **/*Factory.java **/*DefaultNitriteCollection.java **/*SnowflakeIdGenerator.java **/*AttributesAware.java @@ -162,10 +170,31 @@ **/*DBValue.java **/*UnknownType.java **/*AndFilter.java + **/*OrFilter.java **/*BetweenFilter.java **/*ComparableArrayFilter.java **/*ElementMatchFilter.java **/*EqualsFilter.java + **/*TextFilter.java + **/*ComparableIndexer.java + **/*CompoundIndex.java + **/*IndexMap.java + **/*IndexMeta.java + **/*IndexScanner.java + **/*NitriteTextIndexer.java + **/*NonUniqueIndexer.java + **/*SingleFieldIndex.java + **/*TextIndex.java + **/*UniqueIndexer.java + **/*MigrationManager.java + **/*EntityDecoratorScanner.java + **/*IndexValidator.java + **/*ObjectCursor.java + **/*RepositoryOperations.java + **/*EventBus.java + **/*MetaData.java + **/*UserAuthenticationService.java + **/*UserCredential.java diff --git a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java index 8143e526d..62689b596 100644 --- a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java +++ b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java @@ -37,18 +37,33 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * An in-memory, single-file based embedded nosql persistent document store. The store - * can contains multiple named document collections. + * Nitrite is a lightweight, embedded, and self-contained Java NoSQL database. + * It provides an easy-to-use API to store and retrieve data. Nitrite stores + * data in the form of documents and supports indexing on fields within + * the documents to provide efficient search capabilities. Nitrite supports + * transactions, and provides a simple and efficient way to persist data. * + *

+ * Nitrite is thread-safe and can be used in a multi-threaded environment + * without any issues. Nitrite is designed to be embedded within the application + * and does not require any external setup or installation. + * + * + * @see NitriteBuilder + * @see NitriteCollection + * @see ObjectRepository + * @see EntityDecorator + * * @author Anindya Chatterjee * @since 1.0 */ public interface Nitrite extends AutoCloseable { /** - * Returns an instance of a {@link NitriteBuilder}. + * Returns a new instance of {@link NitriteBuilder} to build a new Nitrite + * database instance. * - * @return the nitrite builder + * @return a new instance of {@link NitriteBuilder}. */ static NitriteBuilder builder() { return new NitriteBuilder(); @@ -74,11 +89,11 @@ static NitriteBuilder builder() { * The name cannot contain below reserved strings: * *

    - *
  • {@link Constants#INTERNAL_NAME_SEPARATOR}
  • - *
  • {@link Constants#USER_MAP}
  • - *
  • {@link Constants#INDEX_META_PREFIX}
  • - *
  • {@link Constants#INDEX_PREFIX}
  • - *
  • {@link Constants#OBJECT_STORE_NAME_SEPARATOR}
  • + *
  • {@link Constants#INTERNAL_NAME_SEPARATOR}
  • + *
  • {@link Constants#USER_MAP}
  • + *
  • {@link Constants#INDEX_META_PREFIX}
  • + *
  • {@link Constants#INDEX_PREFIX}
  • + *
  • {@link Constants#OBJECT_STORE_NAME_SEPARATOR}
  • *
* * @param name the name of the collection @@ -102,9 +117,9 @@ static NitriteBuilder builder() { ObjectRepository getRepository(Class type); /** - * Opens a type-safe object repository with a key identifier from the store. If the repository - * does not exist it will be created automatically and returned. If a - * repository is already opened, it is returned as is. + * Opens a type-safe object repository with a key identifier from the store. + * If the repository does not exist it will be created automatically and + * returned. If a repository is already opened, it is returned as is. *

* The returned repository is thread-safe for concurrent use. * @@ -117,28 +132,30 @@ static NitriteBuilder builder() { ObjectRepository getRepository(Class type, String key); /** - * Opens a type-safe object repository using a {@link EntityDecorator}. If the repository - * does not exist it will be created automatically and returned. If a - * repository is already opened, it is returned as is. + * Opens a type-safe object repository using a {@link EntityDecorator}. If the + * repository does not exist it will be created automatically and returned. + * If a repository is already opened, it is returned as is. *

* The returned repository is thread-safe for concurrent use. * - * @param the type parameter + * @param the type parameter * @param entityDecorator the entityDecorator * @return the repository */ ObjectRepository getRepository(EntityDecorator entityDecorator); /** - * Opens a type-safe object repository using a {@link EntityDecorator} and a key identifier - * from the store. If the repository does not exist it will be created automatically and - * returned. If a repository is already opened, it is returned as is. + * Opens a type-safe object repository using a {@link EntityDecorator} and a key + * identifier from the store. If the repository does not exist it will be + * created + * automatically and returned. If a repository is already opened, it is returned + * as is. *

* The returned repository is thread-safe for concurrent use. * - * @param the type parameter + * @param the type parameter * @param entityDecorator the entityDecorator - * @param key the key + * @param key the key * @return the repository */ ObjectRepository getRepository(EntityDecorator entityDecorator, String key); @@ -185,17 +202,17 @@ static NitriteBuilder builder() { void destroyRepository(EntityDecorator type, String key); /** - * Gets the set of all {@link NitriteCollection}s' names saved in the store. + * Gets the set of all {@link NitriteCollection}s' names in the database. * - * @return the set of all collections' names. + * @return a set of all collection names in the database */ Set listCollectionNames(); /** * Gets the set of all fully qualified class names corresponding - * to all {@link ObjectRepository}s in the store. + * to all {@link ObjectRepository}s in the database. * - * @return the set of all registered classes' names. + * @return a set of all the repository names in the Nitrite database. */ Set listRepositories(); @@ -203,21 +220,22 @@ static NitriteBuilder builder() { * Gets the map of all key to the fully qualified class names corresponding * to all keyed-{@link ObjectRepository}s in the store. * - * @return the map of all registered classes' names against the keys. + * @return a map of all keyed-repositories keyed by their names */ Map> listKeyedRepositories(); /** - * Checks whether the store has any unsaved changes. + * Checks if there are any unsaved changes in the Nitrite database. * - * @return true if there are unsaved changes; otherwise false. + * @return {@code true} if there are unsaved changes, {@code false} otherwise. */ boolean hasUnsavedChanges(); /** - * Checks whether the store is closed. + * Checks if the Nitrite database instance is closed. * - * @return true if closed; otherwise false. + * @return {@code true} if the Nitrite database instance is closed; + * {@code false} otherwise. */ boolean isClosed(); @@ -229,16 +247,18 @@ static NitriteBuilder builder() { NitriteConfig getConfig(); /** - * Gets the {@link NitriteStore} instance powering the database. + * Returns the {@link NitriteStore} instance associated with this Nitrite + * database. * - * @return the {@link NitriteStore} instance of the database. + * @return the {@link NitriteStore} instance associated with this Nitrite + * database. */ NitriteStore getStore(); /** - * Gets database meta data. + * Returns the metadata of the database store. * - * @return the database meta data + * @return the metadata of the database store. */ StoreMetaData getDatabaseMetaData(); @@ -247,18 +267,25 @@ static NitriteBuilder builder() { * * @return the session */ + /** + * Creates a new session for the Nitrite database. A session is a lightweight + * container that holds transactions. Multiple sessions can be created for a + * single Nitrite database instance. + * + * @return a new session for the Nitrite database. + */ Session createSession(); /** * Closes the database. - * */ + */ void close(); /** - * Checks whether a particular {@link NitriteCollection} exists in the store. + * Checks if a collection with the given name exists in the database. * - * @param name the name of the collection. - * @return true if the collection exists; otherwise false. + * @param name the name of the collection to check + * @return true if a collection with the given name exists, false otherwise */ default boolean hasCollection(String name) { checkOpened(); @@ -266,11 +293,11 @@ default boolean hasCollection(String name) { } /** - * Checks whether a particular {@link ObjectRepository} exists in the store. + * Checks if a repository of the specified type exists in the database. * - * @param the type parameter - * @param type the type of the object - * @return true if the repository exists; otherwise false. + * @param type the type of the repository to check for + * @param the type of the repository + * @return true if a repository of the specified type exists, false otherwise */ default boolean hasRepository(Class type) { checkOpened(); @@ -279,26 +306,29 @@ default boolean hasRepository(Class type) { } /** - * Checks whether a particular keyed-{@link ObjectRepository} exists in the store. + * Checks if a repository of the specified type and the given key exists in + * the database. * - * @param the type parameter. - * @param type the type of the object. - * @param key the key, which will be appended to the repositories name. - * @return true if the repository exists; otherwise false. + * @param type the entity type of the repository + * @param key the key of the repository + * @param the type of the entity + * @return true if a repository with the given key exists for the specified + * entity type; false otherwise */ default boolean hasRepository(Class type, String key) { checkOpened(); String entityName = ObjectUtils.getEntityName(type); return listKeyedRepositories().containsKey(key) - && listKeyedRepositories().get(key).contains(entityName); + && listKeyedRepositories().get(key).contains(entityName); } /** - * Checks whether a particular {@link ObjectRepository} exists in the store. + * Checks if a repository of the specified type described by the + * {@link EntityDecorator} exists in the database. * - * @param the type parameter + * @param the type parameter * @param entityDecorator entityDecorator - * @return true if the repository exists; otherwise false. + * @return true if the repository exists; false otherwise. */ default boolean hasRepository(EntityDecorator entityDecorator) { checkOpened(); @@ -307,23 +337,27 @@ default boolean hasRepository(EntityDecorator entityDecorator) { } /** - * Checks whether a particular keyed-{@link ObjectRepository} exists in the store. + * Checks if a keyed-repository of the specified type described by the + * {@link EntityDecorator} exists in the database. * - * @param the type parameter. + * @param the type parameter. * @param entityDecorator entityDecorator. - * @param key the key, which will be appended to the repositories name. - * @return true if the repository exists; otherwise false. + * @param key the key, which will be appended to the repositories + * name. + * @return true if the repository exists; false otherwise. */ default boolean hasRepository(EntityDecorator entityDecorator, String key) { checkOpened(); return listKeyedRepositories().containsKey(key) - && listKeyedRepositories().get(key).contains(entityDecorator.getEntityName()); + && listKeyedRepositories().get(key).contains(entityDecorator.getEntityName()); } /** - * Validate the collection name. + * Validates the given collection name. * - * @param name the name + * @param name the name of the collection to validate + * @throws ValidationException if the name is null, empty, or contains any + * reserved names */ default void validateCollectionName(String name) { notNull(name, "name cannot be null"); @@ -337,7 +371,8 @@ default void validateCollectionName(String name) { } /** - * Checks if the store is opened. + * Checks if the Nitrite database is opened or not. Throws a + * {@link NitriteIOException} if the database is closed. */ default void checkOpened() { if (getStore() == null || getStore().isClosed()) { diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java b/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java index 8aafb1913..48b938264 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java @@ -17,22 +17,24 @@ package org.dizitart.no2; import lombok.Getter; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.exceptions.NitriteSecurityException; import org.dizitart.no2.migration.Migration; import org.dizitart.no2.common.module.NitriteModule; /** - * A builder utility to create a {@link Nitrite} database instance. - * + * The NitriteBuilder class provides a fluent API to configure and create a + * Nitrite database instance. + * * @author Anindya Chatterjee * @see Nitrite * @since 1.0 */ -@Slf4j public class NitriteBuilder { @Getter + /** + * The Nitrite configuration object. + */ private final NitriteConfig nitriteConfig; /** @@ -43,11 +45,15 @@ public class NitriteBuilder { } /** - * Sets the embedded field separator character. Default value - * is `.` + * Sets the field separator character for Nitrite. It is used to separate field + * names in a nested document. For example, if a document has a field + * address which is a nested document, then the field street + * of the nested document can be accessed using address.street syntax. + *

+ * The default value is [.]. * - * @param separator the separator - * @return the {@link NitriteBuilder} instance. + * @param separator the field separator character to use + * @return the NitriteBuilder instance */ public NitriteBuilder fieldSeparator(String separator) { this.nitriteConfig.fieldSeparator(separator); @@ -55,10 +61,11 @@ public NitriteBuilder fieldSeparator(String separator) { } /** - * Loads {@link NitriteModule} instance. + * Loads a Nitrite module into the Nitrite database. The module can be used to + * extend the functionality of Nitrite. * - * @param module the {@link NitriteModule} instance. - * @return the {@link NitriteBuilder} instance. + * @param module the {@link NitriteModule} to be loaded + * @return the {@link NitriteBuilder} instance */ public NitriteBuilder loadModule(NitriteModule module) { this.nitriteConfig.loadModule(module); @@ -66,10 +73,11 @@ public NitriteBuilder loadModule(NitriteModule module) { } /** - * Adds instructions to perform during schema migration. + * Adds one or more migrations to the Nitrite database. Migrations are used to + * upgrade the database schema when the application version changes. * - * @param migrations the migrations - * @return the nitrite builder + * @param migrations one or more migrations to add to the Nitrite database. + * @return the NitriteBuilder instance. */ public NitriteBuilder addMigrations(Migration... migrations) { for (Migration migration : migrations) { @@ -79,10 +87,10 @@ public NitriteBuilder addMigrations(Migration... migrations) { } /** - * Sets the current schema version. + * Sets the schema version for the Nitrite database. * - * @param version the version - * @return the nitrite builder + * @param version the schema version to set + * @return the NitriteBuilder instance */ public NitriteBuilder schemaVersion(Integer version) { this.nitriteConfig.currentSchemaVersion(version); @@ -90,15 +98,21 @@ public NitriteBuilder schemaVersion(Integer version) { } /** - * Opens or creates a new nitrite database. If it is an in-memory store, - * then it will create a new one. If it is a file based store, and if the file does not - * exist, then it will create a new file store and open; otherwise it will - * open the existing file store. + * Opens or creates a new Nitrite database. If it is configured as in-memory + * database, then it will create a new database everytime. If it is configured + * as a file based database, and if the file does not exist, then it will create + * a new file store and open the database; otherwise it will open the existing + * database file. * * @return the nitrite database instance. - * @throws org.dizitart.no2.exceptions.NitriteIOException if unable to create a new in-memory database. - * @throws org.dizitart.no2.exceptions.NitriteIOException if the database is corrupt and recovery fails. - * @throws IllegalArgumentException if the directory does not exist. + * @throws org.dizitart.no2.exceptions.NitriteIOException if unable to create a + * new in-memory + * database. + * @throws org.dizitart.no2.exceptions.NitriteIOException if the database is + * corrupt and recovery + * fails. + * @throws IllegalArgumentException if the directory does + * not exist. */ public Nitrite openOrCreate() { this.nitriteConfig.autoConfigure(); @@ -109,23 +123,30 @@ public Nitrite openOrCreate() { } /** - * Opens or creates a new nitrite database. If it is an in-memory store, - * then it will create a new one. If it is a file based store, and if the file does not - * exist, then it will create a new file store and open; otherwise it will - * open the existing file store. + * Opens or creates a new Nitrite database with the given username and password. + * If it is configured as in-memory database, then it will create a new database + * everytime. If it is configured as a file based database, and if the file + * does not exist, then it will create a new file store and open the database; + * otherwise it will open the existing database file. + * *

- * While creating a new database, it will use the specified user credentials. - * While opening an existing database, it will use the specified credentials - * to open it. - *

+ * NOTE: Both username and password must be provided or both must be null. * * @param username the username * @param password the password * @return the nitrite database instance. - * @throws NitriteSecurityException if the user credentials are wrong or one of them is empty string. - * @throws org.dizitart.no2.exceptions.NitriteIOException if unable to create a new in-memory database. - * @throws org.dizitart.no2.exceptions.NitriteIOException if the database is corrupt and recovery fails. - * @throws org.dizitart.no2.exceptions.NitriteIOException if the directory does not exist. + * @throws NitriteSecurityException if the user + * credentials are wrong + * or one of them is + * empty string. + * @throws org.dizitart.no2.exceptions.NitriteIOException if unable to create a + * new in-memory + * database. + * @throws org.dizitart.no2.exceptions.NitriteIOException if the database is + * corrupt and recovery + * fails. + * @throws org.dizitart.no2.exceptions.NitriteIOException if the directory does + * not exist. */ public Nitrite openOrCreate(String username, String password) { this.nitriteConfig.autoConfigure(); diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java b/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java index bc066bf98..ca200a000 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteConfig.java @@ -36,12 +36,12 @@ import java.util.TreeMap; /** - * A class to configure {@link Nitrite} database. - * + * NitriteConfig is a configuration class for Nitrite database. + * * @author Anindya Chatterjee. - * @since 4.0.0 + * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") @ToString public class NitriteConfig implements AutoCloseable { /** @@ -56,12 +56,22 @@ public class NitriteConfig implements AutoCloseable { protected final PluginManager pluginManager; @Getter + /** + * The separator used to separate field names in a nested field. + */ private static String fieldSeparator = "."; @Getter + /** + * A map of migrations to be applied to the database. + */ private final Map> migrations; @Getter + /** + * The schema version of the Nitrite database. Defaults to + * {@link Constants#INITIAL_SCHEMA_VERSION}. + */ private Integer schemaVersion = Constants.INITIAL_SCHEMA_VERSION; /** @@ -73,44 +83,51 @@ public NitriteConfig() { } /** - * Sets the embedded field separator character. Default value - * is `.` + * Sets the field separator for Nitrite database. * - * @param separator the separator + * @param separator the field separator to be set. + * @throws InvalidOperationException if the separator is attempted to be changed + * after database initialization. */ public void fieldSeparator(String separator) { if (configured) { throw new InvalidOperationException("Cannot change the separator after database" + - " initialization"); + " initialization"); } NitriteConfig.fieldSeparator = separator; } /** - * Loads {@link NitritePlugin} instances defined in the {@link NitriteModule}. + * Loads {@link NitritePlugin} instances defined in the {@link NitriteModule} + * into the configuration. * - * @param module the {@link NitriteModule} instances. - * @return the {@link NitriteConfig} instance. + * @param module the Nitrite module to be loaded + * @return the Nitrite configuration instance + * @throws InvalidOperationException if the database is already initialized */ public NitriteConfig loadModule(NitriteModule module) { if (configured) { throw new InvalidOperationException("Cannot load module after database" + - " initialization"); + " initialization"); } pluginManager.loadModule(module); return this; } /** - * Adds schema migration instructions. + * Adds a migration step to the configuration. A migration step is a process of + * updating the database from one version to another. If the database is already + * initialized, then migration steps cannot be added. * - * @param migration the migration - * @return the nitrite config + * @param migration the migration step to be added. + * @return the NitriteConfig instance. + * @throws InvalidOperationException if migration steps are added after database + * initialization. */ public NitriteConfig addMigration(Migration migration) { if (configured) { throw new InvalidOperationException("Cannot add migration steps after database" + - " initialization"); + " initialization"); } if (migration != null) { @@ -127,37 +144,42 @@ public NitriteConfig addMigration(Migration migration) { } /** - * Sets the current schema version. + * Sets the current schema version of the Nitrite database. * - * @param version the version - * @return the nitrite config + * @param version the current schema version. + * @return the NitriteConfig instance. + * @throws InvalidOperationException if the schema version is attempted to be + * added after database initialization. */ public NitriteConfig currentSchemaVersion(Integer version) { if (configured) { throw new InvalidOperationException("Cannot add schema version info after database" + - " initialization"); + " initialization"); } this.schemaVersion = version; return this; } /** - * Autoconfigures nitrite database with default configuration values and - * default built-in plugins. + * Automatically configures Nitrite database by finding and loading plugins. + * + * @throws InvalidOperationException if autoconfigure is executed after database + * initialization. */ public void autoConfigure() { if (configured) { throw new InvalidOperationException("Cannot execute autoconfigure after database" + - " initialization"); + " initialization"); } pluginManager.findAndLoadPlugins(); } /** - * Finds a {@link NitriteIndexer} by indexType. + * Finds the {@link NitriteIndexer} for the given index type. * - * @param indexType the type of {@link NitriteIndexer} to find. - * @return the {@link NitriteIndexer} + * @param indexType the type of the index to find + * @return the {@link NitriteIndexer} for the given index type + * @throws IndexingException if no indexer is found for the given index type */ public NitriteIndexer findIndexer(String indexType) { NitriteIndexer nitriteIndexer = pluginManager.getIndexerMap().get(indexType); @@ -170,23 +192,27 @@ public NitriteIndexer findIndexer(String indexType) { } /** - * Gets the {@link NitriteMapper} instance. + * Returns the {@link NitriteMapper} instance used by Nitrite. * - * @return the {@link NitriteMapper} + * @return the NitriteMapper instance used by Nitrite. */ public NitriteMapper nitriteMapper() { return pluginManager.getNitriteMapper(); } /** - * Gets {@link NitriteStore} instance. + * Returns the {@link NitriteStore} associated with this instance. * - * @return the {@link NitriteStore} + * @return the {@link NitriteStore} associated with this instance. */ public NitriteStore getNitriteStore() { return pluginManager.getNitriteStore(); } + /** + * Closes the NitriteConfig instance and releases any resources + * associated with it. + */ @Override public void close() { if (pluginManager != null) { diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteDatabase.java b/nitrite/src/main/java/org/dizitart/no2/NitriteDatabase.java index e0f6acfdb..602b40195 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteDatabase.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteDatabase.java @@ -47,7 +47,7 @@ * @author Anindya Chatterjee. * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") class NitriteDatabase implements Nitrite { private final CollectionFactory collectionFactory; private final RepositoryFactory repositoryFactory; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java b/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java index d089e8e4b..b4a7e25e7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/SnowflakeIdGenerator.java @@ -41,7 +41,7 @@ * @author Sebastian Schaffert (sschaffert@apache.org) * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") public class SnowflakeIdGenerator { private final SecureRandom random; private final long nodeIdBits = 10L; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventInfo.java b/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventInfo.java index ccf350eff..28954a2b1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventInfo.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/events/CollectionEventInfo.java @@ -59,7 +59,7 @@ public class CollectionEventInfo { * * @param originator name of originator of the event. * @return name of the originator. - * @since 4.0.0 + * @since 4.0 */ private String originator; diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java index 346079661..8a7f73118 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/WriteOperations.java @@ -41,7 +41,7 @@ * @author Anindya Chatterjee * @since 1.0 */ -@Slf4j +@Slf4j(topic = "nitrite") class WriteOperations { private final DocumentIndexWriter documentIndexWriter; private final ReadOperations readOperations; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/Constants.java b/nitrite/src/main/java/org/dizitart/no2/common/Constants.java index c39095bb8..b2dcfc8f6 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/Constants.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/Constants.java @@ -234,7 +234,7 @@ private Constants() { public static final String SYNC_THREAD_NAME = "Sync." + NO2; /** - * The constant INITIAL_REVISION. + * The initial schema version of Nitrite database. */ public static final Integer INITIAL_SCHEMA_VERSION = 1; } diff --git a/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java b/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java index cbffce864..4f2c1985e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/DBNull.java @@ -1,12 +1,10 @@ package org.dizitart.no2.common; -import java.io.Serializable; - /** * @author Anindya Chatterjee * @since 1.0 */ -public class DBNull extends DBValue implements Serializable { +public class DBNull extends DBValue { private static final long serialVersionUID = 1598819770L; private static final DBNull instance = new DBNull(); diff --git a/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java b/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java index 70b3faffd..736a9abdc 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/PersistentCollection.java @@ -94,7 +94,6 @@ default void createIndex(String... fields) { */ void rebuildIndex(String... fields); - /** * Gets a set of all indices in the collection. * diff --git a/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ErrorAwareThreadFactory.java b/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ErrorAwareThreadFactory.java index 44a4e9557..85d350f33 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ErrorAwareThreadFactory.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ErrorAwareThreadFactory.java @@ -27,7 +27,7 @@ * @author Anindya Chatterjee. * @since 1.0 */ -@Slf4j +@Slf4j(topic = "nitrite") public abstract class ErrorAwareThreadFactory implements ThreadFactory { /** * Creates a new {@link Thread}. diff --git a/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ThreadPoolManager.java b/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ThreadPoolManager.java index bf3ace37d..35ab7883c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ThreadPoolManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/concurrent/ThreadPoolManager.java @@ -29,7 +29,7 @@ * @author Anindya Chatterjee. * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") public class ThreadPoolManager { private final static List threadPools; private final static ExecutorService commonPool; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java b/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java index eb463bbed..3f08b5bb4 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/event/NitriteEventBus.java @@ -27,7 +27,7 @@ * @since 1.0 */ public abstract class NitriteEventBus - implements EventBus, AutoCloseable { + implements EventBus { private final Set listeners; private ExecutorService eventExecutor; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java index 2d92d6c98..65e9c466f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/module/PluginManager.java @@ -34,7 +34,7 @@ * @author Anindya Chatterjee. * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") @Getter public class PluginManager implements AutoCloseable { private final Map indexerMap; diff --git a/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java b/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java index ce27d3166..361a7082b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/common/util/ObjectUtils.java @@ -16,14 +16,12 @@ package org.dizitart.no2.common.util; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.collection.Document; import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ObjectMappingException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.repository.EntityDecorator; -import org.dizitart.no2.repository.ObjectRepository; import org.dizitart.no2.repository.annotations.Entity; import java.io.*; @@ -45,7 +43,6 @@ * @since 1.0 */ @SuppressWarnings("rawtypes") -@Slf4j public class ObjectUtils { private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPE; diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java index 24135a4e6..e6be8fc08 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableArrayFilter.java @@ -22,10 +22,12 @@ import static org.dizitart.no2.common.util.ValidationUtils.*; /** + * An abstract class representing a filter that operates on a field with a comparable array value. + * * @author Anindya Chatterjee * @since 4.0 */ -abstract class ComparableArrayFilter extends FieldBasedFilter { +public abstract class ComparableArrayFilter extends FieldBasedFilter { public ComparableArrayFilter(String field, Object value) { super(field, value); diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java index 4bc94f5c0..5e0f37048 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java @@ -24,7 +24,7 @@ import java.util.NavigableMap; /** - * Represents a filter based on document field holding {@link Comparable} values. + * An abstract class representing a filter that compares fields. * * @author Anindya Chatterjee * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/FieldBasedFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/FieldBasedFilter.java index a25971109..9133c114f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/FieldBasedFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/FieldBasedFilter.java @@ -30,8 +30,8 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a filter based on value of a nitrite document field. - * + * The base class for all field-based filters in Nitrite. + * Provides common functionality for filters that operate on a specific field. * @author Anindya Chatterjee * @since 4.0 */ @@ -79,6 +79,14 @@ public Object getValue() { return value; } + /** + * Validates the search term for a given field and value. + * + * @param nitriteMapper the NitriteMapper instance to use for mapping objects + * @param field the field to validate + * @param value the value to validate + * @throws ValidationException if the field is null or empty + */ protected void validateSearchTerm(NitriteMapper nitriteMapper, String field, Object value) { notNull(field, "field cannot be null"); notEmpty(field, "field cannot be empty"); diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java b/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java index a08fecf4b..c7aea99bb 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/Filter.java @@ -105,7 +105,7 @@ static Filter or(Filter... filters) { /** * Creates a not filter which performs a logical NOT operation on a filter and selects - * the documents that do not satisfy the criteria. + * the documents that do not satisfy the criteria. *

* NOTE: This also includes documents that do not contain the value. * diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java index 155c6f77a..6605b5a1e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/FluentFilter.java @@ -170,44 +170,44 @@ public NitriteFilter text(String value) { } /** - * Creates a string filter which provides regular expression capabilities - * for pattern matching strings in documents. + * Creates a filter that matches documents where the value of the specified field matches the + * specified regular expression pattern. * - * @param value the regular expression - * @return the regex filter + * @param value the regular expression pattern to match against the value of the specified field + * @return a filter that matches documents where the value of the specified field + * matches the specified regular expression pattern */ public NitriteFilter regex(String value) { return new RegexFilter(field, value); } /** - * Creates an in filter which matches the documents where - * the value of a field equals any value in the specified array. + * Creates a filter that matches documents where the value of the field is in the specified array of values. * - * @param values the range values - * @return the in filter + * @param values the array of values to match against + * @return the filter object representing the filter */ public NitriteFilter in(Comparable... values) { return new InFilter(field, values); } /** - * Creates a notIn filter which matches the documents where - * the value of a field not equals any value in the specified array. + * Creates a filter that matches documents where the value of the field is not in the specified array of values. * - * @param values the range values - * @return the notIn filter + * @param values the array of values to compare against + * @return a filter that matches documents where the value of the field is not in the specified array of values */ public NitriteFilter notIn(Comparable... values) { return new NotInFilter(field, values); } /** - * Creates an element match filter that matches documents that contain an array - * value with at least one element that matches the specified filter. + * Creates a filter that matches documents where the value of a field contains at least one element that matches the + * specified filter. * - * @param filter the filter to satisfy - * @return the element match filter + * @param filter the filter to apply to the matching elements + * @return a filter that matches documents where the value of a field contains at least one element that matches the + * specified filter */ public NitriteFilter elemMatch(Filter filter) { return new ElementMatchFilter(field, filter); diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/IndexOnlyFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/IndexOnlyFilter.java index 9e5bdc2e8..a0030d208 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/IndexOnlyFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/IndexOnlyFilter.java @@ -18,8 +18,9 @@ package org.dizitart.no2.filters; /** - * Represents an index-only filter. This filter does not support - * collection scan. + * An abstract class representing a filter that can be applied to an index. + *

+ * NOTE: This filter does not support collection scan. * * @since 4.0 * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/NitriteFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/NitriteFilter.java index 61b97dd7a..60d713000 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/NitriteFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/NitriteFilter.java @@ -23,7 +23,7 @@ import java.util.Objects; /** - * Represents a nitrite filter. + * An abstract class representing a filter for Nitrite database. * * @author Anindya Chatterjee. * @since 4.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/StringFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/StringFilter.java index f82c078eb..dde668d74 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/StringFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/StringFilter.java @@ -17,7 +17,7 @@ package org.dizitart.no2.filters; /** - * Represents a filter on string values. + * An abstract class representing a filter for string values. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java index b1d02f4de..8bec4d682 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java @@ -31,8 +31,6 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a nitrite full-text search filter. - * * @author Anindya Chatterjee * @since 1.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/BoundingBox.java b/nitrite/src/main/java/org/dizitart/no2/index/BoundingBox.java index 2d30d8984..f27d5df29 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/BoundingBox.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/BoundingBox.java @@ -25,30 +25,30 @@ */ public interface BoundingBox extends Serializable { /** - * Gets min x. + * Returns the minimum x-coordinate of the bounding box. * - * @return the min x + * @return the minimum x-coordinate of the bounding box. */ float getMinX(); /** - * Gets max x. + * Returns the maximum x-coordinate of the bounding box. * - * @return the max x + * @return the maximum x-coordinate of the bounding box */ float getMaxX(); /** - * Gets min y. + * Returns the minimum y-coordinate of the bounding box. * - * @return the min y + * @return the minimum y-coordinate of the bounding box */ float getMinY(); /** - * Gets max y. + * Returns the maximum Y coordinate of the bounding box. * - * @return the max y + * @return the maximum Y coordinate of the bounding box. */ float getMaxY(); } diff --git a/nitrite/src/main/java/org/dizitart/no2/index/ComparableIndexer.java b/nitrite/src/main/java/org/dizitart/no2/index/ComparableIndexer.java index 4d2d24320..b23a30a6c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/ComparableIndexer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/ComparableIndexer.java @@ -28,8 +28,6 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Represents an indexer for {@link Comparable} values. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/CompoundIndex.java b/nitrite/src/main/java/org/dizitart/no2/index/CompoundIndex.java index 74d1b979a..e4c46f410 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/CompoundIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/CompoundIndex.java @@ -39,8 +39,6 @@ import static org.dizitart.no2.common.util.ObjectUtils.convertToObjectArray; /** - * Represents a nitrite compound index. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexDescriptor.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexDescriptor.java index 0198249cc..02f5f9d5f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexDescriptor.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexDescriptor.java @@ -31,7 +31,7 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents a nitrite database index. + * A class representing the descriptor of a Nitrite index. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java index 828c7ca21..6497768bc 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java @@ -29,8 +29,6 @@ import java.util.concurrent.CopyOnWriteArrayList; /** - * Represents an index map. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexMeta.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexMeta.java index 9729eccfa..36c151267 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexMeta.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexMeta.java @@ -26,8 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Represents index metadata. - * * @since 1.0 * @author Anindya Chatterjee */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexOptions.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexOptions.java index 64b0c4424..7c182d620 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexOptions.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexOptions.java @@ -21,7 +21,7 @@ import lombok.Setter; /** - * Represents options to apply while creating an index. + * Options for configuring an index. * * @author Anindya Chatterjee * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java index 5f0c81763..e036fb3cb 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java @@ -28,30 +28,16 @@ import java.util.NavigableMap; /** - * Represents an {@link IndexMap} scanner. - * * @author Anindya Chatterjee * @since 4.0 */ public class IndexScanner { private final IndexMap indexMap; - /** - * Instantiates a new {@link IndexScanner}. - * - * @param indexMap the index map - */ public IndexScanner(IndexMap indexMap) { this.indexMap = indexMap; } - /** - * Scans the {@link IndexMap} and returns the {@link NitriteId}s of the matching elements. - * - * @param filters the filters - * @param indexScanOrder the index scan order - * @return the linked hash set - */ @SuppressWarnings("unchecked") public LinkedHashSet doScan(List filters, Map indexScanOrder) { // linked-hash-set to return only unique ids preserving the order in index diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexType.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexType.java index efbafec64..48983303e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexType.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexType.java @@ -17,24 +17,24 @@ package org.dizitart.no2.index; /** - * Represents a type of nitrite index. - * + * An interface representing the types of indexes supported by Nitrite. + * * @author Anindya Chatterjee * @since 4.0 */ public interface IndexType { /** - * A unique index. + * Represents a unique index type. */ String UNIQUE = "Unique"; /** - * A non-unique index. + * Represents a non-unique index type. */ String NON_UNIQUE = "NonUnique"; /** - * A nitrite full-text index. + * Represents a full text index type. */ String FULL_TEXT = "Fulltext"; } diff --git a/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndex.java b/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndex.java index 836a0007a..5ee43c8f1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndex.java @@ -31,8 +31,9 @@ import static org.dizitart.no2.common.util.ValidationUtils.validateIterableIndexField; /** - * Represents a nitrite index. - * + * The NitriteIndex interface represents an index in Nitrite database. It provides methods to write, remove and find + * NitriteIds from the index. It also provides methods to drop the index and validate the index field. + * * @author Anindya Chatterjee * @since 4.0 */ @@ -45,26 +46,26 @@ public interface NitriteIndex { IndexDescriptor getIndexDescriptor(); /** - * Writes a {@link FieldValues} in the index. + * Writes the given field values to the index. * - * @param fieldValues the field values + * @param fieldValues the field values to write. */ void write(FieldValues fieldValues); /** - * Removes a {@link FieldValues} from the index. + * Removes the index entry for the specified field values. * - * @param fieldValues the field values + * @param fieldValues the field values to remove the index entry for. */ void remove(FieldValues fieldValues); /** - * Drops this index. + * Drops the index. */ void drop(); /** - * Finds a set of {@link NitriteId}s from the index after executing the {@link FindPlan}. + * Finds the NitriteIds from the index for the given find plan. * * @param findPlan the find plan * @return the linked hash set @@ -72,9 +73,9 @@ public interface NitriteIndex { LinkedHashSet findNitriteIds(FindPlan findPlan); /** - * Indicates if this is an unique index. + * Checks if the index is unique. * - * @return the boolean + * @return true if the index is unique, false otherwise. */ default boolean isUnique() { return getIndexDescriptor().getIndexType().equalsIgnoreCase(IndexType.UNIQUE); @@ -83,8 +84,9 @@ default boolean isUnique() { /** * Validates the index field. * - * @param value the value - * @param field the field + * @param value the value to be validated. + * @param field the name of the field to be validated. + * @throws ValidationException if the index field is not a comparable type. */ default void validateIndexField(Object value, String field) { if (value == null) return; @@ -98,11 +100,12 @@ default void validateIndexField(Object value, String field) { } /** - * Adds a {@link NitriteId} of the {@link FieldValues} to the existing indexed list of {@link NitriteId}s. + * Adds the {@link NitriteId} of the {@link FieldValues} into the existing indexed list of {@link NitriteId}s. * - * @param nitriteIds the nitrite ids - * @param fieldValues the field values - * @return the list + * @param nitriteIds the list of NitriteIds + * @param fieldValues the field values to index + * @return the updated list of NitriteIds + * @throws UniqueConstraintException if the index is unique and the key already exists */ default List addNitriteIds(List nitriteIds, FieldValues fieldValues) { if (nitriteIds == null) { @@ -120,10 +123,10 @@ default List addNitriteIds(List nitriteIds, FieldValues fi } /** - * Removes a {@link NitriteId} of the {@link FieldValues} from the existing indexed list of {@link NitriteId}s. + * Removes the {@link NitriteId} of the {@link FieldValues} from the existing indexed list of {@link NitriteId}s. * - * @param nitriteIds the nitrite ids - * @param fieldValues the field values + * @param nitriteIds the list of NitriteIds + * @param fieldValues the field values to remove from index * @return the list */ default List removeNitriteIds(List nitriteIds, FieldValues fieldValues) { diff --git a/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndexer.java b/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndexer.java index 850aed466..c77d25597 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndexer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/NitriteIndexer.java @@ -26,7 +26,11 @@ import java.util.LinkedHashSet; /** - * Represents an indexer for creating a nitrite index. + * An abstract class representing a Nitrite indexer plugin. + *

+ * NitriteIndexer extends NitritePlugin and provides a base class for all Nitrite + * indexer plugins. It defines the basic structure and functionality of an indexer + * plugin that can be used to index Nitrite collections. * * @author Anindya Chatterjee. * @since 4.0 @@ -40,44 +44,44 @@ public interface NitriteIndexer extends NitritePlugin { String getIndexType(); /** - * Validates an index on the fields. + * Validates the given fields for indexing. * - * @param fields the fields + * @param fields the fields to be validated */ void validateIndex(Fields fields); /** - * Drops the index specified by the index descriptor. + * Drops the index from the collection. * - * @param indexDescriptor the index descriptor - * @param nitriteConfig the nitrite config + * @param indexDescriptor the descriptor of the index to be dropped. + * @param nitriteConfig the Nitrite configuration object. */ void dropIndex(IndexDescriptor indexDescriptor, NitriteConfig nitriteConfig); /** - * Writes an index entry. + * Writes an index entry for the given field values and index descriptor. * - * @param fieldValues the field values - * @param indexDescriptor the index descriptor - * @param nitriteConfig the nitrite config + * @param fieldValues the field values to be indexed + * @param indexDescriptor the descriptor of the index + * @param nitriteConfig the NitriteConfig to use for indexing */ void writeIndexEntry(FieldValues fieldValues, IndexDescriptor indexDescriptor, NitriteConfig nitriteConfig); /** - * Removes an index entry. + * Removes an index entry for the given field values and index descriptor from the Nitrite database. * - * @param fieldValues the field values - * @param indexDescriptor the index descriptor - * @param nitriteConfig the nitrite config + * @param fieldValues the field values to remove the index entry for + * @param indexDescriptor the index descriptor for the index entry to remove + * @param nitriteConfig the Nitrite configuration object */ void removeIndexEntry(FieldValues fieldValues, IndexDescriptor indexDescriptor, NitriteConfig nitriteConfig); /** - * Finds a list of {@link NitriteId} after executing the {@link FindPlan} on the index. + * Finds the NitriteIds of the documents that match the given filter in the specified collection. * - * @param findPlan the find plan - * @param nitriteConfig the nitrite config - * @return the linked hash set + * @param findPlan the plan for finding the documents. + * @param nitriteConfig the Nitrite configuration. + * @return a set of NitriteIds of the documents that match the given filter. */ LinkedHashSet findByFilter(FindPlan findPlan, NitriteConfig nitriteConfig); } diff --git a/nitrite/src/main/java/org/dizitart/no2/index/NitriteTextIndexer.java b/nitrite/src/main/java/org/dizitart/no2/index/NitriteTextIndexer.java index e01b20707..3e80cc548 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/NitriteTextIndexer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/NitriteTextIndexer.java @@ -30,8 +30,6 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Represents a nitrite text indexer. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/NonUniqueIndexer.java b/nitrite/src/main/java/org/dizitart/no2/index/NonUniqueIndexer.java index 9d3c8b6d0..1364372b8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/NonUniqueIndexer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/NonUniqueIndexer.java @@ -17,8 +17,6 @@ package org.dizitart.no2.index; /** - * Represents a non unique indexer. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/SingleFieldIndex.java b/nitrite/src/main/java/org/dizitart/no2/index/SingleFieldIndex.java index 2d6ae64ab..7dd2f357a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/SingleFieldIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/SingleFieldIndex.java @@ -36,8 +36,6 @@ import static org.dizitart.no2.common.util.ObjectUtils.convertToObjectArray; /** - * Represents a nitrite index on a single field. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java b/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java index dcb344364..bc343cd98 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java @@ -42,8 +42,6 @@ import static org.dizitart.no2.common.util.ValidationUtils.validateStringIterableIndexField; /** - * Represents a nitrite full-text index. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/UniqueIndexer.java b/nitrite/src/main/java/org/dizitart/no2/index/UniqueIndexer.java index 2eb859694..d66b7090c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/UniqueIndexer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/UniqueIndexer.java @@ -17,8 +17,6 @@ package org.dizitart.no2.index; /** - * Represents a nitrite unique indexer. - * * @author Anindya Chatterjee. * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/Languages.java b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/Languages.java index 0a1e4790a..35dc1dcd3 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/Languages.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/Languages.java @@ -17,7 +17,7 @@ package org.dizitart.no2.index.fulltext; /** - * All supported languages for full-text search. + * An enum representing the supported languages for full-text search in Nitrite. * * @author Anindya Chatterjee * @since 2.1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/TextTokenizer.java b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/TextTokenizer.java index 9c9b1e07e..ac44d754c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/TextTokenizer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/TextTokenizer.java @@ -19,7 +19,7 @@ import java.util.Set; /** - * A stop-word based string tokenizer. + * An abstract class representing a stop-word based text tokenizer. * * @author Anindya Chatterjee. * @see EnglishTextTokenizer diff --git a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/UniversalTextTokenizer.java b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/UniversalTextTokenizer.java index c9e302cd4..ffe0ec8da 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/fulltext/UniversalTextTokenizer.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/fulltext/UniversalTextTokenizer.java @@ -24,7 +24,7 @@ import static org.dizitart.no2.common.util.Iterables.arrayContains; /** - * A {@link TextTokenizer} implementation for various languages. + * A {@link TextTokenizer} implementation that tokenizes text using a universal approach. * * @author Anindya Chatterjee * @see Languages diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/Generator.java b/nitrite/src/main/java/org/dizitart/no2/migration/Generator.java index 66fff74e0..0c24cfc11 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/Generator.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/Generator.java @@ -3,7 +3,7 @@ import org.dizitart.no2.collection.Document; /** - * Represents a default value generator for the document fields during field manipulation instruction. + * Represents a default value generator for the document fields in field manipulation instruction. * * @param the type parameter * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/Migration.java b/nitrite/src/main/java/org/dizitart/no2/migration/Migration.java index a75354881..26578cfd4 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/Migration.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/Migration.java @@ -5,18 +5,28 @@ import java.util.LinkedList; import java.util.Queue; + /** - * Represents the database migration operation. - * + * Represents the database migration operation. A migration is a way to modify the structure of a database + * from one version to another. It contains a queue of {@link MigrationStep}s that need to be executed + * in order to migrate the database from the start version to the end version. + * * @author Anindya Chatterjee * @since 4.0 */ public abstract class Migration { private final Queue migrationSteps; + /** + * Returns the version number from which the migration is being performed. + * + */ @Getter private final Integer fromVersion; + /** + * Returns the version number to which the migration is being performed. + */ @Getter private final Integer toVersion; @@ -42,7 +52,7 @@ public Migration(Integer fromVersion, Integer toVersion) { public abstract void migrate(InstructionSet instructionSet); /** - * Returns the {@link MigrationStep}s as a queue for execution. + * Returns the queue of {@link MigrationStep}s to be executed for the migration. * * @return the queue */ diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/MigrationManager.java b/nitrite/src/main/java/org/dizitart/no2/migration/MigrationManager.java index 5190ef3d7..cf1357dbb 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/MigrationManager.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/MigrationManager.java @@ -24,8 +24,6 @@ import static org.dizitart.no2.common.util.ObjectUtils.findRepositoryName; /** - * The database migration manager. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/MigrationStep.java b/nitrite/src/main/java/org/dizitart/no2/migration/MigrationStep.java index 0d9c059ff..0e8c8b43d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/MigrationStep.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/MigrationStep.java @@ -6,8 +6,8 @@ import lombok.Setter; /** - * Represents a migration step. - * + * A class representing a migration step in Nitrite database. + * * @author Anindya Chatterjee * @since 4.0 */ @@ -15,6 +15,13 @@ @Setter(AccessLevel.PACKAGE) @NoArgsConstructor(access = AccessLevel.PACKAGE) public final class MigrationStep { + /** + * Returns the instruction type of the migration instruction. + */ private InstructionType instructionType; + + /** + * Returns the arguments passed to the migration function. + */ private Object arguments; } diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/NitriteInstructionSet.java b/nitrite/src/main/java/org/dizitart/no2/migration/NitriteInstructionSet.java index 01f56f3ee..e0d18fe8a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/NitriteInstructionSet.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/NitriteInstructionSet.java @@ -6,8 +6,6 @@ import java.util.Queue; /** - * Default implementation of {@link InstructionSet}. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/AddField.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/AddField.java index b9c6fe4c2..f22b8829d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/AddField.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/AddField.java @@ -13,7 +13,7 @@ * @author Anindya Chatterjee */ @AllArgsConstructor -public class AddField extends BaseCommand implements Command { +public class AddField extends BaseCommand { private final String collectionName; private final String fieldName; private final Object defaultValue; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeDataType.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeDataType.java index ec0685aa7..caa909c68 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeDataType.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeDataType.java @@ -18,7 +18,7 @@ */ @AllArgsConstructor @SuppressWarnings({"unchecked", "rawtypes"}) -public class ChangeDataType extends BaseCommand implements Command { +public class ChangeDataType extends BaseCommand { private final String collectionName; private final String fieldName; private final TypeConverter typeConverter; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeIdField.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeIdField.java index 3eb56806b..8921444a2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeIdField.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/ChangeIdField.java @@ -13,7 +13,7 @@ * @since 4.0 */ @AllArgsConstructor -public class ChangeIdField extends BaseCommand implements Command { +public class ChangeIdField extends BaseCommand { private final String collectionName; private final Fields oldFields; private final Fields newFields; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Command.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Command.java index 9019fde80..7b5adc8d0 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Command.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Command.java @@ -3,17 +3,10 @@ import org.dizitart.no2.Nitrite; /** - * Represents a database migration command. - * * @author Anindya Chatterjee * @since 4.0 */ public interface Command extends AutoCloseable { - /** - * Executes a migration step on the database. - * - * @param nitrite the nitrite database instance - */ void execute(Nitrite nitrite); default void close() { diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/CreateIndex.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/CreateIndex.java index 3081a613a..32ab4204e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/CreateIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/CreateIndex.java @@ -11,7 +11,7 @@ * @since 4.0 */ @AllArgsConstructor -public class CreateIndex extends BaseCommand implements Command { +public class CreateIndex extends BaseCommand { private final String collectionName; private final Fields fields; private final String indexType; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/DeleteField.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/DeleteField.java index 9826e7d38..de913c27e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/DeleteField.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/DeleteField.java @@ -16,7 +16,7 @@ * @since 4.0 */ @AllArgsConstructor -public class DeleteField extends BaseCommand implements Command { +public class DeleteField extends BaseCommand { private final String collectionName; private final String fieldName; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Drop.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Drop.java index c8bf6cc42..454cdbaa2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Drop.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Drop.java @@ -10,7 +10,7 @@ * @since 4.0 */ @AllArgsConstructor -public class Drop extends BaseCommand implements Command { +public class Drop extends BaseCommand { private final String collectionName; @Override diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/DropIndex.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/DropIndex.java index ca242840a..759e057c7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/DropIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/DropIndex.java @@ -11,7 +11,7 @@ * @since 4.0 */ @AllArgsConstructor -public class DropIndex extends BaseCommand implements Command { +public class DropIndex extends BaseCommand { private final String collectionName; private final Fields fields; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Rename.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Rename.java index 5a2bcb47e..02946366b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/Rename.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/Rename.java @@ -14,13 +14,11 @@ import java.util.Collection; /** - * A command to rename a {@link org.dizitart.no2.collection.NitriteCollection}. - * * @author Anindya Chatterjee * @since 4.0 */ @AllArgsConstructor -public class Rename extends BaseCommand implements Command { +public class Rename extends BaseCommand { private final String oldName; private final String newName; diff --git a/nitrite/src/main/java/org/dizitart/no2/migration/commands/RenameField.java b/nitrite/src/main/java/org/dizitart/no2/migration/commands/RenameField.java index 564a4878b..b85bab126 100644 --- a/nitrite/src/main/java/org/dizitart/no2/migration/commands/RenameField.java +++ b/nitrite/src/main/java/org/dizitart/no2/migration/commands/RenameField.java @@ -18,7 +18,7 @@ * @since 4.0 */ @AllArgsConstructor -public class RenameField extends BaseCommand implements Command { +public class RenameField extends BaseCommand { private final String collectionName; private final String oldName; private final String newName; diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java b/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java index be09c0c1d..524563823 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java @@ -23,7 +23,6 @@ import org.dizitart.no2.collection.UpdateOptions; import org.dizitart.no2.collection.events.CollectionEventListener; import org.dizitart.no2.common.WriteResult; -import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.common.processors.Processor; import org.dizitart.no2.filters.Filter; diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecorator.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecorator.java index fee8de619..e879bc9c8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecorator.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecorator.java @@ -20,10 +20,10 @@ import java.util.List; /** - * A class that implements this interface can be used to decorate - * an entity of type T for nitrite database where using - * {@link org.dizitart.no2.repository.annotations.Entity} - * or its related annotations is not possible on a class. + * An interface that can be used to implement a decorator + * for an entity class of type T, where annotating + * the class with {@link org.dizitart.no2.repository.annotations.Entity} + * and its friends is not possible. * * @param the type parameter * @see org.dizitart.no2.Nitrite#getRepository(EntityDecorator) diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java index 46667e643..615dcd924 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java @@ -33,6 +33,7 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ public class EntityDecoratorScanner { private final EntityDecorator entityDecorator; diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java index 387ebc7c5..d8c8a7174 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityId.java @@ -30,9 +30,26 @@ import static org.dizitart.no2.filters.FluentFilter.where; +/** + * Represents the unique identifier for an entity in an {@link ObjectRepository}. + *

+ * An entity ID consists of a field name and optional sub-fields. + * If sub-fields are present, the ID is considered to be embedded. + * + * + * @author Anindya Chatterjee + * @since 4.0 + */ @Getter public class EntityId { + /** + * Returns the name of the id field. + */ private final String fieldName; + + /** + * Returns the sub-fields of the id field. + */ private final String[] subFields; private List embeddedFieldNames; @@ -42,6 +59,11 @@ public EntityId(String fieldName, String... subFields) { this.subFields = subFields; } + /** + * Returns a list of embedded field names. + * + * @return a list of embedded field names. + */ public List getEmbeddedFieldNames() { if (embeddedFieldNames != null) return embeddedFieldNames; embeddedFieldNames = new ArrayList<>(); @@ -54,10 +76,22 @@ public List getEmbeddedFieldNames() { return embeddedFieldNames; } + /** + * Checks if the entity id is embedded. + * + * @return true if the entity id is embedded; false otherwise. + */ public boolean isEmbedded() { return subFields != null && subFields.length != 0; } + /** + * Creates a unique filter for the entity id. + * + * @param value the value of the id. + * @param nitriteMapper the nitrite mapper. + * @return the unique filter. + */ public Filter createUniqueFilter(Object value, NitriteMapper nitriteMapper) { if (isEmbedded()) { Document document = (Document) nitriteMapper.tryConvert(value, Document.class); diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityIndex.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityIndex.java index 1342bfd36..a4d035033 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityIndex.java @@ -28,7 +28,7 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * Represents an index fields. + * Represents an index for an entity in the Nitrite database. * * @author Anindya Chatterjee * @since 4.0 @@ -36,9 +36,15 @@ public class EntityIndex { @Getter + /** + * The type of index to be used for the entity field. + */ private String indexType; @Getter + /** + * The list of field names on which index is created. + */ private List fieldNames; public EntityIndex(String indexType, String... fields) { diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/IndexValidator.java b/nitrite/src/main/java/org/dizitart/no2/repository/IndexValidator.java index 3b225a292..8d78e3e5a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/IndexValidator.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/IndexValidator.java @@ -28,16 +28,10 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ public class IndexValidator { - /** - * Validate an index field of an {@link org.dizitart.no2.repository.annotations.Entity} object. - * - * @param fieldType the field type - * @param field the field - * @param nitriteMapper the nitrite mapper - */ public void validate(Class fieldType, String field, NitriteMapper nitriteMapper) { if (fieldType.isPrimitive() || fieldType == NitriteId.class diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectCursor.java b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectCursor.java index c8502b5f7..66ba28762 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectCursor.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectCursor.java @@ -35,6 +35,7 @@ /** * @author Anindya Chatterjee. + * @since 4.0 */ class ObjectCursor implements Cursor { private final DocumentCursor cursor; diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java index 8a237fab1..c12994da4 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/ObjectIdField.java @@ -31,6 +31,7 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ @Getter @Setter diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java b/nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java index fa334668c..7e89e0cff 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/Reflector.java @@ -34,6 +34,7 @@ /** * @author Anindya Chatterjee + * @since 4.0 */ class Reflector { @SuppressWarnings("rawtypes") diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryFactory.java b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryFactory.java index f3bf6f642..f7fd4485a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryFactory.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryFactory.java @@ -35,8 +35,6 @@ import static org.dizitart.no2.common.util.ValidationUtils.validateRepositoryType; /** - * The {@link ObjectRepository} factory. - * * @author Anindya Chatterjee * @since 1.0 */ @@ -45,38 +43,16 @@ public class RepositoryFactory { private final CollectionFactory collectionFactory; private final ReentrantLock lock; - /** - * Instantiates a new {@link RepositoryFactory}. - * - * @param collectionFactory the collection factory - */ public RepositoryFactory(CollectionFactory collectionFactory) { this.collectionFactory = collectionFactory; this.repositoryMap = new HashMap<>(); this.lock = new ReentrantLock(); } - /** - * Gets an {@link ObjectRepository} by type. - * - * @param the type parameter - * @param nitriteConfig the nitrite config - * @param type the type - * @return the repository - */ public ObjectRepository getRepository(NitriteConfig nitriteConfig, Class type) { return getRepository(nitriteConfig, type, null); } - /** - * Gets an {@link ObjectRepository} by type and a key. - * - * @param the type parameter - * @param nitriteConfig the nitrite config - * @param type the type - * @param key the key - * @return the repository - */ @SuppressWarnings("unchecked") public ObjectRepository getRepository(NitriteConfig nitriteConfig, Class type, String key) { if (type == null) { @@ -107,7 +83,6 @@ public ObjectRepository getRepository(NitriteConfig nitriteConfig, Class< } } - public ObjectRepository getRepository(NitriteConfig nitriteConfig, EntityDecorator entityDecorator) { return getRepository(nitriteConfig, entityDecorator, null); } @@ -142,9 +117,6 @@ public ObjectRepository getRepository(NitriteConfig nitriteConfig, Entity } } - /** - * Closes all opened {@link ObjectRepository}s and clear internal data from this class. - */ public void clear() { try { lock.lock(); diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java index 2a6a95fe4..254c86cba 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java @@ -30,11 +30,6 @@ import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; /** - * The {@link ObjectRepository} operations. - *

- * This class is for internal use only. - *

- * * @author Anindya Chatterjee * @since 4.0 */ @@ -47,13 +42,6 @@ public class RepositoryOperations { private ObjectIdField objectIdField; private EntityDecoratorScanner entityDecoratorScanner; - /** - * Instantiates a new {@link RepositoryOperations}. - * - * @param type the type - * @param nitriteConfig the nitrite config - * @param collection the collection - */ public RepositoryOperations(Class type, NitriteCollection collection, NitriteConfig nitriteConfig) { this.type = type; this.nitriteConfig = nitriteConfig; @@ -72,9 +60,6 @@ public RepositoryOperations(EntityDecorator entityDecorator, NitriteCollectio validateCollection(); } - /** - * Create indices. - */ public void createIndices() { if (annotationScanner != null) { annotationScanner.performScan(); @@ -89,11 +74,6 @@ public void createIndices() { } } - /** - * Serialize fields. - * - * @param document the document - */ public void serializeFields(Document document) { if (document != null) { for (Pair pair : document) { @@ -106,13 +86,6 @@ public void serializeFields(Document document) { } } - /** - * To documents document [ ]. - * - * @param the type parameter - * @param others the others - * @return the document [ ] - */ public Document[] toDocuments(T[] others) { if (others == null || others.length == 0) return null; Document[] documents = new Document[others.length]; @@ -122,14 +95,6 @@ public Document[] toDocuments(T[] others) { return documents; } - /** - * To document document. - * - * @param the type parameter - * @param object the object - * @param update the update - * @return the document - */ public Document toDocument(T object, boolean update) { Document document = (Document) nitriteMapper.tryConvert(object, Document.class); if (document == null) { @@ -167,12 +132,6 @@ public Document toDocument(T object, boolean update) { return document; } - /** - * Create unique filter filter. - * - * @param object the object - * @return the filter - */ public Filter createUniqueFilter(Object object) { if (objectIdField == null) { throw new NotIdentifiableException("No id value found for the object"); @@ -191,11 +150,6 @@ public Filter createUniqueFilter(Object object) { } } - /** - * Remove nitrite id. - * - * @param document the document - */ public void removeNitriteId(Document document) { document.remove(DOC_ID); if (objectIdField != null) { @@ -206,13 +160,6 @@ public void removeNitriteId(Document document) { } } - /** - * Create id filter filter. - * - * @param the type parameter - * @param id the id - * @return the filter - */ public Filter createIdFilter(I id) { if (objectIdField != null) { if (id == null) { @@ -228,12 +175,6 @@ public Filter createIdFilter(I id) { } } - /** - * As object filter filter. - * - * @param filter the filter - * @return the filter - */ public Filter asObjectFilter(Filter filter) { if (filter instanceof NitriteFilter) { NitriteFilter nitriteFilter = (NitriteFilter) filter; @@ -248,15 +189,6 @@ public Filter asObjectFilter(Filter filter) { return filter; } - /** - * Find cursor. - * - * @param the type parameter - * @param filter the filter - * @param findOptions the find options - * @param type the type - * @return the cursor - */ public Cursor find(Filter filter, FindOptions findOptions, Class type) { DocumentCursor documentCursor = collection.find(asObjectFilter(filter), findOptions); return new ObjectCursor<>(nitriteMapper, documentCursor, type); diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Entity.java b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Entity.java index 92822a3d2..2b8de844f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Entity.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Entity.java @@ -22,7 +22,8 @@ import java.lang.annotation.Target; /** - * Represents an entity for an {@link org.dizitart.no2.repository.ObjectRepository}. + * Annotation to mark a class as an entity. An entity is a persistent + * class which can be stored in an {@link org.dizitart.no2.repository.ObjectRepository}. * * @author Anindya Chatterjee * @since 4.0 @@ -39,7 +40,7 @@ String value() default ""; /** - * Index definitions of the entity. + * A list of indices for the repository. * * @return the index definitions */ diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Id.java b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Id.java index afd9c5178..9932adc84 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Id.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Id.java @@ -22,7 +22,7 @@ import java.lang.annotation.Target; /** - * Indicates that an annotated field is the id field. + * Annotation to mark a field as the id field of a repository. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Index.java b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Index.java index 5364fcda5..ed12ab7f9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Index.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Index.java @@ -21,7 +21,7 @@ import java.lang.annotation.*; /** - * Specifies a field to be indexed. + * Annotation to mark a field as indexed. * * @author Anindya Chatterjee. * @since 1.0 diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Indices.java b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Indices.java index 836fc5a93..da8bcfb50 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Indices.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/Indices.java @@ -22,7 +22,7 @@ import java.lang.annotation.Target; /** - * Specifies multiple indexed fields for a class. + * Specifies multiple indexed fields for an entity. * @author Anindya Chatterjee. * @see Index diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/InheritIndices.java b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/InheritIndices.java index 119e7303a..4eec640ae 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/annotations/InheritIndices.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/annotations/InheritIndices.java @@ -19,7 +19,7 @@ import java.lang.annotation.*; /** - * Indicates that a class should consider all index related + * Annotation to mark a class that should consider all index related * annotations - @Id, @Index, * @Indices from its superclass. * diff --git a/nitrite/src/main/java/org/dizitart/no2/store/AbstractNitriteStore.java b/nitrite/src/main/java/org/dizitart/no2/store/AbstractNitriteStore.java index b36b0b74f..3c50ef2cf 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/AbstractNitriteStore.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/AbstractNitriteStore.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.Setter; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.NitriteConfig; import org.dizitart.no2.common.event.NitriteEventBus; import org.dizitart.no2.store.events.EventInfo; @@ -14,30 +13,37 @@ import java.util.Set; /** - * An abstract {@link NitriteStore} implementation. + * An abstract implementation of the {@link NitriteStore} interface + * that provides common functionality for Nitrite data stores. * - * @param the type parameter + * @param the type of the store configuration object * @author Anindya Chatterjee * @since 4.0 */ @Getter -@Slf4j public abstract class AbstractNitriteStore - implements NitriteStore { + implements NitriteStore { @Setter + /** + * The configuration object for the Nitrite store. + */ private Config storeConfig; /** - * The {@link NitriteEventBus} for the database. + * The event bus used to publish and subscribe to store events. */ protected final NitriteEventBus eventBus; /** - * The {@link NitriteConfig} for this store. + * The NitriteConfig object that holds the configuration for the Nitrite + * database. */ protected NitriteConfig nitriteConfig; + /** + * The catalog of all the collections and repositories in the Nitrite database. + */ private StoreCatalog storeCatalog; /** @@ -48,9 +54,9 @@ protected AbstractNitriteStore() { } /** - * Alerts about a {@link StoreEvents} to all subscribed {@link StoreEventListener}s. + * Sends an alert to the event bus for the specified event type. * - * @param eventType the event type + * @param eventType the type of event to send an alert for */ protected void alert(StoreEvents eventType) { EventInfo event = new EventInfo(eventType, nitriteConfig); diff --git a/nitrite/src/main/java/org/dizitart/no2/store/MapMetaData.java b/nitrite/src/main/java/org/dizitart/no2/store/MapMetaData.java index 840ebed23..3ee287239 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/MapMetaData.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/MapMetaData.java @@ -27,8 +27,6 @@ import static org.dizitart.no2.common.Constants.TAG_MAP_METADATA; /** - * The Map metadata. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/MetaData.java b/nitrite/src/main/java/org/dizitart/no2/store/MetaData.java index 24b4ac7b9..21da02c7e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/MetaData.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/MetaData.java @@ -20,8 +20,6 @@ import org.dizitart.no2.collection.Document; /** - * The Metadata interface. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/NitriteStore.java b/nitrite/src/main/java/org/dizitart/no2/store/NitriteStore.java index a3cad2326..891da05cc 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/NitriteStore.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/NitriteStore.java @@ -35,7 +35,7 @@ public interface NitriteStore extends NitritePlugin { /** - * Opens or creates this nitrite store. + * Opens the store if it exists, or creates a new one if it doesn't. */ void openOrCreate(); @@ -47,37 +47,37 @@ public interface NitriteStore extends NitritePlugin boolean isClosed(); /** - * Gets the set of all {@link NitriteCollection} names in store. + * Returns a set of all collection names in the store. * - * @return the set of names. + * @return a set of all collection names in the store */ Set getCollectionNames(); /** - * Gets the set of all {@link ObjectRepository} details in store. + * Returns a set of all the repository names registered in the Nitrite store. * - * @return the details of all {@link ObjectRepository}. + * @return a set of all the repository names registered in the Nitrite store */ Set getRepositoryRegistry(); /** - * Gets the set of all keyed-{@link ObjectRepository} details in store. + * Returns a set of all the keyed-repository names registered in the Nitrite store. * - * @return the details of all {@link ObjectRepository}. + * @return a set of all the keyed-repository names registered in the Nitrite store */ Map> getKeyedRepositoryRegistry(); /** - * Checks whether there are any unsaved changes. + * Checks if the store has any unsaved changes. * - * @return true if here are any changes; false otherwise. + * @return {@code true} if the store has unsaved changes; {@code false} otherwise. */ boolean hasUnsavedChanges(); /** - * Checks whether the store is opened in readonly mode. + * Checks if the store is opened in read-only mode. * - * @return true if he store is opened in readonly mode; false otherwise. + * @return {@code true} if the store is read-only; {@code false} otherwise. */ boolean isReadOnly(); @@ -88,22 +88,23 @@ public interface NitriteStore extends NitritePlugin void commit(); /** - * This method runs before store {@link #close()}, to run cleanup routines. + * This method is called before closing the store. Any cleanup or finalization + * tasks should be performed in this method. */ void beforeClose(); /** - * Checks whether a map with the name already exists in the store or not. + * Checks if a {@link NitriteMap} with the given name exists in the store. * - * @param mapName the map name - * @return true if the map exists; false otherwise + * @param mapName the name of the map to check + * @return true if the map exists, false otherwise */ boolean hasMap(String mapName); /** - * Opens a {@link NitriteMap} with the default settings. The map is - * automatically created if it does not yet exist. If a map with this - * name is already opened, this map is returned. + * Opens a {@link NitriteMap}. The map is automatically created if + * it does not yet exist. If a map with this name is already opened, + * this map is returned. * * @param the key type * @param the value type @@ -115,23 +116,26 @@ public interface NitriteStore extends NitritePlugin NitriteMap openMap(String mapName, Class keyType, Class valueType); /** - * Closes a {@link NitriteMap} in the store. + * Closes a {@link NitriteMap} with the specified name in the store. * * @param mapName the map name */ void closeMap(String mapName); /** - * Removes a {@link NitriteMap} from the store. + * Removes a {@link NitriteMap} with the specified name from the store. * * @param mapName the map name to remove. */ void removeMap(String mapName); /** - * Opens a {@link NitriteRTree} with the default settings. The RTree is - * automatically created if it does not yet exist. If a RTree with this - * name is already open, this RTree is returned. + * Opens a {@link NitriteRTree} with the given key and value types. The key type must + * extend the {@link BoundingBox} class. Returns a {@link NitriteRTree} instance that + * can be used to perform R-Tree operations on the data. + *

+ * RTree is automatically created if it does not yet exist. If a + * RTree with this name is already open, this RTree is returned. * * @param the key type * @param the value type @@ -142,37 +146,36 @@ public interface NitriteStore extends NitritePlugin */ NitriteRTree openRTree(String rTreeName, Class keyType, Class valueType); - /** - * Closes a RTree in the store. + * Closes a {@link NitriteRTree} with the specified name in the store. * * @param rTreeName the RTree name */ void closeRTree(String rTreeName); /** - * Removes a RTree from the store. + * Removes a {@link NitriteRTree} with the specified name from the store. * * @param rTreeName the RTree name to remove. */ void removeRTree(String rTreeName); /** - * Adds a {@link StoreEventListener} to listen to all store events. + * Subscribes a {@link StoreEventListener} to this store. The listener will be notified of any changes made to the store. * - * @param listener the listener instances. + * @param listener the listener to subscribe */ void subscribe(StoreEventListener listener); /** - * Removes a {@link StoreEventListener} to unsubscribe from all store events. + * Unsubscribes a {@link StoreEventListener} from this store. * - * @param listener the listener instances. + * @param listener the listener to unsubscribe */ void unsubscribe(StoreEventListener listener); /** - * Gets the underlying store engine version. + * Gets the underlying storage engine version. * * @return the store version */ @@ -185,7 +188,6 @@ public interface NitriteStore extends NitritePlugin */ Config getStoreConfig(); - /** * Gets the store catalog. * diff --git a/nitrite/src/main/java/org/dizitart/no2/store/StoreCatalog.java b/nitrite/src/main/java/org/dizitart/no2/store/StoreCatalog.java index d8b0a8fd3..6fce86076 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/StoreCatalog.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/StoreCatalog.java @@ -34,7 +34,7 @@ * repositories and keyed-repositories. * * @author Anindya Chatterjee - * @since 4.0.0 + * @since 4.0 */ public class StoreCatalog { private final NitriteMap catalogMap; @@ -49,9 +49,9 @@ public StoreCatalog(NitriteStore nitriteStore) { } /** - * Writes a new collection entry to the catalog. + * Writes a new entry for a collection with the given name to the store catalog. * - * @param name the name + * @param name the name of the collection to add to the catalog */ public void writeCollectionEntry(String name) { Document document = catalogMap.get(TAG_COLLECTIONS); @@ -68,9 +68,9 @@ public void writeCollectionEntry(String name) { } /** - * Writes a repository entry to the catalog. + * Writes a repository entry with the given name to the store catalog. * - * @param name the name + * @param name the name of the repository to be added to the catalog */ public void writeRepositoryEntry(String name) { Document document = catalogMap.get(TAG_REPOSITORIES); @@ -87,9 +87,9 @@ public void writeRepositoryEntry(String name) { } /** - * Writes a keyed repository entries to the catalog + * Writes a keyed repository entry to the store catalog. * - * @param name the name + * @param name the name of the keyed repository to be added */ public void writeKeyedRepositoryEntry(String name) { Document document = catalogMap.get(TAG_KEYED_REPOSITORIES); @@ -105,9 +105,9 @@ public void writeKeyedRepositoryEntry(String name) { } /** - * Gets all collection names. + * Returns a set of all collection names in the Nitrite database. * - * @return the collection names + * @return a set of all collection names in the Nitrite database */ public Set getCollectionNames() { Document document = catalogMap.get(TAG_COLLECTIONS); @@ -118,9 +118,9 @@ public Set getCollectionNames() { } /** - * Gets all repository names. + * Returns a set of all repository names in the Nitrite database. * - * @return the repository names + * @return a set of all repository names in the Nitrite database */ public Set getRepositoryNames() { Document document = catalogMap.get(TAG_REPOSITORIES); @@ -131,9 +131,9 @@ public Set getRepositoryNames() { } /** - * Gets all keyed repository names. + * Returns a set of all keyed-repository names in the Nitrite database. * - * @return the keyed repository names + * @return a set of all keyed-repository names in the Nitrite database */ public Map> getKeyedRepositoryNames() { Document document = catalogMap.get(TAG_KEYED_REPOSITORIES); @@ -160,7 +160,7 @@ public Map> getKeyedRepositoryNames() { } /** - * Removes the entry from the catalog specified by name. + * Removes the entry from the catalog specified by a name. * * @param name the name */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/StoreConfig.java b/nitrite/src/main/java/org/dizitart/no2/store/StoreConfig.java index 9e3ea8106..028506922 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/StoreConfig.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/StoreConfig.java @@ -20,37 +20,38 @@ import org.dizitart.no2.store.events.StoreEventListener; /** - * Represents a {@link NitriteStore} configuration. + * Represents the configuration interface of a {@link NitriteStore}. * * @author Anindya Chatterjee. * @since 4.0 */ public interface StoreConfig { /** - * Gets file path for the store. + * Gets the file path of the store. * - * @return the file path + * @return the file path of the store. */ String filePath(); /** - * Indicates if the {@link NitriteStore} is a readonly store. + * Returns a boolean indicating whether the store is read-only or not. * - * @return true, if readonly store; otherwise false. + * @return a boolean indicating whether the store is read-only or not */ Boolean isReadOnly(); /** - * Adds a {@link StoreEventListener} instance and subscribe it to store event. + * Adds a {@link StoreEventListener} to the store configuration. + * The listener will be notified of any store events. * - * @param listener the listener + * @param listener the listener to add */ void addStoreEventListener(StoreEventListener listener); /** - * Indicates if the {@link NitriteStore} is an in-memory store. + * Checks if the store is in-memory. * - * @return true, if in-memory store; otherwise false. + * @return {@code true} if the store is in-memory; {@code false} otherwise. */ default boolean isInMemory() { return StringUtils.isNullOrEmpty(filePath()); diff --git a/nitrite/src/main/java/org/dizitart/no2/store/StoreMetaData.java b/nitrite/src/main/java/org/dizitart/no2/store/StoreMetaData.java index 9bebc4622..0d5f5bad2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/StoreMetaData.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/StoreMetaData.java @@ -21,8 +21,6 @@ import org.dizitart.no2.collection.Document; /** - * The nitrite database metadata. - * * @author Anindya Chatterjee. * @since 4.0 */ @@ -34,20 +32,10 @@ public class StoreMetaData implements MetaData { private String nitriteVersion; private Integer schemaVersion; - /** - * Instantiates a new {@link StoreMetaData}. - * - * @param document the document - */ public StoreMetaData(Document document) { populateInfo(document); } - /** - * Gets the database info in a document. - * - * @return the info - */ public Document getInfo() { return Document.createDocument() .put("createTime", createTime) diff --git a/nitrite/src/main/java/org/dizitart/no2/store/UserAuthenticationService.java b/nitrite/src/main/java/org/dizitart/no2/store/UserAuthenticationService.java index 5285c3485..41fb2bac1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/UserAuthenticationService.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/UserAuthenticationService.java @@ -32,8 +32,6 @@ import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; /** - * User authentication service for nitrite. - * * @author Anindya Chatterjee * @since 4.0 */ @@ -42,22 +40,11 @@ public class UserAuthenticationService { private final SecureRandom random; private final NitriteStore store; - /** - * Instantiates a new {@link UserAuthenticationService}. - * - * @param store the store - */ public UserAuthenticationService(NitriteStore store) { this.store = store; this.random = new SecureRandom(); } - /** - * Authenticates a user if the authentication data already exists in the database. - * - * @param username the username - * @param password the password - */ public void authenticate(String username, String password) { boolean existing = store.hasMap(USER_MAP); if (!isNullOrEmpty(password) && !isNullOrEmpty(username)) { @@ -90,14 +77,6 @@ public void authenticate(String username, String password) { } } - /** - * Adds or updates the password for a user in the authentication data. - * - * @param update the update - * @param username the username - * @param oldPassword the old password - * @param newPassword the new password - */ public void addOrUpdatePassword(boolean update, String username, SecureString oldPassword, SecureString newPassword) { NitriteMap userMap = null; @@ -132,7 +111,6 @@ public void addOrUpdatePassword(boolean update, String username, SecureString ol userMap.put(username, userCredential); } - private byte[] getNextSalt() { byte[] salt = new byte[16]; random.nextBytes(salt); diff --git a/nitrite/src/main/java/org/dizitart/no2/store/UserCredential.java b/nitrite/src/main/java/org/dizitart/no2/store/UserCredential.java index ff25a6333..66c655215 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/UserCredential.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/UserCredential.java @@ -24,8 +24,6 @@ import java.io.Serializable; /** - * The user credential data for database authentication. - * * @author Anindya Chatterjee. * @since 1.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/events/EventInfo.java b/nitrite/src/main/java/org/dizitart/no2/store/events/EventInfo.java index 49bd27bc1..e8d3cd309 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/events/EventInfo.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/events/EventInfo.java @@ -21,9 +21,11 @@ import lombok.NoArgsConstructor; import org.dizitart.no2.NitriteConfig; + /** - * The nitrite event details. - * + * Represents an event information object that contains the event + * type and Nitrite configuration. + * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventBus.java b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventBus.java index a899b7701..81493c940 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventBus.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventBus.java @@ -19,11 +19,8 @@ import org.dizitart.no2.common.event.NitriteEventBus; /** - * The event bus for nitrite store events. - * - * @see StoreEvents * @author Anindya Chatterjee. - * @since 4.0.0 + * @since 4.0 */ public class StoreEventBus extends NitriteEventBus { @Override diff --git a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventListener.java b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventListener.java index 0e9a248ff..15e7a11ba 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventListener.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEventListener.java @@ -17,9 +17,9 @@ package org.dizitart.no2.store.events; /** - * Represents an event listener for store events. - * - * @see StoreEvents + * An interface for listening to events fired by a + * {@link org.dizitart.no2.store.NitriteStore}. + * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEvents.java b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEvents.java index c5fbb36f5..64285f140 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEvents.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/events/StoreEvents.java @@ -17,29 +17,29 @@ package org.dizitart.no2.store.events; /** - * Nitrite store related events. - * + * An enumeration of events that can occur in a Nitrite store. + * * @author Anindya Chatterjee * @since 4.0 */ public enum StoreEvents { /** - * The store opened event. + * Event emitted when a Nitrite database is opened. */ Opened, /** - * The store commit event. + * Event emitted when a commit is made to the database. */ Commit, /** - * The store closing event. + * Event emitted when a Nitrite database is about to close. */ Closing, /** - * The store closed event. + * Event emitted when a Nitrite database is closed. */ Closed } diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryConfig.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryConfig.java index 377075e02..920e751a7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryConfig.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryConfig.java @@ -11,8 +11,6 @@ import java.util.Set; /** - * The in-memory nitrite store config. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java index 33b6db16f..2394a1fcd 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java @@ -16,10 +16,6 @@ import static org.dizitart.no2.common.util.ValidationUtils.notNull; /** - * The in-memory {@link NitriteMap}. - * - * @param the type parameter - * @param the type parameter * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryModuleBuilder.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryModuleBuilder.java index c9bfa6fb8..e7974e768 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryModuleBuilder.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryModuleBuilder.java @@ -8,8 +8,6 @@ import java.util.Set; /** - * The in-memory store module builder. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryRTree.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryRTree.java index 0b332bb5f..82e7a63c7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryRTree.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryRTree.java @@ -15,10 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * The in-memory {@link NitriteRTree}. - * - * @param the type parameter - * @param the type parameter * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStore.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStore.java index 8a29b0885..cc265f37a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStore.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStore.java @@ -10,13 +10,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; -import java.util.function.Function; - import static org.dizitart.no2.common.Constants.NITRITE_VERSION; /** - * The nitrite in-memory store. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStoreModule.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStoreModule.java index e32ac6c96..cca6753b9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStoreModule.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryStoreModule.java @@ -11,8 +11,6 @@ import static org.dizitart.no2.common.util.Iterables.setOf; /** - * The in-memory store module for nitrite. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/ChangeType.java b/nitrite/src/main/java/org/dizitart/no2/transaction/ChangeType.java index d7c296ed1..9dc2581eb 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/ChangeType.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/ChangeType.java @@ -18,59 +18,18 @@ package org.dizitart.no2.transaction; /** - * Represents a change type in a transaction. - * * @author Anindya Chatterjee * @since 4.0 */ enum ChangeType { - /** - * Insert - */ Insert, - - /** - * Update. - */ Update, - - /** - * Remove. - */ Remove, - - /** - * Clear. Commit only operation, cannot be rolled back. - */ Clear, - - /** - * Create index. - */ CreateIndex, - - /** - * Rebuild index. - */ RebuildIndex, - - /** - * Drop index. - */ DropIndex, - - /** - * Drop all indices. - */ DropAllIndexes, - - /** - * Drop collection. Commit only operation, cannot be rolled back. - */ DropCollection, - - /** - * Set attribute. - */ SetAttributes, } diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/Command.java b/nitrite/src/main/java/org/dizitart/no2/transaction/Command.java index c7856c234..ddad8a243 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/Command.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/Command.java @@ -1,14 +1,9 @@ package org.dizitart.no2.transaction; /** - * Represents an operation in a transaction. - * * @author Anindya Chatterjee * @since 4.0 */ interface Command { - /** - * Executes the command during transaction commit or rollback. - */ void execute(); } diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java index 1e9da1701..52b27d549 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java @@ -7,7 +7,6 @@ import org.dizitart.no2.collection.UpdateOptions; import org.dizitart.no2.collection.events.CollectionEventListener; import org.dizitart.no2.common.WriteResult; -import org.dizitart.no2.common.mapper.NitriteMapper; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.common.processors.Processor; import org.dizitart.no2.filters.Filter; diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/JournalEntry.java b/nitrite/src/main/java/org/dizitart/no2/transaction/JournalEntry.java index 73de9719a..250dc6a2a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/JournalEntry.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/JournalEntry.java @@ -5,8 +5,6 @@ import lombok.NoArgsConstructor; /** - * Represents a transaction journal entry. - * * @author Anindya Chatterjee * @since 4.0 */ diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/NitriteTransaction.java b/nitrite/src/main/java/org/dizitart/no2/transaction/NitriteTransaction.java index ae3d8e94a..2ec8234fa 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/NitriteTransaction.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/NitriteTransaction.java @@ -26,7 +26,7 @@ * @author Anindya Chatterjee * @since 4.0 */ -@Slf4j +@Slf4j(topic = "nitrite") class NitriteTransaction implements Transaction { private final Nitrite nitrite; private final LockService lockService; diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/Session.java b/nitrite/src/main/java/org/dizitart/no2/transaction/Session.java index 22bf76ae5..c2f95503c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/Session.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/Session.java @@ -9,15 +9,15 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * A nitrite transaction session. A session is needed to - * initiate a transaction in nitrite database. - * + * A session represents a transactional context for a Nitrite database. + * It provides methods to create a new transaction. + *

+ * A session should be closed after use to release any resources associated with it. *

* If a session is closed and the transaction is not committed, * all opened transactions will get rolled back and all volatile * data gets discarded for the session. - *

- * + * * @author Anindya Chatterjee * @since 4.0 */ @@ -43,7 +43,7 @@ public Session(Nitrite nitrite, LockService lockService) { /** * Begins a new transaction. * - * @return the transaction + * @return the new transaction. */ public Transaction beginTransaction() { checkState(); diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/Transaction.java b/nitrite/src/main/java/org/dizitart/no2/transaction/Transaction.java index ffc156a72..f1b0185af 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/Transaction.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/Transaction.java @@ -3,25 +3,60 @@ import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.repository.ObjectRepository; import org.dizitart.no2.repository.EntityDecorator; +import org.dizitart.no2.index.IndexOptions; /** - * Represents an ACID transaction on nitrite database. - * + * Represents a transaction in Nitrite database. It provides methods to perform + * ACID operations + * on Nitrite database collections and repositories. + *

+ * A transaction can be committed or rolled back. Once a transaction is + * committed, all changes + * made during the transaction are persisted to the underlying store. If a + * transaction is + * rolled back, all changes made during the transaction are discarded. + *

+ * + * NOTE: Certain operations are auto-committed in Nitrite database. Those + * operations are not + * part of a transaction and cannot be rolled back. The following operations are + * auto-committed: + * + *

    + *
  • {@link NitriteCollection#createIndex(String...)}
  • + *
  • {@link NitriteCollection#createIndex(IndexOptions, String...)}
  • + *
  • {@link NitriteCollection#rebuildIndex(String...)}
  • + *
  • {@link NitriteCollection#dropIndex(String...)}
  • + *
  • {@link NitriteCollection#dropAllIndices()}
  • + *
  • {@link NitriteCollection#clear()}
  • + *
  • {@link NitriteCollection#drop()}
  • + *
  • {@link NitriteCollection#close()}
  • + * + *
  • {@link ObjectRepository#createIndex(String...)}
  • + *
  • {@link ObjectRepository#createIndex(IndexOptions, String...)}
  • + *
  • {@link ObjectRepository#rebuildIndex(String...)}
  • + *
  • {@link ObjectRepository#dropIndex(String...)}
  • + *
  • {@link ObjectRepository#dropAllIndices()}
  • + *
  • {@link ObjectRepository#clear()}
  • + *
  • {@link ObjectRepository#drop()}
  • + *
  • {@link ObjectRepository#close()}
  • + * + * * @author Anindya Chatterjee * @since 4.0 */ public interface Transaction extends AutoCloseable { /** - * Gets the transaction id. + * Gets the unique identifier of the transaction. * - * @return the id + * @return the unique identifier of the transaction. */ String getId(); /** - * Gets the current state of the transaction. + * Returns the current state of the transaction. * - * @return the state + * @return the current state of the transaction. */ TransactionState getState(); @@ -52,11 +87,10 @@ public interface Transaction extends AutoCloseable { */ ObjectRepository getRepository(Class type, String key); - /** * Gets an {@link ObjectRepository} to perform ACID operations on it. * - * @param the type parameter + * @param the type parameter * @param entityDecorator the entityDecorator * @return the repository */ @@ -65,9 +99,9 @@ public interface Transaction extends AutoCloseable { /** * Gets an {@link ObjectRepository} to perform ACID operations on it. * - * @param the type parameter + * @param the type parameter * @param entityDecorator the entityDecorator - * @param key the key + * @param key the key * @return the repository */ ObjectRepository getRepository(EntityDecorator entityDecorator, String key); @@ -78,12 +112,12 @@ public interface Transaction extends AutoCloseable { void commit(); /** - * Rolls back the changes. + * Rolls back the transaction, discarding any changes made during the transaction. */ void rollback(); /** * Closes this {@link Transaction}. - * */ + */ void close(); } diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionConfig.java b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionConfig.java index 3e8e6a979..4e5ec2235 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionConfig.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionConfig.java @@ -1,6 +1,5 @@ package org.dizitart.no2.transaction; -import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.NitriteConfig; import org.dizitart.no2.common.mapper.NitriteMapper; @@ -8,7 +7,6 @@ * @author Anindya Chatterjee * @since 4.0 */ -@Slf4j class TransactionConfig extends NitriteConfig { private final NitriteConfig config; diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionState.java b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionState.java index 88129c048..133ad9529 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionState.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionState.java @@ -1,8 +1,8 @@ package org.dizitart.no2.transaction; /** - * The transaction state. - * + * An enumeration representing the possible states of a transaction. + * * @author Anindya Chatterjee * @since 4.0 */ @@ -28,7 +28,7 @@ public enum TransactionState { Closed, /** - * Transaction failed. + * Transaction failed and rolled back. */ Failed, diff --git a/nitrite/src/test/java/org/dizitart/no2/exceptions/SyncExceptionTest.java b/nitrite/src/test/java/org/dizitart/no2/exceptions/SyncExceptionTest.java deleted file mode 100644 index c3907f827..000000000 --- a/nitrite/src/test/java/org/dizitart/no2/exceptions/SyncExceptionTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.dizitart.no2.exceptions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -import org.junit.Test; - -public class SyncExceptionTest { - @Test - public void testConstructor() { - Throwable throwable = new Throwable(); - assertSame((new SyncException("An error occurred", throwable)).getCause(), throwable); - } - - @Test - public void testConstructor2() { - SyncException actualSyncException = new SyncException("An error occurred"); - assertEquals("org.dizitart.no2.exceptions.SyncException: An error occurred", actualSyncException.toString()); - assertEquals("An error occurred", actualSyncException.getLocalizedMessage()); - assertNull(actualSyncException.getCause()); - assertEquals("An error occurred", actualSyncException.getMessage()); - assertEquals(0, actualSyncException.getSuppressed().length); - } -} - diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt index 90c7b5349..dbe3a6010 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt @@ -25,7 +25,7 @@ import org.dizitart.no2.common.module.NitriteModule.module import org.dizitart.no2.spatial.SpatialIndexer /** - * A builder to create a nitrite database. + * A builder class for creating instances of [Nitrite]. * * @since 2.1.0 * @author Anindya Chatterjee @@ -34,15 +34,15 @@ class Builder internal constructor() { private val modules = mutableSetOf() /** - * Specifies the separator character for embedded field. - * Default value is `.` - * - * */ + * The field separator used by the Nitrite database. By default, it is set to the field + * separator defined in the Nitrite configuration. + */ var fieldSeparator: String = NitriteConfig.getFieldSeparator() /** - * Loads [NitriteModule] instances. - * */ + * Loads a Nitrite module into the Nitrite database. The module can be used to extend the + * functionality of Nitrite. + */ fun loadModule(module: NitriteModule) { modules.add(module) } @@ -59,7 +59,8 @@ class Builder internal constructor() { private fun loadDefaultPlugins(builder: NitriteBuilder) { val mapperFound = modules.any { module -> module.plugins().any { it is NitriteMapper } } - val spatialIndexerFound = modules.any { module -> module.plugins().any { it is SpatialIndexer } } + val spatialIndexerFound = + modules.any { module -> module.plugins().any { it is SpatialIndexer } } if (!mapperFound && spatialIndexerFound) { builder.loadModule(module(KNO2JacksonMapper())) @@ -72,17 +73,20 @@ class Builder internal constructor() { } /** - * Opens or creates a new database. If it is an in-memory store, then it - * will create a new one. If it is a file based store, and if the file does not - * exist, then it will create a new file store and open; otherwise it will - * open the existing file store. + * Opens or creates a new Nitrite database. If it is configured as in-memory database, then it will + * create a new database everytime. If it is configured as a file based database, and if the file + * does not exist, then it will create a new file store and open the database; otherwise it will + * open the existing database file. * * @param [userId] the user id * @param [password] the password * @return the nitrite database instance. */ -fun nitrite(userId: String? = null, password: String? = null, - op: (Builder.() -> Unit)? = null): Nitrite { +fun nitrite( + userId: String? = null, + password: String? = null, + op: (Builder.() -> Unit)? = null +): Nitrite { val builder = Builder() op?.invoke(builder) val nitriteBuilder = builder.createNitriteBuilder() @@ -91,4 +95,4 @@ fun nitrite(userId: String? = null, password: String? = null, } else { nitriteBuilder.openOrCreate(userId, password) } -} \ No newline at end of file +} diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Documents.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Documents.kt index ff22d01d8..530c20835 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Documents.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Documents.kt @@ -25,47 +25,50 @@ import org.dizitart.no2.collection.Document.createDocument * @author Anindya Chatterjee */ + /** - * Creates an empty [Document]. + * Returns an empty [Document]. * - * @return an empty [Document] + * @return the empty [Document]. */ fun emptyDocument(): Document = createDocument() /** - * Creates an empty [Document]. + * Returns an empty [Document]. * - * @return an empty [Document] + * @return the empty [Document]. */ fun documentOf() = emptyDocument() /** - * Creates a [Document] from a [Pair]. + * Creates a new [Document] instance with a single key-value pair. * - * @return a [Document] containing the [pair] + * @param pair the key-value pair to add to the document. + * @return the newly created document instance. */ fun documentOf(pair: Pair): Document { return createDocument(pair.first, pair.second)!! } /** - * Checks if a [Document] is empty. + * Checks if the document is empty. * - * @return boolean value + * @return `true` if the document is empty; `false` otherwise. */ fun Document.isEmpty() = this.size() == 0 /** - * Checks if a [Document] is not empty. + * Checks if the document is not empty. * - * @return boolean value + * @return `true` if the document is not empty; `false` otherwise. */ fun Document.isNotEmpty() = !this.isEmpty() /** - * Creates a [Document] from a list of [Pair]s. + * Creates a new [Document] instance with the given key-value pairs. * - * @return a [Document] containing the [pairs] + * @param pairs the key-value pairs to be added to the document. + * @return the newly created document. */ fun documentOf(vararg pairs: Pair): Document { return if (pairs.isEmpty()) { diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2JacksonMapper.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2JacksonMapper.kt index cf823a79b..87eb22440 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2JacksonMapper.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2JacksonMapper.kt @@ -26,8 +26,9 @@ import org.dizitart.no2.common.mapper.JacksonMapper import org.dizitart.no2.spatial.mapper.GeometryModule /** - * Default [JacksonMapper] for potassium nitrite. - * + * A custom Jackson mapper for Potassium Nitrite (KNO2) library that extends [JacksonMapper] class. + * + * @param modules a vararg of Jackson modules to be registered with the mapper. * @author Anindya Chatterjee * @author Stefan Mandel * @since 2.1.0 diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2Module.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2Module.kt index 247a53775..5beb5dd32 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2Module.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/KNO2Module.kt @@ -23,7 +23,10 @@ import org.dizitart.no2.common.module.NitritePlugin import org.dizitart.no2.spatial.SpatialIndexer /** + * A module for Nitrite database that allows registering additional extensions. * + * @param extensions the additional extensions to be registered. + * @since 4.0 * @author Anindya Chatterjee */ open class KNO2Module(private vararg val extensions: Module) : NitriteModule { diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Nitrite.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Nitrite.kt index bc5759722..ba4a5dcfa 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Nitrite.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Nitrite.kt @@ -28,32 +28,44 @@ import org.dizitart.no2.repository.ObjectRepository */ /** - * Opens a named collection from the store. If the collections does not - * exist it will be created automatically and returned. If a collection - * is already opened, it is returned as is. Returned collection is thread-safe - * for concurrent use. + * Opens a named collection from the store. If the collections does not exist it will be created + * automatically and returned. If a collection is already opened, it is returned as is. + * + * Returned collection is thread-safe for concurrent use. + * + * The name cannot contain below reserved strings: + * + * - {@link Constants#INTERNAL_NAME_SEPARATOR} + * - {@link Constants#USER_MAP} + * - {@link Constants#INDEX_META_PREFIX} + * - {@link Constants#INDEX_PREFIX} + * - {@link Constants#OBJECT_STORE_NAME_SEPARATOR} * * @param [name] name of the collection * @param [op] collection builder block - * @return the collection + * @return the collection with the given name */ -fun Nitrite.getCollection(name: String, op: (NitriteCollection.() -> Unit)? = null): NitriteCollection { +fun Nitrite.getCollection( + name: String, + op: (NitriteCollection.() -> Unit)? = null +): NitriteCollection { val collection = this.getCollection(name) op?.invoke(collection) return collection } /** - * Opens a type-safe object repository from the store. If the repository - * does not exist it will be created automatically and returned. If a - * repository is already opened, it is returned as is. + * Opens a type-safe object repository from the store. If the repository does not exist it will be + * created automatically and returned. If a repository is already opened, it is returned as is. + * + * The returned repository is thread-safe for concurrent use. * * @param [T] type parameter * @param [op] repository builder block - * @return the object repository of type [T] + * @return the repository of type [T] */ inline fun Nitrite.getRepository( - noinline op: (ObjectRepository.() -> Unit)? = null + noinline op: (ObjectRepository.() -> Unit)? = null ): ObjectRepository { val repository = this.getRepository(T::class.java) op?.invoke(repository) @@ -61,18 +73,20 @@ inline fun Nitrite.getRepository( } /** - * Opens a type-safe object repository with a key identifier from the store. If the repository - * does not exist it will be created automatically and returned. If a - * repository is already opened, it is returned as is. + * Opens a type-safe object repository with a key identifier from the store. If the repository does + * not exist it will be created automatically and returned. If a repository is already opened, it is + * returned as is. + * + * The returned repository is thread-safe for concurrent use. * * @param [T] type parameter - * @param key the key that will be appended to the repositories name + * @param key the key that will be appended to the repositories name * @param [op] repository builder block - * @return the object repository of type [T] + * @return the repository of type [T] */ inline fun Nitrite.getRepository( - key: String, - noinline op: (ObjectRepository.() -> Unit)? = null + key: String, + noinline op: (ObjectRepository.() -> Unit)? = null ): ObjectRepository { val repository = this.getRepository(T::class.java, key) op?.invoke(repository) @@ -80,9 +94,10 @@ inline fun Nitrite.getRepository( } /** - * Creates an [IndexOptions] with the specified [indexType]. + * Returns an [IndexOptions] object with the specified index type. * - * @param [indexType] the type of index to be created. - * @return a new [IndexOptions] + * @param indexType the type of index to use, defaults to [IndexType.UNIQUE]. + * @return an [IndexOptions] object with the specified index type. */ -fun option(indexType: String = IndexType.UNIQUE): IndexOptions = IndexOptions.indexOptions(indexType) \ No newline at end of file +fun option(indexType: String = IndexType.UNIQUE): IndexOptions = + IndexOptions.indexOptions(indexType) diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Transaction.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Transaction.kt index b0225f261..1633e1dd0 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Transaction.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Transaction.kt @@ -22,9 +22,16 @@ import org.dizitart.no2.transaction.Session import org.dizitart.no2.transaction.Transaction /** - * + * @since 4.0 * @author Anindya Chatterjee */ + +/** + * Starts a new transactional session with the Nitrite database. + * + * @param op an optional lambda expression to execute within the session. + * @return the session object. + */ fun Nitrite.session(op: (Session.() -> Unit)? = null): Session { val session = this.createSession() op?.invoke(session) @@ -32,6 +39,12 @@ fun Nitrite.session(op: (Session.() -> Unit)? = null): Session { return session } +/** + * Starts a transaction on the current session. + * + * @param op the operation to perform within the transaction. + * @return the [Transaction] object representing the transaction. + */ fun Session.tx(op: (Transaction.() -> Unit)? = null): Transaction { val tx = this.beginTransaction() op?.invoke(tx) diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt index 4dbc4ec59..055725349 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt @@ -20,6 +20,7 @@ import org.dizitart.kno2.isEmpty import org.dizitart.no2.collection.Document /** + * @suppress * @author Joris Jensen * @since 4.2.0 */ @@ -114,6 +115,7 @@ internal class DocumentDecoder(private val document: Document, descriptor: Seria } } + @OptIn(ExperimentalSerializationApi::class) private class ListDecoder(private val list: ArrayDeque) : AbstractDecoder() { private var elementIndex = 0 diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt index 7c03a61c7..bfdf5fe6b 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentEncoder.kt @@ -18,6 +18,7 @@ import org.dizitart.no2.collection.Document import kotlin.reflect.full.starProjectedType /** + * @suppress * @author Joris Jensen * @since 4.2.0 */ diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt index 86e0199be..51703e304 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/KotlinXSerializationMapper.kt @@ -26,8 +26,9 @@ import org.dizitart.no2.exceptions.ObjectMappingException import java.util.Date /** - * org.dizitart.no2.common.mapper.NitriteMapper implementation using kotlinx.serialization - * + * A [org.dizitart.no2.common.mapper.NitriteMapper] module that uses KotlinX Serialization + * for object to [Document] covnersion and vice versa. + * * @author Joris Jensen * @since 4.2.0 */ From 31b1b50462e6e40f495e5975988eebe9f5ecdf19 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Sun, 1 Oct 2023 18:19:47 +0530 Subject: [PATCH 17/18] #704 fixed --- .../dizitart/no2/mvstore/MVStoreUtils.java | 2 +- .../collection/CollectionUpdateTest.java | 33 ++++++++++++++++++- .../collection/CollectionUpdateTest.java | 33 ++++++++++++++++++- .../no2/collection/NitriteDocument.java | 21 +++++++++++- .../collection/CollectionUpdateTest.java | 33 ++++++++++++++++++- pom.xml | 17 ++++++---- 6 files changed, 128 insertions(+), 11 deletions(-) diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java index 4388cb221..93cd5f56a 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVStoreUtils.java @@ -179,7 +179,7 @@ private static MVStore tryUpgrade(File orgFile, MVStoreConfig storeConfig) { try { UpgradeUtil.tryUpgrade(newBuilder, storeConfig); } catch (Exception e) { - // if the update fails, delete te new file and rethrow the exception + // if the update fails, delete the new file and rethrow the exception if (newFile.exists()) { if (!newFile.delete()) { throw new NitriteIOException("Could not upgrade the data file", e); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java index 86bff59b5..4dad51555 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java @@ -214,7 +214,6 @@ public void updateAfterAttributeRemoval() { assertEquals(savedDoc1, clonedDoc1); clonedDoc1.put("group", null); -// clonedDoc1.remove("group"); assertEquals(1, coll.update(clonedDoc1).getAffectedCount()); Document savedDoc2 = coll.find(Filter.ALL).firstOrNull(); @@ -222,6 +221,38 @@ public void updateAfterAttributeRemoval() { assertNull(savedDoc2.get("group")); } + @Test + public void updateNestedDocument() { + // github issue - 704 + Document doc1 = createDocument("conversation", + createDocument("unread", + createDocument("me", 1).put("other", 2))); + Document doc2 = createDocument("conversation", + createDocument("unread", + createDocument("me", 10).put("other", 4))); + + NitriteCollection coll = db.getCollection("test_updateNestedDocument"); + coll.remove(Filter.ALL); + coll.insert(doc1, doc2); + + DocumentCursor cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 1); + + Document update = createDocument("conversation", + createDocument("unread", + createDocument("me", 0))); + coll.update(Filter.ALL, update); + + cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 0); + + cursor = coll.find(where("conversation.unread.other").lt(5)); + assertEquals(cursor.size(), 2); + + cursor = coll.find(where("conversation.unread.other").lt(5).not()); + assertEquals(cursor.size(), 0); + } + @Test(expected = NotIdentifiableException.class) public void testUpdateWithoutId() { NitriteCollection collection = db.getCollection("test"); diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java index 86bff59b5..4dad51555 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java @@ -214,7 +214,6 @@ public void updateAfterAttributeRemoval() { assertEquals(savedDoc1, clonedDoc1); clonedDoc1.put("group", null); -// clonedDoc1.remove("group"); assertEquals(1, coll.update(clonedDoc1).getAffectedCount()); Document savedDoc2 = coll.find(Filter.ALL).firstOrNull(); @@ -222,6 +221,38 @@ public void updateAfterAttributeRemoval() { assertNull(savedDoc2.get("group")); } + @Test + public void updateNestedDocument() { + // github issue - 704 + Document doc1 = createDocument("conversation", + createDocument("unread", + createDocument("me", 1).put("other", 2))); + Document doc2 = createDocument("conversation", + createDocument("unread", + createDocument("me", 10).put("other", 4))); + + NitriteCollection coll = db.getCollection("test_updateNestedDocument"); + coll.remove(Filter.ALL); + coll.insert(doc1, doc2); + + DocumentCursor cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 1); + + Document update = createDocument("conversation", + createDocument("unread", + createDocument("me", 0))); + coll.update(Filter.ALL, update); + + cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 0); + + cursor = coll.find(where("conversation.unread.other").lt(5)); + assertEquals(cursor.size(), 2); + + cursor = coll.find(where("conversation.unread.other").lt(5).not()); + assertEquals(cursor.size(), 0); + } + @Test(expected = NotIdentifiableException.class) public void testUpdateWithoutId() { NitriteCollection collection = db.getCollection("test"); diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java index 6a9fd4041..314d08619 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/NitriteDocument.java @@ -168,7 +168,26 @@ public Document clone() { @Override public Document merge(Document document) { if (document instanceof NitriteDocument) { - super.putAll((NitriteDocument) document); + NitriteDocument nitriteDocument = (NitriteDocument) document; + for (Pair entry : nitriteDocument) { + String key = entry.getFirst(); + Object value = entry.getSecond(); + if (value instanceof NitriteDocument) { + // if the value is a document, merge it recursively + if (containsKey(key)) { + // if the current document already contains the key, + // then merge the embedded document + get(key, Document.class).merge((Document) value); + } else { + // if the current document does not contain the key, + // then put the embedded document as it is + put(key, value); + } + } else { + // if there is no more embedded document, put the field in the document + put(key, value); + } + } } else { throw new InvalidOperationException("Document merge only supports NitriteDocument"); } diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java index 86bff59b5..4dad51555 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionUpdateTest.java @@ -214,7 +214,6 @@ public void updateAfterAttributeRemoval() { assertEquals(savedDoc1, clonedDoc1); clonedDoc1.put("group", null); -// clonedDoc1.remove("group"); assertEquals(1, coll.update(clonedDoc1).getAffectedCount()); Document savedDoc2 = coll.find(Filter.ALL).firstOrNull(); @@ -222,6 +221,38 @@ public void updateAfterAttributeRemoval() { assertNull(savedDoc2.get("group")); } + @Test + public void updateNestedDocument() { + // github issue - 704 + Document doc1 = createDocument("conversation", + createDocument("unread", + createDocument("me", 1).put("other", 2))); + Document doc2 = createDocument("conversation", + createDocument("unread", + createDocument("me", 10).put("other", 4))); + + NitriteCollection coll = db.getCollection("test_updateNestedDocument"); + coll.remove(Filter.ALL); + coll.insert(doc1, doc2); + + DocumentCursor cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 1); + + Document update = createDocument("conversation", + createDocument("unread", + createDocument("me", 0))); + coll.update(Filter.ALL, update); + + cursor = coll.find(where("conversation.unread.me").gt(5)); + assertEquals(cursor.size(), 0); + + cursor = coll.find(where("conversation.unread.other").lt(5)); + assertEquals(cursor.size(), 2); + + cursor = coll.find(where("conversation.unread.other").lt(5).not()); + assertEquals(cursor.size(), 0); + } + @Test(expected = NotIdentifiableException.class) public void testUpdateWithoutId() { NitriteCollection collection = db.getCollection("test"); diff --git a/pom.xml b/pom.xml index 0e12cb90a..28a23f789 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 2.0.9 1.9.3 2.2.224 - 8.5.3 + 8.5.4 5.5.0 1.19.0 1.16.0 @@ -278,17 +278,22 @@ ${lombok.version} - - ${project.basedir}/src/main/java - ${project.build.directory}/delombok - false - + delombok generate-sources delombok + + ${project.basedir}/src/main/java + ${project.build.directory}/delombok + false + + skip + + false + From a15033f3de882d7703de4667b124849b61b457ae Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Sun, 1 Oct 2023 20:41:12 +0530 Subject: [PATCH 18/18] Update NitriteStressTest.java --- .../java/org/dizitart/no2/integration/NitriteStressTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java index 5fc8cc7f4..dbb1fc5a2 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/NitriteStressTest.java @@ -147,7 +147,7 @@ public void testRepoPerformanceWithIndex() { assertNotNull(item); repo.insert(item); } - repo.remove(Filter.ALL); + assertEquals(repo.size(), 10000); repo.drop(); // actual calculation @@ -157,6 +157,7 @@ public void testRepoPerformanceWithIndex() { } repo.remove(Filter.ALL); + assertEquals(repo.size(), 0); } @Test @@ -168,7 +169,6 @@ public void testRepoPerformanceWithoutIndex() { assertNotNull(item); repo.insert(item); } - repo.remove(Filter.ALL); repo.drop(); // actual calculation @@ -178,6 +178,7 @@ public void testRepoPerformanceWithoutIndex() { } repo.remove(Filter.ALL); + assertEquals(repo.size(), 0); } private List createTestSet() {

- * NOTE: This is a derivative work of ... - *