Search in sources :

Example 1 with DocumentEntity

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));
}
Also used : QueryException(jakarta.nosql.QueryException) DocumentEntity(jakarta.nosql.document.DocumentEntity) UpdateQuery(jakarta.nosql.query.UpdateQuery) Params(jakarta.nosql.Params)

Example 2 with DocumentEntity

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);
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Params(jakarta.nosql.Params) UpdateQuery(jakarta.nosql.query.UpdateQuery)

Example 3 with DocumentEntity

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DocumentEntity

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);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) Test(org.junit.jupiter.api.Test)

Example 5 with DocumentEntity

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);
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Params(jakarta.nosql.Params) Duration(java.time.Duration)

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21