use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class DefaultColumnPreparedStatement method getSingleResult.
@Override
public Optional<ColumnEntity> getSingleResult() {
Stream<ColumnEntity> entities = getResult();
final Iterator<ColumnEntity> iterator = entities.iterator();
if (!iterator.hasNext()) {
return Optional.empty();
}
final ColumnEntity next = iterator.next();
if (!iterator.hasNext()) {
return Optional.of(next);
}
throw new NonUniqueResultException("The select returns more than one entity, select: " + query);
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class InsertQueryParser method query.
Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
InsertQuery insertQuery = insertQueryProvider.apply(query);
String columnFamily = insertQuery.getEntity();
Params params = Params.newParams();
ColumnEntity entity = getEntity(insertQuery, columnFamily, params, observer);
Optional<Duration> ttl = insertQuery.getTtl();
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
if (ttl.isPresent()) {
return Stream.of(manager.insert(entity, ttl.get()));
} else {
return Stream.of(manager.insert(entity));
}
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class InsertQueryParserTest method shouldReturnParserQuery5.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 second" })
public void shouldReturnParserQuery5(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
parser.query(query, manager, observer);
Mockito.verify(manager).insert(captor.capture(), durationCaptor.capture());
ColumnEntity entity = captor.getValue();
Duration duration = durationCaptor.getValue();
assertEquals("God", entity.getName());
assertEquals(Column.of("name", "Diana"), entity.find("name").get());
assertEquals(Duration.ofSeconds(10L), duration);
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class InsertQueryParserTest method shouldReturnParserQuery9.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\":\"Ada Lovelace\"} 10 nanosecond" })
public void shouldReturnParserQuery9(String query) {
ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, observer);
Mockito.verify(manager).insert(captor.capture(), durationCaptor.capture());
ColumnEntity entity = captor.getValue();
Duration duration = durationCaptor.getValue();
assertEquals("Person", entity.getName());
assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
assertEquals(Duration.ofNanos(10L), duration);
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class InsertQueryParserTest method shouldReturnParserQuery1.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = 30, name = \"Artemis\")" })
public void shouldReturnParserQuery1(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, observer);
Mockito.verify(manager).insert(captor.capture());
ColumnEntity entity = captor.getValue();
assertEquals("God", entity.getName());
assertEquals(Column.of("name", "Artemis"), entity.find("name").get());
assertEquals(Column.of("age", 30L), entity.find("age").get());
}
Aggregations