Search in sources :

Example 11 with Value

use of org.jnosql.diana.api.Value in project jnosql-diana by eclipse.

the class ColumnTest method shouldReturnGetObject.

@Test
public void shouldReturnGetObject() {
    Value value = Value.of("text");
    Column column = Column.of("name", value);
    assertEquals(value.get(), column.get());
}
Also used : Value(org.jnosql.diana.api.Value) Test(org.junit.jupiter.api.Test)

Example 12 with Value

use of org.jnosql.diana.api.Value in project jnosql-diana-driver by eclipse.

the class HazelcastBucketManagerQueryTest method shouldReturnEqualsMatrixPredicate.

@Test
public void shouldReturnEqualsMatrixPredicate() {
    Predicate predicate = equal("name", "Matrix");
    Collection<Value> result = bucketManager.query(predicate);
    assertEquals(1, result.size());
}
Also used : Value(org.jnosql.diana.api.Value) Predicate(com.hazelcast.query.Predicate) Test(org.junit.jupiter.api.Test)

Example 13 with Value

use of org.jnosql.diana.api.Value in project jnosql-diana-driver by eclipse.

the class ValueJSONTest method shouldConvertMapIgnoringKeyValue.

@Test
public void shouldConvertMapIgnoringKeyValue() {
    Map<Integer, List<String>> map = Collections.singletonMap(10, Arrays.asList("1", "2", "3"));
    Value value = ValueJSON.of(map);
    Map<String, List<String>> result = value.get(new TypeReference<Map<String, List<String>>>() {
    });
    List<String> valueResult = result.get("10");
    assertThat(result.keySet(), containsInAnyOrder("10"));
    assertThat(valueResult, containsInAnyOrder("1", "2", "3"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Value(org.jnosql.diana.api.Value) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 14 with Value

use of org.jnosql.diana.api.Value in project jnosql-diana-driver by eclipse.

the class ValueJSONTest method shouldConvertType.

@Test
public void shouldConvertType() {
    AtomicInteger number = new AtomicInteger(5_000);
    Value value = ValueJSON.of(number);
    assertEquals(Integer.valueOf(5_000), value.get(Integer.class));
    assertEquals("5000", value.get(String.class));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Value(org.jnosql.diana.api.Value) Test(org.junit.jupiter.api.Test)

Example 15 with Value

use of org.jnosql.diana.api.Value in project jnosql-artemis by eclipse.

the class ConverterUtil method getValue.

public static Object getValue(Object value, ClassRepresentation representation, String name, Converters converters) {
    Optional<FieldRepresentation> fieldOptional = representation.getFieldRepresentation(name);
    if (fieldOptional.isPresent()) {
        FieldRepresentation field = fieldOptional.get();
        Field nativeField = field.getNativeField();
        if (!nativeField.getType().equals(value.getClass())) {
            return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElseGet(() -> Value.of(value).get(nativeField.getType()));
        }
        return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElse(value);
    }
    return value;
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Converters(org.jnosql.artemis.Converters) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) Field(java.lang.reflect.Field) Field(java.lang.reflect.Field)

Aggregations

Value (org.jnosql.diana.api.Value)17 Test (org.junit.jupiter.api.Test)12 Predicate (com.hazelcast.query.Predicate)3 List (java.util.List)3 Optional (java.util.Optional)3 FieldRepresentation (org.jnosql.artemis.reflection.FieldRepresentation)3 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Converters (org.jnosql.artemis.Converters)2 ClassRepresentation (org.jnosql.artemis.reflection.ClassRepresentation)2 TypeReference (org.jnosql.diana.api.TypeReference)2 Column (org.jnosql.diana.api.column.Column)2 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)2 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)2 DeleteValue (com.basho.riak.client.api.commands.kv.DeleteValue)1 FetchValue (com.basho.riak.client.api.commands.kv.FetchValue)1 StoreValue (com.basho.riak.client.api.commands.kv.StoreValue)1 IMap (com.hazelcast.core.IMap)1 SqlPredicate (com.hazelcast.query.SqlPredicate)1