KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jspPhoneBook > data > PersonQuery


1
2 /*-----------------------------------------------------------------------------
3  * Enhydra Java Application Server
4  * Copyright 1997-2000 Lutris Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  * must display the following acknowledgement:
17  * This product includes Enhydra software developed by Lutris
18  * Technologies, Inc. and its contributors.
19  * 4. Neither the name of Lutris Technologies nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *-----------------------------------------------------------------------------
35  * phoneList.data/PersonQuery.java
36  *-----------------------------------------------------------------------------
37  */

38
39 package jspPhoneBook.data;
40
41 import org.enhydra.dods.DODS;
42 import com.lutris.dods.builder.generator.query.*;
43 import com.lutris.appserver.server.sql.*;
44 import org.enhydra.dods.cache.LRUCache;
45 import org.enhydra.dods.cache.DataStructCache;
46 import org.enhydra.dods.cache.QueryCache;
47 import org.enhydra.dods.cache.QueryCacheItem;
48 import org.enhydra.dods.cache.QueryResult;
49 import org.enhydra.dods.cache.DataStructShell;
50 import org.enhydra.dods.cache.DOShell;
51 import org.enhydra.dods.cache.Condition;
52 import org.enhydra.dods.statistics.Statistics;
53 import org.enhydra.dods.cache.CacheConstants;
54 import org.enhydra.dods.statistics.*;
55 import com.lutris.logging.LogChannel;
56 import com.lutris.logging.Logger;
57 import com.lutris.appserver.server.sql.standard.StandardDBTransaction;
58
59 import java.sql.*;
60 import java.util.*;
61 import java.math.*;
62 import java.util.Date JavaDoc; // when I say Date, I don't mean java.sql.Date
63

64 /**
65  * PersonQuery is used to query the person table in the database.<BR>
66  * It returns objects of type PersonDO.
67  * <P>
68  * General usage:
69  * <P>
70  * In DODS:
71  * Create a Data Object named "Dog",
72  * and create an Attribute named "Name",
73  * and set that Attribute to "Can be queried."
74  * DODS will then generate the method DogQuery.setQueryName().
75  * <P>
76  * In your Business Layer, prepare the query:<BR>
77  * <P><PRE>
78  * DogQuery dq = new DogQuery();
79  * dq.setQueryName("Rex")
80  * if ( Rex is a reserved name )
81  * dq.requireUniqueInstance();
82  * </PRE>
83  * Then, get the query results one of two ways:
84  * <P>
85  * #1:<PRE>
86  * String names = "";
87  * DogDO[] dogs = dq.getDOArray();
88  * for ( int i = 0; i < dogs.length; i++ ) {
89  * names += dogs[i].getName() + " ";
90  * }
91  * </PRE>
92  * or #2:<PRE>
93  * String names = "";
94  * DogDO dog;
95  * while ( null != ( dog = dq.getNextDO() ) ) {
96  * names += dog.getName() + " ";
97  * }
98  * </PRE>
99  * <P>
100  * Note: If <CODE>requireUniqueInstance()</CODE> was called,
101  * then <CODE>getDOArray()</CODE> or <CODE>getNextDO()</CODE>
102  * will throw an exception if more than one "Rex" was found.
103  * <P>
104  * Note: Results of the query will come from the Data Object cache if:
105  * - The cache is available.
106  * - Matches were found in the cache.
107  * - No other tables (Data Objects of other types) were involved
108  * in the query.
109  * This can happen if you extend the <CODE>DogQuery</CODE> class
110  * and you make calls to the <CODE>QueryBuilder</CODE> object
111  * to add SQL involving other tables.
112  * If any of these conditions is not true,
113  * then any results from the query will come from the database.
114  * <P>
115  * To reuse the query object, call:
116  * <P><PRE>
117  * dq.reset();
118  * </PRE>
119  * @author EnhydraTeam
120  * @version $Revision: 1.1 $
121  */

122 public class PersonQuery implements Query {
123
124     private QueryBuilder builder;
125
126     /**
127      * logical name of the database for which PersonQuery object has been created
128      */

129     private String JavaDoc logicalDatabase;
130
131     private ResultSet resultSet = null;
132     private boolean uniqueInstance = false;
133     private boolean loadData = false;
134     private PersonDO[] DOs = null;
135     private int arrayIndex = -1;
136     private boolean needToRun = true;
137     private LinkedHashMap cacheHits = null;
138     private boolean isQueryByOId = false;
139     private boolean hasNonOidCond = false;
140     private boolean hitDb = false;
141     private boolean userHitDb = false;
142     private int maxDBrows = 0;
143     private boolean orderRelevant = true; // true if order of query results is relavant, otherwise false
144
private QueryCacheItem queryItem = null;
145     private String JavaDoc currentHandle = null;
146     private HashMap refs = new HashMap();
147         private int iCurrentFetchSize = -1;
148         private int iCurrentQueryTimeout = 0;
149     private DBTransaction transaction = null;
150
151     /**
152      * Public constructor.
153          *
154
155      */

156     public PersonQuery() {
157
158         builder = new QueryBuilder( "person", "person.*" );
159
160         String JavaDoc dbName = PersonDO.get_logicalDBName();
161         try {
162             String JavaDoc vendor = DODS.getDatabaseManager().logicalDatabaseType(dbName);
163             if (vendor != null) {
164                 builder.setDatabaseVendor(vendor);
165                 logicalDatabase = dbName;
166             } else {
167                 builder.setDatabaseVendor();
168                 logicalDatabase = DODS.getDatabaseManager().getDefaultDB();
169             }
170         } catch (Exception JavaDoc e) {
171             builder.setDatabaseVendor();
172             logicalDatabase = DODS.getDatabaseManager().getDefaultDB();
173         }
174         builder.setUserStringAppendWildcard( false );
175         builder.setUserStringTrim( false );
176         reset();
177     }
178
179     /**
180      * Public constructor.
181          *
182      * @param dbTrans current database transaction
183      */

184     public PersonQuery(DBTransaction dbTrans) {
185
186         builder = new QueryBuilder( "person", "person.*" );
187
188         String JavaDoc dbName = null;
189         if(dbTrans!=null)
190             dbName = dbTrans.getDatabaseName();
191         else
192             dbName = PersonDO.get_logicalDBName();
193         try {
194             transaction = dbTrans;
195             String JavaDoc vendor = DODS.getDatabaseManager().logicalDatabaseType(dbName);
196             if (vendor != null) {
197                 builder.setDatabaseVendor(vendor);
198                 logicalDatabase = dbName;
199             } else {
200                 builder.setDatabaseVendor();
201                 logicalDatabase = DODS.getDatabaseManager().getDefaultDB();
202             }
203         } catch (Exception JavaDoc e) {
204             builder.setDatabaseVendor();
205             logicalDatabase = DODS.getDatabaseManager().getDefaultDB();
206         }
207         builder.setUserStringAppendWildcard( false );
208         builder.setUserStringTrim( false );
209         reset();
210     }
211
212
213
214     /**
215      * Return logical name of the database that PersonQuery object uses
216      *
217      * @return param logical database name
218      *
219      */

220     public String JavaDoc getLogicalDatabase() {
221         return logicalDatabase;
222     }
223
224     /**
225      * Change logical database to another logical database (which name is dbName)
226      *
227      * @param dbName the logical name of the database
228      *
229      */

230     public void setLogicalDatabase(String JavaDoc dbName) throws SQLException, DatabaseManagerException {
231         String JavaDoc vendor = DODS.getDatabaseManager().logicalDatabaseType(dbName);
232         if (vendor != null) {
233             builder.setDatabaseVendor(vendor);
234             logicalDatabase = dbName;
235         } else {
236             builder.setDatabaseVendor();
237             logicalDatabase = DODS.getDatabaseManager().getDefaultDB();
238         }
239         reset();
240     }
241
242
243
244     // WebDocWf extension for unique query results without SQL DISTINCT
245
// The following lines has been added:
246
private boolean unique = false;
247
248     /**
249      * Set the unique flag of the query
250      *
251      * @param newUnique The unique flag for the query
252      *
253      * WebDocWf extension
254      *
255      */

256     public void setUnique(boolean newUnique) { unique = newUnique; }
257
258     /**
259      * Get the unique flag of the query
260      *
261      * @return The unique flag of the query
262      *
263      * WebDocWf extension
264      *
265      */

266     public boolean getUnique() { return unique; }
267
268     // WebDocWf extension for skipping the n first rows of the result
269
// The following lines has been added:
270
private int readSkip = 0;
271
272     /**
273      * Set the readSkip number of the query
274      *
275      * @param newreadSkip The number of results to skip
276      *
277      * WebDocWf extension
278      *
279      */

280     public void setReadSkip(int newReadSkip) {
281       readSkip = newReadSkip;
282     }
283
284     /**
285      * Get the readSkip number of the query
286      *
287      * @return The number of rows which are skipped
288      *
289      * WebDocWf extension
290      *
291      */

292     public int getReadSkip() { return readSkip; }
293
294     // WebDocWf extension for select rowcount limit
295
// The following lines has been added:
296
private int databaseLimit = 0;
297
298     /**
299      * Set the database limit of the query
300      *
301      * @param newLimit The limit for the query
302      *
303      * WebDocWf extension
304      *
305      */

306     public void setDatabaseLimit(int newLimit) {
307       databaseLimit = newLimit;
308     }
309
310     /**
311      * Get the database limit of the query
312      *
313      * @return The database limit of the query
314      *
315      * WebDocWf extension
316      *
317      */

318     public int getDatabaseLimit() { return databaseLimit; }
319
320     private boolean databaseLimitExceeded = false;
321
322     /**
323      * Get the database limit exceeded flag of the query.
324      *
325      * @return The database limit exceeded flag of the query
326      * True if there would have been more rows than the limit, otherwise false.
327      *
328      * WebDocWf extension
329      */

330     public boolean getDatabaseLimitExceeded() { return databaseLimitExceeded; }
331     // end of WebDocWf extension for select rowcount limit
332

333     /**
334      * Set that all queries go to database, not to cache.
335      */

336     public void hitDatabase() { userHitDb = true; }
337
338     // WebDocWf extension for extended wildcard support
339
// The following rows have been added:
340

341     /**
342      * Set user string wildcard.
343      *
344      * @param newUserStringWildcard New user string wildcard.
345      *
346      * WebDocWf extension
347      */

348     public void setUserStringWildcard(String JavaDoc newUserStringWildcard) {
349         builder.setUserStringWildcard( newUserStringWildcard );
350     }
351
352     /**
353      * Set user string single wildcard.
354      *
355      * @param newUserStringSingleWildcard New user string single wildcard.
356      *
357      * WebDocWf extension
358      */

359     public void setUserStringSingleWildcard(String JavaDoc newUserStringSingleWildcard) {
360         builder.setUserStringSingleWildcard( newUserStringSingleWildcard );
361     }
362
363     /**
364      * Set user string single wildcard escape.
365      *
366      * @param newUserStringSingleWildcardEscape New user string single wildcard escape.
367      *
368      * WebDocWf extension
369      */

370     public void setUserStringSingleWildcardEscape(String JavaDoc newUserStringSingleWildcardEscape) {
371         builder.setUserStringSingleWildcardEscape( newUserStringSingleWildcardEscape );
372     }
373
374     /**
375      * Set user string wildcard escape.
376      *
377      * @param newUserStringWildcardEscape New user string wildcard escape.
378      *
379      * WebDocWf extension
380      */

381     public void setUserStringWildcardEscape(String JavaDoc newUserStringWildcardEscape) {
382         builder.setUserStringWildcardEscape( newUserStringWildcardEscape );
383     }
384
385     /**
386      * Set user string append wildcard.
387      *
388      * @param userStringAppendWildcard New user string append wildcard.
389      *
390      * WebDocWf extension
391      */

392     public void setUserStringAppendWildcard(boolean userStringAppendWildcard ) {
393         builder.setUserStringAppendWildcard( userStringAppendWildcard );
394     }
395
396      /**
397      * Set user string trim.
398      *
399      * @param userStringTrim New user string trim.
400      *
401      * WebDocWf extension
402      */

403     public void setUserStringTrim(boolean userStringTrim ) {
404         builder.setUserStringTrim( userStringTrim );
405     }
406
407     /**
408      * Get user string wildcard.
409      *
410      * @return User string wildcard.
411      *
412      * WebDocWf extension
413      */

414     public String JavaDoc getUserStringWildcard() {
415         return builder.getUserStringWildcard();
416     }
417
418     /**
419      * Get user string single wildcard.
420      *
421      * @return User string single wildcard.
422      *
423      * WebDocWf extension
424      */

425     public String JavaDoc getUserStringSingleWildcard() {
426         return builder.getUserStringSingleWildcard();
427     }
428
429     /**
430      * Get user string single wildcard escape.
431      *
432      * @return User string single wildcard escape.
433      *
434      * WebDocWf extension
435      */

436     public String JavaDoc getUserStringSingleWildcardEscape() {
437         return builder.getUserStringSingleWildcardEscape();
438     }
439
440     /**
441      * Get user string wildcard escape.
442      *
443      * @return User string wildcard escape.
444      *
445      * WebDocWf extension
446      */

447     public String JavaDoc getUserStringWildcardEscape() {
448         return builder.getUserStringWildcardEscape();
449     }
450
451     /**
452      * Get user string append wildcard.
453      *
454      * @return User string append wildcard.
455      *
456      * WebDocWf extension
457      */

458     public boolean getUserStringAppendWildcard() {
459         return builder.getUserStringAppendWildcard();
460     }
461
462     /**
463      * Get user string trim.
464      *
465      * @return User string trim.
466      *
467      * WebDocWf extension
468      */

469     public boolean getUserStringTrim() {
470         return builder.getUserStringTrim();
471     }
472     // end of WebDocWf extension for extended wildcard support
473

474     /**
475      * Perform the query on the database, and prepare the
476      * array of returned DO objects.
477      *
478      * @exception DataObjectException If a database access error occurs.
479      * @exception NonUniqueQueryException If too many rows were found.
480      */

481     private void getQueryByOIds(Vector DOs)
482     throws DataObjectException {
483         if (DOs.size() == 0)
484             return;
485         PersonDO DO = null;
486         DOShell shell = null;
487         PersonQuery tmpQuery = null;
488         Date JavaDoc startQueryTime = new Date JavaDoc();
489         long queryTime = 0;
490         for (int i=0; i<DOs.size(); i++) {
491             shell = (DOShell)DOs.elementAt(i);
492             tmpQuery = new PersonQuery(transaction);
493             try {
494              tmpQuery.setQueryHandle( shell.handle );
495              tmpQuery.requireUniqueInstance();
496
497              DO = tmpQuery.getNextDO();
498              if ( null == DO )
499                     throw new DataObjectException("PersonDO DO not found for id=" + shell.handle );
500             } catch ( Exception JavaDoc e ) {
501                throw new DataObjectException( "Duplicate ObjectId" );
502             }
503             shell.dataObject = DO;
504         }
505         Date JavaDoc stopQueryTime = new Date JavaDoc();
506         queryTime = stopQueryTime.getTime() - startQueryTime.getTime();
507         PersonDO.statistics.updateQueryByOIdAverageTime((new Long JavaDoc(queryTime)).intValue(),DOs.size());
508     }
509
510
511
512     /**
513      * Perform the query on the database, and prepare the
514      * array of returned DO objects.
515      *
516      * @exception DataObjectException If a database access error occurs.
517      * @exception NonUniqueQueryException If too many rows were found.
518      */

519     private void runQuery()
520     throws DataObjectException, NonUniqueQueryException {
521         needToRun = false;
522         arrayIndex = -1;
523         DBQuery dbQuery = null;
524         Date JavaDoc startQueryTime = new Date JavaDoc();
525         long queryTime = 0;
526         boolean readDOs = false;
527         boolean canUseQueryCache = true;
528         CacheStatistics stat = null;
529         boolean resultsFromQCache = false;
530         QueryCacheItem queryCachedItem = null;
531
532         if ((transaction!=null) &&
533         (transaction instanceof com.lutris.appserver.server.sql.standard.StandardDBTransaction)) {
534         if(((com.lutris.appserver.server.sql.standard.StandardDBTransaction)transaction).getAutoWrite()) try {
535             transaction.write();
536         } catch (SQLException sqle) {
537             sqle.printStackTrace();
538             throw new DataObjectException("Couldn't write transaction: "+sqle);
539         }
540         ((com.lutris.appserver.server.sql.standard.StandardDBTransaction)transaction).dontAggregateDOModifications();
541         }
542
543         try {
544             QueryResult results = null;
545             DOShell shell = null;
546             if (isQueryByOId && !hasNonOidCond) { // query by OId
547
results = new QueryResult();
548                 if (currentHandle != null) {
549                     if(transaction!=null && _tr_(transaction).getTransactionCache()!=null && !loadData) {
550                          PersonDO DO= (PersonDO)_tr_(transaction).getTransactionCache().getDOByHandle(currentHandle);
551                          if(DO!=null){
552                             shell = new DOShell(DO);
553                             results.DOs.add(shell);
554                             resultsFromQCache = true;
555                          }
556                          else
557                             resultsFromQCache = false;
558                     }
559                     if(!resultsFromQCache) { // DO isn't found in the transaction cache
560
PersonDataStruct DS = (PersonDataStruct)PersonDO.cache.getDataStructByHandle(currentHandle);
561                         if (DS != null) { // DO is found in the cache
562
PersonDO DO = (PersonDO)PersonDO.createExisting(DS.get_OId(), transaction);
563                           shell = new DOShell(DO);
564                           results.DOs.add(shell);
565                           resultsFromQCache = true;
566                          }else{ // DO isn't found in the cache
567
if (PersonDO.cache.isFull())
568                                  resultsFromQCache = false;
569                          }
570                     }
571                 }//currentHandle != null
572
}
573             else { // other queries
574
if ((PersonDO.cache.isFull()) && (!hitDb)) {
575                       resultsFromQCache = true;
576                 }
577                 else {
578                  if (PersonDO.cache.getLevelOfCaching() == CacheConstants.QUERY_CACHING) {
579                     if (hitDb) { // statistics about complex query
580
stat = null;
581                           stat = PersonDO.statistics.getCacheStatistics(CacheConstants.COMPLEX_QUERY_CACHE);
582                           if (stat!= null){
583                              stat.incrementCacheAccessNum(1);
584                           }
585                       }else{ // statistics about simple query
586
stat = null;
587                           stat = PersonDO.statistics.getCacheStatistics(CacheConstants.SIMPLE_QUERY_CACHE);
588                           if (stat!= null){
589                              stat.incrementCacheAccessNum(1);
590                           }
591                      }
592                  }
593                  if(transaction != null)
594                     canUseQueryCache = !transaction.preventCacheQueries();
595                   if ((PersonDO.cache.getLevelOfCaching() == CacheConstants.QUERY_CACHING) && canUseQueryCache) {
596                         String JavaDoc queryID = builder.getSQLwithParms(); //unique representation of query
597
int resNum = 0;
598                         int evaluateNo = 0;
599                        if (hitDb)
600                           queryCachedItem = ((QueryCache)PersonDO.cache).getComplexQueryCacheItem(logicalDatabase, queryID);
601                        else
602                           queryCachedItem = ((QueryCache)PersonDO.cache).getSimpleQueryCacheItem(logicalDatabase, queryID);
603                         queryItem.setQueryId(queryID); // queryItem defined as private template attribute
604
if (queryCachedItem == null) { // query doesn't exist
605
if ((!builder.isMultiTableJoin()) || PersonDO.isAllReadOnly()) {
606                                if (hitDb)
607                                      ((QueryCache)PersonDO.cache).addComplexQuery(queryItem); // register complex query
608
else
609                                       ((QueryCache)PersonDO.cache).addSimpleQuery(queryItem); // register simple query
610
}
611                         }else{ // query found
612
if ( !(isOrderRelevant() && queryCachedItem.isModifiedQuery()) ) {
613                                 if (hitDb) { // statistics about complex cache
614
stat = null;
615                                  stat = PersonDO.statistics.getCacheStatistics(CacheConstants.COMPLEX_QUERY_CACHE);
616                                  if (stat!= null){
617                                      stat.incrementCacheHitsNum(1);
618                                  }
619                                }else{ // statistics about simple cache
620
stat = null;
621                                  stat = PersonDO.statistics.getCacheStatistics(CacheConstants.SIMPLE_QUERY_CACHE);
622                                  if (stat!= null){
623                                     stat.incrementCacheHitsNum(1);
624                                  }
625                                  }
626
627                               int limitOfRes;
628                               if (databaseLimit == 0)
629                                  limitOfRes = 0;
630                               else
631                                  limitOfRes = readSkip+databaseLimit+1;
632                               if (! unique) {
633                                  if (hitDb)
634                                    results = ((QueryCache)PersonDO.cache).getComplexQueryResults(logicalDatabase, queryID, limitOfRes, maxDBrows);
635                                  else
636                                    results = ((QueryCache)PersonDO.cache).getSimpleQueryResults(logicalDatabase, queryID, limitOfRes, maxDBrows);
637                               }else{ // (! unique)
638
if (hitDb)
639                                     results = ((QueryCache)PersonDO.cache).getComplexQueryResults(logicalDatabase, queryID, limitOfRes, maxDBrows, true);
640                                  else
641                                     results = ((QueryCache)PersonDO.cache).getSimpleQueryResults(logicalDatabase, queryID, limitOfRes, maxDBrows, true);
642                               } // (! unique)
643
if (results != null) {
644  //sinisa 06.08.2003.
645
results = getCachedResults(results);
646                                  resNum = results.DOs.size();
647                                  if (databaseLimit != 0) { // databaseLimitExceeded begin
648
if (resNum == readSkip+databaseLimit+1) {
649                                          resNum--;
650                                          databaseLimitExceeded = true;
651                                          results.DOs.remove(readSkip+databaseLimit);
652                                      }else{
653                                          if ( (resNum == readSkip+databaseLimit) && (!queryCachedItem.isCompleteResult()) )
654                                               databaseLimitExceeded = true;
655                                      }
656                                  } // databaseLimitExceeded end
657
if ( (databaseLimit!=0 &&(resNum == (readSkip+databaseLimit))) || (maxDBrows!=0 && (resNum + results.skippedUnique) == maxDBrows) || (queryCachedItem.isCompleteResult()) ) {
658                                           int lazyTime = PersonDO.statistics.getQueryByOIdAverageTime()*results.lazy.size();
659                                          if (lazyTime <= queryCachedItem.getTime()) {
660                                               resultsFromQCache = true;
661                                                getQueryByOIds(results.lazy); // gets cached query results from database
662
}else
663                                         databaseLimitExceeded = false;
664                                      }else
665                                      databaseLimitExceeded = false;
666                               } // (results != null)
667

668                         } // !(isOrderRelevant() && queryCachedItem.isModifiedQuery())
669
} // query found
670
} // if QUERY_CACHING
671
} // full caching
672
} // other queries
673
if (( userHitDb) || (!resultsFromQCache)) { // go to database
674

675                         dbQuery = PersonDO.createQuery(transaction);
676
677                 results = new QueryResult();
678                 int resultCount=0;
679                    boolean bHasMoreResults = false;
680           if (( (PersonDO.getConfigurationAdministration().getTableConfiguration().isLazyLoading()) || isCaching()) && (!builder.getPreventPrimaryKeySelect()) && !loadData) {
681                  builder.resetSelectedFields();
682                    builder.setSelectClause("person."+PersonDO.get_OIdColumnName()+", person."+PersonDO.get_versionColumnName());
683                }
684                else
685                 builder.setSelectClause( "person.*");
686                    dbQuery.query( this ); // invokes executeQuery
687

688
689                    if (! unique) {
690                     while ( (bHasMoreResults = resultSet.next()) && (databaseLimit==0 || (results.DOs.size()<databaseLimit)) ) {
691                            PersonDO newDO;
692                            PersonDataStruct newDS;
693
694                     if (( (PersonDO.getConfigurationAdministration().getTableConfiguration().isLazyLoading()) || isCaching()) && (!builder.getPreventPrimaryKeySelect()) && !loadData) {
695                            newDO = PersonDO.createExisting ( new ObjectId(resultSet.getBigDecimal(CoreDO.get_OIdColumnName())) , refs, transaction);
696                                                    newDO.set_Version(resultSet.getInt(PersonDO.get_versionColumnName()));
697                         } else
698                             newDO = PersonDO.createExisting ( resultSet , refs, transaction);
699                             if(transaction==null) {
700                              if(newDO!=null && newDO.isTransactionCheck()) {
701                                 String JavaDoc trace="";
702                                 StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
703                                 for(int i=0; i < traceElements.length; i++)
704                                     trace+=traceElements[i].toString()+"\n";
705                                 DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created : Database: "+newDO.get_OriginDatabase()+" PersonDO class, oid: "+newDO.get_OId()+", version: "+newDO.get_Version()+" \n"+trace);
706                              }
707                           }
708     
709                         if (queryItem != null) {
710                             queryItem.add((PersonDataStruct)newDO.originalData_get());
711                         }
712                         if (( (PersonDO.getConfigurationAdministration().getTableConfiguration().isLazyLoading()) || isCaching()) && (!builder.getPreventPrimaryKeySelect()) && !loadData)
713                          {}
714                         else
715                            newDS =PersonDO.addToCache((PersonDataStruct)newDO.originalData_get());
716     
717                                 if (resultCount >= readSkip) {
718                                     shell = new DOShell(newDO);
719                                     results.DOs.add(shell);
720                                 }
721                                 resultCount++;
722     
723                     } // while
724
} // (!unique)
725

726                 else { // (! unique)
727
HashSet hsResult = new HashSet(readSkip+databaseLimit);
728                     while((bHasMoreResults = resultSet.next()) && (databaseLimit==0 || (results.DOs.size()<databaseLimit)) ) {
729                         PersonDO newDO;
730                         PersonDataStruct newDS;
731
732                     if (( (PersonDO.getConfigurationAdministration().getTableConfiguration().isLazyLoading()) || isCaching()) && (!builder.getPreventPrimaryKeySelect()) && !loadData) {
733                            newDO = PersonDO.createExisting ( new ObjectId(resultSet.getBigDecimal(CoreDO.get_OIdColumnName())) , refs, transaction);
734                                                    newDO.set_Version(resultSet.getInt(PersonDO.get_versionColumnName()));
735                         } else
736                               newDO = PersonDO.createExisting ( resultSet , refs , transaction);
737                             if(transaction==null) {
738                                 if(newDO!=null && newDO.isTransactionCheck()) {
739                                    String JavaDoc trace="";
740                                    StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
741                                    for(int i=0; i < traceElements.length; i++)
742                                         trace+=traceElements[i].toString()+"\n";
743                                    DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created : Database: "+newDO.get_OriginDatabase()+" PersonDO class, oid: "+newDO.get_OId()+", version: "+newDO.get_Version()+" \n"+trace);
744                                 }
745                               }
746
747                         if (queryItem != null) {
748                             queryItem.add((PersonDataStruct)newDO.originalData_get());
749                         }
750                         if (( (PersonDO.getConfigurationAdministration().getTableConfiguration().isLazyLoading()) || isCaching()) && (!builder.getPreventPrimaryKeySelect()) && !loadData)
751                          {
752                         } else
753                            newDS = PersonDO.addToCache((PersonDataStruct)newDO.originalData_get());
754
755                                 if (!hsResult.contains(newDO.get_Handle())) {
756                                     hsResult.add(newDO.get_Handle());
757                                     if (resultCount >= readSkip) {
758
759                                         shell = new DOShell(newDO);
760                                         results.DOs.add(shell);
761                                     }
762                                     resultCount++;
763                                 }
764
765                     } // while
766
} // else (! unique)
767

768                 if ((results.DOs.size()==databaseLimit)&& bHasMoreResults) {
769                     resultSet.close();
770                     databaseLimitExceeded = true;
771                 }
772         if (maxDBrows > 0) {
773                     if (!bHasMoreResults) {
774                       if ((databaseLimit > 0) && databaseLimit < maxDBrows )
775                           queryItem.setCompleteResult(true);
776         &nbs