1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Collection ; 24 25 abstract class BooleanExpressionList implements ExpressionList { 26 protected List _expressions; 27 28 public Expression findExpression(String table1, String column1, String table2, String column2) { 30 if (_expressions != null) { 31 for (int index=0; index<_expressions.size(); index++) { 32 Expression cond = (Expression)_expressions.get(index); 33 cond = cond.findExpression(table1, column1, table2, column2); 34 if (cond != null) 35 return cond; 36 } 37 } 38 return null; 39 } 40 41 public void getReferencedColumns(Collection comlumns) { 43 if (_expressions != null) { 44 for (int index=0; index<_expressions.size(); index++) { 45 Expression expr = (Expression)_expressions.get(index); 46 expr.getReferencedColumns(comlumns); 47 } 48 } 49 } 50 51 public void getQueryItems(Collection items) { 52 if (_expressions != null) 53 items.addAll(_expressions); 54 } 55 56 public int size() { 57 if (_expressions != null) 58 return _expressions.size(); 59 return 0; 60 } 61 62 public Expression getExpression(int i) { 63 return (Expression)_expressions.get(i); 64 } 65 66 public void addExpression(Expression expression) { 67 _expressions.add(expression); 68 } 69 70 public void addExpression(int index, Expression expression) { 71 _expressions.add(index, expression); 72 } 73 74 public void replaceExpression(int index, Expression expression) { 75 _expressions.remove(index); 76 _expressions.add(index, expression); 77 } 78 79 public void removeExpression(int index) { 80 _expressions.remove(index); 81 } 82 83 public void removeTable(String tableSpec) { 84 int size = _expressions.size(); 85 for (int i = size - 1; i >= 0; i--) { 86 Expression expr = (Expression)_expressions.get(i); 87 if (expr instanceof ExpressionList) { 88 ExpressionList list = (ExpressionList)expr; 89 list.removeTable(tableSpec); 90 if (list.size() == 0) { 91 _expressions.remove(i); 94 } 95 } 96 else { 97 ArrayList column = new ArrayList (); 99 expr.getReferencedColumns(column); 100 for (int j = 0; j < column.size(); j++) { 101 Column col = (Column)column.get(j); 102 if (col.matches(tableSpec)) { 103 _expressions.remove(i); 104 break; 105 } 106 } 107 } 108 } 109 } 110 111 public boolean isParameterized() { 112 if (_expressions != null) { 113 for (int index=0; index<_expressions.size(); index++) { 114 Expression expr = (Expression)_expressions.get(index); 115 if (expr.isParameterized()) 116 return true; 117 } 118 } 119 return false; 120 } 121 122 public void renameTableSpec(String oldTableSpec, String corrName) { 123 if (_expressions != null) { 124 for (int index=0; index<_expressions.size(); index++) { 125 Expression expr = (Expression)_expressions.get(index); 126 expr.renameTableSpec(oldTableSpec, corrName); 127 } 128 } 129 } 130 131 static protected void flattenExpression(List expressionsToFlatten, Class typeToLookFor, List expressions) { 132 int size = expressionsToFlatten.size(); 133 for (int i = 0; i < size; i++) { 134 Object expr = expressionsToFlatten.get(i); 135 if (expr.getClass() == typeToLookFor) { 136 flattenExpression(((BooleanExpressionList)expr)._expressions, typeToLookFor, expressions); 137 } 138 else { 139 expressions.add(expr); 140 } 141 } 142 } 143 } 144 145 146 | Popular Tags |