1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.List ; 24 25 public class SelectNode implements Select { 26 27 29 32 private ArrayList _selectItemList; 34 private String _quantifier; 35 36 37 39 public SelectNode() { 40 } 41 42 public SelectNode(ArrayList columnList, String quantifier) { 43 _selectItemList = columnList; 44 _quantifier = quantifier; 45 } 46 47 public SelectNode(ArrayList columnList) { 48 this(columnList, "ALL"); } 50 51 52 54 public String genText() { 55 String res = ""; String res_select_quantifier = ""; 58 if (_selectItemList.size() > 0) { 59 60 res_select_quantifier = "SELECT " + _quantifier + " " ; 61 res = res_select_quantifier 62 + ((ColumnItem)_selectItemList.get(0)).genText(true); 64 for (int i=1; i<_selectItemList.size(); i++) { 65 ColumnItem col = (ColumnItem)_selectItemList.get(i); 66 if (col != null) 67 { 68 res += ", " + "\n " + col.genText(true); } 70 } 71 } 72 return res; 73 } 74 75 76 78 public void setColumnList(ArrayList columnList) { 79 _selectItemList = columnList; 80 } 81 82 public void getReferencedColumns(Collection columns) { 83 for (int i = 0; i < _selectItemList.size(); i++) 84 columns.add(((ColumnItem)_selectItemList.get(i)).getReferencedColumn()); 85 } 86 87 public void getQueryItems(Collection items) { 88 items.add(_selectItemList); 89 } 90 91 public void addColumn(Column col) { 92 _selectItemList.add(col); 93 } 94 95 public void addColumn(String tableSpec, String columnName) { 96 _selectItemList.add(new ColumnNode(tableSpec, columnName)); 97 } 98 99 public void removeColumn(String tableSpec, String columnName) { 102 for (int i=_selectItemList.size()-1; i>=0; i--) { 103 ColumnItem item = (ColumnItem) _selectItemList.get(i); 104 ColumnNode c = (ColumnNode) item.getReferencedColumn(); 105 if ((c != null) && (c.getTableSpec().equals(tableSpec)) && (c.getColumnName().equals(columnName))) 106 { 107 _selectItemList.remove(i); 108 } 109 } 110 } 111 112 115 public void setColumnName (String oldColumnName, String newColumnName) { 116 for (int i=0; i<_selectItemList.size(); i++) { 117 ColumnNode c = (ColumnNode) _selectItemList.get(i); 118 if ( c != null) { 119 c.setColumnName(oldColumnName, newColumnName); 120 } 121 } 122 } 123 124 public boolean hasAsteriskQualifier() { 125 for (int i=0; i<_selectItemList.size(); i++) { 126 ColumnItem item = (ColumnItem) _selectItemList.get(i); 127 if (item instanceof ColumnNode) { 128 ColumnNode c = (ColumnNode) item; 129 if (c.getColumnName().equals("*")) { 130 return true; 131 } 132 } 133 } 134 return false; 135 } 136 137 140 void removeTable (String tableSpec) { 141 for (int i=_selectItemList.size()-1; i>=0; i--) { 142 ColumnItem item = (ColumnItem) _selectItemList.get(i); 143 ColumnNode c = (ColumnNode) item.getReferencedColumn(); 144 if (c != null) { 145 String tabSpec = c.getTableSpec(); 146 if (tabSpec != null && tabSpec.equals(tableSpec)) 147 _selectItemList.remove(i); 148 } 149 } 150 } 151 152 155 void renameTableSpec (String oldTableSpec, String corrName) { 156 for (int i=0; i<_selectItemList.size(); i++) { 157 ColumnItem item = (ColumnItem) _selectItemList.get(i); 158 ColumnNode c = (ColumnNode) item.getReferencedColumn(); 159 if ( c != null) 160 { 161 c.renameTableSpec(oldTableSpec, corrName); 162 } 163 } 164 } 165 166 } 167 | Popular Tags |