001    package org.apache.ojb.odmg;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import org.odmg.LockNotGrantedException;
019    import org.apache.ojb.broker.PersistenceBroker;
020    import org.apache.ojb.broker.Identity;
021    import org.apache.ojb.broker.PersistenceBrokerException;
022    
023    /**
024     * Wraps {@link org.odmg.Transaction} in managed environments.
025     *
026     * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
027     */
028    public class NarrowTransaction implements TransactionExt
029    {
030        private TransactionImpl tx;
031    
032        public NarrowTransaction(TransactionImpl tx)
033        {
034            this.tx = tx;
035        }
036    
037        public TransactionImpl getRealTransaction()
038        {
039            return tx;
040        }
041    
042        public void markDelete(Object anObject)
043        {
044            this.tx.markDelete(anObject);
045        }
046    
047        public void markDirty(Object anObject)
048        {
049            this.tx.markDirty(anObject);
050        }
051    
052        public void flush()
053        {
054            tx.flush();
055        }
056    
057        /**
058         * Return associated PB instance, or null if not found.
059         */
060        public PersistenceBroker getBroker()
061        {
062            return tx.getBroker();
063        }
064    
065        /**
066         * Not supported!!
067         */
068        public void join()
069        {
070            throw new UnsupportedOperationException("Not supported operation");
071        }
072    
073        /**
074         * Not supported!!
075         */
076        public void leave()
077        {
078            throw new UnsupportedOperationException("Not supported operation");
079        }
080    
081        /**
082         * Not supported!!
083         */
084        public void begin()
085        {
086            throw new UnsupportedOperationException("Not supported operation");
087        }
088    
089        /**
090         * Not supported!!
091         */
092        public boolean isOpen()
093        {
094            return tx.isOpen();
095        }
096    
097        /**
098         * Not supported!!
099         */
100        public void commit()
101        {
102            throw new UnsupportedOperationException("Not supported operation");
103        }
104    
105        /**
106         * Abort the underlying odmg-transaction
107         */
108        public void abort()
109        {
110            tx.abort();
111            //throw new UnsupportedOperationException("Not supported operation");
112        }
113    
114        /**
115         * Not supported!!
116         */
117        public void checkpoint()
118        {
119            throw new UnsupportedOperationException("Not supported operation");
120        }
121    
122        /**
123         * lock the given object
124         * @see org.odmg.Transaction#lock
125         */
126        public void lock(Object obj, int lockMode)
127                throws LockNotGrantedException
128        {
129            tx.lock(obj, lockMode);
130        }
131    
132        /**
133         * lock the given object if possible
134         * @see org.odmg.Transaction#tryLock
135         */
136        public boolean tryLock(Object obj, int lockMode)
137        {
138            return tx.tryLock(obj, lockMode);
139        }
140    
141            public Object getObjectByIdentity(Identity id)
142                            throws PersistenceBrokerException
143            {
144                    return tx.getObjectByIdentity(id);
145            }
146        /**
147         * @see org.apache.ojb.odmg.TransactionExt#setImplicitLocking(boolean)
148         */
149        public void setImplicitLocking(boolean value)
150        {
151            tx.setImplicitLocking(value);
152        }
153    
154        /**
155         * @see org.apache.ojb.odmg.TransactionExt#isImplicitLocking
156         */
157        public boolean isImplicitLocking()
158        {
159            return tx.isImplicitLocking();
160        }
161    
162        /**
163         * @see org.apache.ojb.odmg.TransactionExt#setCascadingDelete(Class, String, boolean)
164         */
165        public void setCascadingDelete(Class target, String referenceField, boolean doCascade)
166        {
167            tx.setCascadingDelete(target, referenceField, doCascade);
168        }
169    
170        /**
171         * @see org.apache.ojb.odmg.TransactionExt#setCascadingDelete(Class, boolean) 
172         */
173        public void setCascadingDelete(Class target, boolean doCascade)
174        {
175            tx.setCascadingDelete(target, doCascade);
176        }
177    
178        public boolean isOrdering()
179        {
180            return tx.isOrdering();
181        }
182    
183        public void setOrdering(boolean ordering)
184        {
185            tx.setOrdering(ordering);
186        }
187    
188    //    public boolean isNoteUserOrder()
189    //    {
190    //        return tx.isNoteUserOrder();
191    //    }
192    //
193    //    public void setNoteUserOrder(boolean noteUserOrder)
194    //    {
195    //        tx.setNoteUserOrder(noteUserOrder);
196    //    }
197    
198        public boolean isDeleted(Identity id)
199        {
200            return tx.isDeleted(id);
201        }
202    }