KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > db > DatabaseContextImpl


1 /*
2
3    Derby - Class org.apache.derby.impl.db.DatabaseContextImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 /**
35     A context that shutdowns down the database on a databsae exception.
36 */

37 final class DatabaseContextImpl extends ContextImpl implements DatabaseContext
38 {
39
40     private final Database db;
41
42     DatabaseContextImpl(ContextManager cm, Database db) {
43         super(cm, DatabaseContextImpl.CONTEXT_ID);
44         this.db = db;
45     }
46
47     public void cleanupOnError(Throwable JavaDoc t) {
48         if (!(t instanceof StandardException)) 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 JavaDoc 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() {return db;}
76 }
77
Popular Tags