Skip to content

Commit 293c075

Browse files
committed
prepare Query support for byte[]
1 parent 2a8131a commit 293c075

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2018 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,6 @@
4646
* @see QueryBuilder
4747
*/
4848
@SuppressWarnings({"SameParameterValue", "UnusedReturnValue", "WeakerAccess"})
49-
@Beta
5049
public class Query<T> {
5150

5251
native void nativeDestroy(long handle);
@@ -87,6 +86,9 @@ native void nativeSetParameters(long handle, int entityId, int propertyId, @Null
8786
native void nativeSetParameters(long handle, int entityId, int propertyId, @Nullable String parameterAlias,
8887
String[] values);
8988

89+
native void nativeSetParameter(long handle, int entityId, int propertyId, @Nullable String parameterAlias,
90+
byte[] value);
91+
9092
final Box<T> box;
9193
private final BoxStore store;
9294
private final boolean hasOrder;
@@ -598,6 +600,24 @@ public Query<T> setParameters(String alias, String[] values) {
598600
return this;
599601
}
600602

603+
/**
604+
* Sets a parameter previously given to the {@link QueryBuilder} to new values.
605+
*/
606+
public Query<T> setParameter(Property property, byte[] value) {
607+
nativeSetParameter(handle, property.getEntityId(), property.getId(), null, value);
608+
return this;
609+
}
610+
611+
/**
612+
* Sets a parameter previously given to the {@link QueryBuilder} to new values.
613+
*
614+
* @param alias as defined using {@link QueryBuilder#parameterAlias(String)}.
615+
*/
616+
public Query<T> setParameter(String alias, byte[] value) {
617+
nativeSetParameter(handle, 0, 0, alias, value);
618+
return this;
619+
}
620+
601621
/**
602622
* Removes (deletes) all Objects matching the query
603623
*

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2018 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,7 +119,6 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE
119119

120120
private native void nativeSetParameterAlias(long conditionHandle, String alias);
121121

122-
123122
// ------------------------------ (Not)Null------------------------------
124123

125124
private native long nativeNull(long handle, int propertyId);
@@ -161,12 +160,21 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE
161160
private native long nativeIn(long handle, int propertyId, String[] value, boolean caseSensitive);
162161

163162
// ------------------------------ FPs ------------------------------
163+
164164
private native long nativeLess(long handle, int propertyId, double value);
165165

166166
private native long nativeGreater(long handle, int propertyId, double value);
167167

168168
private native long nativeBetween(long handle, int propertyId, double value1, double value2);
169169

170+
// ------------------------------ Bytes ------------------------------
171+
172+
private native long nativeEqual(long handle, int propertyId, byte[] value);
173+
174+
private native long nativeLess(long handle, int propertyId, byte[] value);
175+
176+
private native long nativeGreater(long handle, int propertyId, byte[] value);
177+
170178
@Internal
171179
public QueryBuilder(Box<T> box, long storeHandle, String entityName) {
172180
this.box = box;
@@ -282,6 +290,21 @@ public QueryBuilder<T> sort(Comparator<T> comparator) {
282290
return this;
283291
}
284292

293+
294+
/**
295+
* Asigns the given alias to the previous condition.
296+
*
297+
* @param alias The string alias for use with setParameter(s) methods.
298+
*/
299+
public QueryBuilder<T> parameterAlias(String alias) {
300+
verifyHandle();
301+
if (lastCondition == 0) {
302+
throw new IllegalStateException("No previous condition. Before you can assign an alias, you must first have a condition.");
303+
}
304+
nativeSetParameterAlias(lastCondition, alias);
305+
return this;
306+
}
307+
285308
/**
286309
* Creates a link to another entity, for which you also can describe conditions using the returned builder.
287310
* <p>
@@ -693,12 +716,25 @@ public QueryBuilder<T> between(Property<T> property, double value1, double value
693716
return this;
694717
}
695718

696-
public QueryBuilder<T> parameterAlias(String alias) {
719+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
720+
// Bytes
721+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
722+
723+
public QueryBuilder<T> equal(Property<T> property, byte[] value) {
697724
verifyHandle();
698-
if (lastCondition == 0) {
699-
throw new IllegalStateException("No previous condition. Before you can assign an alias, you must first have a condition.");
700-
}
701-
nativeSetParameterAlias(lastCondition, alias);
725+
checkCombineCondition(nativeEqual(handle, property.getId(), value));
726+
return this;
727+
}
728+
729+
public QueryBuilder<T> less(Property<T> property, byte[] value) {
730+
verifyHandle();
731+
checkCombineCondition(nativeLess(handle, property.getId(), value));
732+
return this;
733+
}
734+
735+
public QueryBuilder<T> greater(Property<T> property, byte[] value) {
736+
verifyHandle();
737+
checkCombineCondition(nativeGreater(handle, property.getId(), value));
702738
return this;
703739
}
704740

0 commit comments

Comments
 (0)