Gets the lucene query from jpa query.

@return the lucene query from jpa query
199258
public static String getLuceneQueryFromJPAQuery(final KunderaQuery kunderaQuery,
            final KunderaMetadata kunderaMetadata)
    {

        LuceneQueryBuilder queryBuilder = new LuceneQueryBuilder();
        EntityMetadata metadata = kunderaQuery.getEntityMetadata();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                metadata.getPersistenceUnit());
        Class valueClazz = null;
        EntityType entity = metaModel.entity(metadata.getEntityClazz());
        boolean partitionKeyCheck = true;

        for (Object object : kunderaQuery.getFilterClauseQueue())
        {
            if (object instanceof FilterClause)
            {
                FilterClause filter = (FilterClause) object;
                String property = filter.getProperty();
                String condition = filter.getCondition();
                String valueAsString = filter.getValue().get(0).toString();
                String fieldName = metadata.getFieldName(property);
                boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
                String idColumn = ((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName();
                valueClazz = getValueType(entity, fieldName);

                if (isEmbeddedId)
                {
                    if (idColumn.equals(property))
                    {
                        valueAsString = prepareCompositeKey(metadata.getIdAttribute(), metaModel, filter.getValue()
                                .get(0));
                        queryBuilder.appendIndexName(metadata.getIndexName()).appendPropertyName(idColumn)
                                .buildQuery(condition, valueAsString, valueClazz);
                    }
                    else
                    {
                        valueClazz = metadata.getIdAttribute().getBindableJavaType();
                        if (property.lastIndexOf('.') != property.indexOf('.') && partitionKeyCheck)
                        {
                            isCompletePartitionKeyPresentInQuery(kunderaQuery.getFilterClauseQueue(), metaModel,
                                    metadata);
                            partitionKeyCheck = false;
                        }

                        if (metaModel.isEmbeddable(filter.getValue().get(0).getClass()))
                        {
                            prepareLuceneQueryForPartitionKey(queryBuilder, filter.getValue().get(0), metaModel,
                                    metadata.getIndexName(), valueClazz);
                        }
                        else
                        {
                            property = property.substring(property.lastIndexOf(".") + 1);
                            queryBuilder.appendIndexName(metadata.getIndexName())
                                    .appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
                                    .buildQuery(condition, valueAsString, valueClazz);
                        }
                    }
                }
                else
                {
                    queryBuilder.appendIndexName(metadata.getIndexName())
                            .appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
                            .buildQuery(condition, valueAsString, valueClazz);
                }
            }
            else
            {
                queryBuilder.buildQuery(object.toString(), object.toString(), String.class);
            }
        }

        queryBuilder.appendEntityName(kunderaQuery.getEntityClass().getCanonicalName().toLowerCase());
        return queryBuilder.getQuery();
    }
1109625
@Deprecated
    // TODO: All lucene specific code (methods that accept lucene query as
    // parameter) from this class should go away
    // and should be moved to LuceneIndexer instead
    public final Map<String, Object> search(Class<?> clazz, String query)
    {

        return search(clazz, query, Constants.INVALID, Constants.INVALID, false);
    }
899943
public String getQueryLanguage() throws UnsupportedQueryException
   {
      if (body.getChild(0).getName().getNamespaceURI().equals("DAV:")
         && body.getChild(0).getName().getLocalPart().equals("sql"))
      {
         return "sql";
      }
      else if (body.getChild(0).getName().getNamespaceURI().equals("DAV:")
         && body.getChild(0).getName().getLocalPart().equals("xpath"))
      {
         return "xpath";
      }

      throw new UnsupportedOperationException();
   }
193178
public MtasSpanQuery getQuery() throws ParseException {
    simplify();
    if (isBasic()) {
      MtasSpanQuery query;
      if (basicSentence == null) {
        throw new ParseException("no condition");
      } else if (basicSentence.isOptional()) {
        List<MtasSpanSequenceItem> clauses = new ArrayList<MtasSpanSequenceItem>();
        clauses.add(new MtasSpanSequenceItem(basicSentence.getQuery(),
            basicSentence.isOptional()));
        query = new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength);
        if (maximumOccurence > 1) {
          query = new MtasSpanRecurrenceQuery(query, minimumOccurence,
              maximumOccurence, ignore, maximumIgnoreLength);
        }
      } else {
        query = basicSentence.getQuery();
        if (maximumOccurence > 1) {
          query = new MtasSpanRecurrenceQuery(query, minimumOccurence,
              maximumOccurence, ignore, maximumIgnoreLength);
        }
      }
      return query;
    } else if (sequenceList.isEmpty()) {
      throw new ParseException("no condition");
    } else if (isSingle()) {
      return createQuery(sequenceList.get(0));
    } else {
      List<MtasSpanQuery> clauses = new ArrayList<MtasSpanQuery>();
      for (List<MtasCQLParserSentenceCondition> sentenceSequence : sequenceList) {
        clauses.add(createQuery(sentenceSequence));
      }
      return new MtasSpanOrQuery(
          clauses.toArray(new MtasSpanQuery[clauses.size()]));
    }
  }
525840
public List<Entity> query(Query query) {
		return query(query, FetchOptions.Builder.withOffset(0));
	}
467743
@Override
    public Map<String, Object> search(Class<?> clazz, EntityMetadata m, String luceneQuery, int start, int count)
    {
        if (log.isInfoEnabled())
        {
            log.info("Executing lucene query " + luceneQuery);
        }

        ListenableActionFuture<SearchResponse> listenableActionFuture = client
                .prepareSearch(m.getSchema().toLowerCase()).setQuery(QueryBuilders.queryStringQuery(luceneQuery))
                .setSize(40000).execute();
        SearchResponse response = listenableActionFuture.actionGet();

        Map<String, Object> results = new HashMap<String, Object>();
        for (SearchHit hit : response.getHits())
        {
            Object id = PropertyAccessorHelper.fromSourceToTargetClass(
                    ((AbstractAttribute) m.getIdAttribute()).getBindableJavaType(), String.class, hit.getId());
            results.put(hit.getId(), id);
        }
        return results;
    }
296822
public TypedQuery<T> select(Filter filter, OrderBy orderBy) {
        CriteriaQuery<T> query = cb.createQuery(getEntityClass());
        Root<T> from = query.from(getEntityClass());

        CriteriaMapper criteriaMapper = new CriteriaMapper(from, cb);

        if (orderBy != null) {
            query.orderBy(criteriaMapper.create(orderBy));
        }
        if (filter != null) {
            query.where(criteriaMapper.create(filter));
        }

        return getEntityManager().createQuery(query);
    }
647509
public Query<T> getCountQuery() {
    if (Strings.isEmpty(countStatement)) { return null; }
    QueryBean<T> bean = new QueryBean<T>();
    bean.setStatement(countStatement);
    bean.setLang(lang);
    bean.setParams(params);
    bean.setCacheable(cacheable);
    return bean;
  }
416052
public java.util.List<QueryInfo> getQueries() {
        if (queries == null) {
            queries = new com.amazonaws.internal.SdkInternalList<QueryInfo>();
        }
        return queries;
    }
950430
public static Parser<Relation> query() {
    Parser.Reference<Relation> relationRef = Parser.newReference();
    Parser<Relation> subQuery = ExpressionParser.paren(relationRef.lazy());
    Parser.Reference<Expression> conditionRef = Parser.newReference();
    Parser<Expression> expr = ExpressionParser.expression(conditionRef.lazy());
    Parser<Expression> cond = ExpressionParser.condition(expr, subQuery);
    Parser<Relation> relation = query(expr, cond, subQuery.or(TABLE));
    conditionRef.set(cond);
    relationRef.set(relation);
    return relation;
  }
478774
public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
    {
        ClassDescriptor cld = getClassDescriptor(query.getSearchClass());
        return getReportQueryIteratorFromQuery(query, cld);
    }
118380
public Rule CriteriaOnlyFindQuery() {
		return Sequence( !peek().isCliQuery(), JsonParameter( JsonObject() ) , peek().setOperation( Operation.FIND ), peek().setCriteria( match() ) );
	}
415767
protected <T> SearchResultsBean<T> find(SearchCriteriaBean criteria, Class<T> type) throws StorageException {
        SearchResultsBean<T> results = new SearchResultsBean<>();
        EntityManager entityManager = getActiveEntityManager();
        try {
            // Set some default in the case that paging information was not included in the request.
            PagingBean paging = criteria.getPaging();
            if (paging == null) {
                paging = new PagingBean();
                paging.setPage(1);
                paging.setPageSize(20);
            }
            int page = paging.getPage();
            int pageSize = paging.getPageSize();
            int start = (page - 1) * pageSize;

            CriteriaBuilder builder = entityManager.getCriteriaBuilder();
            CriteriaQuery<T> criteriaQuery = builder.createQuery(type);
            Root<T> from = criteriaQuery.from(type);
            applySearchCriteriaToQuery(criteria, builder, criteriaQuery, from, false);
            TypedQuery<T> typedQuery = entityManager.createQuery(criteriaQuery);
            typedQuery.setFirstResult(start);
            typedQuery.setMaxResults(pageSize+1);
            boolean hasMore = false;

            // Now query for the actual results
            List<T> resultList = typedQuery.getResultList();

            // Check if we got back more than we actually needed.
            if (resultList.size() > pageSize) {
                resultList.remove(resultList.size() - 1);
                hasMore = true;
            }

            // If there are more results than we needed, then we will need to do another
            // query to determine how many rows there are in total
            int totalSize = start + resultList.size();
            if (hasMore) {
                totalSize = executeCountQuery(criteria, entityManager, type);
            }
            results.setTotalSize(totalSize);
            results.setBeans(resultList);
            return results;
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
            throw new StorageException(t);
        }
    }
386010
public List<NamedQuery<Entity<T>>> getAllNamedQuery()
   {
      List<NamedQuery<Entity<T>>> list = new ArrayList<NamedQuery<Entity<T>>>();
      List<Node> nodeList = childNode.get("named-query");
      for(Node node: nodeList)
      {
         NamedQuery<Entity<T>>  type = new NamedQueryImpl<Entity<T>>(this, "named-query", childNode, node);
         list.add(type);
      }
      return list;
   }
642627
@Override
    public Iterable<T> findAll() {
        return inTransaction(new Callable<Iterable<T>>() {
            @Override
            public Iterable<T> call() throws Exception {
                CriteriaQuery<T> cq = entityManager.getCriteriaBuilder().createQuery(entity);
                Root<T> pet = cq.from(entity);
                cq.select(pet);
                return entityManager.createQuery(cq).getResultList();
            }
        });
    }
501221
@NotNull
    @Size(max = 1000)
    @ApiModelProperty(required = true, value = "")
    public String getQuery() {
        return query;
    }
215095
public Query createQuery( Constraint constraint ) {
        if (constraint instanceof And) {
            return createQuery((And) constraint);
        }
        if (constraint instanceof Or) {
            return createQuery((Or) constraint);
        }
        if (constraint instanceof Not) {
            return createQuery((Not) constraint);
        }
        if (constraint instanceof SetCriteria) {
            return createQuery((SetCriteria) constraint);
        }
        if (constraint instanceof PropertyExistence) {
            return createQuery((PropertyExistence) constraint);
        }
        if (constraint instanceof Between) {
            return createQuery((Between) constraint);
        }
        if (constraint instanceof Relike) {
            return createQuery((Relike) constraint);
        }
        if (constraint instanceof Comparison) {
            return createQuery((Comparison) constraint);
        }
        if (constraint instanceof FullTextSearch) {
            return createQuery((FullTextSearch) constraint);
        }
        // Should not get here ...
        throw new LuceneIndexException(
                "Unexpected Constraint instance: class=" + (constraint != null ? constraint.getClass() : "null")
                + " and instance=" + constraint);
    }