1 24 25 package com.mckoi.database; 26 27 import com.mckoi.util.Stats; 28 29 38 39 final class GTStatisticsDataSource extends GTDataSource { 40 41 44 private String [] statistics_info; 45 46 49 private Stats stats; 50 51 54 public GTStatisticsDataSource(DatabaseConnection connection) { 55 super(connection.getSystem()); 56 stats = connection.getDatabase().stats(); 57 } 58 59 62 public GTStatisticsDataSource init() { 63 64 synchronized (stats) { 65 stats.set((int) (Runtime.getRuntime().freeMemory() / 1024), 66 "Runtime.memory.freeKB"); 67 stats.set((int) (Runtime.getRuntime().totalMemory() / 1024), 68 "Runtime.memory.totalKB"); 69 70 String [] key_set = stats.keyList(); 71 int glob_length = key_set.length * 2; 72 statistics_info = new String [glob_length]; 73 74 for (int i = 0; i < glob_length; i += 2) { 75 String key_name = key_set[i / 2]; 76 statistics_info[i] = key_name; 77 statistics_info[i + 1] = stats.statString(key_name); 78 } 79 80 } 81 return this; 82 } 83 84 86 public DataTableDef getDataTableDef() { 87 return DEF_DATA_TABLE_DEF; 88 } 89 90 public int getRowCount() { 91 return statistics_info.length / 2; 92 } 93 94 public TObject getCellContents(final int column, final int row) { 95 switch (column) { 96 case 0: return columnValue(column, statistics_info[row * 2]); 98 case 1: return columnValue(column, statistics_info[(row * 2) + 1]); 100 default: 101 throw new Error ("Column out of bounds."); 102 } 103 } 104 105 107 public void dispose() { 108 super.dispose(); 109 statistics_info = null; 110 stats = null; 111 } 112 113 115 118 static final DataTableDef DEF_DATA_TABLE_DEF; 119 120 static { 121 122 DataTableDef def = new DataTableDef(); 123 def.setTableName( 124 new TableName(Database.SYSTEM_SCHEMA, "sUSRDatabaseStatistics")); 125 126 def.addColumn(stringColumn("stat_name")); 128 def.addColumn(stringColumn("value")); 129 130 def.setImmutable(); 132 133 DEF_DATA_TABLE_DEF = def; 134 135 } 136 137 } 138 | Popular Tags |