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);
}
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);
}
Aggregations