public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<T>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[0]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[0]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
@Override public <T, E> E getConvertedExpression(String originalExpression, Class<T> beanClass, Class<E> queryClass) { SearchConditionVisitor<T, E> visitor = getVisitor(); if (visitor == null) { return null; } SearchCondition<T> cond = searchContext.getCondition(originalExpression, beanClass); if (cond == null) { return null; } cond.accept(visitor); return queryClass.cast(visitor.getQuery()); }
public <T, E> E getConvertedExpression(String originalExpression, Class<T> beanClass, Class<E> queryClass) { SearchConditionVisitor<T, E> visitor = getVisitor(); if (visitor == null) { return null; } SearchCondition<T> cond = searchContext.getCondition(originalExpression, beanClass); if (cond == null) { return null; } cond.accept(visitor); return queryClass.cast(visitor.getQuery()); }
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<Predicate>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<Predicate>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[predsList.size()]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
public List<Person> getTypedQueryPerson(SearchContext context) { // Get search condition encapsulating the query expression SearchCondition<Person> filter = getSearchCondition(context); // Initialise JPA2 visitor which can convert the captured search expression // into JPA2 TypedQuery SearchConditionVisitor<Person, TypedQuery<Person>> jpa = new JPATypedQueryVisitor<Person>(em, Person.class); // Convert filter.accept(jpa); // Get TypedQuery TypedQuery<Person> typedQuery = jpa.getQuery(); // Run the query and return the results return typedQuery.getResultList(); }
@Override public <T, E> E getConvertedExpression(String originalExpression, Class<T> beanClass, Class<E> queryClass) { SearchConditionVisitor<T, E> visitor = getVisitor(); if (visitor == null) { return null; } SearchCondition<T> cond = searchContext.getCondition(originalExpression, beanClass); if (cond == null) { return null; } cond.accept(visitor); return queryClass.cast(visitor.getQuery()); }
filter.accept(jpa);
public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Filter> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }
public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<Query>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Query> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }
public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Filter> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }
protected SearchCond getSearchCond(final String fiql, final String realm) { try { SearchCondVisitor visitor = new SearchCondVisitor(); visitor.setRealm(realm); SearchCondition<SearchBean> sc = searchContext.getCondition(fiql, SearchBean.class); sc.accept(visitor); return visitor.getQuery(); } catch (Exception e) { LOG.error("Invalid FIQL expression: {}", fiql, e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression); sce.getElements().add(fiql); sce.getElements().add(ExceptionUtils.getRootCauseMessage(e)); throw sce; } }
public void visit(SearchCondition<T> sc) { if (state.get() == null) { reset(); } PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { state.get().peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { state.get().push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Query> queries = state.get().pop(); state.get().peek().add(createCompositeQuery(queries, orCondition)); } }
public void visit(SearchCondition<T> sc) { if (state.get() == null) { reset(); } PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { state.get().peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { state.get().push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Query> queries = state.get().pop(); state.get().peek().add(createCompositeQuery(queries, orCondition)); } }
condition.accept(this); sb = getStringBuilder();
/** * Parses a FIQL expression into Syncope's {@link SearchCond}, using {@link SyncopeFiqlParser}. * * @param fiql FIQL string * @param realms optional realm to provide to {@link SearchCondVisitor} * @return {@link SearchCond} instance for given FIQL expression */ public static SearchCond convert(final String fiql, final String... realms) { SyncopeFiqlParser<SearchBean> parser = new SyncopeFiqlParser<>( SearchBean.class, AbstractFiqlSearchConditionBuilder.CONTEXTUAL_PROPERTIES); try { SearchCondVisitor visitor = new SearchCondVisitor(); if (realms != null && realms.length > 0) { visitor.setRealm(realms[0]); } SearchCondition<SearchBean> sc = parser.parse(URLDecoder.decode(fiql, StandardCharsets.UTF_8)); sc.accept(visitor); return visitor.getQuery(); } catch (Exception e) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression); sce.getElements().add(fiql); sce.getElements().add(ExceptionUtils.getRootCauseMessage(e)); throw sce; } }
new LdapQueryVisitor<>(Collections.singletonMap("name", "cn")); visitor.setEncodeQueryValues(encodeQueryValues); sc.accept(visitor.visitor()); String parsedQuery = visitor.getQuery();