public <T, P> Getter<T, P> getFieldGetter(Field field) { requireNonNull("field", field); boolean accessible = Modifier.isPublic(field.getModifiers()) && Modifier.isPublic(field.getDeclaringClass().getModifiers()); if (asmFactory != null && accessible) { try { return asmFactory.createGetter(field); } catch(Throwable e) {} } if (!accessible) { try { field.setAccessible(true); } catch (Exception e) { // cannot make field accessible return null; } } return new FieldGetter<T, P>(field); }
private SourceMapper<ResultSet, DbObject> getSubMapper(JdbcMapper<DbObject> mapper) throws Exception { Field setRowMapperField = mapper.getClass().getDeclaredField("setRowMapper"); setRowMapperField.setAccessible(true); Object setRowMapper = setRowMapperField.get(mapper); Field mapperField; try { mapperField = setRowMapper.getClass().getDeclaredField("mapper"); } catch(NoSuchFieldException e) { mapperField = setRowMapper.getClass().getSuperclass().getDeclaredField("mapper"); } mapperField.setAccessible(true); SourceMapper<ResultSet, DbObject> mapper1 = new FieldGetter<Object, MapperImpl<ResultSet, DbObject>>(mapperField) .get(setRowMapper); if (mapper1 instanceof ContextualSourceFieldMapperImpl) { return ((ContextualSourceFieldMapperImpl)mapper1).getDelegate(); } return mapper1; }
public <T, P> Getter<T, P> getFieldGetter(Field field) { requireNonNull("field", field); boolean accessible = Modifier.isPublic(field.getModifiers()) && Modifier.isPublic(field.getDeclaringClass().getModifiers()); if (asmFactory != null && accessible) { try { return asmFactory.createGetter(field); } catch(Throwable e) {} } if (!accessible) { try { field.setAccessible(true); } catch (Exception e) { // cannot make field accessible return null; } } return new FieldGetter<T, P>(field); }