Search in sources :

Example 96 with Db

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

Example 97 with Db

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

Example 98 with Db

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

Example 99 with Db

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

Example 100 with Db

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

Aggregations

Database (org.h2.engine.Database)70 Connection (java.sql.Connection)31 Statement (java.sql.Statement)20 Table (org.h2.table.Table)19 PreparedStatement (java.sql.PreparedStatement)18 ResultSet (java.sql.ResultSet)13 SQLException (java.sql.SQLException)13 Column (org.h2.table.Column)12 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)9 StatementBuilder (org.h2.util.StatementBuilder)9 DbObject (org.h2.engine.DbObject)8 File (java.io.File)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 DbException (org.h2.message.DbException)7 Schema (org.h2.schema.Schema)7 Before (org.junit.Before)7 InputStream (java.io.InputStream)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 JdbcConnection (org.h2.jdbc.JdbcConnection)6