1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 import java.util.Collection ; 22 23 26 public class ColumnNode extends ColumnItem implements Column { 27 28 30 private TableNode _table; 31 32 private Identifier _columnName; 33 34 private Identifier _derivedColName; 36 37 39 public ColumnNode(String tableSpec, String columnName) { 42 43 String tableName=null, schemaName=null; 44 45 String [] table = tableSpec.split("\\."); 47 if (table.length>1) { 48 schemaName=table[0]; 49 tableName=table[1]; 50 } else 51 tableName=tableSpec; 52 53 _table = new TableNode(tableName, null, schemaName); 55 _columnName=new Identifier(columnName); 56 } 57 58 public ColumnNode(String tableName, String columnName, String corrName, String schemaName) { 60 _table=new TableNode(tableName, corrName, schemaName); 61 _columnName = new Identifier(columnName); 62 63 } 64 65 69 70 75 76 public ColumnNode(Table table, String columnName) { 78 _table = (TableNode)table; 79 _columnName = new Identifier(columnName); 80 } 81 82 private ColumnNode() { 84 } 85 86 public static ColumnNode make (Identifier tableName, Identifier columnName, Identifier schemaName, 90 Identifier derivedColName) 91 { 92 ColumnNode c = new ColumnNode(); 93 c._columnName = columnName; 94 c._derivedColName = derivedColName; 95 c._table= (tableName!=null) ? TableNode.make(tableName, null, schemaName) : null; 96 return c; 97 } 98 99 100 102 Column getReferencedColumn() { 103 return this; 104 } 105 106 public void getReferencedColumns(Collection columns) {} 107 public void getQueryItems(Collection items) {} 108 109 public boolean matches(String table, String column) { 110 return (table.equals(getTableSpec()) && column.equals(getColumnName())); 111 } 112 113 public boolean matches(String table) { 114 return table.equals(getTableSpec()); 115 } 116 117 public boolean equals(Column column) { 118 return column.matches(getTableSpec(), getColumnName()); 119 } 120 121 public String genText(boolean select) { 122 return 123 ( ((_table!=null) && (_table.getTableSpec()!=null)) ? 125 _table.genText(false)+ "." : "") + 128 _columnName.genText() + 130 131 ( ((select) && (_derivedColName!=null)) ? 133 " AS " + _derivedColName.genText() : ""); } 136 137 138 public String genText() { 139 return genText(false); 140 } 141 142 143 146 public void renameTableSpec(String oldTableSpec, String corrName) { 147 _table.renameTableSpec(oldTableSpec, corrName); 148 } 149 150 151 154 public void setTableSpec (String oldTableSpec, String newTableSpec) { 155 if ( _table == null ) { 156 String tableName=null, schemaName=null; 157 158 String [] table = newTableSpec.split("\\."); 160 if (table.length>1) { 161 schemaName=table[0]; 162 tableName=table[1]; 163 } else 164 tableName=newTableSpec; 165 166 _table = new TableNode(tableName, null, schemaName); 168 } 169 170 _table.setTableSpec ( oldTableSpec, newTableSpec ); 171 } 172 173 174 176 public String getColumnName() { 177 return _columnName.getName(); 178 } 179 180 public String getTableSpec() { 181 return (_table==null) ? null : _table.getTableSpec(); 182 } 183 184 public String getFullTableName() { 185 return (_table==null) ? null : _table.getFullTableName(); 186 } 187 188 public String getDerivedColName() { 189 return 190 (_derivedColName==null) ? null : _derivedColName.getName(); 191 } 192 193 public void setDerivedColName(String derivedColName) { 194 _derivedColName = 195 (derivedColName==null) ? null : new Identifier(derivedColName); 196 } 197 198 199 202 public void setColumnName (String oldColumnName, String newColumnName) { 203 if ( _columnName.getName().equals(oldColumnName) ) { 204 _columnName = new Identifier(newColumnName); 205 } 206 } 207 208 public void setColumnTableName (String tableName ) { 209 if ( _table == null ) { 210 _table = new TableNode(); 212 } 213 _table.setTableName (tableName); 214 } 215 216 public void setColumnCorrName (String corrName ) { 217 if ( _table == null ) { 218 _table = new TableNode(); 220 } 221 _table.setCorrName (corrName); 222 } 223 224 public boolean isParameterized() { 225 return false; 226 } 227 228 public Expression findExpression(String table1, String column1, String table2, String column2) { 229 return null; 230 } 231 } 232 233 234 | Popular Tags |