use of org.jdbi.v3.jpa.internal.JpaMember in project jdbi by jdbi.
the class JpaMapper method specialize.
@Override
public RowMapper<C> specialize(ResultSet rs, StatementContext ctx) throws SQLException {
Constructor<C> constructor;
try {
constructor = clazz.getDeclaredConstructor();
} catch (ReflectiveOperationException e) {
throw new EntityMemberAccessException("Unable to get constructor for " + clazz, e);
}
constructor.setAccessible(true);
List<MemberSetter<C>> setters = new ArrayList<>();
for (int colIndex = rs.getMetaData().getColumnCount(); colIndex >= 1; colIndex--) {
String columnLabel = rs.getMetaData().getColumnLabel(colIndex);
JpaMember member = jpaClass.lookupMember(columnLabel);
if (member != null) {
Type memberType = member.getType();
ColumnMapper<?> columnMapper = ctx.findColumnMapperFor(memberType).orElseThrow(() -> new NoSuchMapperException("No column mapper for " + memberType));
final int columnIndex = colIndex;
setters.add(obj -> member.write(obj, columnMapper.map(rs, columnIndex, ctx)));
}
}
return (r, c) -> {
C obj;
try {
obj = constructor.newInstance();
} catch (ReflectiveOperationException e) {
throw new EntityMemberAccessException("Unable to invoke " + constructor, e);
}
for (MemberSetter<C> setter : setters) {
setter.mapAndSetMember(obj);
}
return obj;
};
}
use of org.jdbi.v3.jpa.internal.JpaMember in project jdbi by jdbi.
the class BindJpaFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
BindJpa bind = (BindJpa) annotation;
final String prefix;
if (bind.value().isEmpty()) {
prefix = "";
} else {
prefix = bind.value() + ".";
}
return (stmt, arg) -> {
JpaClass<?> jpaClass = JpaClass.get(arg.getClass());
for (JpaMember member : jpaClass.members()) {
stmt.bindByType(prefix + member.getColumnName(), readMember(arg, member), member.getType());
}
};
}
Aggregations