1 24 25 package com.mckoi.database; 26 27 import java.util.ArrayList ; 28 import java.util.Date ; 29 30 39 40 final class GTCurrentConnectionsDataSource extends GTDataSource { 41 42 46 private DatabaseConnection database; 47 48 51 private ArrayList key_value_pairs; 52 53 56 public GTCurrentConnectionsDataSource(DatabaseConnection connection) { 57 super(connection.getSystem()); 58 this.database = connection; 59 this.key_value_pairs = new ArrayList (); 60 } 61 62 65 public GTCurrentConnectionsDataSource init() { 66 67 UserManager user_manager = database.getDatabase().getUserManager(); 68 synchronized (user_manager) { 70 for (int i = 0; i < user_manager.userCount(); ++i) { 71 User user = user_manager.userAt(i); 72 key_value_pairs.add(user.getUserName()); 73 key_value_pairs.add(user.getConnectionString()); 74 key_value_pairs.add(new Date (user.getLastCommandTime())); 75 key_value_pairs.add(new Date (user.getTimeConnected())); 76 } 77 } 78 79 return this; 80 } 81 82 84 public DataTableDef getDataTableDef() { 85 return DEF_DATA_TABLE_DEF; 86 } 87 88 public int getRowCount() { 89 return key_value_pairs.size() / 4; 90 } 91 92 public TObject getCellContents(final int column, final int row) { 93 switch (column) { 94 case 0: return columnValue(column, (String ) key_value_pairs.get(row * 4)); 96 case 1: return columnValue(column, (String ) key_value_pairs.get((row * 4) + 1)); 98 case 2: return columnValue(column, (Date ) key_value_pairs.get((row * 4) + 2)); 100 case 3: return columnValue(column, (Date ) key_value_pairs.get((row * 4) + 3)); 102 default: 103 throw new Error ("Column out of bounds."); 104 } 105 } 106 107 109 public void dispose() { 110 super.dispose(); 111 key_value_pairs = null; 112 database = null; 113 } 114 115 117 120 static final DataTableDef DEF_DATA_TABLE_DEF; 121 122 static { 123 124 DataTableDef def = new DataTableDef(); 125 def.setTableName( 126 new TableName(Database.SYSTEM_SCHEMA, "sUSRCurrentConnections")); 127 128 def.addColumn(stringColumn("username")); 130 def.addColumn(stringColumn("host_string")); 131 def.addColumn(dateColumn("last_command")); 132 def.addColumn(dateColumn("time_connected")); 133 134 def.setImmutable(); 136 137 DEF_DATA_TABLE_DEF = def; 138 139 } 140 141 } 142 | Popular Tags |