Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Mar 16, 2019
2 parents f59e9c1 + c695a9d commit 5784453
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions nitrite/asciidoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Set<NitriteId> apply(NitriteMap<NitriteId, Document> 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);
Expand Down
38 changes: 18 additions & 20 deletions nitrite/src/main/java/org/dizitart/no2/internals/DataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class DataService {
}

WriteResultImpl insert(Document... documents) {
List<NitriteId> nitriteIdList = new ArrayList<>();
List<ChangedItem> changedItems = new ArrayList<>();
List<NitriteId> nitriteIdList = new ArrayList<>(documents.length);
List<ChangedItem> 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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 {
Expand All @@ -152,18 +152,17 @@ 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<ChangedItem> changedItems = new ArrayList<>();
List<ChangedItem> changedItems = new ArrayList<>(cursor.size());
for(final Document document : cursor) {
if (document != null) {
NitriteId nitriteId = document.getId();

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);
Expand All @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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<ChangedItem> changedItems = new ArrayList<>();
List<ChangedItem> changedItems = new ArrayList<>(cursor.size());

synchronized (lock) {
for (Document document : cursor) {
Expand All @@ -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);

Expand All @@ -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;
}

Expand All @@ -259,7 +257,7 @@ Document getById(NitriteId nitriteId) {
}

private void notify(ChangeType action, Collection<ChangedItem> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class DefaultNitriteCollection implements NitriteCollection {
private NitriteService nitriteService;
private volatile boolean isDropped;
private EventBus<ChangeInfo, ChangeListener> eventBus;
private String collectionName;
private NitriteContext nitriteContext;
private final String collectionName;
private final NitriteContext nitriteContext;

DefaultNitriteCollection(NitriteMap<NitriteId, Document> nitriteMap, NitriteContext nitriteContext) {
this.nitriteMap = nitriteMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
* @author Anindya Chatterjee.
*/
class NitriteMVMap<Key, Value> implements NitriteMap<Key, Value> {
private MVMap<Key, Value> mvMap;
private NitriteStore nitriteStore;
private final MVMap<Key, Value> mvMap;
private final NitriteStore nitriteStore;

NitriteMVMap(MVMap<Key, Value> mvMap, NitriteStore nitriteStore) {
this.mvMap = mvMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
5 changes: 3 additions & 2 deletions nitrite/src/main/java/org/dizitart/no2/tool/Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions potassium-nitrite/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5784453

Please sign in to comment.