1 21 22 package org.apache.derby.impl.services.locks; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 29 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 30 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 31 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 32 33 import org.apache.derby.iapi.store.access.TransactionController; 34 35 import java.util.Hashtable ; 36 37 public class TableNameInfo { 38 39 private DataDictionary dd; 41 private Hashtable ddCache; private Hashtable tdCache; private Hashtable tableCache; private Hashtable indexCache; 46 public TableNameInfo(LanguageConnectionContext lcc, boolean andIndex) 47 throws StandardException { 48 49 tableCache = new Hashtable (31); 50 if (andIndex) 51 indexCache = new Hashtable (13); 52 53 TransactionController tc = lcc.getTransactionExecute(); 54 55 dd = lcc.getDataDictionary(); 56 ddCache = dd.hashAllConglomerateDescriptorsByNumber(tc); 57 tdCache = dd.hashAllTableDescriptorsByTableId(tc); 58 } 59 60 61 public String getTableName(Long conglomId) { 62 if (conglomId == null) 63 return "?"; 64 65 TableDescriptor td = (TableDescriptor) tableCache.get(conglomId); 67 if (td == null) 68 { 69 ConglomerateDescriptor cd = 72 (ConglomerateDescriptor)ddCache.get(conglomId); 73 74 if (cd != null) 75 { 76 79 td = (TableDescriptor) tdCache.get(cd.getTableID()); 80 } 81 82 if ((cd == null) || (td == null)) 83 { 84 String name; 85 86 if (conglomId.longValue() > 20) 92 { 93 name = "*** TRANSIENT_" + conglomId; 95 } 96 else 97 { 98 101 switch (conglomId.intValue()) 103 { 104 case 0: 105 name = "*** INVALID CONGLOMERATE ***"; 106 break; 107 108 case 1: 109 name = "ConglomerateDirectory"; 110 break; 111 112 case 2: 113 name = "PropertyConglomerate"; 114 break; 115 116 default: 117 name = "*** INTERNAL TABLE " + conglomId; 118 break; 119 } 120 } 121 122 return name; 123 } 124 125 tableCache.put(conglomId, td); 126 127 if ((indexCache != null) && cd.isIndex()) 128 indexCache.put(conglomId, cd.getConglomerateName()); 129 } 130 131 return td.getName(); 132 } 133 134 public String getTableType(Long conglomId) { 135 if (conglomId == null) 136 return "?"; 137 138 String type; 139 140 TableDescriptor td = (TableDescriptor) tableCache.get(conglomId); 141 if (td != null) 142 { 143 switch(td.getTableType()) 144 { 145 case TableDescriptor.BASE_TABLE_TYPE: 146 type = "T"; 147 break; 148 149 case TableDescriptor.SYSTEM_TABLE_TYPE: 150 type = "S"; 151 break; 152 153 default: 154 if (SanityManager.DEBUG) 155 SanityManager.THROWASSERT("Illegal table type " + 156 td.getName() + " " + td.getTableType()); 157 type = "?"; 158 break; 159 } 160 } else if (conglomId.longValue() > 20) 161 { 162 type = "T"; 163 } else { 164 type = "S"; 165 } 166 167 return type; 168 } 169 170 public String getIndexName(Long conglomId) { 171 if (conglomId == null) 172 return "?"; 173 return (String ) indexCache.get(conglomId); 174 } 175 } 176 | Popular Tags |