Search in sources :

Example 1 with SetterProperty

use of org.simpleflatmapper.map.property.SetterProperty in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactory method getSetter.

@SuppressWarnings("unchecked")
private <S, P> Setter<Appendable, ? super P> getSetter(PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> pm, CellWriter cellWriter) {
    final SetterProperty setterProperty = pm.getColumnDefinition().lookFor(SetterProperty.class);
    if (setterProperty != null) {
        return new CellWriterSetterWrapper<P>(cellWriter, (Setter<Appendable, P>) setterProperty.getSetter());
    }
    Setter<Appendable, ? super P> setter = setterFromFactory(pm);
    if (setter != null) {
        return new CellWriterSetterWrapper<P>(cellWriter, setter);
    }
    return null;
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty)

Example 2 with SetterProperty

use of org.simpleflatmapper.map.property.SetterProperty in project SimpleFlatMapper by arnaudroger.

the class CtfmSetterNotFoundTest method csvMapperOverrideGetter.

@Test
public void csvMapperOverrideGetter() throws IOException {
    StringBuilder sb = new StringBuilder();
    CsvWriter.from(Foo2.class).column("bar", new SetterProperty(new Setter<Appendable, Bar2Prop>() {

        @Override
        public void set(Appendable target, Bar2Prop value) throws Exception {
            target.append(value.getVal()).append(":").append(String.valueOf(value.getI()));
        }
    })).to(sb).append(new Foo2(new Bar2Prop("val", 3)));
    assertEquals("bar\r\nval:3\r\n", sb.toString());
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty) Setter(org.simpleflatmapper.reflect.Setter) Test(org.junit.Test)

Example 3 with SetterProperty

use of org.simpleflatmapper.map.property.SetterProperty in project SimpleFlatMapper by arnaudroger.

the class PreparedStatementFieldMapperFactoryTest method testCustomSetter.

@Test
public void testCustomSetter() throws Exception {
    Object o = new Object();
    newFieldMapperAndMapToPS(new ConstantGetter<Object, Object>(o), Object.class, new SetterProperty(new Setter<PreparedStatement, Object>() {

        @Override
        public void set(PreparedStatement target, Object value) throws Exception {
            ps.setString(35, "aa");
        }
    }));
    verify(ps).setString(35, "aa");
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty) Setter(org.simpleflatmapper.reflect.Setter) DbObject(org.simpleflatmapper.test.beans.DbObject) Test(org.junit.Test) ResultSetGetterFactoryTest(org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)

Example 4 with SetterProperty

use of org.simpleflatmapper.map.property.SetterProperty in project SimpleFlatMapper by arnaudroger.

the class Issue365Test method mapperConfig.

private MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig() {
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    provider.addColumnDefinition("benchmark", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new SetterProperty(SETTER)).add(new GetterProperty(GETTER)));
    return MapperConfig.<SampleFieldKey>fieldMapperConfig().columnDefinitions(provider);
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperColumnDefinitionProviderImpl(org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl) GetterProperty(org.simpleflatmapper.map.property.GetterProperty)

Aggregations

SetterProperty (org.simpleflatmapper.map.property.SetterProperty)4 Test (org.junit.Test)2 Setter (org.simpleflatmapper.reflect.Setter)2 ResultSetGetterFactoryTest (org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)1 FieldMapperColumnDefinitionProviderImpl (org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl)1 GetterProperty (org.simpleflatmapper.map.property.GetterProperty)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)1