KickJava   Java API By Example, From Geeks To Geeks.

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


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.PreparedStatement JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.xquark.mapper.RepositoryException;
31 import org.xquark.mapper.dbms.AbstractConnection;
32 import org.xquark.mapper.mapping.ColumnMapping;
33 import org.xquark.mapper.metadata.CollectionMappingInfo;
34 import org.xquark.mapper.metadata.CollectionMetadata;
35 import org.xquark.mapper.metadata.RepositoryConstants;
36 import org.xquark.mapper.util.RepositoryProperties;
37 import org.xquark.schema.Declaration;
38 import org.xquark.schema.validation.ValidationContextProvider;
39 import org.xquark.xml.xdbc.XMLDBCException;
40
41 class DocumentTuple extends Tuple
42 {
43     
44     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
45     private static final String JavaDoc RCSName = "$Name: $";
46     
47     private static Log log = LogFactory.getLog(DocumentTuple.class);
48     
49     DocumentTuple(CollectionMappingInfo table)
50     {
51         super(table);
52     }
53     
54     /** To be used by document reading */
55     void init(AbstractConnection connection, CollectionMetadata collection) throws SQLException JavaDoc, RepositoryException
56     {
57         try
58         {
59             selectStmt = connection.getConnection().prepareStatement(table.getSelectValuesStatement());
60             if (log.isDebugEnabled())
61                 log.debug("Select value statement:\n" + table.getSelectValuesStatement());
62             connection.setFetchSize(selectStmt,
63             RepositoryProperties.getIntProperty(RepositoryConstants.CONF_USER_FETCHSIZE));
64         }
65         catch (SQLException JavaDoc e)
66         {
67             selectStmt.close();
68             throw e;
69         }
70     }
71     
72     /** To be used by document reading */
73     void execQuery(String JavaDoc ID) throws SQLException JavaDoc, RepositoryException
74     {
75         try
76         {
77             if (resultSet != null)
78                 resultSet.close();
79             ((PreparedStatement JavaDoc)selectStmt).setString(1, ID);
80             resultSet = ((PreparedStatement JavaDoc)selectStmt).executeQuery();
81             notExhausted = true;
82         }
83         catch (SQLException JavaDoc e)
84         {
85             selectStmt.close();
86             throw e;
87         }
88     }
89     
90     boolean fetchNextRow() throws SQLException JavaDoc
91     {
92         super.fetchNextRow();
93         try
94         {
95             if (notExhausted)
96             {
97                 notExhausted = resultSet.next();
98                 if (notExhausted)
99                 {
100                     uoid = resultSet.getLong(getMapping().getUOIDIndex() + 1); // num + resultset offset/ List
101
pathoid = resultSet.getShort(getMapping().getPathIDIndex() + 1);
102                 }
103             }
104             
105             if (!notExhausted)
106                 reset();
107             return notExhausted;
108         }
109         catch (SQLException JavaDoc e)
110         {
111             selectStmt.close();
112             throw e;
113         }
114     }
115     
116     protected String JavaDoc fetchValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext)
117     throws SQLException JavaDoc, XMLDBCException
118     {
119         String JavaDoc ret = null;
120         try
121         { // TEST BETWEEN getString et getObject
122
if (notExhausted)
123             {
124                 if (getMapping().isClustered())
125                     ret = column.getTypeInfo().getParameter(resultSet,
126                     column.getInsertColumnIndex() + 1,
127                     decl,
128                     nsContext); // because first index starts at 0 and OID belongs to columns
129
else
130                     ret = column.getTypeInfo().getParameter(resultSet,
131                     column.getInsertColumnIndex() + 3,
132                     decl,
133                     nsContext); // because two first are XQuark index (UOID, pathOID) and index starts at 0
134
}
135         }
136         catch (SQLException JavaDoc e)
137         {
138             selectStmt.close();
139             throw e;
140         }
141         return ret;
142     }
143     
144 }
145
146
Popular Tags