io.objectbox.Box.remove()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(208)

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

Box.remove介绍

[英]Removes (deletes) the Object by its ID.
[中]按对象ID移除(删除)对象。

代码示例

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

@Test
public void testCollectionsNull() {
  box.put((Collection) null);
  box.put((TestEntity[]) null);
  box.remove((Collection) null);
  box.remove((long[]) null);
  box.removeByKeys(null);
}

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

System.out.println(">>" + all.size());
  System.out.println(">>>>" + orders.size());
  orderBox.remove(orders);
  customerBox.remove(customer);
} else if (orders.size() > 1) {
  orderBox.remove(orders.get(random.nextInt(orders.size())));

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

@Test
public void testRemoveMany() {
  List<TestEntity> entities = new ArrayList<>();
  for (int i = 0; i < 10; i++) {
    TestEntity entity = new TestEntity();
    entity.setSimpleInt(2000 + i);
    entities.add(entity);
  }
  box.put(entities);
  assertEquals(entities.size(), box.count());
  box.remove(entities.get(1));
  assertEquals(entities.size() - 1, box.count());
  box.remove(entities.get(4), entities.get(5));
  assertEquals(entities.size() - 3, box.count());
  List<TestEntity> entitiesRemove = new ArrayList<>();
  entitiesRemove.add(entities.get(2));
  entitiesRemove.add(entities.get(8));
  entitiesRemove.add(entities.get(7));
  box.remove(entitiesRemove);
  assertEquals(entities.size() - 6, box.count());
  List<TestEntity> entitiesRead = box.getAll();
  assertEquals(entities.size() - 6, entitiesRead.size());
  assertEquals(2000, entitiesRead.get(0).getSimpleInt());
  assertEquals(2003, entitiesRead.get(1).getSimpleInt());
  assertEquals(2006, entitiesRead.get(2).getSimpleInt());
  assertEquals(2009, entitiesRead.get(3).getSimpleInt());
  box.removeAll();
  assertEquals(0, box.count());
}

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

@Test
public void testRelationToMany_activeRelationshipChanges() {
  Customer customer = putCustomer();
  Order order1 = putOrder(customer, "Bananas");
  Order order2 = putOrder(customer, "Oranges");
  List<Order> orders = customer.getOrders();
  assertEquals(2, orders.size());
  orderBox.remove(order1);
  ((ToMany) orders).reset();
  assertEquals(1, orders.size());
  order2.setCustomer(null);
  orderBox.put(order2);
  ((ToMany) orders).reset();
  assertEquals(0, orders.size());
}

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

orderBox.remove(order1);
logOrders(orderBox, customer);

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

orderBox.remove(order);
order = orderBox.query().eager(Order_.customer).build().findUnique();
assertTrue(order.customer__toOne.isResolved());

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

@Test
public void testBasics() {
  ObfuscatedEntity object = new ObfuscatedEntity();
  long id = box.put(object);
  assertTrue(id > 0);
  assertEquals(id, (long) object.getId());
  ObfuscatedEntity objectRead = box.get(id);
  assertNotNull(objectRead);
  assertEquals(id, (long) objectRead.getId());
  assertEquals(1, box.count());
  box.remove(id);
  assertEquals(0, box.count());
  assertNull(box.get(id));
}

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

customerBox.remove(customer);
customer = customerBox.query().eager(Customer_.orders).build().findUnique();
assertTrue(((ToMany) customer.getOrders()).isResolved());

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

@Test
public void testPutGetUpdateGetRemove() {
  // create an entity
  TestEntity entity = new TestEntity();
  entity.setSimpleInt(1977);
  entity.setSimpleLong(54321);
  String value1 = "lulu321";
  entity.setSimpleString(value1);
  long key = box.put(entity);
  // get it
  TestEntity entityRead = box.get(key);
  assertNotNull(entityRead);
  assertEquals(1977, entityRead.getSimpleInt());
  assertEquals(54321, entityRead.getSimpleLong());
  assertEquals(value1, entityRead.getSimpleString());
  // put with changed values
  String value2 = "lala123";
  entityRead.setSimpleString(value2);
  entityRead.setSimpleLong(12345);
  box.put(entityRead);
  // get the changed entity
  entityRead = box.get(key);
  assertNotNull(entityRead);
  assertEquals(1977, entityRead.getSimpleInt());
  assertEquals(12345, entityRead.getSimpleLong());
  assertEquals(value2, entityRead.getSimpleString());
  // and remove it
  box.remove(key);
  assertNull(box.get(key));
}

代码示例来源:origin: owntracks/android

@Override
  public void delete_impl(org.owntracks.android.data.WaypointModel w) {
    box.remove(w);
  }
}

代码示例来源:origin: dabutaizha/juzimi

private long delete(long modelId) {
  mSentencesBox.remove(modelId);
  return modelId;
}

代码示例来源:origin: dabutaizha/juzimi

private long delete(long modelId) {
  mPremissionBox.remove(modelId);
  return modelId;
}

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

@Override
  public void onNoteClick(@Nullable Note note) {
    if (note == null) {
      return;
    }
    notesBox.remove(note);
    Log.d(App.TAG, "Deleted note, ID: " + note.getId());
  }
};

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

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Note note = notesAdapter.getItem(position);
    notesBox.remove(note);
    Log.d(App.TAG, "Deleted note, ID: " + note.getId());
    updateNotes();
  }
};

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

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Note note = notesAdapter.getItem(position);
    notesBox.remove(note);
    Log.d(App.TAG, "Deleted note, ID: " + note.getId());
  }
};

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

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Note note = notesAdapter.getItem(position);
    notesBox.remove(note);
    Log.d(App.TAG, "Deleted note, ID: " + note.getId());
  }
};

代码示例来源:origin: fengzhizi715/RxCache4a

@Override
public void evict(String key) {
  CacheEntity entity = cacheEntityBox.query().equal(CacheEntity_.key, key).build().findUnique();
  if (entity!=null) {
    cacheEntityBox.remove(entity);
  }
}

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

public void runBatchPerfTest(boolean scalarsOnly) {
  List<SimpleEntity> list = prepareAndPutEntities(scalarsOnly);
  for (SimpleEntity entity : list) {
    if (scalarsOnly) {
      setRandomScalars(entity);
    } else {
      setRandomValues(entity);
    }
  }
  startBenchmark("update");
  box.put(list);
  stopBenchmark();
  list = null;
  startBenchmark("load");
  List<SimpleEntity> reloaded = box.getAll();
  stopBenchmark();
  assertEntityCount(reloaded.size());
  startBenchmark("access");
  accessAll(reloaded);
  stopBenchmark();
  startBenchmark("delete");
  box.remove(reloaded);
  stopBenchmark();
}

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

public void runBatchPerfTestIndexed() {
  List<SimpleEntityIndexed> list = prepareAndPutEntitiesIndexed();
  for (SimpleEntityIndexed entity : list) {
    setRandomValues(entity);
  }
  startBenchmark("update");
  boxIndexed.put(list);
  stopBenchmark();
  list = null;
  startBenchmark("load");
  List<SimpleEntityIndexed> reloaded = boxIndexed.getAll();
  stopBenchmark();
  startBenchmark("access");
  accessAllIndexed(reloaded);
  stopBenchmark();
  startBenchmark("delete");
  boxIndexed.remove(reloaded);
  stopBenchmark();
}

相关文章