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 28 public class OrderByNode implements OrderBy { 29 30 32 34 ArrayList _sortSpecificationList; 35 36 37 39 public OrderByNode() { 40 } 41 42 public OrderByNode(ArrayList sortSpecificationList) { 43 _sortSpecificationList = sortSpecificationList; 44 } 45 46 47 49 public String genText() { 51 String res = ""; if (_sortSpecificationList != null && _sortSpecificationList.size() > 0) { 53 54 res = "\nORDER BY " + ((SortSpecification)_sortSpecificationList.get(0)).genText(); 56 for (int i=1; i<_sortSpecificationList.size(); i++) { 57 res += ", " + "\n " + ((SortSpecification)_sortSpecificationList.get(i)).genText(); 59 } 60 } 61 62 return res; 63 } 64 65 66 67 69 71 void renameTableSpec(String oldTableSpec, String corrName) { 72 if (_sortSpecificationList != null) { 73 for (int i=0; i<_sortSpecificationList.size(); i++) 74 ((SortSpecification)_sortSpecificationList.get(i)).renameTableSpec(oldTableSpec, corrName); 75 } 76 } 77 78 public void removeSortSpecification(String tableSpec) { 79 if (_sortSpecificationList != null) { 80 for (int i=0; i<_sortSpecificationList.size(); i++) { 81 ColumnNode col = (ColumnNode)((SortSpecification)_sortSpecificationList.get(i)).getColumn(); 82 if (col.getTableSpec().equals(tableSpec)) 83 { 84 _sortSpecificationList.remove(i); 85 i=i-1; 89 } 90 } 91 } 92 } 93 94 public void removeSortSpecification(String tableSpec, String columnName) { 95 if (_sortSpecificationList != null) { 96 for (int i=0; i<_sortSpecificationList.size(); i++) { 97 ColumnNode col = (ColumnNode)((SortSpecification)_sortSpecificationList.get(i)).getColumn(); 98 if (col.matches(tableSpec, columnName)) 99 { 100 _sortSpecificationList.remove(i); 101 i=i-1; 105 } 106 } 107 } 108 } 109 110 public void addSortSpecification(String tableSpec, String columnName, String direction, int order) { 111 SortSpecification sortSpec = new SortSpecification(new ColumnNode(tableSpec, columnName), direction); 112 if (_sortSpecificationList == null) 114 _sortSpecificationList = new ArrayList (); 115 _sortSpecificationList.add(order-1, sortSpec); 116 } 117 118 public int getSortSpecificationCount() { 119 return (_sortSpecificationList != null) ? _sortSpecificationList.size() : 0; 120 } 121 122 public SortSpecification getSortSpecification(int i) { 123 return (_sortSpecificationList != null) ? ((SortSpecification)_sortSpecificationList.get(i)) : null; 124 } 125 126 public void getReferencedColumns (Collection columns) { 127 if (_sortSpecificationList != null) { 128 for (int i = 0; i < _sortSpecificationList.size(); i++) 129 ((SortSpecification)_sortSpecificationList.get(i)).getReferencedColumns(columns); 130 } 131 } 132 133 public void getQueryItems(Collection items) { 134 if (_sortSpecificationList != null) 135 items.addAll(_sortSpecificationList); 136 } 137 } 138 | Popular Tags |