1 22 23 package org.xquark.mapper.storage; 24 25 import java.sql.SQLException ; 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 37 public class DocumentExtraDataExplorer extends ExtraDataExplorer 38 { 39 private static final String RCSRevision = "$Revision: 1.1 $"; 40 private static final String RCSName = "$Name: $"; 41 42 private static final int RS_COLUMNOFFSET = 1; 44 private String 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 sql = new StringBuffer (); 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 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 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 e) 83 { 84 pStmt.close(); 85 throw e; 86 } 87 } 89 90 public void getDocument(String ID) 91 throws SQLException 92 { 93 try 94 { 95 pStmt.setString(1, ID); 96 rs = pStmt.executeQuery(); 97 notExhausted = true; 98 } 99 catch (SQLException e) 100 { 101 pStmt.close(); 102 throw e; 103 } 104 } 105 106 109 public boolean fetchNextRow() throws SQLException 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 e) 137 { 138 close(); 139 throw e; 140 } 141 } 142 } 143 | Popular Tags |