KickJava   Java API By Example, From Geeks To Geeks.

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


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.dbms.AbstractConnection;
28 import org.xquark.mapper.dbms.TableSpec;
29 import org.xquark.mapper.metadata.CollectionMetadata;
30 import org.xquark.mapper.metadata.UOIDManager;
31 import org.xquark.mapper.util.RepositoryProperties;
32
33 /**
34  * Object used to perform XML structure node storage.
35  *
36  */

37 public class DocumentExtraDataExplorer extends ExtraDataExplorer
38 {
39     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
40     private static final String JavaDoc RCSName = "$Name: $";
41
42     private static final int RS_COLUMNOFFSET = 1; // column index start at 0 in mapping
43

44     private String JavaDoc selectStmt;
45     
46     public DocumentExtraDataExplorer(CollectionMetadata collection)
47     {
48         super(collection.getTableInfo(TableSpec.TYPE_EXTRA));
49         initStatements(collection);
50         
51     }
52     
53     private void initStatements(CollectionMetadata collection)
54     {
55         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
56         UOIDManager manager = collection.getUOIDManager();
57         
58         sql.append("SELECT e.UOID,e.PATH,e.TYPE,e.POS,e.OFFSET,e.DATA,e.NUM FROM ");
59         sql.append(collection.getTableInfo(TableSpec.TYPE_DOCS).getName());
60         sql.append(" d,");
61         sql.append(tableInfo.getName());
62         sql.append(" e WHERE d.NAME= ? AND e.UOID>=(");
63         sql.append(manager.getDocMultiplier());
64         // assume first local node OID is 0
65
sql.append("*d.UDID) AND e.UOID<=(");
66         sql.append(manager.getDocMultiplier());
67         sql.append("*d.UDID+");
68         sql.append(manager.getDocMaxConstant());
69         sql.append(") ORDER BY e.NUM");
70         selectStmt = sql.toString();
71     }
72     
73     public void initDocReading(AbstractConnection connection)
74     throws SQLException JavaDoc
75     {
76         useStringDelimitor = connection.useStringDelimitor();
77         try
78         {
79             pStmt = connection.getConnection().prepareStatement(selectStmt);
80             connection.setFetchSize(pStmt, RepositoryProperties.getIntProperty(CONF_TREE_FETCHSIZE));
81         }
82         catch (SQLException JavaDoc e)
83         {
84             pStmt.close();
85             throw e;
86         }
87         // NOTE test ORDER BY source, rank to see if equivalent (would match any mapping)
88
}
89     
90     public void getDocument(String JavaDoc ID)
91     throws SQLException JavaDoc
92     {
93         try
94         {
95             pStmt.setString(1, ID);
96             rs = pStmt.executeQuery();
97             notExhausted = true;
98         }
99         catch (SQLException JavaDoc e)
100         {
101             pStmt.close();
102             throw e;
103         }
104     }
105     
106     /**
107      * get the next row from database and store it in the current object.
108      */

109     public boolean fetchNextRow() throws SQLException JavaDoc
110     {
111         try
112         {
113             if (resultActive())
114             {
115                 notExhausted = rs.next();
116                 if (notExhausted)
117                 {
118                 uoid = rs.getLong(RS_COLUMNOFFSET);
119                 node.path = rs.getShort(RS_COLUMNOFFSET + 1);
120                 node.type = rs.getShort(RS_COLUMNOFFSET + 2);
121                 node.position = rs.getShort(RS_COLUMNOFFSET + 3);
122                 node.offset = rs.getInt(RS_COLUMNOFFSET + 4);
123                 node.data = rs.getString(RS_COLUMNOFFSET + 5);
124                 if (useStringDelimitor)
125                     node.data = node.data.substring(0, node.data.length() - STRING_DELIMITOR_LENGTH);
126                 node.rowNum = rs.getShort(RS_COLUMNOFFSET + 6);
127                 }
128                 else
129                     reset();
130             }
131             else
132                 return false;
133             
134             return notExhausted;
135         }
136         catch (SQLException JavaDoc e)
137         {
138             close();
139             throw e;
140         }
141     }
142 }
143
Popular Tags