KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > QueryTuple


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.storage;
24
25 import java.sql.SQLException JavaDoc;
26
27 import org.xquark.mapper.mapping.ColumnMapping;
28 import org.xquark.mapper.metadata.CollectionMappingInfo;
29 import org.xquark.schema.Declaration;
30 import org.xquark.schema.validation.ValidationContextProvider;
31 import org.xquark.xml.xdbc.XMLDBCException;
32
33 abstract class QueryTuple extends Tuple
34 {
35     
36     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
37     private static final String JavaDoc RCSName = "$Name: $";
38     
39     protected int subPathIndex = -1;
40     
41     protected int valueOffset = 0;
42     
43     protected boolean currentResultExhausted = true;
44     
45     protected int currentSubPathIndex = -2;
46     
47     protected short tablePath = 0; // meaningless if table mapping is shared
48

49     QueryTuple(CollectionMappingInfo table)
50     {
51         super(table);
52     }
53
54     QueryTuple(CollectionMappingInfo table, short pathID)
55     {
56         this(table);
57         tablePath = pathID;
58     }
59
60     protected String JavaDoc fetchValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext)
61     throws SQLException JavaDoc, XMLDBCException
62     {
63         String JavaDoc ret = null;
64         try
65         {
66             if (resultActive())
67             {
68                     ret = column.getTypeInfo().getParameter(resultSet,
69                     column.getInsertColumnIndex() + (table.getTableMapping().isClustered()?0:2) + valueOffset,
70                     decl,
71                     nsContext);
72                     // clustered : because first index starts at 0 and OID belongs to columns
73
// not clustered : two first are XQuark index (UOID, pathOID) and index starts at 0
74
}
75         }
76         catch (SQLException JavaDoc e)
77         {
78             selectStmt.close();
79             throw e;
80         }
81         return ret;
82     }
83     
84     boolean resultActive()
85     {
86         return notExhausted && !currentResultExhausted;
87     }
88     
89     long getUOID()
90     {
91         if (resultActive())
92             return uoid;
93         else
94             return -1;
95     }
96     
97     short getPathID()
98     {
99         if (resultActive())
100             return super.getPathID();
101         else
102             return -2;
103     }
104     
105     void reset() throws SQLException JavaDoc
106     {
107         super.reset();
108         subPathIndex = -1;
109         currentResultExhausted = true;
110         currentSubPathIndex = -2;
111     }
112     
113     void freezeCurrentSubPath()
114     {
115         currentSubPathIndex++;
116         updateResultSegmentationFlag();
117     }
118     
119     protected void updateResultSegmentationFlag()
120     {
121         currentResultExhausted = (currentSubPathIndex != subPathIndex);
122     }
123 }
124
125
Popular Tags