lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Kildén <karl.kil...@gmail.com>
Subject PostBind method for DocumentObjectBinder?
Date Fri, 06 Mar 2015 21:48:14 GMT
Hello,

DocumentObjectBinder would benefit from a post bind call imo. Something
like:

  public <T> List<T> getBeans(Class<T> clazz, SolrDocumentList solrDocList,
boolean postBind) {
    List<DocField> fields = getDocFields(clazz);
    List<T> result = new ArrayList<>(solrDocList.size());

    for (SolrDocument sdoc : solrDocList) {
      T bean = getBean(clazz, fields, sdoc);
      if (postBind) {
          runAnnotatedMethod(bean, PostBind.class);
      }
result.add(bean);
    }
    return result;
  }
private void runAnnotatedMethod(final Object instance, Class<? extends
Annotation> annotation) {
for (Method m : instance.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(annotation)) {
m.setAccessible(true);
try {
m.invoke(instance, new Object[] {});
} catch (Exception e) {
throw new BindingException("Could not run postbind " + instance.getClass(),
e);
}
}
}
}


Can probably take some thinking on how to do the API pretty staying
backwards compatible and the found annotated method should be cached.

WDYT?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message