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();
}
}
}
}
}
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();
}
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);
}
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);
}
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();
}
Aggregations