org.hibernate.search.annotations.IndexedEmbedded Java Examples

The following examples show how to use org.hibernate.search.annotations.IndexedEmbedded. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateSearchDependentObjectsReindexer.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
void register(final Class< ? extends BaseDO< ? >> clazz)
{
  final Field[] fields = clazz.getDeclaredFields();
  for (final Field field : fields) {
    if (field.isAnnotationPresent(IndexedEmbedded.class) == true ||
        field.isAnnotationPresent(ContainedIn.class) == true) {
      Class< ? > embeddedClass = field.getType();
      boolean setOrCollection = false;
      if (Set.class.isAssignableFrom(embeddedClass) == true || Collection.class.isAssignableFrom(embeddedClass) == true) {
        // Please use @ContainedIn.
        final Type type = field.getGenericType();
        if (type instanceof ParameterizedType) {
          final Type actualTypeArgument = ((ParameterizedType) type).getActualTypeArguments()[0];
          if (actualTypeArgument instanceof Class) {
            embeddedClass = (Class< ? >) actualTypeArgument;
            setOrCollection = true;
          }
        }
      }
      if (BaseDO.class.isAssignableFrom(embeddedClass) == false) {
        // Only BaseDO objects are supported.
        continue;
      }
      final String name = field.getName();
      final Entry entry = new Entry(clazz, name, setOrCollection);
      List<Entry> list = map.get(embeddedClass);
      if (list == null) {
        list = new ArrayList<Entry>();
        @SuppressWarnings("unchecked")
        final Class< ? extends BaseDO< ? >> embeddedBaseDOClass = (Class< ? extends BaseDO< ? >>) embeddedClass;
        map.put(embeddedBaseDOClass, list);
      } else {
        for (final Entry e : list) {
          if (entry.equals(e) == true) {
            log.warn("Entry already registerd: " + entry);
          }
        }
      }
      list.add(entry);
    }
  }
}