1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 24 28 public final class Predicate implements Expression { 29 30 32 34 Value _val1, _val2; 35 String _op; 37 38 39 41 public Predicate() { 42 } 43 44 public Predicate(Value val1, Value val2) { 45 this(val1, val2, "="); } 47 48 public Predicate (Value val1, Value val2, String op) { 49 _val1 = val1; 50 _val2 = val2; 51 _op = op; 52 } 53 54 public Predicate (String [] rel) { 56 _val1 = new ColumnNode(rel[0], rel[1]); 57 _val2 = new ColumnNode(rel[2], rel[3]); 58 _op = "="; 59 } 60 61 63 public Expression findExpression(String table1, String column1, String table2, String column2) { 64 if ((_val1 instanceof ColumnNode) && (_val2 instanceof ColumnNode)) { 65 ColumnNode col1 = (ColumnNode) _val1; 66 ColumnNode col2 = (ColumnNode) _val2; 67 if ((col1.matches(table1, column1) && col2.matches(table2, column2)) || 68 (col2.matches(table1, column1) && col1.matches(table2, column2))) { 69 return this; 70 } 71 } 72 return null; 73 } 74 75 public void getReferencedColumns(Collection columns) { 77 if (_val1 instanceof ColumnItem) { 78 columns.add (((ColumnItem)_val1).getReferencedColumn()); 79 } 80 81 if (_val2 instanceof ColumnItem) { 82 columns.add(((ColumnItem)_val2).getReferencedColumn()); 83 } 84 } 85 86 public void getQueryItems(Collection items) { 87 items.add(_val1); 88 items.add(_val2); 89 } 90 91 public String genText() { 93 return _val1.genText() + " " + _op + " " + _val2.genText(); } 95 96 public Value getVal1() { 97 return _val1; 98 } 99 100 public void setVal1(Value val1 ) { 101 _val1 = val1; 102 } 103 104 public Value getVal2() { 105 return _val2; 106 } 107 108 public void setVal2(Value val2) { 109 _val2 = val2; 110 } 111 112 public String getOp() { 113 return _op; 114 } 115 116 public void setFields(String tableName1, String columnName1, String tableName2, String columnName2) 117 { 118 _val1 = new ColumnNode(tableName1, columnName1); 119 _val2 = new ColumnNode(tableName2, columnName2); 120 } 121 122 125 public boolean isCriterion () { 126 127 return ( ! ((getVal1() instanceof ColumnNode) && (getVal2() instanceof ColumnNode))); 129 } 130 131 133 public void renameTableSpec(String oldTableSpec, String corrName) { 134 135 if (_val1 instanceof ColumnNode) 136 ((ColumnNode)_val1).renameTableSpec(oldTableSpec, corrName); 137 if (_val2 instanceof ColumnNode) 138 ((ColumnNode)_val2).renameTableSpec(oldTableSpec, corrName); 139 } 140 141 public boolean isParameterized() { 142 return (_val1.isParameterized() || _val2.isParameterized()); 143 } 144 145 } 146 | Popular Tags |