Search in sources :

Example 16 with DbObject

use of org.h2.engine.DbObject in project h2database by h2database.

the class Table method addDependencies.

/**
 * Add all objects that this table depends on to the hash set.
 *
 * @param dependencies the current set of dependencies
 */
public void addDependencies(HashSet<DbObject> dependencies) {
    if (dependencies.contains(this)) {
        // avoid endless recursion
        return;
    }
    if (sequences != null) {
        dependencies.addAll(sequences);
    }
    ExpressionVisitor visitor = ExpressionVisitor.getDependenciesVisitor(dependencies);
    for (Column col : columns) {
        col.isEverything(visitor);
    }
    if (constraints != null) {
        for (Constraint c : constraints) {
            c.isEverything(visitor);
        }
    }
    dependencies.add(this);
}
Also used : Constraint(org.h2.constraint.Constraint) ExpressionVisitor(org.h2.expression.ExpressionVisitor)

Example 17 with DbObject

use of org.h2.engine.DbObject in project h2database by h2database.

the class Database method updateMeta.

/**
 * Update an object in the system table.
 *
 * @param session the session
 * @param obj the database object
 */
public void updateMeta(Session session, DbObject obj) {
    lockMeta(session);
    synchronized (this) {
        int id = obj.getId();
        removeMeta(session, id);
        addMeta(session, obj);
        // for temporary objects
        if (id > 0) {
            objectIds.set(id);
        }
    }
}
Also used : Constraint(org.h2.constraint.Constraint)

Example 18 with DbObject

use of org.h2.engine.DbObject in project h2database by h2database.

the class Database method removeDatabaseObject.

/**
 * Remove the object from the database.
 *
 * @param session the session
 * @param obj the object to remove
 */
public synchronized void removeDatabaseObject(Session session, DbObject obj) {
    checkWritingAllowed();
    String objName = obj.getName();
    int type = obj.getType();
    HashMap<String, DbObject> map = getMap(type);
    if (SysProperties.CHECK && !map.containsKey(objName)) {
        DbException.throwInternalError("not found: " + objName);
    }
    Comment comment = findComment(obj);
    lockMeta(session);
    if (comment != null) {
        removeDatabaseObject(session, comment);
    }
    int id = obj.getId();
    obj.removeChildrenAndResources(session);
    map.remove(objName);
    removeMeta(session, id);
}
Also used : Constraint(org.h2.constraint.Constraint)

Example 19 with DbObject

use of org.h2.engine.DbObject 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 20 with DbObject

use of org.h2.engine.DbObject in project h2database by h2database.

the class DropView method update.

@Override
public int update() {
    session.commit(true);
    Table view = getSchema().findTableOrView(session, viewName);
    if (view == null) {
        if (!ifExists) {
            throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
        }
    } else {
        if (TableType.VIEW != view.getTableType()) {
            throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
        }
        session.getUser().checkRight(view, Right.ALL);
        if (dropAction == ConstraintActionType.RESTRICT) {
            for (DbObject child : view.getChildren()) {
                if (child instanceof TableView) {
                    throw DbException.get(ErrorCode.CANNOT_DROP_2, viewName, child.getName());
                }
            }
        }
        // TODO: Where is the ConstraintReferential.CASCADE style drop processing ? It's
        // supported from imported keys - but not for dependent db objects
        TableView tableView = (TableView) view;
        ArrayList<Table> copyOfDependencies = new ArrayList<>(tableView.getTables());
        view.lock(session, true, true);
        session.getDatabase().removeSchemaObject(session, view);
        // remove dependent table expressions
        for (Table childTable : copyOfDependencies) {
            if (TableType.VIEW == childTable.getTableType()) {
                TableView childTableView = (TableView) childTable;
                if (childTableView.isTableExpression() && childTableView.getName() != null) {
                    session.getDatabase().removeSchemaObject(session, childTableView);
                }
            }
        }
        // make sure its all unlocked
        session.getDatabase().unlockMeta(session);
    }
    return 0;
}
Also used : Table(org.h2.table.Table) DbObject(org.h2.engine.DbObject) ArrayList(java.util.ArrayList) TableView(org.h2.table.TableView)

Aggregations

DbObject (org.h2.engine.DbObject)12 Constraint (org.h2.constraint.Constraint)11 Table (org.h2.table.Table)9 Database (org.h2.engine.Database)8 Right (org.h2.engine.Right)5 Index (org.h2.index.Index)5 Sequence (org.h2.schema.Sequence)5 Schema (org.h2.schema.Schema)4 SchemaObject (org.h2.schema.SchemaObject)4 Column (org.h2.table.Column)4 TableView (org.h2.table.TableView)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Role (org.h2.engine.Role)3 User (org.h2.engine.User)3 DbException (org.h2.message.DbException)3 TriggerObject (org.h2.schema.TriggerObject)3 IOException (java.io.IOException)2 ConstraintReferential (org.h2.constraint.ConstraintReferential)2 Comment (org.h2.engine.Comment)2