KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > core > PersistenceBrokerHandle


1 package org.apache.ojb.broker.core;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 DelegatingPersistenceBroker
22 {
23     /**
24      * Constructor for the handle, set itself in
25      * {@link PersistenceBrokerThreadMapping#setCurrentPersistenceBroker}
26      */

27     public PersistenceBrokerHandle(final PersistenceBrokerInternal broker)
28     {
29         super(broker);
30         PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(broker.getPBKey(), this);
31     }
32
33     public boolean isClosed()
34     {
35         return super.isClosed();
36     }
37
38     public boolean isInTransaction() throws PersistenceBrokerException
39     {
40         return !isClosed() && super.isInTransaction();
41     }
42
43     /**
44      * Destroy this handle and return the underlying (wrapped) PB instance
45      * to pool (when using default implementation of PersistenceBrokerFactory),
46      * unset this instance from {@link PersistenceBrokerThreadMapping}.
47      */

48     public boolean close()
49     {
50         if (getDelegate() == null) return true;
51         try
52         {
53             PersistenceBrokerThreadMapping.unsetCurrentPersistenceBroker(getPBKey(), this);
54             super.close();
55         }
56         finally
57         {
58             /*
59             here we destroy the handle. set the
60             underlying PB instance 'null', thus it's not
61             possible to corrupt a closed PB instance.
62             */

63             setDelegate(null);
64         }
65         return true;
66     }
67 }
68
Popular Tags