Skip to content

Commit

Permalink
add support for multiple join conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Apr 24, 2019
1 parent 4d81e7b commit d78098a
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/main/java/org/citydb/sqlbuilder/select/join/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@

import org.citydb.sqlbuilder.schema.Column;
import org.citydb.sqlbuilder.schema.Table;
import org.citydb.sqlbuilder.select.PredicateToken;
import org.citydb.sqlbuilder.select.operator.comparison.BinaryComparisonOperator;
import org.citydb.sqlbuilder.select.operator.comparison.ComparisonName;
import org.citydb.sqlbuilder.select.operator.logical.BinaryLogicalOperator;
import org.citydb.sqlbuilder.select.operator.logical.LogicalOperationName;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Join {
private final Column fromColumn;
private final Column toColumn;
private final BinaryComparisonOperator condition;
private final List<PredicateToken> conditions;
private JoinName name;

public Join(JoinName name, Table table, String column, ComparisonName binaryComparison, Column fromColumn) {
this.name = name;
this.toColumn = table.getColumn(column);
this.fromColumn = fromColumn;
condition = new BinaryComparisonOperator(this.fromColumn, binaryComparison, this.toColumn);
}
private LogicalOperationName conditionOperationName = LogicalOperationName.AND;

public Join(JoinName joinName, Column toColumn, ComparisonName binaryComparison, Column fromColumn) {
this.name = joinName;
public Join(JoinName name, Column toColumn, ComparisonName binaryComparison, Column fromColumn) {
this.name = name;
this.toColumn = toColumn;
this.fromColumn = fromColumn;
condition = new BinaryComparisonOperator(this.fromColumn, binaryComparison, this.toColumn);

conditions = new ArrayList<>();
conditions.add(new BinaryComparisonOperator(this.fromColumn, binaryComparison, this.toColumn));
}

public Join(JoinName name, Table table, String column, ComparisonName binaryComparison, Column fromColumn) {
this(name, table.getColumn(column), binaryComparison, fromColumn);
}

public Column getFromColumn() {
Expand All @@ -54,10 +59,6 @@ public Column getToColumn() {
return toColumn;
}

public BinaryComparisonOperator getCondition() {
return condition;
}

public JoinName getJoinName() {
return name;
}
Expand All @@ -66,15 +67,27 @@ public void setJoinName(JoinName name) {
if (name != null)
this.name = name;
}


public void addCondition(PredicateToken condition) {
conditions.add(condition);
}

public LogicalOperationName getConditionOperationName() {
return conditionOperationName;
}

public void setConditionOperationName(LogicalOperationName conditionOperationName) {
this.conditionOperationName = conditionOperationName;
}

public void getInvolvedTables(Set<Table> tables) {
fromColumn.getInvolvedTables(tables);
toColumn.getInvolvedTables(tables);
}

@Override
public String toString() {
return name + " " + toColumn.getTable() + " on " + condition;
return name + " " + toColumn.getTable() + " on " + new BinaryLogicalOperator(conditionOperationName, conditions);
}

}

0 comments on commit d78098a

Please sign in to comment.