/** * Returns a mapper for the given bean class * * @param <T> the type to map * @param type the mapped class * @return a mapper for the given bean class */ public static <T> RowMapper<T> of(Class<T> type) { return FieldMapper.of(type, DEFAULT_PREFIX); }
/** * Returns a mapper factory that maps to the given bean class * * @param type the mapped class * @return a mapper factory that maps to the given bean class */ public static RowMapperFactory factory(Class<?> type) { return RowMapperFactory.of(type, FieldMapper.of(type)); }
/** * Returns a mapper factory that maps to the given bean class * * @param type the mapped class * @param prefix the column name prefix for each mapped field * @return a mapper factory that maps to the given bean class */ public static RowMapperFactory factory(Class<?> type, String prefix) { return RowMapperFactory.of(type, FieldMapper.of(type, prefix)); }
@Test public void shouldSetValuesInSuperClassFields() throws Exception { mockColumns("longField", "blongField"); Long aLongVal = 100L; Long bLongVal = 200L; when(resultSet.getLong(1)).thenReturn(aLongVal); when(resultSet.getLong(2)).thenReturn(bLongVal); when(resultSet.wasNull()).thenReturn(false); RowMapper<DerivedBean> mapper = FieldMapper.of(DerivedBean.class); DerivedBean derivedBean = mapper.map(resultSet, ctx); assertThat(derivedBean.getLongField()).isEqualTo(aLongVal); assertThat(derivedBean.getBlongField()).isEqualTo(bLongVal); }
@Test public void testColumnNameAnnotation() { Handle handle = dbRule.getSharedHandle(); handle.execute("insert into something (id, name) values (1, 'foo')"); ColumnNameThing thing = handle.createQuery("select * from something") .map(FieldMapper.of(ColumnNameThing.class)) .findOnly(); assertThat(thing.i).isEqualTo(1); assertThat(thing.s).isEqualTo("foo"); }
/** * Returns a mapper for the given bean class * * @param <T> the type to map * @param type the mapped class * @return a mapper for the given bean class */ public static <T> RowMapper<T> of(Class<T> type) { return FieldMapper.of(type, DEFAULT_PREFIX); }
/** * Returns a mapper factory that maps to the given bean class * * @param type the mapped class * @return a mapper factory that maps to the given bean class */ public static RowMapperFactory factory(Class<?> type) { return RowMapperFactory.of(type, FieldMapper.of(type)); }
/** * Returns a mapper factory that maps to the given bean class * * @param type the mapped class * @param prefix the column name prefix for each mapped field * @return a mapper factory that maps to the given bean class */ public static RowMapperFactory factory(Class<?> type, String prefix) { return RowMapperFactory.of(type, FieldMapper.of(type, prefix)); }