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

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

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

Box.put介绍

[英]Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID will be assigned to the entity (and returned). If the entity was already put in the box before, it will be overwritten.

Performance note: if you want to put several entities, consider #put(Collection), #put(Object[]), BoxStore#runInTx(Runnable), etc. instead.
[中]将给定对象放入框中(也称为持久化对象)。如果这是一个新实体(其ID属性为0),将为该实体分配一个新ID(并返回)。如果之前已将实体放入框中,则该实体将被覆盖。
性能说明:如果您想放置多个实体,请考虑“β放(集合)”、“π放置”(对象[])、“BxSturty*RunTnx”(RunnEnter)等。

代码示例

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

@Override
  public void run() {
    long targetKey = targetBox.put(target);
    setResolvedTarget(target, targetKey);
    entityBox.put(entity);
  }
});

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

protected List<TestEntity> putTestEntities(int count, @Nullable String baseString, int baseNr) {
  List<TestEntity> entities = new ArrayList<>();
  for (int i = baseNr; i < baseNr + count; i++) {
    entities.add(createTestEntity(baseString != null ? baseString + i : null, i));
  }
  getTestEntityBox().put(entities);
  return entities;
}

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

List<TestEntity> putTestEntitiesStrings() {
    List<TestEntity> entities = new ArrayList<>();
    entities.add(createTestEntity("banana", 1));
    entities.add(createTestEntity("apple", 2));
    entities.add(createTestEntity("bar", 3));
    entities.add(createTestEntity("banana milk shake", 4));
    entities.add(createTestEntity("foo bar", 5));
    box.put(entities);
    return entities;
  }
}

代码示例来源: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

@Override
  public void run() {
    for (int i = 0; i < count; i++) {
      Customer customer = new Customer(0, "Customer" + i);
      customerBox.put(customer);
      putOrder(customer, "order" + 1);
    }
  }
});

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

protected Order putOrder(@Nullable Customer customer, @Nullable String text) {
  Order order = new Order();
  order.setCustomer(customer);
  order.setText(text);
  orderBox.put(order);
  return order;
}

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

@Override
  public void run() {
    box.put(new TestEntity());
    counts[0] = box.count();
    box.put(new TestEntity());
    counts[1] = box.count();
  }
});

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

protected Customer putCustomer() {
  Customer customer = new Customer();
  customer.setName("Joe");
  customerBox.put(customer);
  return customer;
}

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

@Override
  public void run() {
    getTestEntityBox().put(new TestEntity());
  }
});

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

@Override
  public Long call() throws Exception {
    TestEntity entity = new TestEntity();
    entity.setId(-1);
    getTestEntityBox().put(entity);
    return null;
  }
};

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

@Test
public void testRemoveAll() {
  int count = 5;
  Customer customer = putCustomerWithOrders(count);
  ToMany<Order> toMany = (ToMany<Order>) customer.orders;
  List<Order> toRemove = new ArrayList<>();
  toRemove.add(toMany.get(1));
  toRemove.add(toMany.get(3));
  assertTrue(toMany.removeAll(toRemove));
  customerBox.put(customer);
  assertOrder2And4Removed(count, customer, toMany);
}

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

protected TestEntity putTestEntity(@Nullable String simpleString, int nr) {
  TestEntity entity = createTestEntity(simpleString, nr);
  long key = getTestEntityBox().put(entity);
  assertTrue(key != 0);
  assertEquals(key, entity.getId());
  return entity;
}

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

@Override
  public void run() {
    putTestEntities(3);
    Box<TestEntityMinimal> boxMini = store.boxFor(TestEntityMinimal.class);
    boxMini.put(new TestEntityMinimal(), new TestEntityMinimal());
    assertEquals(0, classesWithChanges.size());
  }
};

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

@Test
public void testClear_removeFromTargetBox() {
  Customer customer = putCustomerWithOrders(5);
  ToMany<Order> toMany = (ToMany<Order>) customer.orders;
  toMany.setRemoveFromTargetBox(true);
  toMany.clear();
  customerBox.put(customer);
  assertEquals(0, orderBox.count());
}

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

@Test
public void testAddRemove_notPersisted() {
  Customer customer = putCustomer();
  ToMany<Order> toMany = customer.ordersStandalone;
  Order order = new Order();
  toMany.add(order);
  toMany.remove(order);
  customerBox.put(customer);
  assertEquals(0, orderBox.count());
}

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

@Test
public void testRemove() {
  int count = 5;
  Customer customer = putCustomerWithOrders(count);
  ToMany<Order> toMany = customer.ordersStandalone;
  Order removed1 = toMany.remove(3);
  assertEquals("order4", removed1.getText());
  Order removed2 = toMany.get(1);
  assertTrue(toMany.remove(removed2));
  customerBox.put(customer);
  assertOrder2And4Removed(count, customer, toMany);
}

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

@Test
public void testRemove() {
  int count = 5;
  Customer customer = putCustomerWithOrders(count);
  ToMany<Order> toMany = (ToMany<Order>) customer.orders;
  Order removed1 = toMany.remove(3);
  assertEquals("order4", removed1.getText());
  Order removed2 = toMany.get(1);
  assertTrue(toMany.remove(removed2));
  customerBox.put(customer);
  assertOrder2And4Removed(count, customer, toMany);
}

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

@Test
public void testPutAndGet() {
  TestEntity entity = new TestEntity();
  entity.setSimpleInt(1977);
  long key = box.put(entity);
  assertTrue(key != 0);
  assertEquals(key, entity.getId());
  TestEntity entityRead = box.get(key);
  assertNotNull(entityRead);
  assertEquals(1977, entityRead.getSimpleInt());
}

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

@Test
public void testClear() {
  int count = 5;
  Customer customer = putCustomerWithOrders(count);
  ToMany<Order> toMany = customer.ordersStandalone;
  toMany.clear();
  customerBox.put(customer);
  Customer customer2 = customerBox.get(customer.getId());
  assertEquals(0, customer2.getOrdersStandalone().size());
  assertEquals(count, orderBox.count());
}

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

@Test
public void testSumDoubleOfFloats() {
  TestEntity entity = new TestEntity();
  entity.setSimpleFloat(0);
  TestEntity entity2 = new TestEntity();
  entity2.setSimpleFloat(-2.05f);
  box.put(entity, entity2);
  double sum = box.query().build().property(simpleFloat).sumDouble();
  assertEquals(-2.05, sum, 0.0001);
}

相关文章