01: /*
02:
03: Derby - Class org.apache.derby.impl.db.DatabaseContextImpl
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.impl.db;
23:
24: import org.apache.derby.iapi.services.context.ContextImpl;
25: import org.apache.derby.iapi.services.context.ContextManager;
26: import org.apache.derby.iapi.services.context.ContextService;
27: import org.apache.derby.iapi.services.monitor.Monitor;
28: import org.apache.derby.iapi.db.Database;
29: import org.apache.derby.iapi.db.DatabaseContext;
30: import org.apache.derby.iapi.error.StandardException;
31: import org.apache.derby.iapi.error.ExceptionSeverity;
32:
33: /**
34: A context that shutdowns down the database on a databsae exception.
35: */
36: final class DatabaseContextImpl extends ContextImpl implements
37: DatabaseContext {
38:
39: private final Database db;
40:
41: DatabaseContextImpl(ContextManager cm, Database db) {
42: super (cm, DatabaseContextImpl.CONTEXT_ID);
43: this .db = db;
44: }
45:
46: public void cleanupOnError(Throwable t) {
47: if (!(t instanceof StandardException))
48: return;
49: StandardException se = (StandardException) t;
50:
51: // Ensure the context is popped if the session is
52: // going away.
53: if (se.getSeverity() < ExceptionSeverity.SESSION_SEVERITY)
54: return;
55:
56: popMe();
57:
58: if (se.getSeverity() == ExceptionSeverity.DATABASE_SEVERITY) {
59: ContextService.getFactory().notifyAllActiveThreads(this );
60: Monitor.getMonitor().shutdown(db);
61: }
62: }
63:
64: public boolean equals(Object other) {
65: if (other instanceof DatabaseContext) {
66: return ((DatabaseContextImpl) other).db == db;
67: }
68: return false;
69: }
70:
71: public int hashCode() {
72: return db.hashCode();
73: }
74:
75: public Database getDatabase() {
76: return db;
77: }
78: }
|