Search in sources :

Example 31 with Right

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

the class Schema method removeChildrenAndResources.

@Override
public void removeChildrenAndResources(Session session) {
    while (triggers != null && triggers.size() > 0) {
        TriggerObject obj = (TriggerObject) triggers.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (constraints != null && constraints.size() > 0) {
        Constraint obj = (Constraint) constraints.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    // There can be dependencies between tables e.g. using computed columns,
    // so we might need to loop over them multiple times.
    boolean runLoopAgain = false;
    do {
        runLoopAgain = false;
        if (tablesAndViews != null) {
            // Loop over a copy because the map is modified underneath us.
            for (Table obj : new ArrayList<>(tablesAndViews.values())) {
                // in one go underneath us.
                if (obj.getName() != null) {
                    if (database.getDependentTable(obj, obj) == null) {
                        database.removeSchemaObject(session, obj);
                    } else {
                        runLoopAgain = true;
                    }
                }
            }
        }
    } while (runLoopAgain);
    while (indexes != null && indexes.size() > 0) {
        Index obj = (Index) indexes.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (sequences != null && sequences.size() > 0) {
        Sequence obj = (Sequence) sequences.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (constants != null && constants.size() > 0) {
        Constant obj = (Constant) constants.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (functions != null && functions.size() > 0) {
        FunctionAlias obj = (FunctionAlias) functions.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    for (Right right : database.getAllRights()) {
        if (right.getGrantedObject() == this) {
            database.removeDatabaseObject(session, right);
        }
    }
    database.removeMeta(session, getId());
    owner = null;
    invalidate();
}
Also used : RegularTable(org.h2.table.RegularTable) Table(org.h2.table.Table) Constraint(org.h2.constraint.Constraint) FunctionAlias(org.h2.engine.FunctionAlias) ArrayList(java.util.ArrayList) Right(org.h2.engine.Right) Index(org.h2.index.Index)

Example 32 with Right

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

the class TestMVStore method testBackgroundExceptionListener.

private void testBackgroundExceptionListener() throws Exception {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s;
    final AtomicReference<Throwable> exRef = new AtomicReference<>();
    s = new MVStore.Builder().fileName(fileName).backgroundExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            exRef.set(e);
        }
    }).open();
    s.setAutoCommitDelay(10);
    MVMap<Integer, String> m;
    m = s.openMap("data");
    s.getFileStore().getFile().close();
    try {
        m.put(1, "Hello");
        for (int i = 0; i < 200; i++) {
            if (exRef.get() != null) {
                break;
            }
            sleep(10);
        }
        Throwable e = exRef.get();
        assertNotNull(e);
        assertEquals(DataUtils.ERROR_WRITING_FAILED, DataUtils.getErrorCode(e.getMessage()));
    } catch (IllegalStateException e) {
        // sometimes it is detected right away
        assertEquals(DataUtils.ERROR_CLOSED, DataUtils.getErrorCode(e.getMessage()));
    }
    s.closeImmediately();
    FileUtils.delete(fileName);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Aggregations

Right (org.h2.engine.Right)9 Database (org.h2.engine.Database)7 Expression (org.h2.expression.Expression)7 ValueExpression (org.h2.expression.ValueExpression)7 Value (org.h2.value.Value)7 Comparison (org.h2.expression.Comparison)6 ConditionAndOr (org.h2.expression.ConditionAndOr)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 ValueString (org.h2.value.ValueString)6 Column (org.h2.table.Column)5 IOException (java.io.IOException)4 Constraint (org.h2.constraint.Constraint)4 IndexColumn (org.h2.table.IndexColumn)4 ArrayList (java.util.ArrayList)3 DbObject (org.h2.engine.DbObject)3 Index (org.h2.index.Index)3 Sequence (org.h2.schema.Sequence)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 ResultSet (java.sql.ResultSet)2