Search in sources :

Example 1 with ConstantSourceMapperBuilder

use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceMapperBuilderTest method testMapInnerObjectWithMapper.

@Test
public void testMapInnerObjectWithMapper() throws Exception {
    ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
    constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
    MyObjectWithInner o = mapper.map(null);
    assertEquals(DATE, o.prop.date);
    assertNull(o.prop.str);
}
Also used : IdentityFieldMapperColumnDefinitionProvider(org.simpleflatmapper.map.impl.IdentityFieldMapperColumnDefinitionProvider) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder) Test(org.junit.Test)

Example 2 with ConstantSourceMapperBuilder

use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceMapperBuilderTest method testFieldMapperErrorHandler.

@Test
public void testFieldMapperErrorHandler() throws Exception {
    ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()).fieldMapperErrorHandler(new FieldMapperErrorHandler<SampleFieldKey>() {

        @Override
        public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error) throws MappingException {
        }
    }), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
    constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 16), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
    MyObjectWithInner o = mapper.map(null);
    System.out.println("mapper = " + mapper);
    assertNull(o.prop);
}
Also used : SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperErrorHandler(org.simpleflatmapper.map.FieldMapperErrorHandler) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder) MappingException(org.simpleflatmapper.map.MappingException) Test(org.junit.Test)

Example 3 with ConstantSourceMapperBuilder

use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder 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 ConstantSourceMapperBuilder

use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceMapperBuilderTest method testAnonymousParameterWithDifferentType.

@Test
public void testAnonymousParameterWithDifferentType() throws Exception {
    ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
    constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop", 0, Date.class), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
    MyObjectWithInner o = mapper.map(null);
    assertEquals(DATE, o.prop.date);
    assertNull(o.prop.str);
}
Also used : IdentityFieldMapperColumnDefinitionProvider(org.simpleflatmapper.map.impl.IdentityFieldMapperColumnDefinitionProvider) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ConstantSourceMapperBuilder (org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder)4 Test (org.junit.Test)3 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)3 IdentityFieldMapperColumnDefinitionProvider (org.simpleflatmapper.map.impl.IdentityFieldMapperColumnDefinitionProvider)2 GettableByIndexData (com.datastax.driver.core.GettableByIndexData)1 Date (java.util.Date)1 DatastaxColumnKey (org.simpleflatmapper.datastax.DatastaxColumnKey)1 DatastaxMappingContextFactoryBuilder (org.simpleflatmapper.datastax.impl.DatastaxMappingContextFactoryBuilder)1 RowGetterFactory (org.simpleflatmapper.datastax.impl.RowGetterFactory)1 FieldMapperErrorHandler (org.simpleflatmapper.map.FieldMapperErrorHandler)1 MappingException (org.simpleflatmapper.map.MappingException)1 MapperSourceImpl (org.simpleflatmapper.map.mapper.MapperSourceImpl)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1