1 24 25 package com.mckoi.database; 26 27 import java.util.ArrayList ; 28 import com.mckoi.util.BigNumber; 29 30 40 41 public class GTPrivMapDataSource extends GTDataSource { 42 43 46 private static int BIT_COUNT = Privileges.BIT_COUNT; 47 48 49 52 public GTPrivMapDataSource(DatabaseConnection connection) { 53 super(connection.getSystem()); 54 } 55 56 58 public DataTableDef getDataTableDef() { 59 return DEF_DATA_TABLE_DEF; 60 } 61 62 public int getRowCount() { 63 return (1 << BIT_COUNT) * BIT_COUNT; 64 } 65 66 public TObject getCellContents(final int column, final int row) { 67 int c1 = row / BIT_COUNT; 68 if (column == 0) { 69 return columnValue(column, BigNumber.fromInt(c1)); 70 } 71 else { 72 int priv_bit = (1 << (row % BIT_COUNT)); 73 String priv_string = null; 74 if ((c1 & priv_bit) != 0) { 75 priv_string = Privileges.formatPriv(priv_bit); 76 } 77 return columnValue(column, priv_string); 78 } 79 } 80 81 83 public SelectableScheme getColumnScheme(int column) { 84 if (column == 0) { 85 return new PrivMapSearch(this, column); 86 } 87 else { 88 return new BlindSearch(this, column); 89 } 90 } 91 92 94 97 static final DataTableDef DEF_DATA_TABLE_DEF; 98 99 static { 100 101 DataTableDef def = new DataTableDef(); 102 def.setTableName( 103 new TableName(Database.SYSTEM_SCHEMA, "sUSRPrivMap")); 104 105 def.addColumn(numericColumn("priv_bit")); 107 def.addColumn( stringColumn("description")); 108 109 def.setImmutable(); 111 112 DEF_DATA_TABLE_DEF = def; 113 114 } 115 116 118 122 private static final class PrivMapSearch extends CollatedBaseSearch { 123 124 PrivMapSearch(TableDataSource table, int column) { 125 super(table, column); 126 } 127 128 public SelectableScheme copy(TableDataSource table, boolean immutable) { 129 return new BlindSearch(table, getColumn()); 132 } 133 134 protected int searchFirst(TObject val) { 135 if (val.isNull()) { 136 return -1; 137 } 138 139 int num = ((BigNumber) val.getObject()).intValue(); 140 141 if (num < 0) { 142 return -1; 143 } 144 else if (num > (1 << BIT_COUNT)) { 145 return -(((1 << BIT_COUNT) * BIT_COUNT) + 1); 146 } 147 148 return (num * BIT_COUNT); 149 } 150 151 protected int searchLast(TObject val) { 152 int p = searchFirst(val); 153 if (p >= 0) { 154 return p + (BIT_COUNT - 1); 155 } 156 else { 157 return p; 158 } 159 } 160 161 } 162 163 } 164 165 | Popular Tags |