use of com.datastax.driver.core.SettableByIndexData in project SimpleFlatMapper by arnaudroger.
the class DataTypeTest method testNumberSetter.
private <N> void testNumberSetter(Class<N> numberClass, Class<?> primitiveSetter) 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);
Setter<? super SettableByIndexData, N> setter = getSetter(numberClass, dataType);
assertNotNull("No setter for " + numberClass + ", " + dataType, setter);
if (numberClass.isPrimitive() && dataTypeClass.equals(numberClass) && primitiveSetter != null) {
primitiveSetter.isInstance(setter);
}
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
SettableByIndexData settableByDataInstance = (SettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { SettableByIndexData.class }, recorder);
N value = getValue(numberClass);
setter.set(settableByDataInstance, value);
recorder.invokedOnce(setterMethodFor(dataType), 1, getValue(dataTypeClass));
recorder.reset();
setter.set(settableByDataInstance, null);
recorder.invokedOnce("setToNull", 1);
}
}
}
}
use of com.datastax.driver.core.SettableByIndexData in project SimpleFlatMapper by arnaudroger.
the class Datastax3 method testLocalDateSetter.
@SuppressWarnings("unchecked")
@Test
public void testLocalDateSetter() throws Exception {
Setter<SettableByIndexData, Object> setter = DataTypeTest.getSetter((Class<Object>) localDateClass, (DataType) DataType.class.getMethod("date").invoke(null));
RecorderInvocationHandler recorder = new RecorderInvocationHandler();
SettableByIndexData settableByDataInstance = (SettableByIndexData) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { SettableByIndexData.class }, recorder);
Object localDateInstance = localDateClass.getDeclaredMethod("fromMillisSinceEpoch", long.class).invoke(null, System.currentTimeMillis());
setter.set(settableByDataInstance, localDateInstance);
recorder.invokedOnce("setDate", 1, localDateInstance);
recorder.reset();
setter.set(settableByDataInstance, null);
recorder.invokedOnce("setToNull", 1);
}
Aggregations