@Test public void testColumnAlias() throws Exception { JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm(); mapperFactory.addAlias("not_id_column", "id"); 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,", "id as not_id_column,")); }
@Test public void testRename() throws Exception { PreparedStatementMapperBuilder<DMClass> mapperBuilder = JdbcMapperFactory.newInstance() .addAlias("val", "value") .buildFrom(DMClass.class); mapperBuilder.addColumn("val"); FieldMapper<DMClass, PreparedStatement> mapper = mapperBuilder.mapper(); DMClass dmClass = new DMClass(); PreparedStatement ps = mock(PreparedStatement.class); mapper.mapTo(dmClass, ps, null); verify(ps).setString(1, "value"); }
@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,")); }
@Test public void test544() { final String VALUES_VAL = "values_val"; final String VALUES = "values"; JdbcColumnKey valuesKeys = new JdbcColumnKey(VALUES, 1, Types.VARCHAR); JdbcMapperFactory .newInstance() .addAlias(VALUES, VALUES_VAL) .newBuilder(C544.class) .addMapping(valuesKeys) .mapper(); }