1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.sql.dictionary.SystemColumn; 25 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 26 import org.apache.derby.iapi.sql.dictionary.StatisticsDescriptor; 27 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 28 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 29 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory; 30 31 import org.apache.derby.iapi.error.StandardException; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 import org.apache.derby.iapi.sql.execute.ExecRow; 35 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 36 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 37 import org.apache.derby.iapi.types.TypeId; 38 import org.apache.derby.iapi.types.DataValueFactory; 39 import org.apache.derby.iapi.types.RowLocation; 40 import org.apache.derby.iapi.types.DataValueDescriptor; 41 import org.apache.derby.iapi.services.uuid.UUIDFactory; 42 import org.apache.derby.catalog.UUID; 43 import org.apache.derby.catalog.Statistics; 44 import org.apache.derby.iapi.types.*; 45 46 import java.sql.Timestamp ; 47 48 55 56 public class SYSSTATISTICSRowFactory extends CatalogRowFactory 57 { 58 static final String TABLENAME_STRING = "SYSSTATISTICS"; 59 60 61 62 64 protected static final int SYSSTATISTICS_ID = 1; 65 66 67 protected static final int SYSSTATISTICS_REFERENCEID = 2; 68 69 70 protected static final int SYSSTATISTICS_TABLEID = 3; 71 72 73 protected static final int SYSSTATISTICS_TIMESTAMP = 4; 74 75 78 protected static final int SYSSTATISTICS_TYPE = 5; 79 80 85 protected static final int SYSSTATISTICS_VALID = 6; 86 87 88 protected static final int SYSSTATISTICS_COLCOUNT = 7; 89 90 91 protected static final int SYSSTATISTICS_STAT = 8; 92 93 protected static final int SYSSTATISTICS_COLUMN_COUNT = 8; 94 95 96 protected static final int SYSSTATISTICS_INDEX1_ID = 0; 97 98 private static final boolean[] uniqueness = {false}; 99 100 private static final int[][] indexColumnPositions = 101 { 102 {SYSSTATISTICS_TABLEID, SYSSTATISTICS_REFERENCEID} 103 }; 104 105 private static final String [] uuids = 106 { 107 "f81e0010-00e3-6612-5a96-009e3a3b5e00", "08264012-00e3-6612-5a96-009e3a3b5e00", "c013800d-00e3-ffbe-37c6-009e3a3b5e00", }; 111 114 private SystemColumn[] columnList; 115 116 119 public SYSSTATISTICSRowFactory(UUIDFactory uuidf, 120 ExecutionFactory ef, 121 DataValueFactory dvf, 122 boolean convertIdToLower) 123 { 124 super(uuidf,ef,dvf,convertIdToLower); 125 126 initInfo(SYSSTATISTICS_COLUMN_COUNT, TABLENAME_STRING, 127 indexColumnPositions, uniqueness, uuids); 128 } 129 130 131 139 140 public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) 141 throws StandardException 142 { 143 String myID = null, referenceID = null, tableID = null; 144 String statName = null, colMap = null, statType = null; 145 Timestamp updateTime = null; 146 int columnCount = 0; 147 Statistics statisticsObject = null; 148 boolean validStat = false; 149 ExecRow row = getExecutionFactory().getValueRow(SYSSTATISTICS_COLUMN_COUNT); 150 151 if (td != null) 152 { 153 StatisticsDescriptor statDesc = (StatisticsDescriptor)td; 154 myID = statDesc.getUUID().toString(); 155 tableID = statDesc.getTableUUID().toString(); 156 referenceID = statDesc.getReferenceID().toString(); 157 updateTime = statDesc.getUpdateTimestamp(); 158 statType = statDesc.getStatType(); 159 validStat = statDesc.isValid(); 160 statisticsObject = statDesc.getStatistic(); 161 columnCount = statDesc.getColumnCount(); 162 } 163 164 row.setColumn(1, dvf.getCharDataValue(myID)); 165 row.setColumn(2, dvf.getCharDataValue(referenceID)); 166 row.setColumn(3, dvf.getCharDataValue(tableID)); 167 row.setColumn(4, new SQLTimestamp(updateTime)); 168 row.setColumn(5, dvf.getCharDataValue(statType)); 169 row.setColumn(6, dvf.getDataValue(validStat)); 170 row.setColumn(7, dvf.getDataValue(columnCount)); 171 row.setColumn(8, dvf.getDataValue(statisticsObject)); 172 return row; 173 } 174 175 public TupleDescriptor buildDescriptor( 176 ExecRow row, 177 TupleDescriptor parentDesc, 178 DataDictionary dd) 179 throws StandardException 180 181 { 182 if (SanityManager.DEBUG) 183 { 184 SanityManager.ASSERT( 185 row.nColumns() == SYSSTATISTICS_COLUMN_COUNT, 186 "Wrong number of columns for a SYSSTATISTICS row"); 187 } 188 189 DataValueDescriptor col; 190 String scratch; 191 UUIDFactory uuidFactory = getUUIDFactory(); 192 UUID statUUID, statReferenceUUID, statTableUUID; 193 String statName; 194 195 196 col = row.getColumn(SYSSTATISTICS_ID); 197 scratch = col.getString(); 198 statUUID = uuidFactory.recreateUUID(scratch); 199 200 201 col = row.getColumn(SYSSTATISTICS_REFERENCEID); 202 scratch = col.getString(); 203 statReferenceUUID = uuidFactory.recreateUUID(scratch); 204 205 206 col = row.getColumn(SYSSTATISTICS_TABLEID); 207 scratch = col.getString(); 208 statTableUUID = uuidFactory.recreateUUID(scratch); 209 210 211 col = row.getColumn(SYSSTATISTICS_TIMESTAMP); 212 Timestamp updateTime = (Timestamp ) col.getObject(); 213 214 215 col = row.getColumn(SYSSTATISTICS_TYPE); 216 String statType = col.getString(); 217 218 219 col = row.getColumn(SYSSTATISTICS_VALID); 220 boolean valid = col.getBoolean(); 221 222 223 col = row.getColumn(SYSSTATISTICS_COLCOUNT); 224 int columnCount = col.getInt(); 225 226 227 col = row.getColumn(SYSSTATISTICS_STAT); 228 Statistics stat = (Statistics)col.getObject(); 229 230 return new StatisticsDescriptor(dd, statUUID, statReferenceUUID, 231 statTableUUID, statType, stat, columnCount); 233 } 234 235 241 public SystemColumn[] buildColumnList() 242 { 243 if (columnList != null) 244 return columnList; 245 246 columnList = new SystemColumn[SYSSTATISTICS_COLUMN_COUNT]; 247 248 columnList[0] = new SystemColumnImpl( 249 convertIdCase( "STATID"), SYSSTATISTICS_ID, 0, 0, false, "CHAR", true, 36 ); 258 259 columnList[1] = new SystemColumnImpl( 260 convertIdCase( "REFERENCEID"), SYSSTATISTICS_REFERENCEID, 0, 0, false, "CHAR", true, 36 ); 269 270 columnList[2] = new SystemColumnImpl( 271 convertIdCase( "TABLEID"), SYSSTATISTICS_TABLEID, 0, 0, false, "CHAR", true, 36 ); 280 281 columnList[3] = 282 new SystemColumnImpl( 283 convertIdCase( "CREATIONTIMESTAMP"), SYSSTATISTICS_TIMESTAMP, 0, 0, false, "TIMESTAMP", true, TypeId.TIMESTAMP_MAXWIDTH ); 292 293 columnList[4] = 294 new SystemColumnImpl( 295 convertIdCase( "TYPE"), SYSSTATISTICS_TYPE, 0, 0, false, "CHAR", true, 1 ); 304 305 columnList[5] = 306 new SystemColumnImpl( 307 convertIdCase( "VALID"), SYSSTATISTICS_VALID, 0, 0, false, "BOOLEAN", true, 1 ); 316 317 318 columnList[6] = 319 new SystemColumnImpl( 320 convertIdCase( "COLCOUNT"), SYSSTATISTICS_COLCOUNT, 0, 0, false, "INTEGER", true, 4 ); 329 columnList[7] = 330 new SystemColumnImpl( 331 convertIdCase( "STATISTICS"), SYSSTATISTICS_STAT, 0, 0, false, "org.apache.derby.catalog.Statistics", false, 12 ); 340 341 342 343 return columnList; 344 } 345 346 347 } 348 | Popular Tags |