KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > persist > db > HsqlDBListDatabaseUtils


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: HsqlDBListDatabaseUtils.java,v 1.13 2007/01/07 06:14:23 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.listdata.persist.db;
23
24 import java.sql.ResultSet JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.opensubsystems.core.error.OSSException;
28 import org.opensubsystems.patterns.listdata.data.ListOptions;
29
30 /**
31  * This class is used for common list retrieval and manipulation routines
32  * specific for HsqlDB.
33  *
34  * @version $Id: HsqlDBListDatabaseUtils.java,v 1.13 2007/01/07 06:14:23 bastafidli Exp $
35  * @author Julo Legeny
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.10 2006/03/13 16:50:25 bastafidli
38  */

39 public class HsqlDBListDatabaseUtils extends ListDatabaseUtils
40 {
41    // Constructors /////////////////////////////////////////////////////////////
42

43    /**
44     * Constructor
45     */

46    public HsqlDBListDatabaseUtils()
47    {
48       super();
49    }
50
51    // Helper methods ///////////////////////////////////////////////////////////
52

53    /**
54     * {@inheritDoc}
55     */

56    protected int getTotalRecords(
57       ResultSet JavaDoc rsQueryResults,
58       ListOptions options
59    ) throws OSSException,
60             SQLException JavaDoc
61    {
62       int iOutputCount = 0;
63
64       // We should use last() to determine total number of items
65
// timer.reset();
66
// Try to eficiently allocate the memory by first figuring out
67
// how many data objects we have
68
if (rsQueryResults.last())
69       {
70          // The last row number will tell us the total element count
71
// (since it is 1 based)
72
iOutputCount = rsQueryResults.getRow();
73          // s_logger.info("Duration for last() = " + timer.toString());
74

75          // TODO: Bug: HSQLDB: sometimes (FileTypes - DTAttributes) it returns
76
// NULL row (all columns values are NULL) instead of empty result
77
// so we check such NULL row and if so we will reset iCount to zero
78
if (iOutputCount == 1)
79          {
80             // timer.reset();
81
rsQueryResults.absolute(iOutputCount);
82             // s_logger.info("Duration for absolute() for last() = " + timer.toString());
83

84             boolean bNullRow = true;
85             int iHelp;
86             int iRetrievedColumns = options.getRetrieveColumnCodes().length;
87             
88             for (iHelp = 1; bNullRow && (iHelp <= iRetrievedColumns); iHelp++)
89             {
90                bNullRow = (rsQueryResults.getObject(iHelp) == null);
91             }
92             if (bNullRow)
93             {
94                iOutputCount = 0;
95             }
96          }
97       }
98       else
99       {
100          // s_logger.info("Duration for last() = " + timer.toString());
101
}
102
103       return iOutputCount;
104    }
105
106    /**
107     * {@inheritDoc}
108     */

109    protected String JavaDoc preprocessSelectQueryForCreationDate(
110       String JavaDoc inputQuery,
111       ListOptions options,
112       ListDatabaseSchema schema
113    ) throws OSSException
114    {
115       return ListQueryPreprocessor.preprocessSelectQueryForCreationDate(
116                                       inputQuery, options, schema);
117    }
118 }
119
Popular Tags