Search in sources :

Example 91 with Db

use of org.h2.jaqu.Db in project h2database by h2database.

the class AlterTableAlterColumn method removeSequence.

private void removeSequence(Table table, Sequence sequence) {
    if (sequence != null) {
        table.removeSequence(sequence);
        sequence.setBelongsToTable(false);
        Database db = session.getDatabase();
        db.removeSchemaObject(session, sequence);
    }
}
Also used : Database(org.h2.engine.Database)

Example 92 with Db

use of org.h2.jaqu.Db in project h2database by h2database.

the class AlterTableRename method update.

@Override
public int update() {
    session.commit(true);
    Database db = session.getDatabase();
    Table oldTable = getSchema().findTableOrView(session, oldTableName);
    if (oldTable == null) {
        if (ifTableExists) {
            return 0;
        }
        throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, oldTableName);
    }
    session.getUser().checkRight(oldTable, Right.ALL);
    Table t = getSchema().findTableOrView(session, newTableName);
    if (t != null && hidden && newTableName.equals(oldTable.getName())) {
        if (!t.isHidden()) {
            t.setHidden(hidden);
            oldTable.setHidden(true);
            db.updateMeta(session, oldTable);
        }
        return 0;
    }
    if (t != null || newTableName.equals(oldTable.getName())) {
        throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName);
    }
    if (oldTable.isTemporary()) {
        throw DbException.getUnsupportedException("temp table");
    }
    db.renameSchemaObject(session, oldTable, newTableName);
    return 0;
}
Also used : Table(org.h2.table.Table) Database(org.h2.engine.Database)

Example 93 with Db

use of org.h2.jaqu.Db in project h2database by h2database.

the class DropUserDataType method update.

@Override
public int update() {
    session.getUser().checkAdmin();
    session.commit(true);
    Database db = session.getDatabase();
    UserDataType type = db.findUserDataType(typeName);
    if (type == null) {
        if (!ifExists) {
            throw DbException.get(ErrorCode.USER_DATA_TYPE_NOT_FOUND_1, typeName);
        }
    } else {
        db.removeDatabaseObject(session, type);
    }
    return 0;
}
Also used : UserDataType(org.h2.engine.UserDataType) Database(org.h2.engine.Database)

Example 94 with Db

use of org.h2.jaqu.Db in project h2database by h2database.

the class GrantRevoke method update.

@Override
public int update() {
    session.getUser().checkAdmin();
    session.commit(true);
    Database db = session.getDatabase();
    if (roleNames != null) {
        for (String name : roleNames) {
            Role grantedRole = db.findRole(name);
            if (grantedRole == null) {
                throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, name);
            }
            if (operationType == CommandInterface.GRANT) {
                grantRole(grantedRole);
            } else if (operationType == CommandInterface.REVOKE) {
                revokeRole(grantedRole);
            } else {
                DbException.throwInternalError("type=" + operationType);
            }
        }
    } else {
        if (operationType == CommandInterface.GRANT) {
            grantRight();
        } else if (operationType == CommandInterface.REVOKE) {
            revokeRight();
        } else {
            DbException.throwInternalError("type=" + operationType);
        }
    }
    return 0;
}
Also used : Role(org.h2.engine.Role) Database(org.h2.engine.Database)

Example 95 with Db

use of org.h2.jaqu.Db in project h2database by h2database.

the class GrantRevoke method setGranteeName.

public void setGranteeName(String granteeName) {
    Database db = session.getDatabase();
    grantee = db.findUser(granteeName);
    if (grantee == null) {
        grantee = db.findRole(granteeName);
        if (grantee == null) {
            throw DbException.get(ErrorCode.USER_OR_ROLE_NOT_FOUND_1, granteeName);
        }
    }
}
Also used : 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