Skip to content

Commit 7f78db7

Browse files
committed
fixed #212
1 parent eb91a01 commit 7f78db7

File tree

2 files changed

+33
-48
lines changed

2 files changed

+33
-48
lines changed

nitrite/src/main/java/org/dizitart/no2/internals/NitriteService.java

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ public boolean hasIndex(String field) {
102102
*/
103103
public Set<NitriteId> findEqualWithIndex(String field, Object value) {
104104
notNull(field, errorMessage("field can not be null", VE_FIND_EQUAL_INDEX_NULL_FIELD));
105-
try {
106-
readLock.lock();
107-
return indexedSearchService.findEqual(field, value);
108-
} finally {
109-
readLock.unlock();
110-
}
105+
return indexedSearchService.findEqual(field, value);
111106
}
112107

113108
/**
@@ -120,12 +115,7 @@ public Set<NitriteId> findEqualWithIndex(String field, Object value) {
120115
public Set<NitriteId> findGreaterThanWithIndex(String field, Comparable value) {
121116
notNull(field, errorMessage("field can not be null", VE_FIND_GT_INDEX_NULL_FIELD));
122117
notNull(value, errorMessage("value can not be null", VE_FIND_GT_INDEX_NULL_VALUE));
123-
try {
124-
readLock.lock();
125-
return indexedSearchService.findGreaterThan(field, value);
126-
} finally {
127-
readLock.unlock();
128-
}
118+
return indexedSearchService.findGreaterThan(field, value);
129119
}
130120

131121
/**
@@ -138,12 +128,7 @@ public Set<NitriteId> findGreaterThanWithIndex(String field, Comparable value) {
138128
public Set<NitriteId> findGreaterEqualWithIndex(String field, Comparable value) {
139129
notNull(field, errorMessage("field can not be null", VE_FIND_GTE_INDEX_NULL_FIELD));
140130
notNull(value, errorMessage("value can not be null", VE_FIND_GTE_INDEX_NULL_VALUE));
141-
try {
142-
readLock.lock();
143-
return indexedSearchService.findGreaterEqual(field, value);
144-
} finally {
145-
readLock.unlock();
146-
}
131+
return indexedSearchService.findGreaterEqual(field, value);
147132
}
148133

149134
/**
@@ -156,12 +141,7 @@ public Set<NitriteId> findGreaterEqualWithIndex(String field, Comparable value)
156141
public Set<NitriteId> findLesserThanWithIndex(String field, Comparable value) {
157142
notNull(field, errorMessage("field can not be null", VE_FIND_LT_INDEX_NULL_FIELD));
158143
notNull(value, errorMessage("value can not be null", VE_FIND_LT_INDEX_NULL_VALUE));
159-
try {
160-
readLock.lock();
161-
return indexedSearchService.findLesserThan(field, value);
162-
} finally {
163-
readLock.unlock();
164-
}
144+
return indexedSearchService.findLesserThan(field, value);
165145
}
166146

167147
/**
@@ -174,12 +154,7 @@ public Set<NitriteId> findLesserThanWithIndex(String field, Comparable value) {
174154
public Set<NitriteId> findLesserEqualWithIndex(String field, Comparable value) {
175155
notNull(field, errorMessage("field can not be null", VE_FIND_LTE_INDEX_NULL_FIELD));
176156
notNull(value, errorMessage("value can not be null", VE_FIND_LTE_INDEX_NULL_VALUE));
177-
try {
178-
readLock.lock();
179-
return indexedSearchService.findLesserEqual(field, value);
180-
} finally {
181-
readLock.unlock();
182-
}
157+
return indexedSearchService.findLesserEqual(field, value);
183158
}
184159

185160
/**
@@ -192,12 +167,7 @@ public Set<NitriteId> findLesserEqualWithIndex(String field, Comparable value) {
192167
public Set<NitriteId> findInWithIndex(String field, Collection<Object> values) {
193168
notNull(field, errorMessage("field can not be null", VE_FIND_IN_INDEX_NULL_FIELD));
194169
notNull(values, errorMessage("values can not be null", VE_FIND_IN_INDEX_NULL_VALUE));
195-
try {
196-
readLock.lock();
197-
return indexedSearchService.findIn(field, values);
198-
} finally {
199-
readLock.unlock();
200-
}
170+
return indexedSearchService.findIn(field, values);
201171
}
202172

203173
/**
@@ -210,12 +180,7 @@ public Set<NitriteId> findInWithIndex(String field, Collection<Object> values) {
210180
public Set<NitriteId> findNotInWithIndex(String field, Collection<Object> values) {
211181
notNull(field, errorMessage("field can not be null", VE_FIND_NOT_IN_INDEX_NULL_FIELD));
212182
notNull(values, errorMessage("values can not be null", VE_FIND_NOT_IN_INDEX_NULL_VALUE));
213-
try {
214-
readLock.lock();
215-
return indexedSearchService.findNotIn(field, values);
216-
} finally {
217-
readLock.unlock();
218-
}
183+
return indexedSearchService.findNotIn(field, values);
219184
}
220185

221186
/**
@@ -228,12 +193,7 @@ public Set<NitriteId> findNotInWithIndex(String field, Collection<Object> values
228193
public Set<NitriteId> findTextWithIndex(String field, String value) {
229194
notNull(field, errorMessage("field can not be null", VE_FIND_TEXT_INDEX_NULL_FIELD));
230195
notNull(value, errorMessage("value can not be null", VE_FIND_TEXT_INDEX_NULL_VALUE));
231-
try {
232-
readLock.lock();
233-
return indexedSearchService.findText(field, value);
234-
} finally {
235-
readLock.unlock();
236-
}
196+
return indexedSearchService.findText(field, value);
237197
}
238198

239199
/**

nitrite/src/test/java/org/dizitart/no2/NitriteTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import lombok.Data;
2323
import lombok.NoArgsConstructor;
2424
import org.dizitart.no2.exceptions.NitriteIOException;
25+
import org.dizitart.no2.filters.Filters;
2526
import org.dizitart.no2.objects.Id;
2627
import org.dizitart.no2.objects.Index;
2728
import org.dizitart.no2.objects.Indices;
@@ -359,6 +360,30 @@ public void run() {
359360
assertTrue(repository.find().size() <= 5);
360361
}
361362

363+
@Test
364+
public void testIssue212() {
365+
NitriteCollection collection = db.getCollection("test");
366+
Document doc1 = createDocument("key", "key").put("second_key", "second_key").put("third_key", "third_key");
367+
Document doc2 = createDocument("key", "key").put("second_key", "second_key").put("fourth_key", "fourth_key");
368+
Document doc = createDocument("fifth_key", "fifth_key");
369+
370+
if(!collection.hasIndex("key")){
371+
collection.createIndex("key", IndexOptions.indexOptions(IndexType.NonUnique));
372+
}
373+
if(!collection.hasIndex("second_key")){
374+
collection.createIndex("second_key", IndexOptions.indexOptions(IndexType.NonUnique));
375+
}
376+
377+
collection.insert(doc1, doc2);
378+
collection.update(Filters.and(Filters.eq("key", "key"),
379+
Filters.eq("second_key", "second_key")), doc, UpdateOptions.updateOptions(true));
380+
381+
for (Document document : collection.find()) {
382+
System.out.println(document);
383+
}
384+
}
385+
386+
362387
@Data
363388
@NoArgsConstructor
364389
@AllArgsConstructor

0 commit comments

Comments
 (0)