001    package org.apache.ojb.odmg;
002    
003    /* Copyright 2003-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.Transaction;
019    import org.apache.ojb.broker.Identity;
020    
021    /**
022     * Offers useful none odmg-standard methods of the odmg {@link org.odmg.Transaction} interface.
023     * <p>
024     * Note: All listed methods are <strong>not</strong> part of the standard ODMG-api -
025     * they are special (proprietary) OJB extensions.
026     * </p>
027     *
028     * @version $Id: TransactionExt.java,v 1.1 2007-08-24 22:17:37 ewestfal Exp $
029     */
030    public interface TransactionExt extends Transaction, HasBroker
031    {
032        /**
033         * Marks an object for deletion without
034         * locking the object. If the object wasn't locked before,
035         * OJB will ask for a WRITE lock at commit.
036         *
037         * @param  anObject Object to be marked
038         */
039        public void markDelete(Object anObject);
040    
041        /**
042         * Marks an object as dirty without
043         * locking the object. If the object wasn't locked before,
044         * OJB will ask for a WRITE lock at commit.
045         *
046         * @param  anObject Object to be marked
047         */
048        public void markDirty(Object anObject);
049    
050        /**
051         * <p>
052         * Calling <code>flush</code> flushes persistent object modifications
053         * made within the ODMG transaction since the last checkpoint to the underlying
054         * database transaction, but does <b<not</b> commit the database transaction.
055         * The ODMG transaction retains all locks it held on those objects at the time the flush
056         * was invoked.
057         * <p/>
058         * This method is very similair to {@link org.odmg.Transaction#checkpoint}.
059         */
060        public void flush();
061    
062        /**
063         * This method can be used to activate or deactivate the implicit
064         * locking mechanism for the current transaction.
065         * <br/>
066         * If set <em>true</em> OJB implicitly locks objects to ODMG transactions
067         * after performing OQL queries. Also if implicit locking is used
068         * locking objects is recursive, that is associated objects are also
069         * locked. If ImplicitLocking is set to 'false', no locks are obtained
070         * in OQL queries, lookup objects and there is also no recursive locking.
071         * <p/>
072         * Turning off implicit locking may improve performance but requires
073         * additional care to make sure all changed objects are properly
074         * registered to the transaction.
075         *
076         * @param value If set <em>true</em> implicit locking is enabled,
077         *        if <em>false</em>, implicit locking is disabled.
078         * @see ImplementationExt#setImplicitLocking(boolean)
079         **/
080        public void setImplicitLocking(boolean value);
081    
082        /**
083         * Returns <em>true</em> if implicite locking is enabled.
084         * @see #setImplicitLocking(boolean)
085         */
086        public boolean isImplicitLocking();
087    
088        /**
089         * Allows to change the <em>cascading delete</em> behavior of the target class's
090         * reference field while this transaction is in use.
091         *
092         * @param target The class to change cascading delete behavior of the references.
093         * @param referenceField The field name of the 1:1, 1:n or m:n reference.
094         * @param doCascade If <em>true</em> cascading delete is enabled, <em>false</em> disabled.
095         */
096        public void setCascadingDelete(Class target, String referenceField, boolean doCascade);
097    
098        /**
099         * Allows to change the <em>cascading delete</em> behavior of all references of the
100         * specified class while this transaction is in use.
101         *
102         * @param target The class to change cascading delete behavior of all references.
103         * @param doCascade If <em>true</em> cascading delete is enabled, <em>false</em> disabled.
104         */
105        public void setCascadingDelete(Class target, boolean doCascade);
106    
107        /**
108         * Return <em>true</em> if the OJB ordering algorithm is enabled.
109         * @see #setOrdering(boolean)
110         */
111        public boolean isOrdering();
112    
113        /**
114         * Allows to enable/disable the OJB persistent object ordering algorithm. If
115         * <em>true</em> OJB try to order the modified/new/deleted objects in a correct order
116         * (based on a algorithm) before the objects are written to the persistent storage.
117         * <br/>
118         * If the used databases support 'deferred checks' it's recommended to
119         * use this feature and to disable OJB's object ordering.
120         * <p/>
121         * If <em>false</em> the order of the objects rely on the order specified by
122         * the user and on settings like {@link #setImplicitLocking(boolean)}.
123         *
124         * @param ordering Set <em>true</em> to enable object ordering on commit.
125         * @see ImplementationExt#setOrdering(boolean)
126         */
127        public void setOrdering(boolean ordering);
128    
129    //    /**
130    //     * Returns whether or not the persistent method calls determine
131    //     * the persistent object order on commit.
132    //     *
133    //     * @see #setNoteUserOrder(boolean)
134    //     */
135    //    public boolean isNoteUserOrder();
136    //
137    //    /**
138    //     * If <em>true</em> the order of persisting method calls like
139    //     * <br/> - {@link org.odmg.Transaction#lock(Object, int)}).
140    //     * <br/> - {@link org.odmg.Database#deletePersistent(Object)}).
141    //     * <br/> - {@link org.odmg.Database#makePersistent(Object)})
142    //     * determine the order of objects before commit.
143    //     * <br/>
144    //     * If <em>false</em> the ordering was determined by OJB's internal
145    //     * method calls and user calls.
146    //     * <br/>
147    //     * However it's possible to set this value as a global property
148    //     * for all transactions using {@link ImplementationExt#setNoteUserOrder(boolean)}.
149    //     * <p/>
150    //     * <strong>NOTE:</strong> If OJB's ordering algorithm (see
151    //     * {@link #setOrdering(boolean)}) is enabled, the
152    //     * order of objects may change on commit.
153    //     *
154    //     * @param noteUserOrder If <em>true</em> the order of persisting
155    //     * method calls determine the order of objects.
156    //     * @see ImplementationExt#setNoteUserOrder(boolean)
157    //     */
158    //    public void setNoteUserOrder(boolean noteUserOrder);
159    
160        /**
161         * Checks if the object with the given {@link org.apache.ojb.broker.Identity}
162         * has been deleted within the transaction using
163         * {@link org.odmg.Database#deletePersistent(Object)} or {@link #markDelete(Object)}.
164         *
165         * @param id The identity of the object.
166         * @return <em>true</em> if the object has been deleted within the transaction.
167         */
168        public boolean isDeleted(Identity id);
169    }