Search in sources :

Example 1 with AndOrHasContainer

use of org.umlg.sqlg.sql.parse.AndOrHasContainer in project sqlg by pietermartin.

the class BaseStrategy method handleConnectiveStepInternal.

private Optional<AndOrHasContainer> handleConnectiveStepInternal(ConnectiveStep connectiveStep) {
    AndOrHasContainer.TYPE type = AndOrHasContainer.TYPE.from(connectiveStep);
    AndOrHasContainer outerAndOrHasContainer = new AndOrHasContainer(type);
    List<Traversal.Admin<?, ?>> localTraversals = connectiveStep.getLocalChildren();
    for (Traversal.Admin<?, ?> localTraversal : localTraversals) {
        if (!TraversalHelper.hasAllStepsOfClass(localTraversal, HasStep.class, ConnectiveStep.class)) {
            return Optional.empty();
        }
        AndOrHasContainer andOrHasContainer = new AndOrHasContainer(AndOrHasContainer.TYPE.NONE);
        outerAndOrHasContainer.addAndOrHasContainer(andOrHasContainer);
        for (Step<?, ?> step : localTraversal.getSteps()) {
            if (step instanceof HasStep) {
                HasStep<?> hasStep = (HasStep) step;
                for (HasContainer hasContainer : hasStep.getHasContainers()) {
                    if (hasContainerKeyNotIdOrLabel(hasContainer) && SUPPORTED_BI_PREDICATE.contains(hasContainer.getBiPredicate())) {
                        andOrHasContainer.addHasContainer(hasContainer);
                    } else if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) {
                        AndP<?> andP = (AndP) hasContainer.getPredicate();
                        List<? extends P<?>> predicates = andP.getPredicates();
                        if (predicates.size() == 2) {
                            if (predicates.get(0).getBiPredicate() == Compare.gte && predicates.get(1).getBiPredicate() == Compare.lt) {
                                andOrHasContainer.addHasContainer(hasContainer);
                            } else if (predicates.get(0).getBiPredicate() == Compare.gt && predicates.get(1).getBiPredicate() == Compare.lt) {
                                andOrHasContainer.addHasContainer(hasContainer);
                            }
                        }
                    } else if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof OrP) {
                        OrP<?> orP = (OrP) hasContainer.getPredicate();
                        List<? extends P<?>> predicates = orP.getPredicates();
                        if (predicates.size() == 2) {
                            if (predicates.get(0).getBiPredicate() == Compare.lt && predicates.get(1).getBiPredicate() == Compare.gt) {
                                andOrHasContainer.addHasContainer(hasContainer);
                            }
                        }
                    } else if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getBiPredicate() instanceof Text || hasContainer.getBiPredicate() instanceof FullText) {
                        andOrHasContainer.addHasContainer(hasContainer);
                    } else {
                        return Optional.empty();
                    }
                }
            } else {
                ConnectiveStep connectiveStepLocalChild = (ConnectiveStep) step;
                Optional<AndOrHasContainer> result = handleConnectiveStepInternal(connectiveStepLocalChild);
                if (result.isPresent()) {
                    andOrHasContainer.addAndOrHasContainer(result.get());
                } else {
                    return Optional.empty();
                }
            }
        }
    }
    return Optional.of(outerAndOrHasContainer);
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer) LoopTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.LoopTraversal) FullText(org.umlg.sqlg.predicate.FullText) Text(org.umlg.sqlg.predicate.Text) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) FullText(org.umlg.sqlg.predicate.FullText) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Example 2 with AndOrHasContainer

use of org.umlg.sqlg.sql.parse.AndOrHasContainer in project sqlg by pietermartin.

the class SqlgUtil method setParametersOnStatement.

public static void setParametersOnStatement(SqlgGraph sqlgGraph, LinkedList<SchemaTableTree> schemaTableTreeStack, PreparedStatement preparedStatement, int parameterIndex) throws SQLException {
    Multimap<String, Object> keyValueMap = LinkedListMultimap.create();
    for (SchemaTableTree schemaTableTree : schemaTableTreeStack) {
        for (HasContainer hasContainer : schemaTableTree.getHasContainers()) {
            if (!sqlgGraph.getSqlDialect().supportsBulkWithinOut() || !isBulkWithinAndOut(sqlgGraph, hasContainer)) {
                WhereClause whereClause = WhereClause.from(hasContainer.getPredicate());
                whereClause.putKeyValueMap(hasContainer, keyValueMap);
            }
        }
        for (AndOrHasContainer andOrHasContainer : schemaTableTree.getAndOrHasContainers()) {
            andOrHasContainer.setParameterOnStatement(keyValueMap);
        }
    }
    List<ImmutablePair<PropertyType, Object>> typeAndValues = SqlgUtil.transformToTypeAndValue(keyValueMap);
    // This is for selects
    setKeyValuesAsParameter(sqlgGraph, false, parameterIndex, preparedStatement, typeAndValues);
}
Also used : SchemaTableTree(org.umlg.sqlg.sql.parse.SchemaTableTree) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer) WhereClause(org.umlg.sqlg.sql.parse.WhereClause) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Aggregations

HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 AndOrHasContainer (org.umlg.sqlg.sql.parse.AndOrHasContainer)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 LoopTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.LoopTraversal)1 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)1 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)1 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)1 FullText (org.umlg.sqlg.predicate.FullText)1 Text (org.umlg.sqlg.predicate.Text)1 SchemaTableTree (org.umlg.sqlg.sql.parse.SchemaTableTree)1 WhereClause (org.umlg.sqlg.sql.parse.WhereClause)1