use of org.h2.engine.Database in project h2database by h2database.
the class GrantRevoke method revokeRole.
private void revokeRole(Role grantedRole) {
Right right = grantee.getRightForRole(grantedRole);
if (right == null) {
return;
}
Database db = session.getDatabase();
db.removeDatabaseObject(session, right);
}
use of org.h2.engine.Database in project h2database by h2database.
the class GrantRevoke method grantRight.
private void grantRight(DbObject object) {
Database db = session.getDatabase();
Right right = grantee.getRightForObject(object);
if (right == null) {
int id = getObjectId();
right = new Right(db, id, grantee, rightMask, object);
grantee.grantRight(object, right);
db.addDatabaseObject(session, right);
} else {
right.setRightMask(right.getRightMask() | rightMask);
db.updateMeta(session, right);
}
}
use of org.h2.engine.Database in project h2database by h2database.
the class DropRole method update.
@Override
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
if (roleName.equals(Constants.PUBLIC_ROLE_NAME)) {
throw DbException.get(ErrorCode.ROLE_CAN_NOT_BE_DROPPED_1, roleName);
}
Role role = db.findRole(roleName);
if (role == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, roleName);
}
} else {
db.removeDatabaseObject(session, role);
}
return 0;
}
use of org.h2.engine.Database in project h2database by h2database.
the class DropTable method executeDrop.
private void executeDrop() {
// need to get the table again, because it may be dropped already
// meanwhile (dependent object, or same object)
table = getSchema().findTableOrView(session, tableName);
if (table != null) {
table.setModified();
Database db = session.getDatabase();
db.lockMeta(session);
db.removeSchemaObject(session, table);
}
if (next != null) {
next.executeDrop();
}
}
use of org.h2.engine.Database in project h2database by h2database.
the class SetComment method update.
@Override
public int update() {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkAdmin();
DbObject object = null;
int errorCode = ErrorCode.GENERAL_ERROR_1;
if (schemaName == null) {
schemaName = session.getCurrentSchemaName();
}
switch(objectType) {
case DbObject.CONSTANT:
object = db.getSchema(schemaName).getConstant(objectName);
break;
case DbObject.CONSTRAINT:
object = db.getSchema(schemaName).getConstraint(objectName);
break;
case DbObject.FUNCTION_ALIAS:
object = db.getSchema(schemaName).findFunction(objectName);
errorCode = ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1;
break;
case DbObject.INDEX:
object = db.getSchema(schemaName).getIndex(objectName);
break;
case DbObject.ROLE:
schemaName = null;
object = db.findRole(objectName);
errorCode = ErrorCode.ROLE_NOT_FOUND_1;
break;
case DbObject.SCHEMA:
schemaName = null;
object = db.findSchema(objectName);
errorCode = ErrorCode.SCHEMA_NOT_FOUND_1;
break;
case DbObject.SEQUENCE:
object = db.getSchema(schemaName).getSequence(objectName);
break;
case DbObject.TABLE_OR_VIEW:
object = db.getSchema(schemaName).getTableOrView(session, objectName);
break;
case DbObject.TRIGGER:
object = db.getSchema(schemaName).findTrigger(objectName);
errorCode = ErrorCode.TRIGGER_NOT_FOUND_1;
break;
case DbObject.USER:
schemaName = null;
object = db.getUser(objectName);
break;
case DbObject.USER_DATATYPE:
schemaName = null;
object = db.findUserDataType(objectName);
errorCode = ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1;
break;
default:
}
if (object == null) {
throw DbException.get(errorCode, objectName);
}
String text = expr.optimize(session).getValue(session).getString();
if (column) {
Table table = (Table) object;
table.getColumn(columnName).setComment(text);
} else {
object.setComment(text);
}
if (column || objectType == DbObject.TABLE_OR_VIEW || objectType == DbObject.USER || objectType == DbObject.INDEX || objectType == DbObject.CONSTRAINT) {
db.updateMeta(session, object);
} else {
Comment comment = db.findComment(object);
if (comment == null) {
if (text == null) {
// reset a non-existing comment - nothing to do
} else {
int id = getObjectId();
comment = new Comment(db, id, object);
comment.setCommentText(text);
db.addDatabaseObject(session, comment);
}
} else {
if (text == null) {
db.removeDatabaseObject(session, comment);
} else {
comment.setCommentText(text);
db.updateMeta(session, comment);
}
}
}
return 0;
}
Aggregations