Search in sources :

Example 1 with JdbcPredicatesTranslator

use of org.unipop.jdbc.utils.JdbcPredicatesTranslator in project unipop by unipop-graph.

the class AbstractRowSchema method getSearch.

@Override
public Select getSearch(SearchQuery<E> query, PredicatesHolder predicatesHolder) {
    if (predicatesHolder.isAborted()) {
        return null;
    }
    Condition conditions = new JdbcPredicatesTranslator().translate(predicatesHolder);
    int finalLimit = query.getLimit() < 0 ? Integer.MAX_VALUE : query.getLimit();
    SelectConditionStep<Record> where = createSqlQuery(query.getPropertyKeys()).where(conditions);
    List<Pair<String, Order>> orders = query.getOrders();
    if (orders != null) {
        List<SortField<Object>> orderValues = orders.stream().filter(order -> !order.getValue1().equals(Order.shuffle)).filter(order -> getFieldByPropertyKey(order.getValue0()) != null).map(order -> order.getValue1().equals(Order.incr) ? field(getFieldByPropertyKey(order.getValue0())).asc() : field(getFieldByPropertyKey(order.getValue0())).desc()).collect(Collectors.toList());
        if (orderValues.size() > 0)
            return where.orderBy(orderValues).limit(finalLimit);
    }
    return where.limit(finalLimit);
}
Also used : java.util(java.util) DSL(org.jooq.impl.DSL) ContextManager(org.unipop.jdbc.utils.ContextManager) DSL.field(org.jooq.impl.DSL.field) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Pair(org.javatuples.Pair) DSL.or(org.jooq.impl.DSL.or) Element(org.apache.tinkerpop.gremlin.structure.Element) JSONObject(org.json.JSONObject) Stream(java.util.stream.Stream) PredicateQuery(org.unipop.query.predicates.PredicateQuery) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) org.jooq(org.jooq) JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) AbstractElementSchema(org.unipop.schema.element.AbstractElementSchema) UniGraph(org.unipop.structure.UniGraph) JdbcPredicatesTranslator(org.unipop.jdbc.utils.JdbcPredicatesTranslator) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) SearchQuery(org.unipop.query.search.SearchQuery) DSL.table(org.jooq.impl.DSL.table) JdbcPredicatesTranslator(org.unipop.jdbc.utils.JdbcPredicatesTranslator) Pair(org.javatuples.Pair)

Aggregations

java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 Element (org.apache.tinkerpop.gremlin.structure.Element)1 Pair (org.javatuples.Pair)1 org.jooq (org.jooq)1 DSL (org.jooq.impl.DSL)1 DSL.field (org.jooq.impl.DSL.field)1 DSL.or (org.jooq.impl.DSL.or)1 DSL.table (org.jooq.impl.DSL.table)1 JSONObject (org.json.JSONObject)1 JdbcSchema (org.unipop.jdbc.schemas.jdbc.JdbcSchema)1 ContextManager (org.unipop.jdbc.utils.ContextManager)1 JdbcPredicatesTranslator (org.unipop.jdbc.utils.JdbcPredicatesTranslator)1 PredicateQuery (org.unipop.query.predicates.PredicateQuery)1 PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)1 SearchQuery (org.unipop.query.search.SearchQuery)1 AbstractElementSchema (org.unipop.schema.element.AbstractElementSchema)1