/* (non-Javadoc)
@see org.talend.esb.sam.server.persistence.criterias.Criteria#getFilterClause()
188514
@Override
    public StringBuilder getFilterClause() {
        StringBuilder builder = new StringBuilder();
        builder.append(columnName);
        if (name.lastIndexOf('_') > 0) {
            String suffix = name.substring(name.lastIndexOf('_') + 1);
            if ("before".equals(suffix)) {
                builder.append(" < ");
            } else if ("after".equals(suffix)) {
                builder.append(" > ");
            } else {
                builder.append(" = ");
            }
        } else {
            builder.append(" = ");
        }
        builder.append(':').append(name);
        return builder;
    }
1096625
@SuppressWarnings("unchecked")
    private static Filter<ArchivePath> getFilterInstance(final String filterClassName, final Class<?>[] ctorTypes,
        final Object[] ctorArguments) {
        // Precondition checks
        assert filterClassName != null && filterClassName.length() > 0 : "Filter class name must be specified";
        assert ctorTypes != null : "Construction types must be specified";
        assert ctorArguments != null : "Construction arguments must be specified";
        assert ctorTypes.length == ctorArguments.length : "The number of ctor arguments and their types must match";

        // Find the filter impl class in the configured CLs
        final Class<Filter<ArchivePath>> filterClass;
        try {
            filterClass = (Class<Filter<ArchivePath>>) ClassLoaderSearchUtil.findClassFromClassLoaders(filterClassName,
                ShrinkWrap.getDefaultDomain().getConfiguration().getClassLoaders());
        } catch (final ClassNotFoundException cnfe) {
            throw new IllegalStateException("Could not find filter implementation class " + filterClassName
                + " in any of the configured CLs", cnfe);
        }

        // Make the new instance
        return SecurityActions.newInstance(filterClass, ctorTypes, ctorArguments, Filter.class);
    }
999983
public QueryScopeInfo getQueryServiceMetricInfo(CharacterFilter filter) {
		if (queryServiceScopeInfo == null) {
			queryServiceScopeInfo = createQueryServiceMetricInfo(filter);
		}
		return queryServiceScopeInfo;
	}
479892
private void validateFilter(Filter filter) throws IllegalArgumentException {
    switch (filter.getFilterTypeCase()) {
      case COMPOSITE_FILTER:
        for (Filter subFilter : filter.getCompositeFilter().getFiltersList()) {
          validateFilter(subFilter);
        }
        break;
      case PROPERTY_FILTER:
        if (UNSUPPORTED_OPERATORS.contains(filter.getPropertyFilter().getOp())) {
          throw new IllegalArgumentException("Query cannot have any inequality filters.");
        }
        break;
      default:
        throw new IllegalArgumentException(
            "Unsupported filter type: " + filter.getFilterTypeCase());
    }
  }
776955
@Override
    public String getDataQuery(QueryFilter filter) {
        String query = getQuery();
        String whereClause = filter.getWhereClause();
        String result = null;
        if (whereClause != null && whereClause.length() > 0) {
            result = query.replaceAll(SUBSTITUTION_STRING, " AND " + whereClause);	
        } else {
            result = query.replaceAll(SUBSTITUTION_STRING, "");
        }
        return result;
    }
212175
public Query<S> query(String filter) throws FetchException {
        synchronized (mStringToQuery) {
            Query<S> query = mStringToQuery.get(filter);
            if (query == null) {
                if (filter == null) {
                    throw new IllegalArgumentException("Query filter must not be null");
                }
                query = query(Filter.filterFor(mType, filter), null);
                mStringToQuery.put(filter, query);
            }
            return query;
        }
    }
372926
public static <T> List<T> listFromClause(Class<T> clazz, String clause, Object... args)
    {
       return SqlClosure.sqlExecute(c -> OrmElf.listFromClause(c, clazz, clause, args));
    }
835299
public CmsLockFilter getBlockingFilter() {

        if (m_blockingFilter == null) {
            m_blockingFilter = CmsLockFilter.FILTER_ALL;
            m_blockingFilter = m_blockingFilter.filterNotLockableByUser(getCms().getRequestContext().getCurrentUser());
        }
        return m_blockingFilter;
    }
845471
private FilterClause populateFilterClause(ComparisonExpression conditionalExpression)
    {
        String property = ((StateFieldPathExpression) conditionalExpression.getLeftExpression()).getPath(1);
        String condition = conditionalExpression.getComparisonOperator();
        Expression rightExpression = conditionalExpression.getRightExpression();
        Object value = (rightExpression instanceof InputParameter) ? kunderaQuery.getParametersMap().get(
                (rightExpression).toParsedText()) : rightExpression.toParsedText();

        return (condition != null && property != null) ? kunderaQuery.new FilterClause(property, condition, value, property)
                : null;
    }
786626
public final hqlParser.selectClause_return selectClause() throws RecognitionException {
		hqlParser.selectClause_return retval = new hqlParser.selectClause_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token SELECT45=null;
		Token DISTINCT46=null;
		ParserRuleReturnScope selectedPropertiesList47 =null;
		ParserRuleReturnScope newExpression48 =null;
		ParserRuleReturnScope selectObject49 =null;

		CommonTree SELECT45_tree=null;
		CommonTree DISTINCT46_tree=null;

		try {
			// hql.g:257:2: ( SELECT ^ ( DISTINCT )? ( selectedPropertiesList | newExpression | selectObject ) )
			// hql.g:257:4: SELECT ^ ( DISTINCT )? ( selectedPropertiesList | newExpression | selectObject )
			{
			root_0 = (CommonTree)adaptor.nil();


			SELECT45=(Token)match(input,SELECT,FOLLOW_SELECT_in_selectClause1018);
			SELECT45_tree = (CommonTree)adaptor.create(SELECT45);
			root_0 = (CommonTree)adaptor.becomeRoot(SELECT45_tree, root_0);

			 WeakKeywords();
			// hql.g:259:3: ( DISTINCT )?
			int alt17=2;
			int LA17_0 = input.LA(1);
			if ( (LA17_0==DISTINCT) ) {
				alt17=1;
			}
			switch (alt17) {
				case 1 :
					// hql.g:259:4: DISTINCT
					{
					DISTINCT46=(Token)match(input,DISTINCT,FOLLOW_DISTINCT_in_selectClause1030);
					DISTINCT46_tree = (CommonTree)adaptor.create(DISTINCT46);
					adaptor.addChild(root_0, DISTINCT46_tree);

					}
					break;

			}

			// hql.g:259:15: ( selectedPropertiesList | newExpression | selectObject )
			int alt18=3;
			switch ( input.LA(1) ) {
			case ALL:
			case ANY:
			case AVG:
			case BNOT:
			case CASE:
			case COLON:
			case COUNT:
			case ELEMENTS:
			case EMPTY:
			case EXISTS:
			case FALSE:
			case IDENT:
			case INDICES:
			case MAX:
			case MIN:
			case MINUS:
			case NOT:
			case NULL:
			case NUM_DECIMAL:
			case NUM_DOUBLE:
			case NUM_FLOAT:
			case NUM_INT:
			case NUM_LONG:
			case OPEN:
			case PARAM:
			case PLUS:
			case QUOTED_String:
			case SOME:
			case SUM:
			case TRUE:
				{
				alt18=1;
				}
				break;
			case NEW:
				{
				alt18=2;
				}
				break;
			case OBJECT:
				{
				alt18=3;
				}
				break;
			default:
				NoViableAltException nvae =
					new NoViableAltException("", 18, 0, input);
				throw nvae;
			}
			switch (alt18) {
				case 1 :
					// hql.g:259:17: selectedPropertiesList
					{
					pushFollow(FOLLOW_selectedPropertiesList_in_selectClause1036);
					selectedPropertiesList47=selectedPropertiesList();
					state._fsp--;

					adaptor.addChild(root_0, selectedPropertiesList47.getTree());

					}
					break;
				case 2 :
					// hql.g:259:42: newExpression
					{
					pushFollow(FOLLOW_newExpression_in_selectClause1040);
					newExpression48=newExpression();
					state._fsp--;

					adaptor.addChild(root_0, newExpression48.getTree());

					}
					break;
				case 3 :
					// hql.g:259:58: selectObject
					{
					pushFollow(FOLLOW_selectObject_in_selectClause1044);
					selectObject49=selectObject();
					state._fsp--;

					adaptor.addChild(root_0, selectObject49.getTree());

					}
					break;

			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1323538
private static QueryComponent getQueryComponent(Queue filterClauseQueue)
    {
        QueryComponent subQuery = new QueryComponent();
        QueryComponent currentSubQuery = subQuery;

        for (Object object : filterClauseQueue)
        {
            if (object instanceof FilterClause)
            {
                currentSubQuery.clauses.add(object);
            }
            else if (object instanceof String)
            {
                String interClauseConstruct = (String) object;
                if (interClauseConstruct.equals("("))
                {
                    QueryComponent temp = new QueryComponent();
                    currentSubQuery.children.add(temp);
                    temp.parent = currentSubQuery;
                    currentSubQuery = temp;
                }
                else if (interClauseConstruct.equals(")"))
                {
                    currentSubQuery = currentSubQuery.parent;
                }
                else if (interClauseConstruct.equalsIgnoreCase("AND"))
                {
                    currentSubQuery.isAnd = true;
                }
                else if (interClauseConstruct.equalsIgnoreCase("OR"))
                {
                    currentSubQuery.isAnd = false;
                }
            }
        }

        return subQuery;
    }
1244447
@Override
	public String getLimitClause(final long limit, final long offset) {
		StringBuilder builder = new StringBuilder();
		if (limit > 0) {
			builder.append("LIMIT ").append(limit).append(" ");
		}
		if (offset > 0) {
			builder.append("OFFSET ").append(offset);
		}
		if (builder.length() > 0) {
			builder.append(System.lineSeparator());
		}
		return builder.toString();
	}
1045762
public String[] getFilters() {
		try {
			if (isStarted()) {
				final MiniRoxFilterAcknowledger acknowledger = new MiniRoxFilterAcknowledger();
				
				// Be sure that the emit/ack is synchronous to get the filters before the test are run
				new Thread(new Runnable() {
					@Override
					public void run() {
						try {
							LOGGER.trace("Retrieve filters");
							socket.emit("filters:get", acknowledger);
						}
						catch (Exception e) {
							LOGGER.warn("Unable to get the filters: {}", e.getMessage());
							synchronized (acknowledger) {
								acknowledger.notify();
							}
						}
					}
				}).start();

				synchronized (acknowledger) {
					acknowledger.wait();
				}

				if (!acknowledger.isFilters()) {
					for (String filter : acknowledger.getFilters()) {
						LOGGER.info("Filter element: {}", filter);
					}
				}

				return acknowledger.getFilters();
			}
		}
		catch (Exception e) {
			LOGGER.warn("Unable to retrieve the filters from MINI ROX. Cause: {}", e.getMessage());
			
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Exception: ", e);
			}
		}
		
		return null;
	}
1100118
private QueryBuilder getQueryBuilder(FilterClause clause, final EntityMetadata metadata)
    {
        String condition = clause.getCondition();
        String value = clause.getValue().get(0).toString();
        String name = ((AbstractAttribute) ((MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                metadata.getPersistenceUnit())).entity(metadata.getEntityClazz()).getAttribute(clause.getProperty()))
                .getJPAColumnName();

        String likePattern = value.contains(ESConstants.PERCENTAGE) ? value.replaceAll(ESConstants.PERCENTAGE,
                ESConstants.ASTERISK) : ESConstants.ASTERISK + value + ESConstants.ASTERISK;

        QueryBuilder queryBuilder = null;
        if (condition.equals(Expression.LIKE))
        {
            queryBuilder = QueryBuilders.wildcardQuery(name, likePattern);
        }

        return QueryBuilders.queryFilter(queryBuilder);
    }
1321453
@Override
    public DBObject getUpdateClause() {
        if (clear) {
            // If clear() was called, updates will either be an empty BasicDBList or items added
            return new BasicDBObject($set.name(), new BasicDBObject(getNameFromPrefix(), updates));
        } else {
            if (operation == null) {
                return new BasicDBObject();     // If there are no updates, return an empty DBObject
            } else if (operation == UpdateOperation.$set) {
                return new BasicDBObject(operation.name(), updates);
            } else {
                return new BasicDBObject(operation.name(), new BasicDBObject(getNameFromPrefix(), updates));
            }
        }
    }
827226
@Override
    public String getPartialFilterSelector() {
        return (def.selector != null) ? def.selector.toString() : null;
    }
558454
public static policyexpression[] get_filtered(nitro_service service, String filter) throws Exception{
		policyexpression obj = new policyexpression();
		options option = new options();
		option.set_filter(filter);
		policyexpression[] response = (policyexpression[]) obj.getfiltered(service, option);
		return response;
	}