io.objectbox.query.Query.setParameter()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中io.objectbox.query.Query.setParameter方法的一些代码示例,展示了Query.setParameter的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setParameter方法的具体详情如下:
包路径:io.objectbox.query.Query
类名称:Query
方法名:setParameter

Query.setParameter介绍

[英]Sets a parameter previously given to the QueryBuilder to a new value.
[中]将之前提供给QueryBuilder的参数设置为新值。

代码示例

代码示例来源:origin: objectbox/objectbox-java

/**
 * Sets a parameter previously given to the {@link QueryBuilder} to a new value.
 */
public Query<T> setParameter(Property property, boolean value) {
  return setParameter(property, value ? 1 : 0);
}

代码示例来源:origin: objectbox/objectbox-java

/**
 * Sets a parameter previously given to the {@link QueryBuilder} to a new value.
 *
 * @param alias as defined using {@link QueryBuilder#parameterAlias(String)}.
 */
public Query<T> setParameter(String alias, boolean value) {
  return setParameter(alias, value ? 1 : 0);
}

代码示例来源:origin: objectbox/objectbox-java

/**
 * Sets a parameter previously given to the {@link QueryBuilder} to a new value.
 *
 * @throws NullPointerException if given date is null
 */
public Query<T> setParameter(Property property, Date value) {
  return setParameter(property, value.getTime());
}

代码示例来源:origin: objectbox/objectbox-java

/**
 * Sets a parameter previously given to the {@link QueryBuilder} to a new value.
 *
 * @param alias as defined using {@link QueryBuilder#parameterAlias(String)}.
 * @throws NullPointerException if given date is null
 */
public Query<T> setParameter(String alias, Date value) {
  return setParameter(alias, value.getTime());
}

代码示例来源:origin: objectbox/objectbox-java

@Override
public void setParameterFor(Query query, Object parameter) {
  if (parameter == null) {
    throw new IllegalArgumentException("The new parameter can not be null.");
  }
  if (operation == Operation.BETWEEN) {
    throw new UnsupportedOperationException("The BETWEEN condition requires two parameters.");
  }
  if (operation == Operation.IN) {
    throw new UnsupportedOperationException("The IN condition does not support changing parameters.");
  }
  if (parameter instanceof Long) {
    query.setParameter(property, (Long) parameter);
  } else if (parameter instanceof Integer) {
    query.setParameter(property, (Integer) parameter);
  } else if (parameter instanceof String) {
    query.setParameter(property, (String) parameter);
  } else if (parameter instanceof Double) {
    query.setParameter(property, (Double) parameter);
  } else if (parameter instanceof Float) {
    query.setParameter(property, (Float) parameter);
  } else {
    throw new IllegalArgumentException("Only LONG, INTEGER, DOUBLE, FLOAT or STRING parameters are supported.");
  }
}

代码示例来源:origin: objectbox/objectbox-java

@Override
  public void run() {
    query.setParameter(EntityLongIndex_.indexedLong, initialValue);
    EntityLongIndex unique = query.findUnique();
    assertNull(unique);
    latchRead1.countDown();
    System.out.println("BEFORE put: " + box.getReaderDebugInfo());
    System.out.println("count before: " + box.count());
    try {
      latchPut.await();
    } catch (InterruptedException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
    System.out.println("AFTER put: " + box.getReaderDebugInfo());
    System.out.println("count after: " + box.count());
    query.setParameter(EntityLongIndex_.indexedLong, initialValue);
    results[0] = query.findUnique();
    results[1] = box.get(1);
    results[2] = query.findUnique();
    query.setParameter(EntityLongIndex_.indexedLong, 0);
    results[3] = query.findUnique();
    latchRead2.countDown();
  }
}.start();

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testOldReaderWithIndex() throws InterruptedException {
  final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class);
  final int initialValue = 1;
  final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build();
  assertNull(query.findUnique());
  System.out.println("BEFORE put: " + box.getReaderDebugInfo());
  System.out.println("count before: " + box.count());
  box.put(createEntityLongIndex(initialValue));
  System.out.println("AFTER put: " + box.getReaderDebugInfo());
  System.out.println("count after: " + box.count());
  query.setParameter(EntityLongIndex_.indexedLong, initialValue);
  assertNotNull(query.findUnique());
  query.setParameter(EntityLongIndex_.indexedLong, 0);
  assertNull(query.findUnique());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testSetParameterString() {
  putTestEntitiesStrings();
  Query<TestEntity> query = box.query().equal(simpleString, "banana").parameterAlias("foo").build();
  assertEquals(1, query.findUnique().getId());
  query.setParameter(simpleString, "bar");
  assertEquals(3, query.findUnique().getId());
  assertNull(query.setParameter(simpleString, "not here!").findUnique());
  query.setParameter("foo", "apple");
  assertEquals(2, query.findUnique().getId());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testSetParameterInt() {
  String versionNative = BoxStore.getVersionNative();
  String minVersion = "1.5.1-2018-06-21";
  String versionStart = versionNative.substring(0, minVersion.length());
  assertTrue(versionStart, versionStart.compareTo(minVersion) >= 0);
  putTestEntitiesScalars();
  Query<TestEntity> query = box.query().equal(simpleInt, 2007).parameterAlias("foo").build();
  assertEquals(8, query.findUnique().getId());
  query.setParameter(simpleInt, 2004);
  assertEquals(5, query.findUnique().getId());
  query.setParameter("foo", 2002);
  assertEquals(3, query.findUnique().getId());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testSetParameterFloat() {
  putTestEntitiesScalars();
  Query<TestEntity> query = box.query().greater(simpleFloat, 400.65).parameterAlias("foo").build();
  assertEquals(3, query.count());
  query.setParameter(simpleFloat, 400.75);
  assertEquals(2, query.count());
  query.setParameter("foo", 400.85);
  assertEquals(1, query.count());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testStringLess() {
  putTestEntitiesStrings();
  putTestEntity("BaNaNa Split", 100);
  Query<TestEntity> query = box.query().less(simpleString, "banana juice").order(simpleString).build();
  List<TestEntity> entities = query.find();
  assertEquals(2, entities.size());
  assertEquals("apple", entities.get(0).getSimpleString());
  assertEquals("banana", entities.get(1).getSimpleString());
  query.setParameter(simpleString, "BANANA MZ");
  entities = query.find();
  assertEquals(3, entities.size());
  assertEquals("apple", entities.get(0).getSimpleString());
  assertEquals("banana", entities.get(1).getSimpleString());
  assertEquals("banana milk shake", entities.get(2).getSimpleString());
  // Case sensitive
  query = box.query().less(simpleString, "BANANA", StringOrder.CASE_SENSITIVE).order(simpleString).build();
  assertEquals(0, query.count());
  query.setParameter(simpleString, "banana a");
  entities = query.find();
  assertEquals(3, entities.size());
  assertEquals("apple", entities.get(0).getSimpleString());
  assertEquals("banana", entities.get(1).getSimpleString());
  assertEquals("BaNaNa Split", entities.get(2).getSimpleString());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testStringGreater() {
  putTestEntitiesStrings();
  putTestEntity("FOO", 100);
  Query<TestEntity> query = box.query().greater(simpleString, "banana juice").order(simpleString).build();
  List<TestEntity> entities = query.find();
  assertEquals(4, entities.size());
  assertEquals("banana milk shake", entities.get(0).getSimpleString());
  assertEquals("bar", entities.get(1).getSimpleString());
  assertEquals("FOO", entities.get(2).getSimpleString());
  assertEquals("foo bar", entities.get(3).getSimpleString());
  query.setParameter(simpleString, "FO");
  entities = query.find();
  assertEquals(2, entities.size());
  assertEquals("FOO", entities.get(0).getSimpleString());
  assertEquals("foo bar", entities.get(1).getSimpleString());
  // Case sensitive
  query = box.query().greater(simpleString, "banana", StringOrder.CASE_SENSITIVE).order(simpleString).build();
  entities = query.find();
  assertEquals(3, entities.size());
  assertEquals("banana milk shake", entities.get(0).getSimpleString());
  assertEquals("bar", entities.get(1).getSimpleString());
  assertEquals("foo bar", entities.get(2).getSimpleString());
}

代码示例来源:origin: objectbox/objectbox-java

assertNull(results[3]);
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
assertNotNull(query.findUnique());

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testByteArrayEqualsAndSetParameter() {
  putTestEntitiesScalars();
  byte[] value = {1, 2, (byte) 2000};
  Query<TestEntity> query = box.query().equal(simpleByteArray, value).parameterAlias("bytes").build();
  assertEquals(1, query.count());
  TestEntity first = query.findFirst();
  assertNotNull(first);
  assertTrue(Arrays.equals(value, first.getSimpleByteArray()));
  byte[] value2 = {1, 2, (byte) 2001};
  query.setParameter(simpleByteArray, value2);
  assertEquals(1, query.count());
  TestEntity first2 = query.findFirst();
  assertNotNull(first2);
  assertTrue(Arrays.equals(value2, first2.getSimpleByteArray()));
  byte[] value3 = {1, 2, (byte) 2002};
  query.setParameter("bytes", value3);
  assertEquals(1, query.count());
  TestEntity first3 = query.findFirst();
  assertNotNull(first3);
  assertTrue(Arrays.equals(value3, first3.getSimpleByteArray()));
}

代码示例来源:origin: objectbox/objectbox-java

assertNull(transformResults[2]);
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
query.setParameter(EntityLongIndex_.indexedLong, initialValue);
assertNotNull(query.findUnique());
assertNotNull(query.findUnique());

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testDateParam() {
  store.close();
  assertTrue(store.deleteAllFiles());
  store = MyObjectBox.builder().baseDirectory(boxStoreDir).debugFlags(DebugFlags.LOG_QUERY_PARAMETERS).build();
  Date now = new Date();
  Order order = new Order();
  order.setDate(now);
  Box<Order> box = store.boxFor(Order.class);
  box.put(order);
  Query<Order> query = box.query().equal(Order_.date, 0).build();
  assertEquals(0, query.count());
  query.setParameter(Order_.date, now);
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testBooleanEqual() {
  putTestEntitiesScalars();
  Query<TestEntity> query = box.query().equal(simpleBoolean, true).build();
  assertEquals(5, query.count());
  assertEquals(1, query.findFirst().getId());
  query.setParameter(simpleBoolean, false);
  assertEquals(5, query.count());
  assertEquals(2, query.findFirst().getId());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testFindString() {
  Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
  PropertyQuery propertyQuery = query.property(simpleString);
  assertNull(propertyQuery.findString());
  assertNull(propertyQuery.reset().unique().findString());
  putTestEntities(5);
  assertEquals("foo3", propertyQuery.reset().findString());
  query = box.query().greater(simpleLong, 1004).build();
  propertyQuery = query.property(simpleString);
  assertEquals("foo5", propertyQuery.reset().unique().findString());
  putTestEntity(null, 6);
  putTestEntity(null, 7);
  query.setParameter(simpleLong, 1005);
  assertEquals("nope", propertyQuery.reset().distinct().nullValue("nope").unique().findString());
}

代码示例来源:origin: objectbox/objectbox-java

@Test
public void testFindInt() {
  Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
  assertNull(query.property(simpleInt).findInt());
  assertNull(query.property(simpleInt).unique().findInt());
  putTestEntities(5);
  assertEquals(3, (int) query.property(simpleInt).findInt());
  query = box.query().greater(simpleLong, 1004).build();
  assertEquals(5, (int) query.property(simpleInt).distinct().unique().findInt());
  TestEntityCursor.INT_NULL_HACK = true;
  try {
    putTestEntity(null, 6);
  } finally {
    TestEntityCursor.INT_NULL_HACK = false;
  }
  query.setParameter(simpleLong, 1005);
  assertEquals(-99, (int) query.property(simpleInt).nullValue(-99).unique().findInt());
}

代码示例来源:origin: objectbox/objectbox-performance

private void runQueryByIntegerIndexed() {
  List<SimpleEntityIndexed> entities = prepareAndPutEntitiesIndexed();
  final int[] valuesToLookup = new int[numberEntities];
  for (int i = 0; i < numberEntities; i++) {
    valuesToLookup[i] = entities.get(random.nextInt(numberEntities)).getSimpleInt();
  }
  startBenchmark("query");
  long entitiesFound = 0;
  Query<SimpleEntityIndexed> query = boxIndexed.query()
      .equal(SimpleEntityIndexed_.simpleInt, 0)
      .parameterAlias("int")
      .build();
  for (int i = 0; i < numberEntities; i++) {
    query.setParameter("int", valuesToLookup[i]);
    List<SimpleEntityIndexed> result = query.find();
    accessAllIndexed(result);
    entitiesFound += result.size();
  }
  stopBenchmark();
  log("Entities found: " + entitiesFound);
  assertGreaterOrEqualToNumberOfEntities(entitiesFound);
}

相关文章