KickJava   Java API By Example, From Geeks To Geeks.

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


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

39 public class DocumentStructExplorer extends StructExplorer
40 {
41     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
42     private static final String JavaDoc RCSName = "$Name: $";
43     
44     private static Log log = LogFactory.getLog(DocumentStructExplorer.class);
45     
46     private static final int RS_COLUMNOFFSET = 1; // column index start at 0 in mapping
47

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

114     public boolean fetchNextRow() throws SQLException JavaDoc
115     {
116         try
117         {
118             if (resultActive())
119             {
120                 notExhausted = rs.next();
121                 if (notExhausted)
122                 {
123                     uoid = rs.getLong(RS_COLUMNOFFSET);
124                     last = rs.getLong(RS_COLUMNOFFSET + 1);
125                     path = rs.getShort(RS_COLUMNOFFSET + 2);
126                 }
127                 else
128                     reset();
129             }
130             else
131                 return false;
132             
133             return notExhausted;
134         }
135         catch (SQLException JavaDoc e)
136         {
137             close();
138             throw e;
139         }
140     }
141 }
142
Popular Tags