SimpleFlatMapper
SimpleFlatMapper copied to clipboard
Sfm-jdbc - Read columns from ResultSet by column's name instead of column's index
Hi, thanks for great library and also thanks for your fast and great support.
This is question or request about new feature.
I'd like use custom GetterFactory, which will read column from ResultSet by column's name instead of read by column's index. Because creating huge mapper(most column, most association with discriminator) is expensive therefore I use cache of mappers. I'd like to create mapper, which knows to map subset of column and it doesn't matter to order columns in ResultSet. Now I don't know how can i do it, because JdbcMapperBuilder use JdbcKeySourceGetter, which read column by column's index. Does some solution exist?
So I believe there is a way, let me confirm how,
So, could I ask you, how?
sorry been crazy last couple of weeks. will check today
It's okay :) Thanks
so looking into it it won;t be that straight forward.
You can provide a GetterFactoryProperty
.addColumnProperty(ConstantPredicate.truePredicate(), new GetterFactoryProperty(new GetterFactory<ResultSet, JdbcColumnKey>() {
@Override
public <P> Getter<ResultSet, P> newGetter(Type targetType, JdbcColumnKey key, Object... properties) {
return new Getter<ResultSet, P>() {
@Override
public P get(ResultSet target) throws Exception {
return target.getObject(key.getOrginalName(), TypeHelper.toClass(targetType));
}
};
}
}), ResultSet.class)
but then you can't leverage all the convertion logic in the ResultSetGetterFactory
if there getter from ResultSetGetterFactory where to provide a indexed access then you could first resolve the column index and then delegate to the IndexedGetter. but does not look possible right now.
Thanks. This is exactly my problem. I have many associations with many keys.
I have one question. Are you planning to make support for getter by column's name?
It's possible will see if I can do that. It should not be too bad