Package org.hibernate.search.impl

Examples of org.hibernate.search.impl.ConfigContext


   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */

  private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );
    Iterator<Class<?>> iter = cfg.getClassMappings();
    DirectoryProviderFactory factory = new DirectoryProviderFactory();

    initProgrammaticAnalyzers( context, reflectionManager );
    initProgrammaticallyDefinedFilterDef( reflectionManager );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, DocumentBuilderIndexedEntity<?>> documentBuildersIndexedEntities = factoryState.getDocumentBuildersIndexedEntities();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    while ( iter.hasNext() ) {
      Class<?> mappedClass = iter.next();
      if ( mappedClass == null ) {
        continue;
      }
      @SuppressWarnings("unchecked")
      XClass mappedXClass = reflectionManager.toXClass( mappedClass );
      if ( mappedXClass == null ) {
        continue;
      }

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.warn( "Abstract classes can never insert index documents. Remove @Indexed." );
          continue;
        }

        DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders(
            mappedXClass, cfg, buildContext, reflectionManager
        );
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderIndexedEntity<?> documentBuilder =
            new DocumentBuilderIndexedEntity(
                mappedXClass,
                context,
                providers,
                reflectionManager
        );

        indexingHierarchy.addIndexedClass( mappedClass );
        documentBuildersIndexedEntities.put( mappedClass, documentBuilder );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, reflectionManager
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at tyher sqme level???
    }
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
    factory.startDirectoryProviders();
  }
View Full Code Here


  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, BuildContext buildContext, SearchMapping searchMapping) {
    ConfigContext context = new ConfigContext( cfg, searchMapping );

    initProgrammaticAnalyzers( context, cfg.getReflectionManager() );
    initProgrammaticallyDefinedFilterDef( cfg.getReflectionManager() );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinding> documentBuildersIndexedEntities = factoryState.getIndexBindings();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class<?>> classMappings = initializeClassMappings( cfg, cfg.getReflectionManager() );

    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();

    for ( Map.Entry<XClass, Class<?>> mapping : classMappings.entrySet() ) {

      XClass mappedXClass = mapping.getKey();
      Class<?> mappedClass = mapping.getValue();

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, cfg.getReflectionManager(), optimizationBlackListedTypes, cfg.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }

    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();

    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {

      Class<?> mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding mappedEntity = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );
      //interceptor might use non indexed state
      if ( mappedEntity.getEntityIndexingInterceptor() != null ) {
        optimizationBlackListedTypes.add( mappedXClass );
      }
      // Create all DocumentBuilderIndexedEntity
      //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      //XClass unfortunately is not (yet) genericized: TODO?
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              context,
              mappedEntity.getSimilarity(),
              cfg.getReflectionManager(),
              optimizationBlackListedTypes,
              cfg.getInstanceInitializer()
          );
      mappedEntity.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, mappedEntity );
    }

    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );

    initProgrammaticAnalyzers( context, cfg.getReflectionManager() );
    initProgrammaticallyDefinedFilterDef( cfg.getReflectionManager() );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinder> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class> classMappings = initializeClassMappings( cfg, cfg.getReflectionManager() );
   
    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
   
    for ( Map.Entry<XClass, Class> mapping : classMappings.entrySet() ) {

      XClass mappedXClass = mapping.getKey();
      Class mappedClass = mapping.getValue();
     
      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, cfg.getReflectionManager(), optimizationBlackListedTypes, cfg.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }
   
    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();
   
    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
     
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding mappedEntity = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );
      //interceptor might use non indexed state
        if ( mappedEntity.getEntityIndexingInterceptor() != null ) {
        optimizationBlackListedTypes.add( mappedXClass );
      }
      // Create all DocumentBuilderIndexedEntity
      //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      //XClass unfortunately is not (yet) genericized: TODO?
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              context,
              mappedEntity.getSimilarity(),
              cfg.getReflectionManager(),
              optimizationBlackListedTypes,
              cfg.getInstanceInitializer()
          );
      mappedEntity.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, mappedEntity );
    }
   
    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );

    initProgrammaticAnalyzers( context, reflectionManager );
    initProgrammaticallyDefinedFilterDef( reflectionManager );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinder<?>> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class> classMappings = initializeClassMappings( cfg, reflectionManager );
   
    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
   
    for ( Map.Entry<XClass, Class> mapping : classMappings.entrySet() ) {

      XClass mappedXClass = mapping.getKey();
      Class mappedClass = mapping.getValue();
     
      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, reflectionManager, optimizationBlackListedTypes, cfg.getClassHelper()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }
   
    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();
   
    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
     
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding mappedEntity = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext, reflectionManager );
   
      // Create all DocumentBuilderIndexedEntity
      //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      //XClass unfortunately is not (yet) genericized: TODO?
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              context,
              mappedEntity.getSimilarity(),
              reflectionManager,
              optimizationBlackListedTypes,
              cfg.getClassHelper()
          );
      mappedEntity.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, mappedEntity );
    }
   
    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */

  private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );
    Iterator<Class<?>> iter = cfg.getClassMappings();
    DirectoryProviderFactory factory = new DirectoryProviderFactory();

    initProgrammaticAnalyzers( context, reflectionManager );
    initProgrammaticallyDefinedFilterDef( reflectionManager );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, DocumentBuilderIndexedEntity<?>> documentBuildersIndexedEntities = factoryState.getDocumentBuildersIndexedEntities();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    while ( iter.hasNext() ) {
      Class<?> mappedClass = iter.next();
      if ( mappedClass == null ) {
        continue;
      }
      @SuppressWarnings("unchecked")
      XClass mappedXClass = reflectionManager.toXClass( mappedClass );
      if ( mappedXClass == null ) {
        continue;
      }

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.warn( "Abstract classes can never insert index documents. Remove @Indexed." );
          continue;
        }

        DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders(
            mappedXClass, cfg, buildContext, reflectionManager
        );
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderIndexedEntity<?> documentBuilder =
            new DocumentBuilderIndexedEntity(
                mappedXClass,
                context,
                providers,
                reflectionManager
            );

        indexingHierarchy.addIndexedClass( mappedClass );
        documentBuildersIndexedEntities.put( mappedClass, documentBuilder );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, reflectionManager
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
    factory.startDirectoryProviders();
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, BuildContext buildContext, SearchMapping searchMapping) {
    ConfigContext context = new ConfigContext( cfg, searchMapping );

    initProgrammaticAnalyzers( context, cfg.getReflectionManager() );
    initProgrammaticallyDefinedFilterDef( cfg.getReflectionManager() );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinding> documentBuildersIndexedEntities = factoryState.getIndexBindings();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class<?>> classMappings = initializeClassMappings( cfg, cfg.getReflectionManager() );

    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
    final org.hibernate.search.engine.metadata.impl.MetadataProvider metadataProvider =
        new AnnotationMetadataProvider( cfg.getReflectionManager(), context );

    for ( Map.Entry<XClass, Class<?>> mapping : classMappings.entrySet() ) {
      XClass mappedXClass = mapping.getKey();
      Class<?> mappedClass = mapping.getValue();

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else if ( metadataProvider.containsSearchMetadata( mappedClass ) ) {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?

        TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass );
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, typeMetadata, cfg.getReflectionManager(), optimizationBlackListedTypes, cfg.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }

    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();

    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding entityIndexBinding = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );

      // interceptor might use non indexed state
      if ( entityIndexBinding.getEntityIndexingInterceptor() != null ) {
        optimizationBlackListedTypes.add( mappedXClass );
      }

      // Create all DocumentBuilderIndexedEntity
      // FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      // XClass unfortunately is not (yet) genericized: TODO ?
      TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass );
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              typeMetadata,
              context,
              cfg.getReflectionManager(),
              optimizationBlackListedTypes,
              cfg.getInstanceInitializer()
          );
      entityIndexBinding.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, entityIndexBinding );
    }

    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration searchConfiguration, BuildContext buildContext, SearchMapping searchMapping) {
    ConfigContext configContext = new ConfigContext( searchConfiguration, buildContext, searchMapping );

    initProgrammaticAnalyzers( configContext, searchConfiguration.getReflectionManager() );
    initProgrammaticallyDefinedFilterDef( searchConfiguration.getReflectionManager() );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinding> documentBuildersIndexedEntities = factoryState.getIndexBindings();
    final Map<Class<?>, DocumentBuilderContainedEntity> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class<?>> classMappings = initializeClassMappings(
        searchConfiguration,
        searchConfiguration.getReflectionManager()
    );

    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
    final org.hibernate.search.engine.metadata.impl.MetadataProvider metadataProvider =
        new AnnotationMetadataProvider( searchConfiguration.getReflectionManager(), configContext );

    for ( Map.Entry<XClass, Class<?>> mapping : classMappings.entrySet() ) {
      XClass mappedXClass = mapping.getKey();
      Class<?> mappedClass = mapping.getValue();

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments( mappedXClass.getName() );
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else if ( metadataProvider.containsSearchMetadata( mappedClass ) ) {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?

        TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass );
        final DocumentBuilderContainedEntity documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass,
            typeMetadata,
            searchConfiguration.getReflectionManager(),
            optimizationBlackListedTypes,
            searchConfiguration.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }

    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();

    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding entityIndexBinding = indexesFactory.buildEntityIndexBinding(
          mappedXClass,
          mappedClass,
          searchConfiguration,
          buildContext
      );

      // interceptor might use non indexed state
      if ( entityIndexBinding.getEntityIndexingInterceptor() != null ) {
        optimizationBlackListedTypes.add( mappedXClass );
      }

      // Create all DocumentBuilderIndexedEntity
      // FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      // XClass unfortunately is not (yet) genericized: TODO ?
      TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass );
      final DocumentBuilderIndexedEntity documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              typeMetadata,
              configContext,
              searchConfiguration.getReflectionManager(),
              optimizationBlackListedTypes,
              searchConfiguration.getInstanceInitializer()
          );
      entityIndexBinding.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, entityIndexBinding );
    }

    disableBlackListedTypesOptimization(
        classMappings,
        optimizationBlackListedTypes,
        documentBuildersIndexedEntities,
        documentBuildersContainedEntities
    );
    factoryState.setAnalyzers( configContext.initLazyAnalyzers() );
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );

    initProgrammaticAnalyzers( context, reflectionManager );
    initProgrammaticallyDefinedFilterDef( reflectionManager );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinder> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class> classMappings = initializeClassMappings( cfg, reflectionManager );
   
    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
   
    for ( Map.Entry<XClass, Class> mapping : classMappings.entrySet() ) {

      XClass mappedXClass = mapping.getKey();
      Class mappedClass = mapping.getValue();
     
      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, reflectionManager, optimizationBlackListedTypes, cfg.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }
   
    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();
   
    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
     
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding mappedEntity = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );
   
      // Create all DocumentBuilderIndexedEntity
      //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      //XClass unfortunately is not (yet) genericized: TODO?
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              context,
              mappedEntity.getSimilarity(),
              reflectionManager,
              optimizationBlackListedTypes,
              cfg.getInstanceInitializer()
          );
      mappedEntity.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, mappedEntity );
    }
   
    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

  /*
   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */
  private void initDocumentBuilders(SearchConfiguration cfg, BuildContext buildContext, SearchMapping searchMapping) {
    ConfigContext context = new ConfigContext( cfg, searchMapping );

    initProgrammaticAnalyzers( context, cfg.getReflectionManager() );
    initProgrammaticallyDefinedFilterDef( cfg.getReflectionManager() );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, EntityIndexBinding> documentBuildersIndexedEntities = factoryState.getIndexBindings();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
    final Map<XClass, Class<?>> classMappings = initializeClassMappings( cfg, cfg.getReflectionManager() );

    //we process the @Indexed classes last, so we first start all IndexManager(s).
    final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
    final org.hibernate.search.engine.metadata.impl.MetadataProvider metadataProvider =
        new AnnotationMetadataProvider( cfg.getReflectionManager(), context );

    for ( Map.Entry<XClass, Class<?>> mapping : classMappings.entrySet() ) {

      XClass mappedXClass = mapping.getKey();
      Class<?> mappedClass = mapping.getValue();

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.abstractClassesCannotInsertDocuments();
          continue;
        }

        rootIndexedEntities.add( mappedXClass );
        indexingHierarchy.addIndexedClass( mappedClass );
      }
      else if ( metadataProvider.containsSearchMetadata( mappedClass ) ) {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?

        TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass);
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, typeMetadata, cfg.getReflectionManager(), optimizationBlackListedTypes, cfg.getInstanceInitializer()
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at their same level???
    }

    IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();

    // Create all IndexManagers, configure and start them:
    for ( XClass mappedXClass : rootIndexedEntities ) {
      Class mappedClass = classMappings.get( mappedXClass );
      MutableEntityIndexBinding entityIndexBinding = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );

      // interceptor might use non indexed state
      if ( entityIndexBinding.getEntityIndexingInterceptor() != null ) {
        optimizationBlackListedTypes.add( mappedXClass );
      }

      // Create all DocumentBuilderIndexedEntity
      // FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
      // XClass unfortunately is not (yet) genericized: TODO ?
      TypeMetadata typeMetadata = metadataProvider.getTypeMetadataFor( mappedClass);
      final DocumentBuilderIndexedEntity<?> documentBuilder =
          new DocumentBuilderIndexedEntity(
              mappedXClass,
              typeMetadata,
              context,
              cfg.getReflectionManager(),
              optimizationBlackListedTypes,
              cfg.getInstanceInitializer()
          );
      entityIndexBinding.setDocumentBuilderIndexedEntity( documentBuilder );

      documentBuildersIndexedEntities.put( mappedClass, entityIndexBinding );
    }

    disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
  }
View Full Code Here

   * Initialize the document builder
   * This algorithm seems to be safe for incremental search factories.
   */

  private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
    ConfigContext context = new ConfigContext( cfg );
    Iterator<Class<?>> iter = cfg.getClassMappings();
    DirectoryProviderFactory factory = new DirectoryProviderFactory();

    initProgrammaticAnalyzers( context, reflectionManager );
    initProgrammaticallyDefinedFilterDef( reflectionManager );
    final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
    final Map<Class<?>, DocumentBuilderIndexedEntity<?>> documentBuildersIndexedEntities = factoryState.getDocumentBuildersIndexedEntities();
    final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
    while ( iter.hasNext() ) {
      Class<?> mappedClass = iter.next();
      if ( mappedClass == null ) {
        continue;
      }
      @SuppressWarnings("unchecked")
      XClass mappedXClass = reflectionManager.toXClass( mappedClass );
      if ( mappedXClass == null ) {
        continue;
      }

      if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {

        if ( mappedXClass.isAbstract() ) {
          log.warn( "Abstract classes can never insert index documents. Remove @Indexed." );
          continue;
        }

        DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders(
            mappedXClass, cfg, buildContext, reflectionManager
        );
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderIndexedEntity<?> documentBuilder = new DocumentBuilderIndexedEntity(
            mappedXClass, context, providers.getProviders(), providers.getSelectionStrategy(),
            reflectionManager
        );

        indexingHierarchy.addIndexedClass( mappedClass );
        documentBuildersIndexedEntities.put( mappedClass, documentBuilder );
      }
      else {
        //FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
        //XClass unfortunately is not (yet) genericized: TODO?
        final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
            mappedXClass, context, reflectionManager
        );
        //TODO enhance that, I don't like to expose EntityState
        if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
          documentBuildersContainedEntities.put( mappedClass, documentBuilder );
        }
      }
      bindFilterDefs( mappedXClass );
      //TODO should analyzer def for classes at tyher sqme level???
    }
    factoryState.setAnalyzers( context.initLazyAnalyzers() );
    factory.startDirectoryProviders();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.impl.ConfigContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.