01: package org.apache.ojb.broker.core;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.PersistenceBrokerException;
19: import org.apache.ojb.broker.PersistenceBrokerInternal;
20:
21: public class PersistenceBrokerHandle extends
22: DelegatingPersistenceBroker {
23: /**
24: * Constructor for the handle, set itself in
25: * {@link PersistenceBrokerThreadMapping#setCurrentPersistenceBroker}
26: */
27: public PersistenceBrokerHandle(
28: final PersistenceBrokerInternal broker) {
29: super (broker);
30: PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(
31: broker.getPBKey(), this );
32: }
33:
34: public boolean isClosed() {
35: return super .isClosed();
36: }
37:
38: public boolean isInTransaction() throws PersistenceBrokerException {
39: return !isClosed() && super .isInTransaction();
40: }
41:
42: /**
43: * Destroy this handle and return the underlying (wrapped) PB instance
44: * to pool (when using default implementation of PersistenceBrokerFactory),
45: * unset this instance from {@link PersistenceBrokerThreadMapping}.
46: */
47: public boolean close() {
48: if (getDelegate() == null)
49: return true;
50: try {
51: PersistenceBrokerThreadMapping
52: .unsetCurrentPersistenceBroker(getPBKey(), this );
53: super .close();
54: } finally {
55: /*
56: here we destroy the handle. set the
57: underlying PB instance 'null', thus it's not
58: possible to corrupt a closed PB instance.
59: */
60: setDelegate(null);
61: }
62: return true;
63: }
64: }
|