use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLive.
@Test
public void shouldLive() throws InterruptedException {
List<DocumentEntity> entities = new ArrayList<>();
OrientDBLiveCreateCallback<DocumentEntity> callback = entities::add;
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.live(query, OrientDBLiveCallbackBuilder.builder().onCreate(callback).build());
entityManager.insert(getEntity());
Thread.sleep(3_000L);
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSave.
@Test
public void shouldSave() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
assertNotNull(documentEntity);
Optional<Document> document = documentEntity.find(RID_FIELD);
assertTrue(document.isPresent());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLiveWithNativeQuery.
@Test
public void shouldLiveWithNativeQuery() throws InterruptedException {
List<DocumentEntity> entities = new ArrayList<>();
OrientDBLiveCreateCallback<DocumentEntity> callback = entities::add;
DocumentEntity entity = entityManager.insert(getEntity());
Document name = entity.find("name").get();
entityManager.live("LIVE SELECT FROM person WHERE name = ?", OrientDBLiveCallbackBuilder.builder().onCreate(callback).build(), name.get());
entityManager.insert(getEntity());
Thread.sleep(3_000L);
assertFalse(entities.isEmpty());
}
Aggregations