Skip to content

Commit 56d2081

Browse files
committed
added Query.cursorHandle()
1 parent 75aebf3 commit 56d2081

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

objectbox-java/src/main/java/io/objectbox/query/PropertyQuery.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public String[] findStrings() {
7878
return (String[]) query.callInReadTx(new Callable<String[]>() {
7979
@Override
8080
public String[] call() {
81-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
8281
boolean distinctNoCase = distinct && noCaseIfDistinct;
83-
return query.nativeFindStrings(query.handle, cursorHandle, property.id, distinct, distinctNoCase);
82+
long cursorHandle = query.cursorHandle();
83+
return query.nativeFindStrings(query.handle, cursorHandle, property.id, distinct,distinctNoCase);
8484
}
8585
});
8686
}
@@ -100,8 +100,7 @@ public long[] findLongs() {
100100
return (long[]) query.callInReadTx(new Callable<long[]>() {
101101
@Override
102102
public long[] call() {
103-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
104-
return query.nativeFindLongs(query.handle, cursorHandle, property.id, distinct);
103+
return query.nativeFindLongs(query.handle, query.cursorHandle(), property.id, distinct);
105104
}
106105
});
107106
}
@@ -119,8 +118,7 @@ public int[] findInts() {
119118
return (int[]) query.callInReadTx(new Callable<int[]>() {
120119
@Override
121120
public int[] call() {
122-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
123-
return query.nativeFindInts(query.handle, cursorHandle, property.id, distinct);
121+
return query.nativeFindInts(query.handle, query.cursorHandle(), property.id, distinct);
124122
}
125123
});
126124
}
@@ -138,8 +136,7 @@ public short[] findShorts() {
138136
return (short[]) query.callInReadTx(new Callable<short[]>() {
139137
@Override
140138
public short[] call() {
141-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
142-
return query.nativeFindShorts(query.handle, cursorHandle, property.id, distinct);
139+
return query.nativeFindShorts(query.handle, query.cursorHandle(), property.id, distinct);
143140
}
144141
});
145142
}
@@ -157,8 +154,7 @@ public char[] findChars() {
157154
return (char[]) query.callInReadTx(new Callable<char[]>() {
158155
@Override
159156
public char[] call() {
160-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
161-
return query.nativeFindChars(query.handle, cursorHandle, property.id, distinct);
157+
return query.nativeFindChars(query.handle, query.cursorHandle(), property.id, distinct);
162158
}
163159
});
164160
}
@@ -174,8 +170,7 @@ public byte[] findBytes() {
174170
return (byte[]) query.callInReadTx(new Callable<byte[]>() {
175171
@Override
176172
public byte[] call() {
177-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
178-
return query.nativeFindBytes(query.handle, cursorHandle, property.id, distinct);
173+
return query.nativeFindBytes(query.handle, query.cursorHandle(), property.id, distinct);
179174
}
180175
});
181176
}
@@ -193,8 +188,7 @@ public float[] findFloats() {
193188
return (float[]) query.callInReadTx(new Callable<float[]>() {
194189
@Override
195190
public float[] call() {
196-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
197-
return query.nativeFindFloats(query.handle, cursorHandle, property.id, distinct);
191+
return query.nativeFindFloats(query.handle, query.cursorHandle(), property.id, distinct);
198192
}
199193
});
200194
}
@@ -212,8 +206,7 @@ public double[] findDoubles() {
212206
return (double[]) query.callInReadTx(new Callable<double[]>() {
213207
@Override
214208
public double[] call() {
215-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(query.box);
216-
return query.nativeFindDoubles(query.handle, cursorHandle, property.id, distinct);
209+
return query.nativeFindDoubles(query.handle, query.cursorHandle(), property.id, distinct);
217210
}
218211
});
219212
}

objectbox-java/src/main/java/io/objectbox/query/Query.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public synchronized void close() {
147147
}
148148
}
149149

150+
/** To be called inside a read TX */
151+
long cursorHandle() {
152+
return InternalAccess.getActiveTxCursorHandle(box);
153+
}
154+
150155
/**
151156
* Find the first Object matching the query.
152157
*/
@@ -157,7 +162,7 @@ public T findFirst() {
157162
@Override
158163
public T call() {
159164
@SuppressWarnings("unchecked")
160-
T entity = (T) nativeFindFirst(handle, InternalAccess.getActiveTxCursorHandle(box));
165+
T entity = (T) nativeFindFirst(handle, cursorHandle());
161166
resolveEagerRelation(entity);
162167
return entity;
163168
}
@@ -191,7 +196,7 @@ public T findUnique() {
191196
@Override
192197
public T call() {
193198
@SuppressWarnings("unchecked")
194-
T entity = (T) nativeFindUnique(handle, InternalAccess.getActiveTxCursorHandle(box));
199+
T entity = (T) nativeFindUnique(handle, cursorHandle());
195200
resolveEagerRelation(entity);
196201
return entity;
197202
}
@@ -206,8 +211,7 @@ public List<T> find() {
206211
return callInReadTx(new Callable<List<T>>() {
207212
@Override
208213
public List<T> call() throws Exception {
209-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(box);
210-
List<T> entities = nativeFind(Query.this.handle, cursorHandle, 0, 0);
214+
List<T> entities = nativeFind(Query.this.handle, cursorHandle(), 0, 0);
211215
if (filter != null) {
212216
Iterator<T> iterator = entities.iterator();
213217
while (iterator.hasNext()) {
@@ -235,8 +239,7 @@ public List<T> find(final long offset, final long limit) {
235239
return callInReadTx(new Callable<List<T>>() {
236240
@Override
237241
public List<T> call() {
238-
long cursorHandle = InternalAccess.getActiveTxCursorHandle(box);
239-
List entities = nativeFind(handle, cursorHandle, offset, limit);
242+
List entities = nativeFind(handle, cursorHandle(), offset, limit);
240243
resolveEagerRelations(entities);
241244
return entities;
242245
}

0 commit comments

Comments
 (0)