use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class DatabaseInformationFull method SCHEMATA.
/**
* SCHEMATA<p>
*
* <b>Function</b><p>
*
* The SCHEMATA view has one row for each accessible schema. <p>
*
* <b>Definition</b><p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SCHEMATA (
* CATALOG_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* SCHEMA_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* SCHEMA_OWNER INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT SCHEMA_OWNER_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_CATALOG_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_SCHEMA_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_NAME_NOT_NULL
* NOT NULL,
* SQL_PATH INFORMATION_SCHEMA.CHARACTER_DATA,
*
* CONSTRAINT SCHEMATA_PRIMARY_KEY
* PRIMARY KEY ( CATALOG_NAME, SCHEMA_NAME ),
* CONSTRAINT SCHEMATA_FOREIGN_KEY_AUTHORIZATIONS
* FOREIGN KEY ( SCHEMA_OWNER )
* REFERENCES AUTHORIZATIONS,
* CONSTRAINT SCHEMATA_FOREIGN_KEY_CATALOG_NAMES
* FOREIGN KEY ( CATALOG_NAME )
* REFERENCES CATALOG_NAMES
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li>The value of CATALOG_NAME is the name of the catalog of the
* schema described by this row.<p>
*
* <li>The value of SCHEMA_NAME is the unqualified schema name of
* the schema described by this row.<p>
*
* <li>The values of SCHEMA_OWNER are the authorization identifiers
* that own the schemata.<p>
*
* <li>The values of DEFAULT_CHARACTER_SET_CATALOG,
* DEFAULT_CHARACTER_SET_SCHEMA, and DEFAULT_CHARACTER_SET_NAME
* are the catalog name, unqualified schema name, and qualified
* identifier, respectively, of the default character set for
* columns and domains in the schemata.<p>
*
* <li>Case:<p>
* <ul>
* <li>If <schema path specification> was specified in
* the <schema definition> that defined the schema
* described by this row and the character representation
* of the <schema path specification> can be
* represented without truncation, then the value of
* SQL_PATH is that character representation.<p>
*
* <li>Otherwise, the value of SQL_PATH is the null value.
* </ul>
* </ol>
*
* @return Table
*/
Table SCHEMATA() {
Table t = sysTables[SCHEMATA];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SCHEMATA]);
addColumn(t, "CATALOG_NAME", SQL_IDENTIFIER);
addColumn(t, "SCHEMA_NAME", SQL_IDENTIFIER);
addColumn(t, "SCHEMA_OWNER", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "SQL_PATH", CHARACTER_DATA);
// order: CATALOG_NAME, SCHEMA_NAME
// false PK, as rows may have NULL CATALOG_NAME
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SCHEMATA].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
Iterator schemas;
String schema;
String dcsSchema = SqlInvariants.INFORMATION_SCHEMA;
String dcsName = ValuePool.getString("UTF16");
String sqlPath = null;
Grantee user = session.getGrantee();
Object[] row;
// column number mappings
final int schema_catalog = 0;
final int schema_name = 1;
final int schema_owner = 2;
final int default_character_set_catalog = 3;
final int default_character_set_schema = 4;
final int default_character_set_name = 5;
final int sql_path = 6;
// Initialization
schemas = database.schemaManager.fullSchemaNamesIterator();
// Do it.
while (schemas.hasNext()) {
schema = (String) schemas.next();
if (!user.hasSchemaUpdateOrGrantRights(schema)) {
continue;
}
row = t.getEmptyRowData();
row[schema_catalog] = database.getCatalogName().name;
row[schema_name] = schema;
row[schema_owner] = database.schemaManager.toSchemaOwner(schema).getNameString();
row[default_character_set_catalog] = database.getCatalogName().name;
row[default_character_set_schema] = dcsSchema;
row[default_character_set_name] = dcsName;
row[sql_path] = sqlPath;
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class DatabaseInformationFull method ROLE_AUTHORIZATION_DESCRIPTORS.
//------------------------------------------------------------------------------
// SQL SCHEMATA BASE TABLES
/**
* ROLE_AUTHORIZATION_DESCRIPTORS<p>
*
* <b>Function</b><p>
*
* Contains a representation of the role authorization descriptors.<p>
* <b>Definition</b>
*
* <pre class="SqlCodeExample">
* CREATE TABLE ROLE_AUTHORIZATION_DESCRIPTORS (
* ROLE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* GRANTEE INFORMATION_SCHEMA.SQL_IDENTIFIER,
* GRANTOR INFORMATION_SCHEMA.SQL_IDENTIFIER,
* IS_GRANTABLE INFORMATION_SCHEMA.CHARACTER_DATA
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_IS_GRANTABLE_CHECK
* CHECK ( IS_GRANTABLE IN
* ( 'YES', 'NO' ) ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_PRIMARY_KEY
* PRIMARY KEY ( ROLE_NAME, GRANTEE ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_CHECK_ROLE_NAME
* CHECK ( ROLE_NAME IN
* ( SELECT AUTHORIZATION_NAME
* FROM AUTHORIZATIONS
* WHERE AUTHORIZATION_TYPE = 'ROLE' ) ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTOR
* FOREIGN KEY ( GRANTOR )
* REFERENCES AUTHORIZATIONS,
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTEE
* FOREIGN KEY ( GRANTEE )
* REFERENCES AUTHORIZATIONS
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li>The value of ROLE_NAME is the <role name> of some
* <role granted> by the <grant role statement> or
* the <role name> of a <role definition>. <p>
*
* <li>The value of GRANTEE is an <authorization identifier>,
* possibly PUBLIC, or <role name> specified as a
* <grantee> contained in a <grant role statement>,
* or the <authorization identifier> of the current
* SQLsession when the <role definition> is executed. <p>
*
* <li>The value of GRANTOR is the <authorization identifier>
* of the user or role who granted the role identified by
* ROLE_NAME to the user or role identified by the value of
* GRANTEE. <p>
*
* <li>The values of IS_GRANTABLE have the following meanings:<p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>YES</td>
* <td nowrap>The described role is grantable.</td>
* <tr>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The described role is not grantable.</td>
* <tr>
* </table> <p>
* </ol>
*
* @return Table
*/
Table ROLE_AUTHORIZATION_DESCRIPTORS() {
Table t = sysTables[ROLE_AUTHORIZATION_DESCRIPTORS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS]);
// not null
addColumn(t, "ROLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1 }, true);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
String grantorName = SqlInvariants.SYSTEM_AUTHORIZATION_NAME;
Iterator grantees;
Grantee granteeObject;
String granteeName;
Iterator roles;
String roleName;
String isGrantable;
Object[] row;
// Column number mappings
final int role_name = 0;
final int grantee = 1;
final int grantor = 2;
final int is_grantable = 3;
// Initialization
grantees = session.getGrantee().visibleGrantees().iterator();
//
while (grantees.hasNext()) {
granteeObject = (Grantee) grantees.next();
granteeName = granteeObject.getNameString();
roles = granteeObject.getDirectRoles().iterator();
isGrantable = granteeObject.isAdmin() ? Tokens.T_YES : Tokens.T_NO;
;
while (roles.hasNext()) {
Grantee role = (Grantee) roles.next();
row = t.getEmptyRowData();
row[role_name] = role.getNameString();
row[grantee] = granteeName;
row[grantor] = grantorName;
row[is_grantable] = isGrantable;
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class DatabaseInformationFull method AUTHORIZATIONS.
/**
* SYSTEM_AUTHORIZATIONS<p>
*
* <b>Function</b><p>
*
* The AUTHORIZATIONS table has one row for each <role name> and
* one row for each <authorization identifier > referenced in the
* Information Schema. These are the <role name>s and
* <authorization identifier>s that may grant privileges as well as
* those that may create a schema, or currently own a schema created
* through a <schema definition>. <p>
*
* <b>Definition</b><p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE AUTHORIZATIONS (
* AUTHORIZATION_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* AUTHORIZATION_TYPE INFORMATION_SCHEMA.CHARACTER_DATA
* CONSTRAINT AUTHORIZATIONS_AUTHORIZATION_TYPE_NOT_NULL
* NOT NULL
* CONSTRAINT AUTHORIZATIONS_AUTHORIZATION_TYPE_CHECK
* CHECK ( AUTHORIZATION_TYPE IN ( 'USER', 'ROLE' ) ),
* CONSTRAINT AUTHORIZATIONS_PRIMARY_KEY
* PRIMARY KEY (AUTHORIZATION_NAME)
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li> The values of AUTHORIZATION_TYPE have the following meanings:<p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>USER</td>
* <td nowrap>The value of AUTHORIZATION_NAME is a known
* <user identifier>.</td>
* <tr>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The value of AUTHORIZATION_NAME is a <role
* name> defined by a <role definition>.</td>
* <tr>
* </table> <p>
* </ol>
*
* @return Table
*/
Table AUTHORIZATIONS() {
Table t = sysTables[AUTHORIZATIONS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[AUTHORIZATIONS]);
// not null
addColumn(t, "AUTHORIZATION_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "AUTHORIZATION_TYPE", SQL_IDENTIFIER);
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[AUTHORIZATIONS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, true);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
Iterator grantees;
Grantee grantee;
Object[] row;
// initialization
grantees = session.getGrantee().visibleGrantees().iterator();
// Do it.
while (grantees.hasNext()) {
grantee = (Grantee) grantees.next();
row = t.getEmptyRowData();
row[0] = grantee.getNameString();
row[1] = grantee.isRole() ? "ROLE" : "USER";
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class DatabaseInformationFull method ROUTINE_PRIVILEGES.
Table ROUTINE_PRIVILEGES() {
Table t = sysTables[ROUTINE_PRIVILEGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROUTINE_PRIVILEGES]);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
//
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_PRIVILEGES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false);
return t;
}
// column number mappings
final int grantor = 0;
final int grantee = 1;
final int specific_catalog = 2;
final int specific_schema = 3;
final int specific_name = 4;
final int routine_catalog = 5;
final int routine_schema = 6;
final int routine_name = 7;
final int privilege_type = 8;
final int is_grantable = 9;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
Grantee granteeObject;
String privilege;
// intermediate holders
Iterator routines;
RoutineSchema routine;
Object[] row;
OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
routines = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
while (routines.hasNext()) {
routine = (RoutineSchema) routines.next();
for (int i = 0; i < grantees.size(); i++) {
granteeObject = (Grantee) grantees.get(i);
OrderedHashSet rights = granteeObject.getAllDirectPrivileges(routine);
OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(routine);
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();
for (int k = 0; k < Right.privilegeTypes.length; k++) {
if (!right.canAccess(Right.privilegeTypes[k])) {
continue;
}
Routine[] specifics = routine.getSpecificRoutines();
for (int m = 0; m < specifics.length; m++) {
privilege = Right.privilegeNames[k];
row = t.getEmptyRowData();
//
row[grantor] = right.getGrantor().getName().name;
row[grantee] = right.getGrantee().getName().name;
row[specific_catalog] = database.getCatalogName().name;
row[specific_schema] = specifics[m].getSchemaName().name;
row[specific_name] = specifics[m].getName().name;
row[routine_catalog] = database.getCatalogName().name;
row[routine_schema] = routine.getSchemaName().name;
row[routine_name] = routine.getName().name;
row[privilege_type] = privilege;
row[is_grantable] = right.getGrantee() == routine.getOwner() || grantableRight.canAccess(Right.privilegeTypes[k]) ? "YES" : "NO";
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class TableWorks method checkCreateForeignKey.
void checkCreateForeignKey(Constraint c) {
if (c.core.mainName == table.getName()) {
if (ArrayUtil.haveCommonElement(c.core.refCols, c.core.mainCols, c.core.refCols.length)) {
throw Error.error(ErrorCode.X_42527);
}
}
// column defaults
boolean check = c.core.updateAction == Constraint.SET_DEFAULT || c.core.deleteAction == Constraint.SET_DEFAULT;
if (check) {
for (int i = 0; i < c.core.refCols.length; i++) {
ColumnSchema col = table.getColumn(c.core.refCols[i]);
Expression defExpr = col.getDefaultExpression();
if (defExpr == null) {
String columnName = col.getName().statementName;
throw Error.error(ErrorCode.X_42521, columnName);
}
}
}
check = c.core.updateAction == Constraint.SET_NULL || c.core.deleteAction == Constraint.SET_NULL;
if (check) {
for (int i = 0; i < c.core.refCols.length; i++) {
ColumnSchema col = table.getColumn(c.core.refCols[i]);
if (!col.isNullable()) {
String columnName = col.getName().statementName;
throw Error.error(ErrorCode.X_42520, columnName);
}
}
}
database.schemaManager.checkSchemaObjectNotExists(c.getName());
// duplicate name check for a new table
if (table.getConstraint(c.getName().name) != null) {
throw Error.error(ErrorCode.X_42504, c.getName().statementName);
}
// existing FK check
if (table.getFKConstraintForColumns(c.core.mainTable, c.core.mainCols, c.core.refCols) != null) {
throw Error.error(ErrorCode.X_42528, c.getName().statementName);
}
if (c.core.mainTable.isTemp() != table.isTemp()) {
throw Error.error(ErrorCode.X_42524, c.getName().statementName);
}
if (c.core.mainTable.getUniqueConstraintForColumns(c.core.mainCols, c.core.refCols) == null) {
throw Error.error(ErrorCode.X_42529, c.getMain().getName().statementName);
}
// check after UNIQUE check
c.core.mainTable.checkColumnsMatch(c.core.mainCols, table, c.core.refCols);
boolean[] checkList = c.core.mainTable.getColumnCheckList(c.core.mainCols);
// Grantee grantee = table.getOwner();
Grantee grantee = session.getGrantee();
grantee.checkReferences(c.core.mainTable, checkList);
}
Aggregations