KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > standard > StandardDBTransaction


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: StandardDBTransaction.java,v 1.4 2005/03/03 17:33:29 tanja Exp $
22  *
23  */

24 package com.lutris.appserver.server.sql.standard;
25
26 import com.lutris.appserver.server.sql.*;
27
28 import java.util.*;
29
30 import com.lutris.dods.builder.generator.dataobject.GenericDO;
31 import com.lutris.dods.builder.generator.query.DataObjectException;
32 import com.lutris.logging.Logger;
33 import java.sql.PreparedStatement JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import org.enhydra.dods.DODS;
36 import org.enhydra.dods.cache.DOCache;
37 import org.enhydra.dods.cache.TransactionCacheImpl;
38 import org.enhydra.dods.cache.Wrapper;
39 import org.enhydra.dods.exceptions.CacheObjectException;
40
41 /**
42  * Standard implementation of SQL database transaction.
43  *
44  * @see DBTransaction
45  * @author Kyle Clark
46  * @since LBS1.8
47  * @version $Revision: 1.4 $
48  */

49 public class StandardDBTransaction implements CachedDBTransaction {
50     // Identifier for this transaction object.
51
protected int id;
52     // Next available identifier.
53
protected static int nextId;
54     // Connection used by this transaction object.
55
protected DBConnection conn;
56     // Is this object still active, or has it been released.
57
protected boolean released = false;
58     protected boolean _preventCacheQueries = false;
59     protected Vector vecAlreadyHidden = new Vector();
60     protected Vector vecExecutedTransaction = new Vector();
61     // compliance with WEBDOCWF begin
62
protected Vector vecSortedTransaction = new Vector();
63     protected HashMap hmpObjectTransaction = new HashMap();
64     // original line
65
//
66
// compliance with WEBDOCWF end
67
// Objects that make up this transaction
68
protected Transaction[] trans = {};
69     // Action (INSERT, UPDATE, DELETE) to apply to each object
70
// in the objects array.
71
protected int[] transAction = {};
72     // Index of next action to apply
73
protected int transIdx = 0;
74     // Counts how many times commit will be retried on deadlock exception
75
protected int dbLockCounter = 0;
76     // Amount by which to increment the array size if it is full.
77
protected final int SIZE_DELTA = 10;
78     // Transaction Cache size: number of DO objects (-1 unlimited)
79
protected final int CACHE_SIZE = -1;
80
81     // Transaction Complex Query Cache size
82
protected final int COMPLEX_QUERY_CACHE_SIZE = 0;
83
84     // Transaction Simple Query Cache size
85
protected final int SIMPLE_QUERY_CACHE_SIZE = 0;
86
87     // Transaction cache
88
protected DOCache cache = null;
89
90     // Transaction deleted DO's - circular references
91
protected Vector deletedRefs = null;
92
93     /*
94      * The log channel.
95      */

96     // private LogChannel channel;
97
protected static final int INSERT = 1;
98     protected static final int UPDATE = 2;
99     protected static final int DELETE = 3;
100
101     protected boolean isTransactionCaches;
102     protected boolean isAutoWrite = false;
103     protected boolean sqlBatch;
104     protected boolean firstWrite = true;
105
106     /**
107      * Construct a transaction object for use on the supplied dB connection.
108      *
109      * @param conn
110      * The database connection to use.
111      * @exception java.sql.SQLException
112      * If a database access error occurs.
113      */

114     protected StandardDBTransaction(DBConnection conn) throws SQLException JavaDoc {
115         try {
116             firstWrite=true;
117             id = nextId++;
118             logDebug("new instance");
119             this.conn = conn;
120             this.conn.setAutoCommit(false);
121             setDatabaseName(conn.getDatabaseName());
122             readConfigValues();
123             if (isTransactionCaches) {
124                 cache = new TransactionCacheImpl(SIMPLE_QUERY_CACHE_SIZE,
125                                                  COMPLEX_QUERY_CACHE_SIZE);
126             }
127         } catch (SQLException JavaDoc sqlExcept) {
128             this.conn.handleException(sqlExcept);
129             this.conn.release();
130             throw sqlExcept;
131         } catch (CacheObjectException cacheExcept) {
132             DODS.getLogChannel().write(Logger.ERROR,
133                                        "Error during transacion cache initialization");
134         }
135     }
136
137     /**
138      * This constructor is only for use in inherited class.
139      * Don't direct call.
140      */

141     protected StandardDBTransaction(){}
142
143
144     /* Method find a DO in the transaction
145      *
146      * @param transaction
147      * Object that implements transaction interface.
148      * @return DO if the oid was in the transaction, null if it was not
149      *
150      * WebDocWf extension
151      */

152     public synchronized Transaction getDO(Transaction transaction) {
153         return getDO(transaction, NONE);
154     }
155
156     /**
157      * Method find a DO in the transaction
158      *
159      * @param transaction
160      * Object that implements transaction interface.
161      * @param action
162      * if not NONE=0, the DO is found only woth the matching action
163      * @return DO if the oid was in the transaction, null if it was not
164      *
165      * WebDocWf extension
166      */

167     public synchronized Transaction getDO(Transaction transaction, int action) {
168         CoreDO foundDO = null;
169
170         if (transaction instanceof CoreDO) {
171             String JavaDoc strOID = ((CoreDO) transaction).get_OId().toString();
172
173             // if (this.hmpObjectTransaction.containsValue(strOID)) {
174
if (this.hmpObjectTransaction.containsKey(strOID)) {
175                 if (action == NONE
176                     || ((DOAction) this.hmpObjectTransaction.get(strOID)).getAction()
177                     == action) {
178                     foundDO = (CoreDO) ((DOAction) this.hmpObjectTransaction.get(strOID)).getDO();
179                 }
180             }
181         }
182         return foundDO;
183     }
184     // Parameter for no special action
185
protected static final int NONE = 0;
186     // original line
187
//
188
// compliance with WEBDOCWF end
189
/**
190      * Method to add an object to the transaction list.
191      *
192      * @param transaction
193      * Object that implements transaction interface.
194      */

195     // compliance with WEBDOCWF begin
196
private synchronized void add(Transaction transaction, int action) {
197         if (transaction instanceof CoreDO) {
198             String JavaDoc strOID = ((CoreDO) transaction).get_OId().toString();
199             int iDOAction = NONE;
200
201             if (aggregateModifications && this.vecSortedTransaction.size() > 0) {
202                 DOAction doa = (DOAction) this.vecSortedTransaction.lastElement();
203
204                 if (((CoreDO) doa.getDO()).get_OId().toString().equals(strOID)) {
205                     iDOAction = ((DOAction) this.vecSortedTransaction.lastElement()).getAction();
206                     if (iDOAction == UPDATE
207                         && (action == INSERT || action == UPDATE)) {
208                         return;
209                     }
210                     if (iDOAction == INSERT
211                         && (action == INSERT || action == UPDATE)) {
212                         return;
213                     }
214                     if (iDOAction == DELETE && action == DELETE) {
215                         return;
216                     }
217                 }
218             }
219             if (isAutoWrite && this.vecSortedTransaction.size() > 0) {
220                 try {
221                     write();
222                 } catch (SQLException JavaDoc sqle) {
223                     sqle.printStackTrace();
224                     // FIXME:
225
}
226             }
227             DOAction objDOAction = new DOAction(transaction, action);
228
229             this.hmpObjectTransaction.put(strOID, objDOAction);
230             this.vecSortedTransaction.add(objDOAction);
231         }
232     }
233
234     /**
235      * Method to update an object in the database.
236      *
237      * @param transaction
238      * Object that implements transaction interface.
239      */

240     public void update(Transaction transaction) {
241         add(transaction, UPDATE);
242         aggregateModifications = true;
243     }
244
245     /**
246      * Method to delete an object in the database.
247      *
248      * @param transaction
249      * Object that implements transaction interface.
250      */

251     public void delete(Transaction transaction) {
252         // If the transaction is an instance of CoreDO and we're
253
// doing a DELETE, then check if the oid of this CoreDO
254
// is the same as the oid of an existing CoreDO in our
255
// transaction. If this is true, do not add this
256
// transaction because we are already deleting the DO.
257
// This will happen occassionally during complex CASCADE DELETE
258
// scenarios when the programmer passes their own
259
// DBTransaction to the ***DO.delete() methods.
260
add(transaction, DELETE);
261         aggregateModifications = true;
262     }
263
264     /**
265      * Method to insert an object in the database.
266      *
267      * @param transaction
268      * Object that implements transaction interface.
269      */

270     public void insert(Transaction transaction) {
271         add(transaction, INSERT);
272         aggregateModifications = true;
273     }
274
275     /**
276      * Method to commit upates.
277      *
278      *
279      * contains WebDocWf bug fix, transaction needs to be cleared
280      *
281      * @exception java.sql.SQLException If a database access error occurs.
282      * @exception DBRowUpdateException If a version error occurs.
283      */

284     public void commit() throws SQLException JavaDoc, DBRowUpdateException {
285         int retryCount = lockRetryCount;
286         long wrapperHandle = 0;
287         Vector vecDOclass = new Vector();
288
289         logDebug("commit");
290         validate();
291         if (!wasReadOnly()) {
292             // if this transaction has accumulated any writes
293
// (either previously done, or pending), we do the drill
294
try {
295                 conn.incrRequestCount(); // Record request
296
write();
297                 // lock the main cache wrapper
298
while (0 == (wrapperHandle = Wrapper.getInstance().lock())) {
299                     try {
300                         Thread.sleep(lockWaitTime);
301                     } catch (InterruptedException JavaDoc ie) {}
302                     if (retryCount-- == 0) {
303                         throw new SQLException JavaDoc("Can't wait anymore.");
304                     }
305                 }
306                 // hide DOs before commit, and gather Class objects for them
307
for (Enumeration e = vecExecutedTransaction.elements(); e.hasMoreElements();) {
308                     CoreDO cdo = (CoreDO) ((DOAction) e.nextElement()).getDO();
309                     Class JavaDoc doClass = cdo.getClass();
310
311                     if (!vecDOclass.contains(doClass)) {
312                         vecDOclass.add(doClass);
313                     }
314                     if (!vecAlreadyHidden.contains(cdo)) {
315                         cdo.makeInvisible();
316                         vecAlreadyHidden.add(cdo);
317                     }
318                 }
319                 Wrapper.getInstance().makeSimpleComplexQCachesInvisible(vecDOclass);
320                 Wrapper.getInstance().makeMultiJoinQCachesInvisible(); // tj 01.03.2005
321
// Wrapper.getInstance().removeAllMultiJoinQueries(); // tj 29.08.2004
322
Wrapper.getInstance().unlock(wrapperHandle);
323                 wrapperHandle = 0;
324                 conn.commit();
325                 // Notify all objects that the transaction succeeded.
326
transactionNotify(true);
327                 Wrapper.getInstance().removeAllMultiJoinQueries(); // tj 29.08.2004, moved 01.03.2005
328
} catch (SQLException JavaDoc sqlExcept) {
329                 handleException(sqlExcept);
330                 rollback();
331                 throw sqlExcept;
332             } finally {
333                 if (retryCount >= 0) {
334                     while (0 == (wrapperHandle = Wrapper.getInstance().lock())) {
335                         try {
336                             Thread.sleep(lockWaitTime);
337                         } catch (InterruptedException JavaDoc ie) {}
338                         if (--retryCount == 0) {
339                             logDebug("spent " + lockRetryCount + " times "
340                                          + lockWaitTime
341                                          + "miliseconds, but musn't give up.");
342                             retryCount = lockRetryCount;
343                         }
344                     }
345                     for (Enumeration e = vecAlreadyHidden.elements(); e.hasMoreElements();) {
346                         ((CoreDO) e.nextElement()).makeVisible();
347                     }
348                     Wrapper.getInstance().makeSimpleComplexQCachesVisible(vecDOclass);
349                     Wrapper.getInstance().makeMultiJoinQCachesVisible(); // tj 01.03.2005.
350
Wrapper.getInstance().unlock(wrapperHandle);
351                 }
352                 // compliance with WEBDOCWF begin
353
this.hmpObjectTransaction = new HashMap();
354                 this.vecSortedTransaction = new Vector();
355                 this.vecExecutedTransaction = new Vector();
356                 this.vecAlreadyHidden = new Vector();
357                 _preventCacheQueries = false;
358             }
359         } else {
360             // this transaciton didn't changed anything in database,
361
// so this commit may be safely ignored
362
logDebug("Nothing to write.");
363         }
364     }
365
366     /**
367      * Method to rollback changes.
368      *
369      *
370      * contains WebDocWf bug fix, transaction needs to be cleared
371      *
372      * @exception java.sql.SQLException
373      * If a database access error occurs.
374      */

375     public void rollback() throws SQLException JavaDoc {
376         try {
377             logDebug("rollback");
378             validate();
379             conn.rollback();
380             // Updates cache after transaction's rollback
381
for (int iCounter = 0; iCounter < this.vecSortedTransaction.size(); iCounter++) {
382                 try {
383                     DOAction objDOAction = (DOAction) this.vecSortedTransaction.get(iCounter);
384
385                     ((CoreDO) objDOAction.getDO()).refresh();
386                 } catch (DataObjectException dataExept) {
387                     // removes DO from cache if it doesn't exist in the database
388
if (dataExept.getMessage().indexOf("DO not found for id")
389                         != -1) { // if DO doesn't exist
390
DOAction objDOAction = (DOAction) this.vecSortedTransaction.get(iCounter);
391
392                         ((CoreDO) objDOAction.getDO()).evict();
393                     } else {
394                         SQLException JavaDoc g = new SQLException JavaDoc("INTERNAL ERROR: unexpected DataObjectException");
395                         throw g;
396                     }
397                 }
398             }
399         } catch (SQLException JavaDoc sqlExcept) {
400             handleException(sqlExcept);
401             throw sqlExcept;
402         }
403         finally {
404             // Notify all objects that the transaction failed.
405
transactionNotify(false);
406             // compliance with WEBDOCWF begin
407
this.hmpObjectTransaction = new HashMap();
408             this.vecSortedTransaction = new Vector();
409             // original line
410
//
411
// compliance with WEBDOCWF end
412
}
413     }
414
415     /**
416      * Notify all objects in this transaction if the
417      * transaction was successfully commited to the database.
418      * An object will only be notified once of success or failure
419      * even if this method is called multiple times.
420      *
421      * @param succeeded true if the transaction commited successfully.
422      */

423     private synchronized void transactionNotify(boolean succeeded) {
424         for (int iCounter = 0; iCounter < this.vecExecutedTransaction.size(); iCounter++) {
425             DOAction objDOAction = (DOAction) this.vecExecutedTransaction.get(iCounter);
426
427             switch (objDOAction.getAction()) {
428                 case INSERT:
429                     objDOAction.getDO().finalizeInsert(succeeded);
430                     break;
431
432                 case UPDATE:
433                     objDOAction.getDO().finalizeUpdate(succeeded);
434                     break;
435
436                 case DELETE:
437                     objDOAction.getDO().finalizeDelete(succeeded);
438                     break;
439             }
440         }
441     }
442
443     /**
444      * Frees all resources consumed by this transaction
445      * Connections are returned to the connection pool.
446      * Subsequent transactions via this object,
447      * will allocate a new set of resources (i.e. connection).
448      *
449      * contains WebDocWf bug fix, transaction needs to be cleared
450      *
451      */

452     public synchronized void release() {
453         try {
454             logDebug("release");
455             if (!released) {
456                 if (vecExecutedTransaction.size() > 0) {
457                     rollback();
458                 }
459                 conn.reset();
460             }
461         } catch (SQLException JavaDoc sqlExcept) {
462             handleException(sqlExcept);
463         }
464         finally {
465             if(conn!=null)
466                 conn.release();
467             conn = null;
468             released = true;
469             cache = null;
470             this.hmpObjectTransaction = new HashMap(); // TODO should be null?
471
this.vecSortedTransaction = new Vector();
472             this.vecExecutedTransaction = new Vector();
473         }
474     }
475
476     /**
477      * Exception handeler. This object is should not be
478      * used for subsequent queries if this method returns
479      * false.
480      *
481      * @return boolean True if the exception can be handeled
482      * and the object is still valid, false otherwise.
483      */

484     public synchronized boolean handleException(SQLException JavaDoc e) {
485         logDebug("handle exception");
486         return conn.handleException(e);
487     }
488
489     /**
490      * Method to ensure this object is still valid.
491      * Once this object has been released it cannot be
492      * used any more.
493      *
494      * @exception java.sql.SQLException
495      * If a database access error occurs.
496      */

497     protected void validate() throws SQLException JavaDoc {
498         if (released) {
499             throw new SQLException JavaDoc("Cannot access DBTransaction object "
500                                         + "once it has been released.");
501         }
502     }
503
504
505     /**
506      * Method to ensure this object is still valid.
507      * Once this object has been released it cannot be
508      * used any more.
509      *
510      * @return boolean True if the transaction is released, otherwise false
511      */

512     public boolean isReleased() {
513         return released;
514     }
515
516     /**
517      * If this object has not been <A HREF=#release>released</A>,
518      * this method ensures that garbage collection does so.
519      */

520     protected void finalize() {
521         if (!released) {
522             release();
523         }
524     }
525
526     /**
527      * Logging. For debuging only, since it effects all Query objects.
528      *
529      * @param str
530      * The data to log.
531      */

532     protected void logDebug(String JavaDoc str) {
533         if (DatabaseManager.debug) {
534             DODS.getLogChannel().write(Logger.DEBUG, "DBTransaction[" + id + "]: " + str);
535         }
536     }
537     protected class DOAction {
538         private Transaction transDO;
539         private int iAction;
540         public DOAction(Transaction transDOIn, int iActionIn) {
541             this.transDO = transDOIn;
542             this.iAction = iActionIn;
543         }
544
545         public Transaction getDO() {
546             return this.transDO;
547         }
548
549         public int getAction() {
550             return this.iAction;
551         }
552
553         public void setAction(int action) {
554             this.iAction = action;
555         }
556         public boolean equals(Object JavaDoc o) {
557             return o instanceof DOAction
558                 && iAction == ((DOAction)o).iAction
559                 && transDO.equals(((DOAction)o).transDO);
560         }
561     }
562
563     /**
564      * Name of used database
565      */

566     protected String JavaDoc databaseName;
567
568     /**
569      * Method return name of used database
570      *
571      * @return name of used database
572      */

573     public String JavaDoc getDatabaseName() {
574         return databaseName;
575     }
576
577     /**
578      * Method set name of used database
579      *
580      * @param dbName name of used database
581      */

582     public void setDatabaseName(String JavaDoc dbName) {
583         databaseName = dbName;
584     }
585
586     /**
587      * Gets an array of DOs.
588      *
589      * @return array of DOs from this transaction
590      */

591     public CoreDO[] getDOs() {
592         return (CoreDO[]) vecSortedTransaction.toArray();
593     }
594
595     /**
596      *
597      */

598     public void saveDirtyDOs() {
599         throw new RuntimeException JavaDoc("NOT implemented, yet!");
600     }
601
602     /**
603      *
604      * @exception java.sql.SQLException If a database access error occurs.
605      * @exception DBRowUpdateException If a version error occurs.
606      */

607     public void write() throws SQLException JavaDoc, DBRowUpdateException {
608         logDebug("write");
609         validate();
610         // compliance with WEBDOCWF begin
611
if (firstWrite){
612             firstWrite=false;
613             if (conn.getConnection().isClosed()){
614                 logDebug("Write failed, connection are closed by driver");
615                 throw new SQLException JavaDoc("Write failed, connection are closed by driver");
616             }
617         }
618         try {
619             PreparedStatement JavaDoc stmt = null;
620             ArrayList batch = new ArrayList();
621             for (int iCounter = 0; iCounter < this.vecSortedTransaction.size();/* iCounter++*/) {
622                 DOAction objDOAction = (DOAction) this.vecSortedTransaction.get(iCounter);
623                 int action = objDOAction.getAction();
624                 CoreDO aDO = (CoreDO) objDOAction.getDO();
625
626                 if (this.vecSortedTransaction.size() > 1) {
627                     DOAction objNextDOAction = (DOAction) this.vecSortedTransaction
628                         .get(1 + iCounter);
629
630                     if (DELETE == objNextDOAction.getAction()
631                         && aDO.get_OId().equals(((CoreDO) objNextDOAction.getDO()).get_OId())) {
632                         if (!aDO.isPersistent()) {
633                             this.vecSortedTransaction.remove(objNextDOAction);
634                         }
635                         this.vecSortedTransaction.remove(objDOAction);
636                         continue;
637                     }
638                 }
639                 switch (action) {
640                     case INSERT:
641                         if (isSQLbatch()) {
642                             if (!(aDO instanceof GenericDO)
643                                 || ((GenericDO)aDO).isDirty()) {
644                                 stmt = (aDO.isPersistent())
645                                     ? aDO.getUpdateStatement(conn)
646                                     : aDO.getInsertStatement(conn);
647                                 stmt.addBatch();
648                                 aDO.setPersistent(true);
649                                 if (!batch.contains(stmt)) {
650                                     batch.add(stmt);
651                                 }
652                             }
653                         } else
654                             aDO.executeInsert(conn);
655                         break;
656
657                     case UPDATE:
658                         if (isSQLbatch()) {
659                             if (!(aDO instanceof GenericDO)
660                                 || ((GenericDO)aDO).isDirty()) {
661                                 stmt = aDO.getUpdateStatement(conn);
662                                 stmt.addBatch();
663                                 if (!batch.contains(stmt)) {
664                                     batch.add(stmt);
665                                 }
666                             }
667                         } else
668                             aDO.executeUpdate(conn);
669                         break;
670
671                     case DELETE:
672                         if (isSQLbatch()) {
673                             stmt = aDO.getDeleteStatement(conn);
674                             stmt.addBatch();
675                             if (!batch.contains(stmt))
676                                 batch.add(stmt);
677                         } else
678                             aDO.executeDelete(conn);
679                         break;
680                 }
681                 _preventCacheQueries = true;
682
683                 this.vecExecutedTransaction.add(objDOAction);
684                 this.vecSortedTransaction.remove(iCounter);
685             }
686             if (isSQLbatch()) {
687                 //new Throwable("BATCH_SIZE:"+batch.size()).printStackTrace();
688
for (Iterator iter = batch.iterator();
689                      iter.hasNext();) {
690                     PreparedStatement JavaDoc element = (PreparedStatement JavaDoc)iter.next();
691                     int[] affected = element.executeBatch();
692                     element.clearBatch();
693                     for (int _i = 0; _i < affected.length; ++_i) {
694                         if (affected[_i] <= 0)
695                             throw new DBRowUpdateException("batch failed for "
696                                                                + element
697                                                                +" returned "
698                                                                +affected[_i]);
699                     }
700                 }
701             }
702         } catch (SQLException JavaDoc e) {
703             logDebug("Write failed, there are " + vecSortedTransaction.size()
704                          + " DOs unwritten.");
705             throw e;
706         }
707     }
708
709     /**
710      * Method return transaction Cache
711      *
712      * @return implementation of DOCache
713      */

714     public DOCache getTransactionCache() {
715         return cache;
716     }
717
718     /**
719      * Method set Transaction Cache
720      *
721      * @param implementation of DOCache
722      */

723     private void setTransactionCache(DOCache transCache) {
724         cache = transCache;
725     }
726     private long lockWaitTime;
727     private int lockRetryCount;
728
729     /**
730      *
731      */

732     public Vector getDeletedDOs() {
733
734         return deletedRefs;
735     }
736
737     /**
738      *
739      */

740     public void addDeletedDO(CoreDO DO) {
741
742         if (deletedRefs == null) {
743             deletedRefs = new Vector();
744         }
745         String JavaDoc handle = null;
746
747         if (DO.get_OId() != null) {
748             handle = getDatabaseName() + "." + DO.get_OId();
749             deletedRefs.addElement(handle);
750         }
751     }
752
753     /**
754      *
755      */

756     public void resetDeletedDOs() {
757         if (deletedRefs != null) {
758             deletedRefs = new Vector();
759         }
760     }
761
762     public void lockDO(Transaction cdo) throws SQLException JavaDoc {
763         ((CoreDO) cdo).executeLockingStatement(conn);
764     }
765
766     /**
767      * @return true if this transaction has executed a statement
768      * against database, so cached queries are obsolete
769      */

770     public boolean preventCacheQueries() {
771         return _preventCacheQueries;
772     }
773
774     /**
775      * Return a query for use with this TRANSACTION please!!!
776      *
777      * @return The query object.
778      * @exception SQLException
779      * if a SQL error occurs.
780      */

781     public DBQuery createQuery() throws SQLException JavaDoc {
782         StandardDBQuery sdbq = new StandardDBQuery(conn);
783
784         sdbq.setReleaseConnection(false);
785         return sdbq;
786     }
787     protected boolean aggregateModifications = true;
788
789     /**
790      *
791      */

792     public void dontAggregateDOModifications() {
793         aggregateModifications = false;
794     }
795
796     /**
797      * Return a query for use with this TRANSACTION please!!!
798      *
799      * @return The query object.
800      * @exception SQLException
801      * if a SQL error occurs.
802      */

803     protected void readConfigValues() {
804         try {
805             isTransactionCaches = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(getDatabaseName()))).getDatabaseConfiguration().getTransactionCaches();
806         } catch (Exception JavaDoc ex) {
807             isTransactionCaches = ((StandardDatabaseManager) (DODS.getDatabaseManager())).getDatabaseManagerConfiguration().getTransactionCaches();
808         }
809         try {
810             lockWaitTime = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(getDatabaseName()))).getDatabaseConfiguration().getDeadlockWaitTime();
811         } catch (Exception JavaDoc ex) {
812             lockWaitTime = ((StandardDatabaseManager) (DODS.getDatabaseManager())).getDatabaseManagerConfiguration().getDeadlockWaitTime();
813         }
814         try {
815             lockRetryCount = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(getDatabaseName()))).getDatabaseConfiguration().getDeadlockRetryCount();
816         } catch (Exception JavaDoc ex) {
817             lockRetryCount = ((StandardDatabaseManager) (DODS.getDatabaseManager())).getDatabaseManagerConfiguration().getDeadlockRetryCount();
818         }
819         try {
820             isAutoWrite = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(getDatabaseName()))).getDatabaseConfiguration().getAutoWrite();
821         } catch (Exception JavaDoc ex) {
822             isAutoWrite = ((StandardDatabaseManager) (DODS.getDatabaseManager())).getDatabaseManagerConfiguration().getAutoWrite();
823         }
824         try {
825             sqlBatch = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(getDatabaseName()))).getDatabaseConfiguration().isSqlBatch();
826         } catch (Exception JavaDoc ex) {
827             sqlBatch = ((StandardDatabaseManager) (DODS.getDatabaseManager())).getDatabaseManagerConfiguration().isSqlBatch();
828         }
829     }
830
831     /**
832      * Method returns value of a data member.
833      *
834      * @return value of config parameter AutoWrite
835      * true means all DOs are writen into database, as they come in
836      * false - no writes are done implicitly
837      */

838     public boolean getAutoWrite() {
839         return isAutoWrite;
840     }
841     public boolean isSQLbatch() {
842         return sqlBatch;
843     }
844
845     /**
846      *
847      */

848     public boolean isFirstWrite(){
849         return firstWrite;
850     }
851
852
853     /**
854      *
855      */

856     public void setFirstWrite(boolean newfw){
857         firstWrite=newfw;
858     }
859
860    public boolean wasReadOnly() {
861       return 0 == vecExecutedTransaction.size() + vecSortedTransaction.size();
862    }
863 }
864
Popular Tags