01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.rdbms.algebra;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: import org.openrdf.sail.rdbms.algebra.base.FromItem;
12: import org.openrdf.sail.rdbms.algebra.base.RdbmsQueryModelVisitorBase;
13:
14: /**
15: * An SQL join.
16: *
17: * @author James Leigh
18: *
19: */
20: public class JoinItem extends FromItem {
21: private String tableName;
22: private Number predId;
23: private List<ColumnVar> vars = new ArrayList<ColumnVar>();
24:
25: public JoinItem(String alias, String tableName, Number predId) {
26: super (alias);
27: this .tableName = tableName;
28: this .predId = predId;
29: }
30:
31: public JoinItem(String alias, String tableName) {
32: super (alias);
33: this .tableName = tableName;
34: this .predId = 0;
35: }
36:
37: public String getTableName() {
38: return tableName;
39: }
40:
41: public Number getPredId() {
42: return predId;
43: }
44:
45: public void addVar(ColumnVar var) {
46: this .vars.add(var);
47: }
48:
49: @Override
50: public ColumnVar getVarForChildren(String name) {
51: for (ColumnVar var : vars) {
52: if (var.getName().equals(name))
53: return var;
54: }
55: return super .getVarForChildren(name);
56: }
57:
58: @Override
59: public List<ColumnVar> appendVars(List<ColumnVar> vars) {
60: vars.addAll(this .vars);
61: return super .appendVars(vars);
62: }
63:
64: @Override
65: public String getSignature() {
66: StringBuilder sb = new StringBuilder();
67: if (isLeft()) {
68: sb.append("LEFT ");
69: }
70: sb.append(super .getSignature());
71: sb.append(" ").append(tableName);
72: sb.append(" ").append(getAlias());
73: return sb.toString();
74: }
75:
76: @Override
77: public JoinItem clone() {
78: JoinItem clone = (JoinItem) super .clone();
79: clone.vars = new ArrayList<ColumnVar>(vars);
80: return clone;
81: }
82:
83: @Override
84: public <X extends Exception> void visit(
85: RdbmsQueryModelVisitorBase<X> visitor) throws X {
86: visitor.meet(this);
87: }
88:
89: }
|