use of org.h2.jaqu.Db in project h2database by h2database.
the class GrantRevoke method grantRole.
private void grantRole(Role grantedRole) {
if (grantedRole != grantee && grantee.isRoleGranted(grantedRole)) {
return;
}
if (grantee instanceof Role) {
Role granteeRole = (Role) grantee;
if (grantedRole.isRoleGranted(granteeRole)) {
// cyclic role grants are not allowed
throw DbException.get(ErrorCode.ROLE_ALREADY_GRANTED_1, grantedRole.getSQL());
}
}
Database db = session.getDatabase();
int id = getObjectId();
Right right = new Right(db, id, grantee, grantedRole);
db.addDatabaseObject(session, right);
grantee.grantRole(grantedRole, right);
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class GrantRevoke method revokeRight.
private void revokeRight(DbObject object) {
Right right = grantee.getRightForObject(object);
if (right == null) {
return;
}
int mask = right.getRightMask();
int newRight = mask & ~rightMask;
Database db = session.getDatabase();
if (newRight == 0) {
db.removeDatabaseObject(session, right);
} else {
right.setRightMask(newRight);
db.updateMeta(session, right);
}
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class DropFunctionAlias method update.
@Override
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
FunctionAlias functionAlias = getSchema().findFunction(aliasName);
if (functionAlias == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1, aliasName);
}
} else {
db.removeSchemaObject(session, functionAlias);
}
return 0;
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class DropSequence method update.
@Override
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
Sequence sequence = getSchema().findSequence(sequenceName);
if (sequence == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
}
} else {
if (sequence.getBelongsToTable()) {
throw DbException.get(ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName);
}
db.removeSchemaObject(session, sequence);
}
return 0;
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class DropUser method update.
@Override
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
User user = db.findUser(userName);
if (user == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.USER_NOT_FOUND_1, userName);
}
} else {
if (user == session.getUser()) {
int adminUserCount = 0;
for (User u : db.getAllUsers()) {
if (u.isAdmin()) {
adminUserCount++;
}
}
if (adminUserCount == 1) {
throw DbException.get(ErrorCode.CANNOT_DROP_CURRENT_USER);
}
}
user.checkOwnsNoSchemas();
db.removeDatabaseObject(session, user);
}
return 0;
}
Aggregations