use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomMapping.
@Test
public void testCustomMapping() throws SQLException, Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm();
mapperFactory.addCustomFieldMapper("id", new FieldMapper<ResultSet, DbObject>() {
@Override
public void mapTo(ResultSet source, DbObject target, MappingContext<? super ResultSet> mappingContext) throws MappingException {
target.setId(1);
}
});
final JdbcMapper<DbObject> mapper = mapperFactory.newMapper(DbObject.class);
DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {
@Override
public void handle(PreparedStatement t) throws Exception {
ResultSet r = t.executeQuery();
r.next();
DbHelper.assertDbObjectMapping(mapper.map(r));
}
}, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "33 as id,"));
}
use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomReaderOnConstructor.
@Test
public void testCustomReaderOnConstructor() throws SQLException, Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm().addCustomGetter("id", new Getter<ResultSet, Long>() {
@Override
public Long get(ResultSet target) throws Exception {
return 1l;
}
});
final JdbcMapper<DbFinalObject> mapper = mapperFactory.newMapper(DbFinalObject.class);
DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {
@Override
public void handle(PreparedStatement t) throws Exception {
ResultSet r = t.executeQuery();
r.next();
DbHelper.assertDbObjectMapping(mapper.map(r));
}
}, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "33 as id,"));
}
use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomReaderOnSetter.
@Test
public void testCustomReaderOnSetter() throws SQLException, Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm().addCustomGetter("id", new Getter<ResultSet, Long>() {
@Override
public Long get(ResultSet target) throws Exception {
return 1l;
}
});
final JdbcMapper<DbObject> mapper = mapperFactory.newMapper(DbObject.class);
DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {
@Override
public void handle(PreparedStatement t) throws Exception {
ResultSet r = t.executeQuery();
r.next();
DbHelper.assertDbObjectMapping(mapper.map(r));
}
}, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "33 as id,"));
}
use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomMappingStatic.
@Test
public void testCustomMappingStatic() throws SQLException, Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm();
mapperFactory.addCustomFieldMapper("id", new FieldMapper<ResultSet, DbObject>() {
@Override
public void mapTo(ResultSet source, DbObject target, MappingContext<? super ResultSet> mappingContext) throws MappingException {
target.setId(1);
}
});
final JdbcMapper<DbObject> mapper = JdbcMapperDbObjectTest.addColumn(mapperFactory.newBuilder(DbObject.class)).mapper();
DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {
@Override
public void handle(PreparedStatement t) throws Exception {
ResultSet r = t.executeQuery();
r.next();
DbHelper.assertDbObjectMapping(mapper.map(r));
}
}, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "33 as id,"));
}
Aggregations