Java Code Examples for io.objectbox.Box#put()
The following examples show how to use
io.objectbox.Box#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryTest.java From objectbox-java with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: IndexReaderRenewTest.java From objectbox-java with Apache License 2.0 | 6 votes |
@Test public void testOldReaderWithIndex() { 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()); }
Example 3
Source File: ObjectBoxDB.java From Hentoid with Apache License 2.0 | 5 votes |
void updateImageFileStatusParamsMimeTypeUriSize(@NonNull ImageFile image) { Box<ImageFile> imgBox = store.boxFor(ImageFile.class); ImageFile img = imgBox.get(image.getId()); if (img != null) { img.setStatus(image.getStatus()); img.setDownloadParams(image.getDownloadParams()); img.setMimeType(image.getMimeType()); img.setFileUri(image.getFileUri()); img.setSize(image.getSize()); imgBox.put(img); } }
Example 4
Source File: ObjectBoxDB.java From Hentoid with Apache License 2.0 | 5 votes |
void updateImageFileUrl(@NonNull final ImageFile image) { Box<ImageFile> imgBox = store.boxFor(ImageFile.class); ImageFile img = imgBox.get(image.getId()); if (img != null) { img.setUrl(image.getUrl()); imgBox.put(img); } }
Example 5
Source File: IndexReaderRenewTest.java From objectbox-java with Apache License 2.0 | 4 votes |
@Test public void testOverwriteIndexedValue() throws InterruptedException { final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class); final int initialValue = 1; final EntityLongIndex[] transformResults = {null, null, null}; final CountDownLatch transformLatch1 = new CountDownLatch(1); final CountDownLatch transformLatch2 = new CountDownLatch(1); final AtomicInteger transformerCallCount = new AtomicInteger(); final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build(); store.subscribe(EntityLongIndex.class).transform(javaClass -> { int callCount = transformerCallCount.incrementAndGet(); if (callCount == 1) { query.setParameter(EntityLongIndex_.indexedLong, 1); EntityLongIndex unique = query.findUnique(); transformLatch1.countDown(); return unique; } else if (callCount == 2) { query.setParameter(EntityLongIndex_.indexedLong, 1); transformResults[0] = query.findUnique(); transformResults[1] = query.findUnique(); query.setParameter(EntityLongIndex_.indexedLong, 0); transformResults[2] = query.findUnique(); transformLatch2.countDown(); return transformResults[0]; } else { throw new RuntimeException("Unexpected: " + callCount); } }).observer(data -> { // Dummy }); assertTrue(transformLatch1.await(5, TimeUnit.SECONDS)); box.put(createEntityLongIndex(initialValue)); assertTrue(transformLatch2.await(5, TimeUnit.SECONDS)); assertEquals(2, transformerCallCount.intValue()); assertNotNull(transformResults[0]); assertNotNull(transformResults[1]); assertNull(transformResults[2]); query.setParameter(EntityLongIndex_.indexedLong, initialValue); assertNotNull(query.findUnique()); query.setParameter(EntityLongIndex_.indexedLong, initialValue); assertNotNull(query.findUnique()); assertNotNull(query.findUnique()); }
Example 6
Source File: IndexReaderRenewTest.java From objectbox-java with Apache License 2.0 | 4 votes |
@Test public void testOldReaderInThread() throws InterruptedException { final Box<EntityLongIndex> box = store.boxFor(EntityLongIndex.class); final int initialValue = 1; final EntityLongIndex[] results = new EntityLongIndex[5]; final CountDownLatch latchRead1 = new CountDownLatch(1); final CountDownLatch latchPut = new CountDownLatch(1); final CountDownLatch latchRead2 = new CountDownLatch(1); final Query<EntityLongIndex> query = box.query().equal(EntityLongIndex_.indexedLong, 0).build(); new Thread(() -> { 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(); box.closeThreadResources(); }).start(); assertTrue(latchRead1.await(5, TimeUnit.SECONDS)); box.put(createEntityLongIndex(initialValue)); latchPut.countDown(); assertTrue(latchRead2.await(5, TimeUnit.SECONDS)); assertNotNull(results[1]); assertNotNull(results[0]); assertNotNull(results[2]); assertNull(results[3]); query.setParameter(EntityLongIndex_.indexedLong, initialValue); assertNotNull(query.findUnique()); query.setParameter(EntityLongIndex_.indexedLong, initialValue); assertNotNull(query.findUnique()); assertNotNull(query.findUnique()); }
Example 7
Source File: ObjectBoxDB.java From Hentoid with Apache License 2.0 | 4 votes |
void updateQueue(@NonNull final List<QueueRecord> queue) { Box<QueueRecord> queueRecordBox = store.boxFor(QueueRecord.class); queueRecordBox.put(queue); }