use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.
the class DatabaseInformationFull method USAGE_PRIVILEGES.
/**
* The USAGE_PRIVILEGES view has one row for each usage privilege
* descriptor. <p>
*
* It effectively contains a representation of the usage privilege
* descriptors. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SYSTEM_USAGE_PRIVILEGES (
* GRANTOR VARCHAR NOT NULL,
* GRANTEE VARCHAR NOT NULL,
* OBJECT_CATALOG VARCHAR NULL,
* OBJECT_SCHEMA VARCHAR NULL,
* OBJECT_NAME VARCHAR NOT NULL,
* OBJECT_TYPE VARCHAR NOT NULL
*
* CHECK ( OBJECT_TYPE IN (
* 'DOMAIN',
* 'CHARACTER SET',
* 'COLLATION',
* 'TRANSLATION',
* 'SEQUENCE' ) ),
*
* IS_GRANTABLE VARCHAR NOT NULL
*
* CHECK ( IS_GRANTABLE IN ( 'YES', 'NO' ) ),
*
* UNIQUE( GRANTOR, GRANTEE, OBJECT_CATALOG,
* OBJECT_SCHEMA, OBJECT_NAME, OBJECT_TYPE )
* )
* </pre>
*
* <b>Description:</b><p>
*
* <ol>
* <li> The value of GRANTOR is the <authorization identifier> of the
* user or role who granted usage privileges on the object of the type
* identified by OBJECT_TYPE that is identified by OBJECT_CATALOG,
* OBJECT_SCHEMA, and OBJECT_NAME, to the user or role identified by the
* value of GRANTEE forthe usage privilege being described. <p>
*
* <li> The value of GRANTEE is the <authorization identifier> of some
* user or role, or PUBLIC to indicate all users, to whom the usage
* privilege being described is granted. <p>
*
* <li> The values of OBJECT_CATALOG, OBJECT_SCHEMA, and OBJECT_NAME are the
* catalog name, unqualified schema name, and qualified identifier,
* respectively, of the object to which the privilege applies. <p>
*
* <li> The values of OBJECT_TYPE have the following meanings: <p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>DOMAIN</td>
* <td nowrap>The object to which the privilege applies is
* a domain.</td>
* <tr>
* <tr>
* <td nowrap>CHARACTER SET</td>
* <td nowrap>The object to which the privilege applies is a
* character set.</td>
* <tr>
* <tr>
* <td nowrap>COLLATION</td>
* <td nowrap>The object to which the privilege applies is a
* collation.</td>
* <tr>
* <tr>
* <td nowrap>TRANSLATION</td>
* <td nowrap>The object to which the privilege applies is a
* transliteration.</td>
* <tr>
* <tr>
* <td nowrap>SEQUENCE</td>
* <td nowrap>The object to which the privilege applies is a
* sequence generator.</td>
* <tr>
* </table> <p>
*
* <li> The values of IS_GRANTABLE have the following meanings: <p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>YES</td>
* <td nowrap>The privilege being described was granted
* WITH GRANT OPTION and is thus grantable.</td>
* <tr>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The privilege being described was not granted
* WITH GRANT OPTION and is thus not grantable.</td>
* <tr>
* </table> <p>
* <ol>
*
* @return Table
*/
Table USAGE_PRIVILEGES() {
Table t = sysTables[USAGE_PRIVILEGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[USAGE_PRIVILEGES]);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
addColumn(t, "OBJECT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "OBJECT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "OBJECT_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "OBJECT_TYPE", CHARACTER_DATA);
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
// order: COLUMN_NAME, PRIVILEGE
// for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEM, TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[USAGE_PRIVILEGES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, false);
return t;
}
//
Object[] row;
//
final int grantor = 0;
final int grantee = 1;
final int object_catalog = 2;
final int object_schema = 3;
final int object_name = 4;
final int object_type = 5;
final int privilege_type = 6;
final int is_grantable = 7;
PersistentStore store = database.persistentStoreCollection.getStore(t);
Iterator objects = new WrapperIterator(database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE), database.schemaManager.databaseObjectIterator(SchemaObject.COLLATION));
objects = new WrapperIterator(objects, database.schemaManager.databaseObjectIterator(SchemaObject.CHARSET));
objects = new WrapperIterator(objects, database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN));
/*
objects = new WrapperIterator(
objects,
database.schemaManager.databaseObjectIterator(SchemaObject.TYPE));
*/
OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
while (objects.hasNext()) {
SchemaObject object = (SchemaObject) objects.next();
for (int i = 0; i < grantees.size(); i++) {
Grantee granteeObject = (Grantee) grantees.get(i);
OrderedHashSet rights = granteeObject.getAllDirectPrivileges(object);
OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(object);
if (!grants.isEmpty()) {
grants.addAll(rights);
rights = grants;
}
for (int j = 0; j < rights.size(); j++) {
Right right = (Right) rights.get(j);
Right grantableRight = right.getGrantableRights();
row = t.getEmptyRowData();
row[grantor] = right.getGrantor().getName().name;
row[grantee] = right.getGrantee().getName().name;
row[object_catalog] = database.getCatalogName().name;
row[object_schema] = object.getSchemaName().name;
row[object_name] = object.getName().name;
row[object_type] = SchemaObjectSet.getName(object.getName().type);
row[privilege_type] = Tokens.T_USAGE;
row[is_grantable] = right.getGrantee() == object.getOwner() || grantableRight.isFull() ? Tokens.T_YES : Tokens.T_NO;
;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.
the class DatabaseInformationFull method PARAMETERS.
Table PARAMETERS() {
Table t = sysTables[PARAMETERS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[PARAMETERS]);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
addColumn(t, "IS_RESULT", YES_OR_NO);
addColumn(t, "AS_LOCATOR", YES_OR_NO);
addColumn(t, "PARAMETER_NAME", SQL_IDENTIFIER);
//
addColumn(t, "FROM_SQL_SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "FROM_SQL_SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "FROM_SQL_SPECIFIC_NAME", SQL_IDENTIFIER);
//
addColumn(t, "TO_SQL_SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TO_SQL_SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TO_SQL_SPECIFIC_NAME", SQL_IDENTIFIER);
//
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", CHARACTER_DATA);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
// NULL
addColumn(t, "MAXIMUM_CARDINALITY", CARDINAL_NUMBER);
addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[PARAMETERS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// column number mappings
final int specific_cat = 0;
final int specific_schem = 1;
final int specific_name = 2;
final int ordinal_position = 3;
final int is_result = 4;
final int as_locator = 5;
final int parameter_name = 6;
final int from_specific_catalog = 7;
final int from_specific_schema = 8;
final int from_specific_name = 9;
final int to_specific_catalog = 10;
final int to_specific_schema = 11;
final int to_specific_name = 12;
final int data_type = 13;
final int character_maximum_length = 14;
final int character_octet_length = 15;
final int character_set_catalog = 16;
final int character_set_schema = 17;
final int character_set_name = 18;
final int collation_catalog = 19;
final int collation_schema = 20;
final int collation_name = 21;
final int numeric_precision = 22;
final int numeric_precision_radix = 23;
final int numeric_scale = 24;
final int datetime_precision = 25;
final int interval_type = 26;
final int interval_precision = 27;
final int udt_catalog = 28;
final int udt_schema = 29;
final int udt_name = 30;
final int scope_catalog = 31;
final int scope_schema = 32;
final int scope_name = 33;
final int maximum_cardinality = 34;
final int dtd_identifier = 35;
final int declared_data_type = 36;
final int declared_numeric_precision = 37;
final int declared_numeric_scale = 38;
return t;
}
use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_USERS.
/**
* Retrieves a <code>Table</code> object describing the
* visible <code>Users</code> defined within this database.
* @return table containing information about the users defined within
* this database
*/
Table SYSTEM_USERS() {
Table t = sysTables[SYSTEM_USERS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_USERS]);
addColumn(t, "USER_NAME", SQL_IDENTIFIER);
addColumn(t, "ADMIN", Type.SQL_BOOLEAN);
addColumn(t, "INITIAL_SCHEMA", SQL_IDENTIFIER);
// order: USER
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_USERS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, true);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
HsqlArrayList users;
User user;
Object[] row;
HsqlName initialSchema;
// Initialization
users = database.getUserManager().listVisibleUsers(session);
// Do it.
for (int i = 0; i < users.size(); i++) {
row = t.getEmptyRowData();
user = (User) users.get(i);
initialSchema = user.getInitialSchema();
row[0] = user.getNameString();
row[1] = ValuePool.getBoolean(user.isAdmin());
row[2] = ((initialSchema == null) ? null : initialSchema.name);
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.
the class DatabaseInformationMain method init.
/**
* One time initialisation of instance attributes
* at construction time. <p>
*
*/
protected final void init() {
ns = new DINameSpace(database);
pi = new DIProcedureInfo(ns);
// flag the Session-dependent cached tables
Table t;
for (int i = 0; i < sysTables.length; i++) {
t = sysTables[i] = generateTable(i);
if (t != null) {
t.setDataReadOnly(true);
}
}
GranteeManager gm = database.getGranteeManager();
Right right = new Right();
right.set(GrantConstants.SELECT, null);
for (int i = 0; i < sysTableHsqlNames.length; i++) {
if (sysTables[i] != null) {
gm.grantSystemToPublic(sysTables[i], right);
}
}
right = Right.fullRights;
gm.grantSystemToPublic(SqlInvariants.YES_OR_NO, right);
gm.grantSystemToPublic(SqlInvariants.TIME_STAMP, right);
gm.grantSystemToPublic(SqlInvariants.CARDINAL_NUMBER, right);
gm.grantSystemToPublic(SqlInvariants.CHARACTER_DATA, right);
gm.grantSystemToPublic(SqlInvariants.SQL_CHARACTER, right);
gm.grantSystemToPublic(SqlInvariants.SQL_IDENTIFIER_CHARSET, right);
gm.grantSystemToPublic(SqlInvariants.SQL_IDENTIFIER, right);
gm.grantSystemToPublic(SqlInvariants.SQL_TEXT, right);
}
use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.
the class DatabaseInformationMain method SEQUENCES.
/**
* The SEQUENCES view has one row for each external sequence
* generator. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
*
* SEQUENCE_CATALOG VARCHAR NULL,
* SEQUENCE_SCHEMA VARCHAR NULL,
* SEQUENCE_NAME VARCHAR NOT NULL,
* DATA_TYPE CHARACTER_DATA
* DATA_TYPE CHARACTER_DATA
* NUMERIC_PRECISION CARDINAL_NUMBER
* NUMERIC_PRECISION_RADIX CARDINAL_NUMBER
* NUMERIC_SCALE CARDINAL_NUMBER
* MAXIMUM_VALUE VARCHAR NOT NULL,
* MINIMUM_VALUE VARCHAR NOT NULL,
* INCREMENT VARCHAR NOT NULL,
* CYCLE_OPTION VARCHAR {'YES', 'NO'},
* START_WITH VARCHAR NOT NULL,
* DECLARED_DATA_TYPE CHARACTER_DATA
* DECLARED_NUMERIC_PRECISION CARDINAL_NUMBER
* DECLARED_NUMERIC_SCLAE CARDINAL_NUMBER
*
* </pre>
*
* <b>DESCRIPTION:</b><p>
*
* <ol>
* <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, and
* SEQUENCE_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the sequence generator
* being described. <p>
*
* <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME, and
* DTD_IDENTIFIER are the values of OBJECT_CATALOG, OBJECT_SCHEMA,
* OBJECT_NAME, and DTD_IDENTIFIER, respectively, of the row in
* DATA_TYPE_DESCRIPTOR (not yet implemented) that describes the data
* type of the sequence generator. <p>
*
* <li> The values of MAXIMUM_VALUE, MINIMUM_VALUE, and INCREMENT are the
* character representations of maximum value, minimum value,
* and increment, respectively, of the sequence generator being
* described. <p>
*
* <li> The values of CYCLE_OPTION have the following meanings: <p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>YES</td>
* <td nowrap>The cycle option of the sequence generator
* is CYCLE.</td>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The cycle option of the sequence generator is
* NO CYCLE.</td>
* </tr>
* </table> <p>
*
* <li> The value of START_WITH is HSQLDB-specific (not in the SQL 200n
* spec). <p>
*
* It is the character representation of the START WITH value. <p>
*
* <li> The value of NEXT_VALUE is HSQLDB-specific (not in the SQL 200n)<p>
* This is the character representation of the value that
* would be generated by NEXT VALUE FOR when this sequence
* is materialized in an SQL statement. <p>
* </ol>
*
* @return Table
*/
final Table SEQUENCES() {
Table t = sysTables[SEQUENCES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SEQUENCES]);
addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "MAXIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "MINIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "INCREMENT", CHARACTER_DATA);
addColumn(t, "CYCLE_OPTION", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
// HSQLDB-specific
addColumn(t, "START_WITH", CHARACTER_DATA);
addColumn(t, "NEXT_VALUE", CHARACTER_DATA);
// order SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME
// false PK, as CATALOG may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SEQUENCES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
//
final int sequence_catalog = 0;
final int sequence_schema = 1;
final int sequence_name = 2;
final int data_type = 3;
final int numeric_precision = 4;
final int numeric_precision_radix = 5;
final int numeric_scale = 6;
final int maximum_value = 7;
final int minimum_value = 8;
final int increment = 9;
final int cycle_option = 10;
final int declared_data_type = 11;
final int declared_numeric_precision = 12;
final int declared_numeric_scale = 13;
final int start_with = 14;
final int next_value = 15;
//
Iterator it;
Object[] row;
NumberSequence sequence;
it = database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE);
while (it.hasNext()) {
sequence = (NumberSequence) it.next();
if (!session.getGrantee().isAccessible(sequence)) {
continue;
}
row = t.getEmptyRowData();
NumberType type = (NumberType) sequence.getDataType();
int radix = (type.typeCode == Types.SQL_NUMERIC || type.typeCode == Types.SQL_DECIMAL) ? 10 : 2;
row[sequence_catalog] = database.getCatalogName().name;
row[sequence_schema] = sequence.getSchemaName().name;
row[sequence_name] = sequence.getName().name;
row[data_type] = sequence.getDataType().getFullNameString();
row[numeric_precision] = ValuePool.getInt((int) type.getPrecision());
row[numeric_precision_radix] = ValuePool.getInt(radix);
row[numeric_scale] = ValuePool.INTEGER_0;
row[maximum_value] = String.valueOf(sequence.getMaxValue());
row[minimum_value] = String.valueOf(sequence.getMinValue());
row[increment] = String.valueOf(sequence.getIncrement());
row[cycle_option] = sequence.isCycle() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[declared_numeric_scale];
row[start_with] = String.valueOf(sequence.getStartValue());
row[next_value] = String.valueOf(sequence.peek());
t.insertSys(store, row);
}
return t;
}
Aggregations