Search in sources :

Example 1 with GettableByIndexData

use of com.datastax.driver.core.GettableByIndexData in project SimpleFlatMapper by arnaudroger.

the class DataTypeTest method testNumberGetter.

private <N> void testNumberGetter(Class<N> numberClass, Class<?> primitiveGetter) throws Exception {
    Method[] methods = DataType.class.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getReturnType().equals(DataType.class) && Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0) {
            DataType dataType = (DataType) method.invoke(null);
            if (DataTypeHelper.isNumber(dataType)) {
                Class dataTypeClass = DataTypeHelper.asJavaClass(dataType);
                Getter<? super GettableByIndexData, N> getter = getGetter(numberClass, dataType);
                assertNotNull("No getter for " + numberClass + ", " + dataType, getter);
                if (numberClass.isPrimitive() && dataTypeClass.equals(numberClass) && primitiveGetter != null) {
                    primitiveGetter.isInstance(getter);
                }
                RecorderInvocationHandler recorder = new RecorderInvocationHandler();
                GettableByIndexData gettableByDataInstance = (GettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { GettableByIndexData.class }, recorder);
                getter.get(gettableByDataInstance);
                recorder.invokedOnce(getterMethodFor(dataType), 1);
                if (!(dataTypeClass.equals(numberClass) && (BigInteger.class.equals(numberClass)) || BigDecimal.class.equals(numberClass))) {
                    recorder.when("isNull", 1, true);
                    assertNull(" fail isNull check " + numberClass + " - " + dataTypeClass, getter.get(gettableByDataInstance));
                    recorder.reset();
                }
            }
        }
    }
}
Also used : RecorderInvocationHandler(org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler) GettableByIndexData(com.datastax.driver.core.GettableByIndexData) DataType(com.datastax.driver.core.DataType) BigInteger(java.math.BigInteger) Method(java.lang.reflect.Method) BigDecimal(java.math.BigDecimal)

Example 2 with GettableByIndexData

use of com.datastax.driver.core.GettableByIndexData in project SimpleFlatMapper by arnaudroger.

the class DatastaxUDTGetter method newUDTMapper.

public static <P> Mapper<GettableByIndexData, P> newUDTMapper(Type target, UserType tt, DatastaxMapperFactory factory) {
    ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> builder = newFieldMapperBuilder(factory, target);
    Iterator<UserType.Field> iterator = tt.iterator();
    int i = 0;
    while (iterator.hasNext()) {
        UserType.Field f = iterator.next();
        FieldMapperColumnDefinition<DatastaxColumnKey> identity = FieldMapperColumnDefinition.identity();
        builder.addMapping(new DatastaxColumnKey(f.getName(), i, f.getType()), identity);
        i++;
    }
    return builder.mapper();
}
Also used : GettableByIndexData(com.datastax.driver.core.GettableByIndexData) DatastaxColumnKey(org.simpleflatmapper.datastax.DatastaxColumnKey) UserType(com.datastax.driver.core.UserType)

Example 3 with GettableByIndexData

use of com.datastax.driver.core.GettableByIndexData in project SimpleFlatMapper by arnaudroger.

the class DatastaxUDTGetter method newFieldMapperBuilder.

public static <P> ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> newFieldMapperBuilder(DatastaxMapperFactory factory, Type target) {
    MapperConfig<DatastaxColumnKey, FieldMapperColumnDefinition<DatastaxColumnKey>> config = factory.mapperConfig();
    MapperSourceImpl<GettableByIndexData, DatastaxColumnKey> mapperSource = new MapperSourceImpl<GettableByIndexData, DatastaxColumnKey>(GettableByIndexData.class, new RowGetterFactory(factory));
    ClassMeta<P> classMeta = factory.getClassMeta(target);
    return new ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey>(mapperSource, classMeta, config, new DatastaxMappingContextFactoryBuilder(), DatastaxMapperBuilder.KEY_FACTORY);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) GettableByIndexData(com.datastax.driver.core.GettableByIndexData) DatastaxMappingContextFactoryBuilder(org.simpleflatmapper.datastax.impl.DatastaxMappingContextFactoryBuilder) MapperSourceImpl(org.simpleflatmapper.map.mapper.MapperSourceImpl) RowGetterFactory(org.simpleflatmapper.datastax.impl.RowGetterFactory) DatastaxColumnKey(org.simpleflatmapper.datastax.DatastaxColumnKey) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder)

Example 4 with GettableByIndexData

use of com.datastax.driver.core.GettableByIndexData in project SimpleFlatMapper by arnaudroger.

the class Datastax3 method testLocalDateGetter.

@Test
public void testLocalDateGetter() throws Exception {
    Getter<GettableByIndexData, ?> getter = DataTypeTest.getGetter(localDateClass, (DataType) DataType.class.getMethod("date").invoke(null));
    RecorderInvocationHandler recorder = new RecorderInvocationHandler();
    GettableByIndexData gettableByDataInstance = (GettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { GettableByIndexData.class }, recorder);
    getter.get(gettableByDataInstance);
    recorder.invokedOnce("getDate", 1);
}
Also used : GettableByIndexData(com.datastax.driver.core.GettableByIndexData) RecorderInvocationHandler(org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler) DataType(com.datastax.driver.core.DataType) Test(org.junit.Test)

Example 5 with GettableByIndexData

use of com.datastax.driver.core.GettableByIndexData in project SimpleFlatMapper by arnaudroger.

the class DatastaxTupleGetter method newTupleMapper.

public static <P extends Tuple2<?, ?>> Mapper<GettableByIndexData, P> newTupleMapper(Type target, TupleType tt, DatastaxMapperFactory factory) {
    ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> builder = DatastaxUDTGetter.newFieldMapperBuilder(factory, target);
    List<DataType> componentTypes = tt.getComponentTypes();
    for (int i = 0; i < componentTypes.size(); i++) {
        FieldMapperColumnDefinition<DatastaxColumnKey> identity = FieldMapperColumnDefinition.identity();
        builder.addMapping(new DatastaxColumnKey("elt" + i, i, componentTypes.get(i)), identity);
    }
    return builder.mapper();
}
Also used : GettableByIndexData(com.datastax.driver.core.GettableByIndexData) DatastaxColumnKey(org.simpleflatmapper.datastax.DatastaxColumnKey) DataType(com.datastax.driver.core.DataType)

Aggregations

GettableByIndexData (com.datastax.driver.core.GettableByIndexData)5 DataType (com.datastax.driver.core.DataType)3 DatastaxColumnKey (org.simpleflatmapper.datastax.DatastaxColumnKey)3 RecorderInvocationHandler (org.simpleflatmapper.datastax.test.utils.RecorderInvocationHandler)2 UserType (com.datastax.driver.core.UserType)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 DatastaxMappingContextFactoryBuilder (org.simpleflatmapper.datastax.impl.DatastaxMappingContextFactoryBuilder)1 RowGetterFactory (org.simpleflatmapper.datastax.impl.RowGetterFactory)1 ConstantSourceMapperBuilder (org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder)1 MapperSourceImpl (org.simpleflatmapper.map.mapper.MapperSourceImpl)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1