public boolean equalsUpToVariableIds(Object object) { if (!(object instanceof VariableSelectionCondition)) { return false; } VariableSelectionCondition other = (VariableSelectionCondition) object; boolean result = this.condition.equalsUpToVariableIds(other.getCondition()); return result; }
private static String generateWhereClauseForIntersection(ComplexConjunctiveQuery view) { StringBuilder result = new StringBuilder(); result.append(INDENT).append("where \n"); List<VariableSelectionCondition> allSelectionConditions = view.getAllSelections(); List<VariableJoinCondition> joinConditions = new ArrayList<VariableJoinCondition>(view.getJoinConditions()); for (SimpleConjunctiveQuery simpleConjunctiveQuery : view.getConjunctions()) { joinConditions.addAll(simpleConjunctiveQuery.getAllJoinConditions()); } if (!joinConditions.isEmpty()) { for (int i = 0; i < joinConditions.size(); i++) { VariableJoinCondition joinCondition = joinConditions.get(i); result .append(DOUBLE_INDENT) .append(generateSQLStringForJoinConditionForIntersection(joinCondition, view)); result.append(" AND\n"); } } // check selection conditions for (int i = 0; i < allSelectionConditions.size(); i++) { VariableSelectionCondition condition = allSelectionConditions.get(i); result.append(DOUBLE_INDENT).append(GenerateSQL.sqlString(condition.getCondition())); if (i != allSelectionConditions.size() - 1 || view.hasIntersection()) result.append(" AND\n"); } if (view.hasIntersection()) { List<VariablePathExpression> leftIntersectionPaths = generateTargetPaths(view.getIntersectionEqualities().getLeftCorrespondences()); List<VariablePathExpression> rightIntersectionPaths = generateTargetPaths(view.getIntersectionEqualities().getRightCorrespondences()); List<VariableCorrespondence> allCorrespondences = new ArrayList<VariableCorrespondence>(); allCorrespondences.addAll(view.getIntersectionEqualities().getLeftCorrespondences()); allCorrespondences.addAll(view.getIntersectionEqualities().getRightCorrespondences()); for (int i = 0; i < leftIntersectionPaths.size(); i++) { VariablePathExpression leftPath = leftIntersectionPaths.get(i); VariablePathExpression rightPath = rightIntersectionPaths.get(i); VariablePathExpression leftSourcePath = findSourcePathWithEqualsId(allCorrespondences, leftPath); if (leftSourcePath == null) { leftSourcePath = leftPath; } VariablePathExpression rightSourcePath = findSourcePathWithEqualsId(allCorrespondences, rightPath); if (rightSourcePath == null) { rightSourcePath = rightPath; } result .append(DOUBLE_INDENT) .append(attributeNameWithVariable(leftSourcePath)) .append(" = ") .append(attributeNameWithVariable(rightSourcePath)); if (i != leftIntersectionPaths.size() - 1) result.append(" AND\n"); } } result.append("\n"); return result.toString(); }
public VariableSelectionCondition clone() { try { VariableSelectionCondition clone = (VariableSelectionCondition) super.clone(); clone.condition = condition.clone(); return clone; } catch (CloneNotSupportedException ex) { return null; } }
private String generateBuiltinsForSelections(ComplexConjunctiveQuery query) { StringBuilder localResult = new StringBuilder(); if (query.getAllSelections().size() > 0) { localResult.append(", "); } for (int i = 0; i < query.getAllSelections().size(); i++) { VariableSelectionCondition selection = query.getAllSelections().get(i); Expression expression = selection.getCondition().clone(); utility.setVariableDescriptions(expression, variables); if (useSaveFormat) { String expressionString = expression.toSaveString(); localResult.append(expressionString); } else { localResult.append(expression.toString()); } if (i != query.getAllSelections().size() - 1) { localResult.append(", "); } } return localResult.toString(); }
private static String generateWhereClauseWithoutWhere(ComplexConjunctiveQuery view) { if (!isNeededAWhereClause(view)) { return ""; } StringBuilder result = new StringBuilder(); List<VariableSelectionCondition> allSelectionConditions = view.getAllSelections(); List<SimpleConjunctiveQuery> conjunctions = view.getConjunctions(); List<VariableJoinCondition> joinConditions = new ArrayList<VariableJoinCondition>(view.getJoinConditions()); for (SimpleConjunctiveQuery simpleConjunctiveQuery : conjunctions) { joinConditions.addAll(simpleConjunctiveQuery.getAllJoinConditions()); } if (!joinConditions.isEmpty()) { result.append("\n"); for (int i = 0; i < joinConditions.size(); i++) { VariableJoinCondition joinCondition = joinConditions.get(i); List<VariableCorrespondence> correspondences = new ArrayList<VariableCorrespondence>(); for (List<VariableCorrespondence> list : view.getCorrespondencesForConjunctions()) { correspondences.addAll(list); } result .append(DOUBLE_INDENT) .append(generateSQLStringForJoinConditionSourcePath(joinCondition, correspondences)); if (i != joinConditions.size() - 1 || !allSelectionConditions.isEmpty()) result.append(" AND\n"); } } // check selection conditions for (int i = 0; i < allSelectionConditions.size(); i++) { VariableSelectionCondition condition = allSelectionConditions.get(i); result.append(DOUBLE_INDENT).append(GenerateSQL.sqlString(condition.getCondition())); if (i != allSelectionConditions.size() - 1) result.append(" AND\n"); } result.append("\n"); return result.toString(); }