1 19 package org.netbeans.modules.db.sql.visualeditor.querymodel; 20 21 22 import java.util.Collection ; 23 24 27 public class TableNode implements Table { 28 29 31 private Identifier _tableName; 32 33 private Identifier _corrName; 34 35 private Identifier _schemaName; 36 37 38 40 public TableNode(String tableName, String corrName, String schemaName) { 41 _tableName = new Identifier(tableName); 42 _corrName = corrName==null ? null : new Identifier(corrName); 43 _schemaName = schemaName==null ? null : new Identifier(schemaName); 44 } 45 46 public TableNode(String tableName, String corrName) { 47 this(tableName, corrName, null); 48 } 49 50 public TableNode(String tableName) { 51 this(tableName, null, null); 52 } 53 54 public TableNode() { 55 } 56 57 public static TableNode make(Identifier tableName, Identifier corrName, Identifier schemaName) { 60 TableNode t = new TableNode(); 61 t._tableName = tableName; 62 t._corrName = corrName; 63 t._schemaName = schemaName; 64 return t; 65 } 66 67 68 public String genText() { 70 return genText(false); 71 } 72 73 public String genText(boolean from) { 78 if (from) return 80 ((_schemaName==null) ? "" : _schemaName.genText()+".") + _tableName.genText() + 82 ((_corrName==null) ? "" : " " + _corrName.genText()); else return 86 ((_corrName!=null) 87 ? _corrName.genText() 88 : ((_schemaName==null) ? "" : _schemaName.genText()+".") + _tableName.genText()); 90 } 91 92 93 95 public String getTableName() { 96 return _tableName.getName(); 97 } 98 99 public String getFullTableName() { 100 return 101 ((_schemaName==null) ? "" : _schemaName.getName()+".") + _tableName.getName(); 103 } 104 105 public String getCorrName() { 106 return (_corrName==null) ? null : _corrName.getName(); 107 } 108 109 public String getSchemaName() { 110 return (_schemaName==null) ? null : _schemaName.getName(); 111 } 112 113 public String getTableSpec() { 114 return (_corrName!=null) ? 115 _corrName.getName() : 116 getFullTableName(); 117 } 118 119 public void renameTableSpec(String oldTableSpec, String corrName) { 121 if (oldTableSpec == null) { 123 String [] table = corrName.split("\\."); if (table.length>1) { 125 _schemaName= new Identifier(table[0]); 126 _tableName = new Identifier(table[1]); 127 } else 128 _tableName= new Identifier(table[0]); 129 } 130 else if (getTableSpec().equals(oldTableSpec)) 131 _corrName=(corrName==null) ? null : new Identifier(corrName); 132 } 133 134 void setTableName (String tableName) { 135 String [] table = tableName.split("\\."); if (table.length>1) { 137 _schemaName= new Identifier(table[0]); 138 _tableName = new Identifier(table[1]); 139 } else 140 _tableName=new Identifier(table[0]); 141 } 142 143 void setCorrName (String corrName) { 144 _corrName=new Identifier(corrName); 145 } 146 147 void setTableSpec(String oldTableSpec, String newTableSpec) { 148 if (getTableSpec().equals(oldTableSpec)) { 149 String [] table = newTableSpec.split("\\."); if (table.length>1) { 151 _schemaName= new Identifier(table[0]); 152 _tableName = new Identifier(table[1]); 153 } else 154 _tableName=new Identifier(table[0]); 155 } 156 157 } 158 159 public void getReferencedColumns(Collection columns) {} 160 public void getQueryItems(Collection items) {} 161 } 162 | Popular Tags |