use of org.h2.test.db.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);
}
}
use of org.h2.test.db.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;
}
use of org.h2.test.db.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;
}
use of org.h2.test.db.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;
}
use of org.h2.test.db.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);
}
}
}
Aggregations