本文整理了Java中io.objectbox.Box
类的一些代码示例,展示了Box
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Box
类的具体详情如下:
包路径:io.objectbox.Box
类名称:Box
[英]A box to store objects of a particular class.
Thread-safe.
[中]用于存储特定类的对象的框。
线程安全。
代码示例来源:origin: objectbox/objectbox-java
@Override
public void run() {
long targetKey = targetBox.put(target);
setResolvedTarget(target, targetKey);
entityBox.put(entity);
}
});
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testBuild() {
Query query = box.query().build();
assertNotNull(query);
}
代码示例来源: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 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() {
box.put(new TestEntity());
counts[0] = box.count();
box.put(new TestEntity());
counts[1] = box.count();
}
});
代码示例来源:origin: objectbox/objectbox-java
@Override
public void run() {
putTestEntities(2);
box.removeAll();
putTestEntity("hello", 3);
counts[0] = box.count();
}
});
代码示例来源:origin: objectbox/objectbox-java
@Override
public Long call() throws Exception {
assertNotSame(mainTestThread, Thread.currentThread());
for (int i = 0; i < countEntities; i++) {
TestEntity entity = new TestEntity();
final int value = number.incrementAndGet();
entity.setSimpleInt(value);
long key = box.put(entity);
TestEntity read = box.get(key);
assertEquals(value, read.getSimpleInt());
}
return box.count();
}
};
代码示例来源: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-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();
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testToManyBulk() {
// JNI local refs are limited on Android (for example, 512 on Android 7)
final int count = runExtensiveTests ? 10000 : 1000;
Customer customer = new Customer();
List<Order> orders = customer.getOrders();
List<Order> ordersStandalone = customer.getOrdersStandalone();
for (int i = 0; i < count; i++) {
Order order = new Order();
order.setText("order" + i);
orders.add(order);
Order orderStandalone = new Order();
orderStandalone.setText("orderStandalone" + i);
ordersStandalone.add(orderStandalone);
}
long customerId = customerBox.put(customer);
assertEquals(count, customerBox.get(customerId).getOrders().size());
assertEquals(count, customerBox.get(customerId).getOrdersStandalone().size());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testPutManyAndGetAll() {
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());
List<TestEntity> entitiesRead = box.getAll();
assertEquals(entities.size(), entitiesRead.size());
for (int i = 0; i < entities.size(); i++) {
assertEquals(2000 + i, entitiesRead.get(i).getSimpleInt());
}
}
代码示例来源:origin: objectbox/objectbox-java
List<Order> orders = orderBox.query().eager(Order_.customer).build().find();
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
orders = orderBox.query().eager(Order_.customer).build().find(0, 10);
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
orders = orderBox.query().eager(1, Order_.customer).build().find();
assertEquals(2, orders.size());
assertTrue(orders.get(0).customer__toOne.isResolved());
customerBox.query().eager(1, Customer_.orders).build().forEach(new QueryConsumer<Customer>() {
@Override
public void accept(Customer data) {
Order order = orderBox.query().eager(Order_.customer).build().findFirst();
assertTrue(order.customer__toOne.isResolved());
orderBox.remove(order);
order = orderBox.query().eager(Order_.customer).build().findUnique();
assertTrue(order.customer__toOne.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: objectbox/objectbox-java
@Test
public void testAddAll() {
Customer customer = putCustomer();
ToMany<Order> toMany = customer.ordersStandalone;
List<Order> orders = new ArrayList<>();
Order order1 = new Order();
order1.setText("order1");
Order order2 = new Order();
order2.setText("order2");
orders.add(order1);
orders.add(order2);
toMany.addAll(orders);
customerBox.put(customer);
List<Order> all = orderBox.getAll();
assertEquals(2, all.size());
assertEquals("order1", all.get(0).getText());
assertEquals("order2", all.get(1).getText());
toMany.reset();
assertEquals(2, toMany.size());
}
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testGetAllAfterGetAndRemove() {
assertEquals(0, box.count());
assertEquals(0, box.getAll().size());
System.out.println("PUT");
List<TestEntity> entities = putTestEntities(10);
// explicitly get an entity (any will do)
System.out.println("GET");
TestEntity entity = box.get(entities.get(1).getId());
assertNotNull(entity);
System.out.println("REMOVE_ALL");
box.removeAll();
System.out.println("COUNT");
assertEquals(0, box.count());
System.out.println("GET_ALL");
List<TestEntity> all = box.getAll();
// note only 1 entity is returned by getAll, it is the one we explicitly get (last) above
assertEquals(0, all.size());
}
代码示例来源:origin: objectbox/objectbox-examples
customerBox.removeAll();
orderBox.removeAll();
Order order1 = new Order();
order1.customer.setTarget(customer);
orderBox.put(order1);
logOrders(orderBox, customer);
customerBox.put(customer);
logOrders(orderBox, customer);
orderBox.remove(order1);
logOrders(orderBox, customer);
customer.orders.reset();
customer.orders.remove(0);
customerBox.put(customer);
logOrders(orderBox, customer);
代码示例来源:origin: objectbox/objectbox-examples
studentBox.removeAll();
teacherBox.removeAll();
Student anakin = new Student("Anakin Skywalker");
anakin.teachers.add(obiWan);
studentBox.put(luke, anakin);
logTeachers(studentBox, teacherBox);
QueryBuilder<Student> builder = studentBox.query().contains(Student_.name, "Skywalker");
builder.link(Student_.teachers).equal(Teacher_.name, yoda.name);
List<Student> studentsTaughtByYoda = builder.build().find();
代码示例来源: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-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);
}
代码示例来源:origin: owntracks/android
@Override
public void delete_impl(org.owntracks.android.data.WaypointModel w) {
box.remove(w);
}
}
内容来源于网络,如有侵权,请联系作者删除!