本文整理了Java中io.objectbox.Box.getAll()
方法的一些代码示例,展示了Box.getAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Box.getAll()
方法的具体详情如下:
包路径:io.objectbox.Box
类名称:Box
方法名:getAll
[英]Returns all stored Objects in this Box.
[中]返回此框中存储的所有对象。
代码示例来源:origin: objectbox/objectbox-java
@Test
public void testToOneBulk() {
// JNI local refs are limited on Android (for example, 512 on Android 7)
final int count = runExtensiveTests ? 10000 : 1000;
store.runInTx(new Runnable() {
@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);
}
}
});
assertEquals(count, customerBox.getAll().size());
assertEquals(count, orderBox.getAll().size());
}
代码示例来源:origin: objectbox/objectbox-java
Customer customer = null;
if (random.nextFloat() > 0.5f) {
List<Customer> all = customerBox.getAll();
if (!all.isEmpty()) {
customer = all.get(random.nextInt(all.size()));
putOrder(customer, "Mangos");
final List<Customer> all = customerBox.getAll();
if (all.size() > 1) {
Customer customer2 = all.get(random.nextInt(all.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
@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-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 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 testAddAll() {
Customer customer = putCustomer();
ToMany<Order> toMany = (ToMany<Order>) customer.orders;
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(customer.getId(), all.get(0).getCustomerId());
assertEquals("order2", all.get(1).getText());
assertEquals(customer.getId(), all.get(1).getCustomerId());
toMany.reset();
assertEquals(2, toMany.size());
}
代码示例来源:origin: owntracks/android
@Override
public List<org.owntracks.android.data.WaypointModel> getAll() {
return this.box.getAll();
}
代码示例来源:origin: fengzhizi715/RxCache4a
@Override
public List<String> allKeys() {
List<CacheEntity> list = cacheEntityBox.getAll();
List<String> result = new ArrayList<>();
for (CacheEntity entity:list) {
result.add(entity.key);
}
return result;
}
代码示例来源:origin: objectbox/objectbox-examples
public static void main(String[] args) {
BoxStore store = MyObjectBox.builder().name("objectbox-notes-db").build();
Box<Note> box = store.boxFor(Note.class);
String text = args.length > 0 ? String.join(" ", args) : "No text given";
box.put(new Note(text));
System.out.println(box.count() + " notes in ObjectBox database:");
for (Note note : box.getAll()) {
System.out.println(note);
}
store.close();
}
}
代码示例来源:origin: objectbox/objectbox-examples
private void logTeachers(Box<Student> studentBox, Box<Teacher> teacherBox) {
log("There are " + teacherBox.count() + " teachers");
List<Student> students = studentBox.getAll();
for (Student student : students) {
ToMany<Teacher> teachersToMany = student.teachers;
for (Teacher teacher : teachersToMany) {
log("Student " + student.id + " is taught by teacher " + teacher.id);
}
}
log("");
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!