Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.infinispan.query.remote.search;
 
 import  com.google.protobuf.Descriptors;
 import  org.apache.lucene.search.Query;
 import  org.hibernate.hql.ast.spi.AstProcessingChain;
 import  org.hibernate.hql.ast.spi.AstProcessor;
 import  org.hibernate.hql.ast.spi.EntityNamesResolver;
 import  org.hibernate.hql.ast.spi.QueryRendererProcessor;
 import  org.hibernate.hql.ast.spi.QueryResolverProcessor;
import  org.hibernate.hql.ast.spi.SingleEntityQueryBuilder;
import  org.hibernate.hql.lucene.LuceneQueryParsingResult;
import  org.hibernate.hql.lucene.internal.LuceneQueryRendererDelegate;
import  org.hibernate.hql.lucene.internal.builder.LucenePropertyHelper;
import  org.hibernate.search.spi.SearchFactoryIntegrator;
import  org.infinispan.protostream.SerializationContext;
AST processing chain for creating Lucene queries from HQL queries.

Author(s):
Gunnar Morling
anistor@redhat.com
public class IspnLuceneProcessingChain implements AstProcessingChain<IspnLuceneQueryParsingResult> {
   private static final Integer TRUE_INT = 1;
   private static final Integer FALSE_INT = 0;
   private final QueryResolverProcessor resolverProcessor;
   private final QueryRendererProcessor rendererProcessor;
   private final LuceneQueryRendererDelegate rendererDelegate;
   public IspnLuceneProcessingChain(SerializationContext serializationContext, SearchFactoryIntegrator searchFactory, EntityNamesResolver entityNamesMap<StringObjectnamedParameters) {
       = new IspnLuceneQueryResolverDelegate(serializationContext);
       = new QueryResolverProcessor();
      LucenePropertyHelper propertyHelper = new LucenePropertyHelper(searchFactory) {
         @Override
         public Object convertToPropertyType(String valueClass<?> entityTypeString... propertyPath) {
            Descriptors.FieldDescriptor field = .getTargetType().findFieldByName(propertyPath[propertyPath.length - 1]);
            if (field != null) {
               switch (field.getJavaType()) {
                  case INT:
                     return Integer.parseInt(value);
                  case LONG:
                     return Long.parseLong(value);
                  case FLOAT:
                     return Float.parseFloat(value);
                  case DOUBLE:
                     return Double.parseDouble(value);
                  case BOOLEAN:
                     return Boolean.valueOf(value) ?  : ;
                  case ENUM:
                     return field.getEnumType().findValueByName(value).getNumber();
               }
            }
            return value;
         }
      };
      SingleEntityQueryBuilder<Query> queryBuilder = SingleEntityQueryBuilder.getInstance(new IspnLucenePredicateFactory(searchFactory.buildQueryBuilder(), propertyHelper), propertyHelper);
       = new LuceneQueryRendererDelegate(entityNamesqueryBuildernamedParameters);
       = new QueryRendererProcessor();
   }
   @Override
   public Iterator<AstProcessor> iterator() {
      return Arrays.asList().iterator();
   }
   @Override
      LuceneQueryParsingResult result = .getResult();
      return new IspnLuceneQueryParsingResult(result.getQuery(), .getTargetType(), result.getTargetEntity(), result.getProjections());
   }
New to GrepCode? Check out our FAQ X