Package org.hibernate.search.engine.spi

Examples of org.hibernate.search.engine.spi.EntityIndexBinder


    this.transactionContext = new InstanceTransactionContext();
    transactionContext.beginTransaction();
  }

  public <T> T get(Class<T> entityType, Serializable id) {
    final EntityIndexBinder entityIndexBinding = searchFactory.getIndexBindingForEntity( entityType );
    if ( entityIndexBinding == null ) {
      String msg = "Entity to retrueve is not an @Indexed entity: " + entityType.getClass().getName();
      throw new IllegalArgumentException( msg );
    }
    if (id == null) {
      throw new IllegalArgumentException( "Identifier cannot be null" );
    }
    DocumentBuilderIndexedEntity<?> docBuilder = entityIndexBinding.getDocumentBuilder();
    Query luceneQuery = new TermQuery( docBuilder.getTerm( id ) );
    FullTextQuery searchQuery = createFullTextQuery( luceneQuery, entityType );
    List<?> results = searchQuery.list();
    if (results.size() > 1) {
      //TODO find correct exception
View Full Code Here


    }

    Class<?> clazz = getClass( entity );
    //TODO cache that at the FTSession level
    //not strictly necessary but a small optimization
    final EntityIndexBinder entityIndexBinding = searchFactory.getIndexBindingForEntity( clazz );
    if ( entityIndexBinding == null ) {
      String msg = "Entity to index is not an @Indexed entity: " + entity.getClass().getName();
      throw new IllegalArgumentException( msg );
    }
    Serializable id = entityIndexBinding.getDocumentBuilder().getId( entity );
    Work<T> work = new Work<T>( entity, id, WorkType.INDEX );
    searchFactory.getWorker().performWork( work, transactionContext );

    //TODO
    //need to add elements in a queue kept at the Session level
View Full Code Here

  }

  static DocumentBuilderIndexedEntity<?> getDocumentBuilder(QueryBuildingContext queryContext) {
    final SearchFactoryImplementor factory = queryContext.getFactory();
    final Class<?> type = queryContext.getEntityType();
    EntityIndexBinder indexBinding = factory.getIndexBindingForEntity( type );
    if ( indexBinding == null ) {
      throw new AssertionFailure( "Class in not indexed: " + type );
    }
    return indexBinding.getDocumentBuilder();
  }
View Full Code Here

    }
    else {
      Set<Class<?>> involvedClasses = new HashSet<Class<?>>( indexedTargetedEntities.size() );
      involvedClasses.addAll( indexedTargetedEntities );
      for ( Class<?> clazz : indexedTargetedEntities ) {
        EntityIndexBinder indexBinder = builders.get( clazz );
        if ( indexBinder != null ) {
          DocumentBuilderIndexedEntity<?> builder = indexBinder.getDocumentBuilder();
          involvedClasses.addAll( builder.getMappedSubclasses() );
        }
      }

      for ( Class clazz : involvedClasses ) {
        EntityIndexBinder indexBinder = builders.get( clazz );
        //TODO should we rather choose a polymorphic path and allow non mapped entities
        if ( indexBinder == null ) {
          throw new SearchException( "Not a mapped entity (don't forget to add @Indexed): " + clazz );
        }
        DocumentBuilderIndexedEntity<?> builder = indexBinder.getDocumentBuilder();
        if ( builder.getIdKeywordName() != null ) {
          idFieldNames.add( builder.getIdKeywordName() );
          allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
        }
        searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
        useFieldCacheOnClassTypes = useFieldCacheOnClassTypes || builder.getFieldCacheOption()
            .contains( FieldCacheType.CLASS );
        populateIndexManagers( targetedIndexes, indexBinder.getSelectionStrategy() );
      }
      this.classesAndSubclasses = involvedClasses;
    }
    this.idFieldNames = idFieldNames;
View Full Code Here

    Map<Class<?>, EntityIndexBinder> builders = searchFactoryImplementor.getIndexBindingForEntity();
    Set<FieldCacheCollectorFactory> allCollectors = new HashSet<FieldCacheCollectorFactory>();
    // we need all documentBuilder to agree on type, fieldName, and enabling the option:
    FieldCacheCollectorFactory anyImplementation = null;
    for ( Class<?> clazz : classesAndSubclasses ) {
      EntityIndexBinder docBuilder = builders.get( clazz );
      FieldCacheCollectorFactory fieldCacheCollectionFactory = docBuilder.getIdFieldCacheCollectionFactory();
      if ( fieldCacheCollectionFactory == null ) {
        // some implementation disable it, so we won't use it
        return null;
      }
      anyImplementation = fieldCacheCollectionFactory;
View Full Code Here

  @SuppressWarnings("unchecked")
  private void index( Object entity, Session session, InstanceInitializer sessionInitializer ) throws InterruptedException {
    Serializable id = session.getIdentifier( entity );
    Class<?> clazz = HibernateHelper.getClass( entity );
    EntityIndexBinder entityIndexBinding = entityIndexBinders.get( clazz );
    if ( entityIndexBinding == null ) {
      // it might be possible to receive not-indexes subclasses of the currently indexed type;
      // being not-indexed, we skip them.
      // FIXME for improved performance: avoid loading them in an early phase.
      return;
    }
    DocumentBuilderIndexedEntity docBuilder = entityIndexBinding.getDocumentBuilder();
    TwoWayFieldBridge idBridge = docBuilder.getIdBridge();
    ContextualException2WayBridge contextualBridge = new ContextualException2WayBridge()
        .setClass(clazz)
        .setFieldName(docBuilder.getIdKeywordName())
        .setFieldBridge(idBridge);
View Full Code Here

      im.optimize();
    }
  }

  public void optimize(Class entityType) {
    EntityIndexBinder entityIndexBinding = getSafeIndexBindingForEntity( entityType );
    for ( IndexManager im: entityIndexBinding.getIndexManagers() ) {
      im.optimize();
    }
  }
View Full Code Here

    }
    return analyzer;
  }

  public Analyzer getAnalyzer(Class<?> clazz) {
    EntityIndexBinder entityIndexBinding = getSafeIndexBindingForEntity( clazz );
    DocumentBuilderIndexedEntity<?> builder = entityIndexBinding.getDocumentBuilder();
    return builder.getAnalyzer();
  }
View Full Code Here

  @Override
  public IndexReader openIndexReader(Class<?>... entities) {
    HashMap<String,IndexManager> indexManagers = new HashMap<String,IndexManager>();
    for ( Class<?> type : entities ) {
      EntityIndexBinder entityIndexBinding = getSafeIndexBindingForEntity( type );
      IndexManager[] indexManagersForAllShards = entityIndexBinding.getSelectionStrategy().getIndexManagersForAllShards();
      for (IndexManager im : indexManagersForAllShards) {
        indexManagers.put( im.getIndexName(), im );
      }
    }
    IndexManager[] uniqueIndexManagers = indexManagers.values().toArray( new IndexManager[indexManagers.size()]);
View Full Code Here

  private EntityIndexBinder getSafeIndexBindingForEntity(Class entityType) {
    if ( entityType == null ) {
      throw new IllegalArgumentException( "Null is not a valid indexed entity type" );
    }
    EntityIndexBinder entityIndexBinding = getIndexBindingForEntity( entityType );
    if ( entityIndexBinding == null ) {
      throw new IllegalArgumentException( "Entity is not an indexed type: " + entityType );
    }
    return entityIndexBinding;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.engine.spi.EntityIndexBinder

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.