diff --git a/nitrite/asciidoc.gradle b/nitrite/asciidoc.gradle index d7297dc06..d2adffd80 100644 --- a/nitrite/asciidoc.gradle +++ b/nitrite/asciidoc.gradle @@ -52,6 +52,7 @@ javadoc { options.docletpath = configurations.asciidoclet.files as List options.doclet = 'org.asciidoctor.Asciidoclet' options.overview = "$generatedSources/overview.adoc" + options.encoding = "UTF-8" options.addStringOption "-base-dir", "${projectDir}" options.addStringOption "doctitle", "${project.name.capitalize()} ${project.version} API" options.addStringOption "windowtitle", "${project.name.capitalize()} ${project.version} API" 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 62dc5d39c..52bf30ede 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java @@ -73,7 +73,7 @@ public Set apply(NitriteMap documentMap) { if (fieldValue.getClass().isArray()) { int length = Array.getLength(fieldValue); - List list = new ArrayList(); + List list = new ArrayList(length); for (int i = 0; i < length; i++) { Object item = Array.get(fieldValue, i); list.add(item); diff --git a/nitrite/src/main/java/org/dizitart/no2/internals/DataService.java b/nitrite/src/main/java/org/dizitart/no2/internals/DataService.java index 8dd7a98eb..f0aa23cdd 100644 --- a/nitrite/src/main/java/org/dizitart/no2/internals/DataService.java +++ b/nitrite/src/main/java/org/dizitart/no2/internals/DataService.java @@ -59,10 +59,10 @@ class DataService { } WriteResultImpl insert(Document... documents) { - List nitriteIdList = new ArrayList<>(); - List changedItems = new ArrayList<>(); + List nitriteIdList = new ArrayList<>(documents.length); + List changedItems = new ArrayList<>(documents.length); - log.debug("Total " + documents.length + " document(s) to be inserted in " + name); + log.debug("Total {} document(s) to be inserted in {}", documents.length, name); for (Document document : documents) { NitriteId nitriteId = document.getId(); @@ -81,12 +81,12 @@ WriteResultImpl insert(Document... documents) { synchronized (lock) { Document already = underlyingMap.putIfAbsent(nitriteId, document); - log.debug("Inserting document " + document + " in " + name); + log.debug("Inserting document {} in {}", document, name); if (already != null) { // rollback changes underlyingMap.put(nitriteId, already); - log.debug("Another document already exists with id " + nitriteId); + log.debug("Another document already exists with id {}", nitriteId); throw new UniqueConstraintException(errorMessage("id constraint violation, " + "entry with same id already exists in " + name, UCE_CONSTRAINT_VIOLATED)); } else { @@ -115,7 +115,7 @@ WriteResultImpl insert(Document... documents) { WriteResultImpl result = new WriteResultImpl(); result.setNitriteIdList(nitriteIdList); - log.debug("Returning write result " + result + " for collection " + name); + log.debug("Returning write result {} for collection {}", result, name); return result; } @@ -129,7 +129,7 @@ WriteResultImpl update(Filter filter, Document update, UpdateOptions updateOptio WriteResultImpl writeResult = new WriteResultImpl(); if (cursor == null || cursor.size() == 0) { - log.debug("No document found to update by the filter " + filter + " in " + name); + log.debug("No document found to update by the filter {} in {}", filter, name); if (updateOptions.isUpsert()) { return insert(update); } else { @@ -152,10 +152,9 @@ WriteResultImpl update(Filter filter, Document update, UpdateOptions updateOptio return writeResult; } - log.debug("Filter " + filter + " found total " + cursor.size() - + " document(s) to update with options " + updateOptions + " in " + name); + log.debug("Filter {} found total {} document(s) to update with options {} in {}", filter, cursor.size(), updateOptions, name); - List changedItems = new ArrayList<>(); + List changedItems = new ArrayList<>(cursor.size()); for(final Document document : cursor) { if (document != null) { NitriteId nitriteId = document.getId(); @@ -163,7 +162,7 @@ WriteResultImpl update(Filter filter, Document update, UpdateOptions updateOptio synchronized (lock) { Document oldDocument = new Document(document); - log.debug("Document to update " + document + " in " + name); + log.debug("Document to update {} in {}", document, name); if (!REPLICATOR.contentEquals(update.getSource())) { update.remove(DOC_SOURCE); @@ -177,7 +176,7 @@ WriteResultImpl update(Filter filter, Document update, UpdateOptions updateOptio } underlyingMap.put(nitriteId, document); - log.debug("Document " + document + " updated in " + name); + log.debug("Document {} updated in {}", document, name); // if 'update' only contains id value, affected count = 0 if (update.size() > 0) { @@ -198,7 +197,7 @@ WriteResultImpl update(Filter filter, Document update, UpdateOptions updateOptio notify(ChangeType.UPDATE, changedItems); } - log.debug("Returning write result " + writeResult + " for collection " + name); + log.debug("Returning write result {} for collection {}", writeResult, name); return writeResult; } @@ -212,14 +211,13 @@ WriteResultImpl remove(Filter filter, RemoveOptions removeOptions) { WriteResultImpl result = new WriteResultImpl(); if (cursor == null) { - log.debug("No document found to remove by the filter " + filter + " in " + name); + log.debug("No document found to remove by the filter {} in {}", filter, name); return result; } - log.debug("Filter " + filter + " found total " + cursor.size() - + " document(s) to remove with options " + removeOptions + " from " + name); + log.debug("Filter {} found total {} document(s) to remove with options {} from {}", filter, cursor.size(), removeOptions, name); - List changedItems = new ArrayList<>(); + List changedItems = new ArrayList<>(cursor.size()); synchronized (lock) { for (Document document : cursor) { @@ -231,7 +229,7 @@ WriteResultImpl remove(Filter filter, RemoveOptions removeOptions) { removed.put(DOC_REVISION, rev + 1); removed.put(DOC_MODIFIED, System.currentTimeMillis()); - log.debug("Document removed " + removed + " from " + name); + log.debug("Document removed {} from {}", removed, name); result.addToList(nitriteId); @@ -250,7 +248,7 @@ WriteResultImpl remove(Filter filter, RemoveOptions removeOptions) { notify(ChangeType.REMOVE, changedItems); - log.debug("Returning write result " + result + " for collection " + name); + log.debug("Returning write result {} for collection {}", result, name); return result; } @@ -259,7 +257,7 @@ Document getById(NitriteId nitriteId) { } private void notify(ChangeType action, Collection changedItems) { - log.debug("Notifying " + action + " event for items " + changedItems + " from " + name); + log.debug("Notifying {} event for items {} from {}", action, changedItems, name); if (eventBus != null) { ChangeInfo changeInfo = new ChangeInfo(action); changeInfo.setChangedItems(changedItems); diff --git a/nitrite/src/main/java/org/dizitart/no2/internals/DefaultNitriteCollection.java b/nitrite/src/main/java/org/dizitart/no2/internals/DefaultNitriteCollection.java index 493a8c117..f9113f208 100644 --- a/nitrite/src/main/java/org/dizitart/no2/internals/DefaultNitriteCollection.java +++ b/nitrite/src/main/java/org/dizitart/no2/internals/DefaultNitriteCollection.java @@ -50,8 +50,8 @@ class DefaultNitriteCollection implements NitriteCollection { private NitriteService nitriteService; private volatile boolean isDropped; private EventBus eventBus; - private String collectionName; - private NitriteContext nitriteContext; + private final String collectionName; + private final NitriteContext nitriteContext; DefaultNitriteCollection(NitriteMap nitriteMap, NitriteContext nitriteContext) { this.nitriteMap = nitriteMap; diff --git a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVMap.java b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVMap.java index 3b8eb8b0d..c07f15fff 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVMap.java @@ -33,8 +33,8 @@ * @author Anindya Chatterjee. */ class NitriteMVMap implements NitriteMap { - private MVMap mvMap; - private NitriteStore nitriteStore; + private final MVMap mvMap; + private final NitriteStore nitriteStore; NitriteMVMap(MVMap mvMap, NitriteStore nitriteStore) { this.mvMap = mvMap; diff --git a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVStore.java b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVStore.java index 548bacf1b..e92d246d6 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVStore.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMVStore.java @@ -33,7 +33,7 @@ * @author Anindya Chatterjee. */ public final class NitriteMVStore implements NitriteStore { - private MVStore mvStore; + private final MVStore mvStore; /** * Instantiates a new {@link NitriteMVStore}. diff --git a/nitrite/src/main/java/org/dizitart/no2/tool/Importer.java b/nitrite/src/main/java/org/dizitart/no2/tool/Importer.java index 20427d1bb..6ff95536b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/tool/Importer.java +++ b/nitrite/src/main/java/org/dizitart/no2/tool/Importer.java @@ -80,8 +80,9 @@ public void importFrom(String file) { * @throws NitriteIOException if there is any low-level I/O error. */ public void importFrom(File file) { - try { - importFrom(new FileInputStream(file)); + + try(FileInputStream stream = new FileInputStream(file);) { + importFrom(stream); } catch (IOException ioe) { throw new NitriteIOException( errorMessage("I/O error while reading content from file " + file, diff --git a/potassium-nitrite/README.adoc b/potassium-nitrite/README.adoc index 045bbf7d0..748db2cf8 100644 --- a/potassium-nitrite/README.adoc +++ b/potassium-nitrite/README.adoc @@ -54,6 +54,14 @@ val db = nitrite("userId", "password") { autoCompact = false } +// for android context +val db = nitrite { + file = File(applicationContext.filesDir, fileName) + autoCommitBufferSize = 2048 + compress = true + autoCompact = false +} + -- *Collection / Repository* diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ImportExportTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ImportExportTest.kt index 79745b8b3..59a6c175a 100644 --- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ImportExportTest.kt +++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/ImportExportTest.kt @@ -38,7 +38,7 @@ class ImportExportTest : BaseExternalTest() { @Test fun testImportExport() { schemaFile = (System.getProperty("java.io.tmpdir") + File.separator - + "nitrite" + File.separator + "schema.json") + + "kno2" + File.separator + "schema.json") val random = Random() for (i in 0..4) {