Skip to content

Commit 05edb7b

Browse files
committed
Box: remove find methods except with Property param, adjust tests
1 parent 0fad1f5 commit 05edb7b

File tree

4 files changed

+17
-86
lines changed

4 files changed

+17
-86
lines changed

objectbox-java/src/main/java/io/objectbox/Box.java

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -284,51 +284,11 @@ public long count() {
284284
}
285285
}
286286

287-
@Temporary
288-
public List<T> find(String propertyName, String value) {
289-
Cursor<T> reader = getReader();
290-
try {
291-
return reader.find(propertyName, value);
292-
} finally {
293-
releaseReader(reader);
294-
}
295-
}
296-
297-
@Temporary
298-
public List<T> find(String propertyName, long value) {
299-
Cursor<T> reader = getReader();
300-
try {
301-
return reader.find(propertyName, value);
302-
} finally {
303-
releaseReader(reader);
304-
}
305-
}
306-
307-
@Temporary
308-
public List<T> find(int propertyId, long value) {
309-
Cursor<T> reader = getReader();
310-
try {
311-
return reader.find(propertyId, value);
312-
} finally {
313-
releaseReader(reader);
314-
}
315-
}
316-
317-
@Temporary
318-
public List<T> find(int propertyId, String value) {
319-
Cursor<T> reader = getReader();
320-
try {
321-
return reader.find(propertyId, value);
322-
} finally {
323-
releaseReader(reader);
324-
}
325-
}
326-
327287
@Temporary
328288
public List<T> find(Property property, String value) {
329289
Cursor<T> reader = getReader();
330290
try {
331-
return reader.find(property.dbName, value);
291+
return reader.find(property, value);
332292
} finally {
333293
releaseReader(reader);
334294
}
@@ -338,7 +298,7 @@ public List<T> find(Property property, String value) {
338298
public List<T> find(Property property, long value) {
339299
Cursor<T> reader = getReader();
340300
try {
341-
return reader.find(property.dbName, value);
301+
return reader.find(property, value);
342302
} finally {
343303
releaseReader(reader);
344304
}

tests/objectbox-java-test/src/main/java/io/objectbox/BoxTest.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertNotNull;
30-
import static org.junit.Assert.assertNull;
31-
import static org.junit.Assert.assertTrue;
27+
import static org.junit.Assert.*;
3228

3329
public class BoxTest extends AbstractObjectBoxTest {
3430

@@ -222,19 +218,7 @@ public void testFindString() {
222218
putTestEntity("apple", 0);
223219
putTestEntity("banana", 0);
224220

225-
List<TestEntity> list = box.find(new Property(2, 0, String.class, "wrongname", false, "simpleString"), "banana");
226-
assertEquals(2, list.size());
227-
assertEquals(1, list.get(0).getId());
228-
assertEquals(3, list.get(1).getId());
229-
}
230-
231-
@Test
232-
public void testFindString_preparedPropertyId() {
233-
putTestEntity("banana", 0);
234-
putTestEntity("apple", 0);
235-
putTestEntity("banana", 0);
236-
int propertyId = box.getPropertyId("simpleString");
237-
List<TestEntity> list = box.find(propertyId, "banana");
221+
List<TestEntity> list = box.find(TestEntity_.simpleString, "banana");
238222
assertEquals(2, list.size());
239223
assertEquals(1, list.get(0).getId());
240224
assertEquals(3, list.get(1).getId());
@@ -246,7 +230,7 @@ public void testFindInt() {
246230
putTestEntity(null, 23);
247231
putTestEntity(null, 42);
248232

249-
List<TestEntity> list = box.find(new Property(2, 0, int.class, "wrongname", false, "simpleInt"), 42);
233+
List<TestEntity> list = box.find(TestEntity_.simpleInt, 42);
250234
assertEquals(2, list.size());
251235
assertEquals(1, list.get(0).getId());
252236
assertEquals(3, list.get(1).getId());
@@ -259,17 +243,4 @@ public void testGetId() {
259243
assertEquals(entity.getId(), box.getId(entity));
260244
}
261245

262-
@Test
263-
public void testFindInt_preparedPropertyId() {
264-
putTestEntity(null, 42);
265-
putTestEntity(null, 23);
266-
putTestEntity(null, 42);
267-
268-
int propertyId = box.getPropertyId("simpleInt");
269-
List<TestEntity> list = box.find(propertyId, 42);
270-
assertEquals(2, list.size());
271-
assertEquals(1, list.get(0).getId());
272-
assertEquals(3, list.get(1).getId());
273-
}
274-
275246
}

tests/objectbox-java-test/src/main/java/io/objectbox/CursorTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testPutGetUpdateDeleteEntity() {
107107

108108
// and find via index
109109
assertEquals(key, cursor.lookupKeyUsingIndex(9, value1));
110-
assertEquals(key, cursor.find("simpleString", value1).get(0).getId());
110+
assertEquals(key, cursor.find(TestEntity_.simpleString, value1).get(0).getId());
111111

112112
// change entity values
113113
String value2 = "lala123";
@@ -118,10 +118,10 @@ public void testPutGetUpdateDeleteEntity() {
118118
cursor.put(entityRead);
119119

120120
// indexes ok?
121-
assertEquals(0, cursor.find("simpleString", value1).size());
121+
assertEquals(0, cursor.find(TestEntity_.simpleString, value1).size());
122122
assertEquals(0, cursor.lookupKeyUsingIndex(9, value1));
123123

124-
assertEquals(key, cursor.find("simpleString", value2).get(0).getId());
124+
assertEquals(key, cursor.find(TestEntity_.simpleString, value2).get(0).getId());
125125

126126
// get the changed entity
127127
entityRead = cursor.get(key);
@@ -136,8 +136,8 @@ public void testPutGetUpdateDeleteEntity() {
136136
cursor.deleteEntity(key);
137137

138138
// not in any index anymore
139-
assertEquals(0, cursor.find("simpleString", value1).size());
140-
assertEquals(0, cursor.find("simpleString", value2).size());
139+
assertEquals(0, cursor.find(TestEntity_.simpleString, value1).size());
140+
assertEquals(0, cursor.find(TestEntity_.simpleString, value2).size());
141141

142142
cursor.close();
143143
transaction.abort();
@@ -168,7 +168,7 @@ public void testFindStringInEntity() {
168168

169169
Transaction transaction = store.beginTx();
170170
Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class);
171-
TestEntity entityRead = cursor.find("simpleString", "find me").get(0);
171+
TestEntity entityRead = cursor.find(TestEntity_.simpleString, "find me").get(0);
172172
assertNotNull(entityRead);
173173
assertEquals(1, entityRead.getId());
174174

@@ -177,7 +177,7 @@ public void testFindStringInEntity() {
177177

178178
transaction = store.beginTx();
179179
cursor = transaction.createCursor(TestEntity.class);
180-
entityRead = cursor.find("simpleString", "not me").get(0);
180+
entityRead = cursor.find(TestEntity_.simpleString, "not me").get(0);
181181
assertNotNull(entityRead);
182182
assertEquals(2, entityRead.getId());
183183

@@ -186,7 +186,7 @@ public void testFindStringInEntity() {
186186

187187
transaction = store.beginTx();
188188
cursor = transaction.createCursor(TestEntity.class);
189-
assertEquals(0, cursor.find("simpleString", "non-existing").size());
189+
assertEquals(0, cursor.find(TestEntity_.simpleString, "non-existing").size());
190190

191191
cursor.close();
192192
transaction.abort();
@@ -205,7 +205,7 @@ public void testFindScalars() {
205205

206206
Transaction transaction = store.beginReadTx();
207207
Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class);
208-
List<TestEntity> result = cursor.find("simpleInt", 2016);
208+
List<TestEntity> result = cursor.find(TestEntity_.simpleInt, 2016);
209209
assertEquals(2, result.size());
210210

211211
assertEquals("foo", result.get(0).getSimpleString());

tests/objectbox-java-test/src/main/java/io/objectbox/PerformanceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ private void findSingle(int idx, TestEntity[] entities, boolean findString) {
7474
cursor.seek(1);
7575
long start = System.nanoTime();
7676
TestEntity foundEntity = findString ?
77-
cursor.find("simpleString", entity.getSimpleString()).get(0) :
78-
cursor.find("simpleLong", entity.getSimpleLong()).get(0);
77+
cursor.find(TestEntity_.simpleString, entity.getSimpleString()).get(0) :
78+
cursor.find(TestEntity_.simpleLong, entity.getSimpleLong()).get(0);
7979
long time = System.nanoTime() - start;
8080
cursor.close();
8181
transaction.close();
@@ -122,7 +122,7 @@ public void testFindStringWithIndex() {
122122
long start = time();
123123
Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class);
124124
for (int i = 0; i < count; i++) {
125-
List<TestEntity> found = cursor.find("simpleString", stringsToLookup[i]);
125+
List<TestEntity> found = cursor.find(TestEntity_.simpleString, stringsToLookup[i]);
126126
//assertEquals(stringsToLookup[i], found.get(0).getSimpleString());
127127
}
128128
cursor.close();

0 commit comments

Comments
 (0)