use of org.simpleflatmapper.map.property.ConstantValueProperty in project SimpleFlatMapper by arnaudroger.
the class AbstractConstantTargetMapperBuilder method addColumn.
@SuppressWarnings("unchecked")
public B addColumn(K key, FieldMapperColumnDefinition<K> columnDefinition) {
final FieldMapperColumnDefinition<K> composedDefinition = columnDefinition.compose(mapperConfig.columnDefinitions().getColumnDefinition(key));
final K mappedColumnKey = composedDefinition.rename(key);
if (composedDefinition.has(ConstantValueProperty.class)) {
ConstantValueProperty staticValueProperty = composedDefinition.lookFor(ConstantValueProperty.class);
PropertyMeta<T, Object> meta = new ObjectPropertyMeta<T, Object>(key.getName(), classMeta.getType(), reflectionService, staticValueProperty.getType(), ScoredGetter.of(new ConstantGetter<T, Object>(staticValueProperty.getValue()), 1), null, null);
propertyMappingsBuilder.addProperty(key, columnDefinition, meta);
} else {
propertyMappingsBuilder.addProperty(mappedColumnKey, composedDefinition);
}
return (B) this;
}
use of org.simpleflatmapper.map.property.ConstantValueProperty in project SimpleFlatMapper by arnaudroger.
the class QueryPreparerBuilderTest method testCustomGetterOnNonExistantProp.
@Test
public void testCustomGetterOnNonExistantProp() throws Exception {
PreparedStatementMapperBuilder<Object> mapperBuilder = JdbcMapperFactory.newInstance().addColumnProperty("text", new ConstantValueProperty<String>("value2", String.class)).buildFrom(Object.class);
mapperBuilder.addColumn("text");
Mapper<Object, PreparedStatement> mapper = mapperBuilder.mapper();
PreparedStatement ps = mock(PreparedStatement.class);
mapper.mapTo(new Object(), ps, null);
verify(ps).setString(1, "value2");
}
use of org.simpleflatmapper.map.property.ConstantValueProperty in project SimpleFlatMapper by arnaudroger.
the class SqlParameterSourceBuilder method add.
public SqlParameterSourceBuilder<T> add(JdbcColumnKey key, FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition) {
final FieldMapperColumnDefinition<JdbcColumnKey> composedDefinition = columnDefinition.compose(mapperConfig.columnDefinitions().getColumnDefinition(key));
final JdbcColumnKey mappedColumnKey = composedDefinition.rename(key);
if (composedDefinition.has(ConstantValueProperty.class)) {
ConstantValueProperty staticValueProperty = composedDefinition.lookFor(ConstantValueProperty.class);
PropertyMeta<T, Object> meta = new ObjectPropertyMeta<T, Object>(key.getName(), builder.getClassMeta().getType(), reflectionService, staticValueProperty.getType(), ScoredGetter.of(new ConstantGetter<T, Object>(staticValueProperty.getValue()), 1), null, null);
builder.addProperty(key, columnDefinition, meta);
} else {
builder.addProperty(mappedColumnKey, composedDefinition);
}
return this;
}
use of org.simpleflatmapper.map.property.ConstantValueProperty in project SimpleFlatMapper by arnaudroger.
the class SqlParameterSourceTest method testConstantValue.
@Test
public void testConstantValue() {
SqlParameterSourceFactory<DbObject> parameterSourceFactory = JdbcTemplateMapperFactory.newInstance().addColumnProperty("id", new ConstantValueProperty<Long>(-3l, Long.class)).newSqlParameterSourceFactory(DbObject.class);
SqlParameterSource parameterSource = parameterSourceFactory.newSqlParameterSource(new DbObject());
assertEquals(-3l, parameterSource.getValue("id"));
}
Aggregations