Java 类org.hibernate.search.annotations.Indexed 实例源码

项目:debop4j    文件:SearchTool.java   
/**
 * 인덱싱된 엔티티의 수형을 반환합니다.
 *
 * @param sessionFactory the session factory
 * @return 인덱싱된 엔티티의 수형들
 */
public static Set<Class> getIndexedClasses(SessionFactory sessionFactory) {
    if (log.isDebugEnabled())
        log.debug("매핑된 엔티티중에 인덱싱을 수행할 엔티티들을 조회합니다.");

    final Set<Class> classes = Sets.newHashSet();
    Collection<ClassMetadata> metadatas = sessionFactory.getAllClassMetadata().values();

    for (ClassMetadata meta : metadatas) {
        Class clazz = meta.getMappedClass();
        if (clazz.getAnnotation(Indexed.class) != null) {
            classes.add(clazz);

                log.trace("인덱싱된 엔티티=[{}]", clazz);
        }
    }
    return classes;
}
项目:UMLS-Terminology-Server    文件:LuceneReindexAlgorithm.java   
/**
 * Clear lucene indexes.
 *
 * @throws Exception the exception
 */
private void clearLuceneIndexes() throws Exception {

  final Reflections reflections = new Reflections();
  for (final Class<?> clazz : reflections
      .getTypesAnnotatedWith(Indexed.class)) {
    fullTextEntityManager.purgeAll(clazz);
  }
}
项目:Hibernate-Search-GenericJPA    文件:MetaModelParser.java   
public void parse(Metamodel metaModel) {
    // clear the (old) state
    this.isRootType.clear();
    this.managedTypes.clear();
    this.idProperties.clear();
    this.managedTypes.clear();
    this.managedTypes.putAll(
            metaModel.getManagedTypes().stream().filter(
                    (meta3) -> {
                        return meta3 instanceof EntityType;
                    }
            ).collect(
                    Collectors.toMap(
                            (meta) -> {
                                return meta.getJavaType();
                            }, (meta2) -> {
                                return meta2;
                            }
                    )
            )
    );
    Set<EntityType<?>> emptyVisited = Collections.emptySet();
    this.totalVisitedEntities.clear();
    for ( EntityType<?> curEntType : metaModel.getEntities() ) {
        // we only consider Entities that are @Indexed here
        if ( curEntType.getJavaType().isAnnotationPresent( Indexed.class ) ) {
            this.idProperties.put( curEntType.getJavaType(), this.getIdProperty( metaModel, curEntType ) );
            this.isRootType.put( curEntType.getJavaType(), true );
            Map<Class<? extends Annotation>, Set<Attribute<?, ?>>> attributeForAnnotationType = buildAttributeForAnnotationType(
                    curEntType
            );
            // and do the recursion
            this.doRecursion( attributeForAnnotationType, curEntType, emptyVisited );
        }
    }
}
项目:UMLS-Terminology-Server    文件:LuceneReindexAlgorithm.java   
/**
 * Compute lucene indexes.
 *
 * @param indexedObjects the indexed objects
 * @throws Exception the exception
 */
private void computeLuceneIndexes(String indexedObjects) throws Exception {
  // set of objects to be re-indexed
  final Set<String> objectsToReindex = new HashSet<>();
  final Map<String, Class<?>> reindexMap = new HashMap<>();
  final Reflections reflections = new Reflections();
  for (final Class<?> clazz : reflections
      .getTypesAnnotatedWith(Indexed.class)) {
    reindexMap.put(clazz.getSimpleName(), clazz);
  }

  // if no parameter specified, re-index all objects
  if (indexedObjects == null || indexedObjects.isEmpty()) {

    // Add all class names
    for (final String className : reindexMap.keySet()) {
      if (objectsToReindex.contains(className)) {
        // This restriction can be removed by using full class names
        // however, then calling the mojo is more complicated
        throw new Exception(
            "Reindex process assumes simple class names are different.");
      }
      objectsToReindex.add(className);
    }

    // otherwise, construct set of indexed objects
  } else {

    // remove white-space and split by comma
    String[] objects = indexedObjects.replaceAll(" ", "").split(",");

    // add each value to the set
    for (final String object : objects)
      objectsToReindex.add(object);

  }

  Logger.getLogger(getClass()).info("Starting reindexing for:");
  for (final String objectToReindex : objectsToReindex) {
    Logger.getLogger(getClass()).info("  " + objectToReindex);
  }

  // Reindex each object
  for (final String key : reindexMap.keySet()) {
    // Concepts
    if (objectsToReindex.contains(key)) {
      Logger.getLogger(getClass()).info("  Creating indexes for " + key);
      fullTextEntityManager.purgeAll(reindexMap.get(key));
      fullTextEntityManager.flushToIndexes();
      fullTextEntityManager.createIndexer(reindexMap.get(key))
          .batchSizeToLoadObjects(100).cacheMode(CacheMode.IGNORE)
          .idFetchSize(100).threadsToLoadObjects(10).startAndWait();
      // optimize flags are default true.
      objectsToReindex.remove(key);
    }
  }

  if (objectsToReindex.size() != 0) {
    throw new Exception(
        "The following objects were specified for re-indexing, but do not exist as indexed objects: "
            + objectsToReindex.toString());
  }

  // Cleanup
  Logger.getLogger(getClass()).info("done ...");
}