use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testColumnAliasStatic.
@Test
public void testColumnAliasStatic() throws Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm();
mapperFactory.addAlias("not_id_column", "id");
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,", "id as not_id_column,"));
}
use of org.simpleflatmapper.test.beans.DbObject 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.test.beans.DbObject 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.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomReaderOnSetterStatic.
@SuppressWarnings("unchecked")
@Test
public void testCustomReaderOnSetterStatic() throws Exception {
final JdbcMapper<DbObject> mapper = JdbcMapperFactoryHelper.asm().newBuilder(DbObject.class).addMapping("id", new GetterProperty(new Getter<ResultSet, Long>() {
@Override
public Long get(ResultSet target) throws Exception {
return 1l;
}
})).addMapping(// email, creation_time, type_ordinal, type_name
"name").addMapping("email").addMapping("creation_time").addMapping("type_ordinal").addMapping("type_name").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,"));
}
use of org.simpleflatmapper.test.beans.DbObject 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