All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mckoi.database.GTPrivMapDataSource Maven / Gradle / Ivy

Go to download

A full SQL database system with JDBC driver that can be embedded in a Java application or operate as a stand-alone server with clients connecting via TCP/IP.

The newest version!
/**
 * com.mckoi.database.GTPrivMapDataSource  26 Aug 2002
 *
 * Mckoi SQL Database ( http://www.mckoi.com/database )
 * Copyright (C) 2000, 2001, 2002  Diehl and Associates, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * Version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 2 for more details.
 *
 * You should have received a copy of the GNU General Public License
 * Version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Change Log:
 * 
 * 
 */

package com.mckoi.database;

import java.util.ArrayList;
import com.mckoi.util.BigNumber;

/**
 * A GTDataSource that maps a Privs 11-bit set to strings that represent the
 * priv in human understandable string.  Each 11-bit priv set contains 12
 * entries for each bit that was set.
 * 

* This table provides a convenient way to join the system grant table and * 'expand' the privs that are allowed though it. * * @author Tobias Downer */ public class GTPrivMapDataSource extends GTDataSource { /** * Number of bits. */ private static int BIT_COUNT = Privileges.BIT_COUNT; /** * Constructor. */ public GTPrivMapDataSource(DatabaseConnection connection) { super(connection.getSystem()); } // ---------- Implemented from GTDataSource ---------- public DataTableDef getDataTableDef() { return DEF_DATA_TABLE_DEF; } public int getRowCount() { return (1 << BIT_COUNT) * BIT_COUNT; } public TObject getCellContents(final int column, final int row) { int c1 = row / BIT_COUNT; if (column == 0) { return columnValue(column, BigNumber.fromInt(c1)); } else { int priv_bit = (1 << (row % BIT_COUNT)); String priv_string = null; if ((c1 & priv_bit) != 0) { priv_string = Privileges.formatPriv(priv_bit); } return columnValue(column, priv_string); } } // ---------- Overwritten from GTDataSource ---------- public SelectableScheme getColumnScheme(int column) { if (column == 0) { return new PrivMapSearch(this, column); } else { return new BlindSearch(this, column); } } // ---------- Static ---------- /** * The data table def that describes this table of data source. */ static final DataTableDef DEF_DATA_TABLE_DEF; static { DataTableDef def = new DataTableDef(); def.setTableName( new TableName(Database.SYSTEM_SCHEMA, "sUSRPrivMap")); // Add column definitions def.addColumn(numericColumn("priv_bit")); def.addColumn( stringColumn("description")); // Set to immutable def.setImmutable(); DEF_DATA_TABLE_DEF = def; } // ---------- Inner classes ---------- /** * A SelectableScheme that makes searching on the 'priv_bit' column a lot * less painless! */ private static final class PrivMapSearch extends CollatedBaseSearch { PrivMapSearch(TableDataSource table, int column) { super(table, column); } public SelectableScheme copy(TableDataSource table, boolean immutable) { // Return a fresh object. This implementation has no state so we can // ignore the 'immutable' flag. return new BlindSearch(table, getColumn()); } protected int searchFirst(TObject val) { if (val.isNull()) { return -1; } int num = ((BigNumber) val.getObject()).intValue(); if (num < 0) { return -1; } else if (num > (1 << BIT_COUNT)) { return -(((1 << BIT_COUNT) * BIT_COUNT) + 1); } return (num * BIT_COUNT); } protected int searchLast(TObject val) { int p = searchFirst(val); if (p >= 0) { return p + (BIT_COUNT - 1); } else { return p; } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy