Search in sources :

Example 46 with Database

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);
}
Also used : Right(org.h2.engine.Right) Database(org.h2.engine.Database)

Example 47 with Database

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);
    }
}
Also used : Database(org.h2.engine.Database) Right(org.h2.engine.Right)

Example 48 with Database

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;
}
Also used : Role(org.h2.engine.Role) Database(org.h2.engine.Database)

Example 49 with Database

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();
    }
}
Also used : Database(org.h2.engine.Database)

Example 50 with Database

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;
}
Also used : Comment(org.h2.engine.Comment) Table(org.h2.table.Table) DbObject(org.h2.engine.DbObject) Database(org.h2.engine.Database)

Aggregations

Database (org.h2.engine.Database)79 SQLException (java.sql.SQLException)45 PreparedStatement (java.sql.PreparedStatement)38 DbException (org.h2.message.DbException)37 ResultSet (java.sql.ResultSet)34 Statement (java.sql.Statement)32 SimpleResultSet (org.h2.tools.SimpleResultSet)32 Connection (java.sql.Connection)27 Table (org.h2.table.Table)25 Value (org.h2.value.Value)25 Column (org.h2.table.Column)22 IOException (java.io.IOException)19 Constraint (org.h2.constraint.Constraint)18 Expression (org.h2.expression.Expression)17 ExpressionColumn (org.h2.expression.ExpressionColumn)17 ValueString (org.h2.value.ValueString)15 ValueExpression (org.h2.expression.ValueExpression)14 Session (org.h2.engine.Session)13 JdbcConnection (org.h2.jdbc.JdbcConnection)13 Schema (org.h2.schema.Schema)13