use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class ParserDDL method compileDrop.
/*
CompiledStatementInterface compileAlter() {
CompiledStatementInterface cs = null;
read();
String sql = getStatement(getParsePosition(), endStatementTokensAlter);
cs = new CompiledStatementSchema(sql, StatementCodes.ALTER_TYPE, null);
return cs;
}
*/
Statement compileDrop() {
int objectTokenType;
int objectType;
int statementType;
boolean canCascade = false;
boolean cascade = false;
boolean useIfExists = false;
boolean ifExists = false;
HsqlName readName = null;
HsqlName writeName = null;
read();
objectTokenType = this.token.tokenType;
switch(objectTokenType) {
case Tokens.INDEX:
{
read();
statementType = StatementTypes.DROP_INDEX;
objectType = SchemaObject.INDEX;
useIfExists = true;
break;
}
case Tokens.ASSERTION:
{
read();
statementType = StatementTypes.DROP_ASSERTION;
objectType = SchemaObject.ASSERTION;
canCascade = true;
break;
}
case Tokens.PROCEDURE:
{
read();
statementType = StatementTypes.DROP_ROUTINE;
objectType = SchemaObject.PROCEDURE;
canCascade = true;
break;
}
case Tokens.FUNCTION:
{
read();
statementType = StatementTypes.DROP_ROUTINE;
objectType = SchemaObject.FUNCTION;
canCascade = true;
break;
}
case Tokens.SCHEMA:
{
read();
statementType = StatementTypes.DROP_SCHEMA;
objectType = SchemaObject.SCHEMA;
useIfExists = true;
canCascade = true;
break;
}
case Tokens.SEQUENCE:
{
read();
statementType = StatementTypes.DROP_SEQUENCE;
objectType = SchemaObject.SEQUENCE;
canCascade = true;
useIfExists = true;
break;
}
case Tokens.TRIGGER:
{
read();
statementType = StatementTypes.DROP_TRIGGER;
objectType = SchemaObject.TRIGGER;
canCascade = false;
break;
}
case Tokens.USER:
{
read();
statementType = StatementTypes.DROP_USER;
objectType = SchemaObject.GRANTEE;
canCascade = true;
break;
}
case Tokens.ROLE:
{
read();
statementType = StatementTypes.DROP_ROLE;
objectType = SchemaObject.GRANTEE;
canCascade = true;
break;
}
case Tokens.DOMAIN:
read();
statementType = StatementTypes.DROP_DOMAIN;
objectType = SchemaObject.DOMAIN;
canCascade = true;
break;
case Tokens.TYPE:
read();
statementType = StatementTypes.DROP_TYPE;
objectType = SchemaObject.TYPE;
canCascade = true;
break;
case Tokens.CHARACTER:
read();
readThis(Tokens.SET);
statementType = StatementTypes.DROP_CHARACTER_SET;
objectType = SchemaObject.CHARSET;
canCascade = false;
break;
case Tokens.VIEW:
read();
statementType = StatementTypes.DROP_VIEW;
objectType = SchemaObject.VIEW;
canCascade = true;
useIfExists = true;
break;
case Tokens.STREAM:
case Tokens.TABLE:
read();
statementType = StatementTypes.DROP_TABLE;
objectType = SchemaObject.TABLE;
canCascade = true;
useIfExists = true;
break;
default:
throw unexpectedToken();
}
checkIsIdentifier();
HsqlName name = null;
switch(objectTokenType) {
case Tokens.USER:
{
checkIsSimpleName();
checkDatabaseUpdateAuthorisation();
Grantee grantee = database.getUserManager().get(token.tokenString);
name = grantee.getName();
read();
break;
}
case Tokens.ROLE:
{
checkIsSimpleName();
checkDatabaseUpdateAuthorisation();
Grantee role = database.getGranteeManager().getRole(token.tokenString);
name = role.getName();
read();
break;
}
case Tokens.SCHEMA:
{
name = readNewSchemaName();
writeName = database.getCatalogName();
break;
}
default:
name = readNewSchemaObjectNameNoCheck(objectType);
try {
String schemaName = name.schema == null ? session.getSchemaName(null) : name.schema.name;
SchemaObject object = /* disable 3 lines ...
database.schemaManager.getSchemaObject(name.name,
schemaName, objectType);
... disabled 3 lines */
database.schemaManager.findSchemaObject(name.name, schemaName, objectType);
if (object == null) {
writeName = null;
} else // End of VoltDB extension
if (cascade) {
writeName = database.getCatalogName();
} else {
writeName = object.getName();
if (writeName.parent != null) {
writeName = writeName.parent;
}
if (writeName.type != SchemaObject.TABLE) {
writeName = null;
}
}
} catch (HsqlException e) {
}
}
if (useIfExists && token.tokenType == Tokens.IF) {
read();
readThis(Tokens.EXISTS);
ifExists = true;
}
if (canCascade) {
if (token.tokenType == Tokens.CASCADE) {
cascade = true;
read();
} else if (token.tokenType == Tokens.RESTRICT) {
read();
}
}
Object[] args = new Object[] { name, new Integer(objectType), Boolean.valueOf(cascade), Boolean.valueOf(ifExists) };
String sql = getLastPart();
return new StatementSchema(sql, statementType, args, readName, writeName);
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class ParserDDL method compileCreateUser.
StatementSchema compileCreateUser() {
HsqlName name;
String password;
boolean admin = false;
Grantee grantor = session.getGrantee();
read();
name = readNewUserIdentifier();
readThis(Tokens.PASSWORD);
password = readPassword();
if (token.tokenType == Tokens.ADMIN) {
read();
admin = true;
}
checkDatabaseUpdateAuthorisation();
String sql = getLastPart();
Object[] args = new Object[] { name, password, grantor, Boolean.valueOf(admin) };
return new StatementSchema(sql, StatementTypes.CREATE_USER, args, null, null);
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class ParserDDL method compileCreateSchema.
StatementSchema compileCreateSchema() {
HsqlName schemaName = null;
String authorisation = null;
read();
if (token.tokenType != Tokens.AUTHORIZATION) {
schemaName = readNewSchemaName();
}
if (token.tokenType == Tokens.AUTHORIZATION) {
read();
checkIsSimpleName();
authorisation = token.tokenString;
read();
if (schemaName == null) {
Grantee owner = database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
schemaName = database.nameManager.newHsqlName(owner.getName().name, isDelimitedIdentifier(), SchemaObject.SCHEMA);
SqlInvariants.checkSchemaNameNotSystem(token.tokenString);
}
}
if (SqlInvariants.PUBLIC_ROLE_NAME.equals(authorisation)) {
throw Error.error(ErrorCode.X_28502, authorisation);
}
Grantee owner = authorisation == null ? session.getGrantee() : database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
if (!session.getGrantee().isSchemaCreator()) {
throw Error.error(ErrorCode.X_0L000, session.getGrantee().getNameString());
}
if (database.schemaManager.schemaExists(schemaName.name)) {
throw Error.error(ErrorCode.X_42504, schemaName.name);
}
String sql = getLastPart();
Object[] args = new Object[] { schemaName, owner };
HsqlArrayList list = new HsqlArrayList();
StatementSchema cs = new StatementSchema(sql, StatementTypes.CREATE_SCHEMA, args, null, null);
cs.setSchemaHsqlName(schemaName);
list.add(cs);
getCompiledStatementBody(list);
StatementSchema[] array = new StatementSchema[list.size()];
list.toArray(array);
boolean swapped;
do {
swapped = false;
for (int i = 0; i < array.length - 1; i++) {
if (array[i].order > array[i + 1].order) {
StatementSchema temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
swapped = true;
}
}
} while (swapped);
return new StatementSchemaDefinition(array);
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class StatementSchema method dropRole.
private static void dropRole(Session session, HsqlName name, boolean cascade) {
Grantee role = session.database.getGranteeManager().getRole(name.name);
if (!cascade && session.database.schemaManager.hasSchemas(role)) {
HsqlArrayList list = session.database.schemaManager.getSchemas(role);
Schema schema = (Schema) list.get(0);
throw Error.error(ErrorCode.X_42502, schema.getName().statementName);
}
session.database.schemaManager.dropSchemas(role, cascade);
session.database.getGranteeManager().dropRole(name.name);
}
use of org.hsqldb_voltpatches.rights.Grantee in project voltdb by VoltDB.
the class DatabaseInformationFull method ENABLED_ROLES.
/**
* ENABLED_ROLES<p>
*
* <b>Function</b><p>
*
* Identify the enabled roles for the current SQL-session.<p>
*
* Definition<p>
*
* <pre class="SqlCodeExample">
* CREATE RECURSIVE VIEW ENABLED_ROLES ( ROLE_NAME ) AS
* VALUES ( CURRENT_ROLE )
* UNION
* SELECT RAD.ROLE_NAME
* FROM DEFINITION_SCHEMA.ROLE_AUTHORIZATION_DESCRIPTORS RAD
* JOIN ENABLED_ROLES R
* ON RAD.GRANTEE = R.ROLE_NAME;
*
* GRANT SELECT ON TABLE ENABLED_ROLES
* TO PUBLIC WITH GRANT OPTION;
* </pre>
*/
Table ENABLED_ROLES() {
Table t = sysTables[ENABLED_ROLES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ENABLED_ROLES]);
addColumn(t, "ROLE_NAME", SQL_IDENTIFIER);
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ENABLED_ROLES].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().getAllRoles().iterator();
while (grantees.hasNext()) {
grantee = (Grantee) grantees.next();
row = t.getEmptyRowData();
row[0] = grantee.getNameString();
t.insertSys(store, row);
}
return t;
}
Aggregations