Search in sources :

Example 1 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryParser method prepare.

ColumnPreparedStatement prepare(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    InsertQuery insertQuery = insertQueryProvider.apply(query);
    String columnFamily = observer.fireEntity(insertQuery.getEntity());
    Params params = Params.newParams();
    Optional<Duration> ttl = insertQuery.getTtl();
    ColumnEntity entity = getEntity(insertQuery, columnFamily, params, observer);
    return DefaultColumnPreparedStatement.insert(entity, params, query, ttl.orElse(null), manager);
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Params(jakarta.nosql.Params) Duration(java.time.Duration)

Example 2 with InsertQuery

use of jakarta.nosql.query.InsertQuery 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)

Example 3 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryParser method query.

Stream<DocumentEntity> query(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
    InsertQuery insertQuery = insertQueryProvider.apply(query);
    String collection = insertQuery.getEntity();
    Params params = Params.newParams();
    DocumentEntity entity = getEntity(insertQuery, collection, 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(collectionManager.insert(entity, ttl.get()));
    } else {
        return Stream.of(collectionManager.insert(entity));
    }
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) QueryException(jakarta.nosql.QueryException) DocumentEntity(jakarta.nosql.document.DocumentEntity) Params(jakarta.nosql.Params) Duration(java.time.Duration)

Example 4 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery11.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 millisecond" })
public void shouldReturnParserQuery11(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    checkTTL(insertQuery, Duration.ofMillis(10L));
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with InsertQuery

use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.

the class InsertQueryProviderTest method shouldReturnParserQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (siblings = {\"Apollo\": \"Brother\", \"Zeus\": \"Father\"})" })
public void shouldReturnParserQuery3(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    List<Condition> conditions = insertQuery.getConditions();
    assertEquals(1, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("siblings", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof JSONQueryValue);
    JsonObject jsonObject = JSONQueryValue.class.cast(value).get();
    assertEquals("Brother", jsonObject.getString("Apollo"));
    assertEquals("Father", jsonObject.getString("Zeus"));
    assertFalse(insertQuery.getTtl().isPresent());
}
Also used : Condition(jakarta.nosql.query.Condition) InsertQuery(jakarta.nosql.query.InsertQuery) JsonObject(javax.json.JsonObject) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InsertQuery (jakarta.nosql.query.InsertQuery)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 Condition (jakarta.nosql.query.Condition)7 JsonObject (javax.json.JsonObject)5 Params (jakarta.nosql.Params)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)4 Duration (java.time.Duration)4 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)3 QueryException (jakarta.nosql.QueryException)2 ColumnEntity (jakarta.nosql.column.ColumnEntity)2 DocumentEntity (jakarta.nosql.document.DocumentEntity)2 StringQueryValue (jakarta.nosql.query.StringQueryValue)2 Function (jakarta.nosql.query.Function)1 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)1 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)1 JsonArray (javax.json.JsonArray)1