本文整理了Java中io.objectbox.query.Query.setParameters
方法的一些代码示例,展示了Query.setParameters
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setParameters
方法的具体详情如下:
包路径:io.objectbox.query.Query
类名称:Query
方法名:setParameters
[英]Sets a parameter previously given to the QueryBuilder to new values.
[中]将之前提供给QueryBuilder的参数设置为新值。
代码示例来源:origin: objectbox/objectbox-java
@Override
public void setParameterFor(Query query, Object parameter1, Object parameter2) {
if (parameter1 == null || parameter2 == null) {
throw new IllegalArgumentException("The new parameters can not be null.");
}
if (operation != Operation.BETWEEN) {
throw new UnsupportedOperationException("Only the BETWEEN condition supports two parameters.");
}
if (parameter1 instanceof Long && parameter2 instanceof Long) {
query.setParameters(property, (Long) parameter1, (Long) parameter2);
} else if (parameter1 instanceof Integer && parameter2 instanceof Integer) {
query.setParameters(property, (Integer) parameter1, (Integer) parameter2);
} else if (parameter1 instanceof Double && parameter2 instanceof Double) {
query.setParameters(property, (Double) parameter1, (Double) parameter2);
} else if (parameter1 instanceof Float && parameter2 instanceof Float) {
query.setParameters(property, (Float) parameter1, (Float) parameter2);
} else {
throw new IllegalArgumentException("The BETWEEN condition only supports LONG, INTEGER, DOUBLE or FLOAT parameters.");
}
}
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testSetParameter2Floats() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().between(simpleFloat, 400.15, 400.75).parameterAlias("foo").build();
assertEquals(6, query.count());
query.setParameters(simpleFloat, 400.65, 400.85);
List<TestEntity> entities = query.find();
assertEquals(2, entities.size());
assertEquals(8, entities.get(0).getId());
assertEquals(9, entities.get(1).getId());
query.setParameters("foo", 400.45, 400.55);
assertEquals(6, query.findUnique().getId());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testSetParameter2Ints() {
putTestEntitiesScalars();
Query<TestEntity> query = box.query().between(simpleInt, 2005, 2008).parameterAlias("foo").build();
assertEquals(4, query.count());
query.setParameters(simpleInt, 2002, 2003);
List<TestEntity> entities = query.find();
assertEquals(2, entities.size());
assertEquals(3, entities.get(0).getId());
assertEquals(4, entities.get(1).getId());
query.setParameters("foo", 2007, 2007);
assertEquals(8, query.findUnique().getId());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testLongIn() {
putTestEntitiesScalars();
long[] valuesLong = {1, 1, 2, 3, 3003, 3007, 3002, -1};
Query<TestEntity> query = box.query().in(simpleLong, valuesLong).parameterAlias("long").build();
assertEquals(3, query.count());
long[] valuesLong2 = {3003};
query.setParameters(simpleLong, valuesLong2);
assertEquals(1, query.count());
long[] valuesLong3 = {3003, 3007};
query.setParameters("long", valuesLong3);
assertEquals(2, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testIntIn() {
putTestEntitiesScalars();
int[] valuesInt = {1, 1, 2, 3, 2003, 2007, 2002, -1};
Query<TestEntity> query = box.query().in(simpleInt, valuesInt).parameterAlias("int").build();
assertEquals(3, query.count());
int[] valuesInt2 = {2003};
query.setParameters(simpleInt, valuesInt2);
assertEquals(1, query.count());
int[] valuesInt3 = {2003, 2007};
query.setParameters("int", valuesInt3);
assertEquals(2, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testIntNotIn() {
putTestEntitiesScalars();
int[] valuesInt = {1, 1, 2, 3, 2003, 2007, 2002, -1};
Query<TestEntity> query = box.query().notIn(simpleInt, valuesInt).parameterAlias("int").build();
assertEquals(7, query.count());
int[] valuesInt2 = {2003};
query.setParameters(simpleInt, valuesInt2);
assertEquals(9, query.count());
int[] valuesInt3 = {2003, 2007};
query.setParameters("int", valuesInt3);
assertEquals(8, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testLongNotIn() {
putTestEntitiesScalars();
long[] valuesLong = {1, 1, 2, 3, 3003, 3007, 3002, -1};
Query<TestEntity> query = box.query().notIn(simpleLong, valuesLong).parameterAlias("long").build();
assertEquals(7, query.count());
long[] valuesLong2 = {3003};
query.setParameters(simpleLong, valuesLong2);
assertEquals(9, query.count());
long[] valuesLong3 = {3003, 3007};
query.setParameters("long", valuesLong3);
assertEquals(8, query.count());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testStringIn() {
putTestEntitiesStrings();
putTestEntity("BAR", 100);
String[] values = {"bar", "foo bar"};
Query<TestEntity> query = box.query().in(simpleString, values).order(simpleString, OrderFlags.CASE_SENSITIVE)
.build();
List<TestEntity> entities = query.find();
assertEquals(3, entities.size());
assertEquals("BAR", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
assertEquals("foo bar", entities.get(2).getSimpleString());
String[] values2 = {"bar"};
query.setParameters(simpleString, values2);
entities = query.find();
assertEquals(2, entities.size());
assertEquals("BAR", entities.get(0).getSimpleString());
assertEquals("bar", entities.get(1).getSimpleString());
// Case sensitive
query = box.query().in(simpleString, values, StringOrder.CASE_SENSITIVE).order(simpleString).build();
entities = query.find();
assertEquals(2, entities.size());
assertEquals("bar", entities.get(0).getSimpleString());
assertEquals("foo bar", entities.get(1).getSimpleString());
}
内容来源于网络,如有侵权,请联系作者删除!