1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 31 public class JoinTableNode implements JoinTable { 32 33 35 private String _joinType; private TableNode _table; 37 private Expression _condition; 39 41 public JoinTableNode () { 42 } 43 44 public JoinTableNode(TableNode table, String joinType, Expression condition) { 45 _table = table; 46 _joinType = joinType; 47 _condition = condition; 48 } 49 50 public JoinTableNode(TableNode table) { 51 this(table, null, null); 52 } 53 54 55 57 public String genText() { 60 String res = 61 (((_joinType==null)||(_joinType.equals("CROSS"))) 62 ? ", " 63 : "\n " +_joinType + " JOIN ") + _table.genText(true); 65 66 if (_condition != null) { 67 res += " ON " + _condition.genText(); } 69 70 return res; 71 } 72 73 74 public String genText(boolean first) { 77 return (first ? _table.genText(true) : this.genText()); 78 } 79 80 81 83 85 public Table getTable() { 86 return _table; 87 } 88 89 public String getTableName() { 90 return _table.getTableName(); 91 } 92 93 public String getCorrName() { 94 return _table.getCorrName(); 95 } 96 97 public String getTableSpec() { 98 return _table.getTableSpec(); 99 } 100 101 public String getFullTableName() { 102 return _table.getFullTableName(); 103 } 104 105 public String getJoinType () { 106 return _joinType; 107 } 108 109 public void setJoinType (String joinType) { 110 _joinType = joinType; 111 } 112 113 public Expression getExpression() { 114 return _condition; 115 } 116 117 public void setExpression(Expression condition) { 118 _condition = condition; 119 } 120 121 public void getReferencedColumns (Collection columns) { 123 if (_condition != null) 124 _condition.getReferencedColumns(columns); 125 } 126 127 public void getQueryItems(Collection items) { 128 if (_condition != null) { 129 items.add(_table); 130 items.add(_condition); 131 } 132 } 133 134 void renameTableSpec(String oldTableSpec, String corrName) { 135 ((TableNode)this.getTable()).renameTableSpec(oldTableSpec, corrName); 136 137 if (_condition instanceof Predicate) 138 ((Predicate)_condition).renameTableSpec(oldTableSpec, corrName); 139 } 140 141 void setTableSpec(String oldTableSpec, String newTableSpec) 142 { 143 ((TableNode)this.getTable()).setTableSpec(oldTableSpec, newTableSpec); 144 } 145 146 public void addJoinCondition(String [] rel) { 147 148 ColumnNode col1 = new ColumnNode(rel[0], rel[1]); 150 ColumnNode col2 = new ColumnNode(rel[2], rel[3]); 151 Predicate pred = new Predicate(col1, col2); 152 153 setJoinType("INNER"); setExpression(pred); 156 } 157 } 158 | Popular Tags |