From d2a4fb6306a4bcbc56a8be83cf02cfd9cabd0827 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Sun, 26 Aug 2018 23:54:56 +0530 Subject: [PATCH] fix #106 --- .../main/java/org/dizitart/no2/NitriteContext.java | 14 ++++++++++++++ .../org/dizitart/no2/internals/NitriteService.java | 1 + 2 files changed, 15 insertions(+) diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteContext.java b/nitrite/src/main/java/org/dizitart/no2/NitriteContext.java index ea52aab2e..629f9f2a7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteContext.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteContext.java @@ -28,6 +28,7 @@ import org.dizitart.no2.mapper.JacksonMapper; import org.dizitart.no2.mapper.NitriteMapper; import org.dizitart.no2.util.ExecutorUtils; +import org.dizitart.no2.util.StringUtils; import java.util.HashSet; import java.util.Map; @@ -36,6 +37,7 @@ import java.util.concurrent.ScheduledExecutorService; import static org.dizitart.no2.util.ExecutorUtils.shutdownAndAwaitTermination; +import static org.dizitart.no2.util.ObjectUtils.isObjectStore; /** * Represents a readonly view of all contextual information of a nitrite database. @@ -174,6 +176,18 @@ public Set getRegisteredModules() { return new HashSet<>(jacksonModule); } + public void dropCollection(String name) { + if (!StringUtils.isNullOrEmpty(name)) { + if (isObjectStore(name)) { + repositoryRegistry.remove(name); + } else { + collectionRegistry.remove(name); + } + } + } + + + void shutdown() { shutdownAndAwaitTermination(scheduledWorkerPool, 5); shutdownAndAwaitTermination(workerPool, 5); diff --git a/nitrite/src/main/java/org/dizitart/no2/internals/NitriteService.java b/nitrite/src/main/java/org/dizitart/no2/internals/NitriteService.java index 96d8669ac..d3bee19e1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/internals/NitriteService.java +++ b/nitrite/src/main/java/org/dizitart/no2/internals/NitriteService.java @@ -377,6 +377,7 @@ WriteResultImpl remove(Filter filter, RemoveOptions removeOptions) { */ void dropCollection() { indexingService.dropAllIndices(); + nitriteContext.dropCollection(mapStore.getName()); mapStore.getStore().removeMap(mapStore); }