use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class UpdateQueryParser method query.
Stream<DocumentEntity> query(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
UpdateQuery updateQuery = supplier.apply(query);
Params params = Params.newParams();
DocumentEntity entity = getEntity(params, updateQuery, observer);
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return Stream.of(collectionManager.update(entity));
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class UpdateQueryParser method prepare.
DocumentPreparedStatement prepare(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
Params params = Params.newParams();
UpdateQuery updateQuery = supplier.apply(query);
DocumentEntity entity = getEntity(params, updateQuery, observer);
return DefaultDocumentPreparedStatement.update(entity, params, query, collectionManager);
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldReturnEmptySingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
Mockito.when(manager.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.empty());
DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
prepare.bind("age", 12);
final Optional<DocumentEntity> result = prepare.getSingleResult();
Mockito.verify(manager).select(captor.capture());
DocumentQuery columnQuery = captor.getValue();
DocumentCondition columnCondition = columnQuery.getCondition().get();
Document column = columnCondition.getDocument();
assertEquals(Condition.EQUALS, columnCondition.getCondition());
assertEquals("age", column.getName());
assertEquals(12, column.get());
assertFalse(result.isPresent());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldExecuteSingleResultManager.
@Test
public void shouldExecuteSingleResultManager() {
DocumentCollectionManager manager = Mockito.mock(DocumentCollectionManager.class);
ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
String collection = "collection";
Optional<DocumentEntity> entities = select().from(collection).getSingleResult(manager);
Mockito.verify(manager).singleResult(queryCaptor.capture());
checkQuery(queryCaptor, collection);
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class InsertQueryParser method prepare.
DocumentPreparedStatement prepare(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
InsertQuery insertQuery = insertQueryProvider.apply(query);
String collection = observer.fireEntity(insertQuery.getEntity());
Params params = Params.newParams();
Optional<Duration> ttl = insertQuery.getTtl();
DocumentEntity entity = getEntity(insertQuery, collection, params, observer);
return DefaultDocumentPreparedStatement.insert(entity, params, query, ttl.orElse(null), collectionManager);
}
Aggregations