1 22 23 package org.xquark.mapper.storage; 24 25 import java.sql.SQLException ; 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 39 public class DocumentStructExplorer extends StructExplorer 40 { 41 private static final String RCSRevision = "$Revision: 1.2 $"; 42 private static final String RCSName = "$Name: $"; 43 44 private static Log log = LogFactory.getLog(DocumentStructExplorer.class); 45 46 private static final int RS_COLUMNOFFSET = 1; 48 private String 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 sql = new StringBuffer (); 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 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 81 { 82 try 83 { 84 pStmt = connection.getConnection().prepareStatement(selectStmt); 85 connection.setFetchSize(pStmt, RepositoryProperties.getIntProperty(CONF_TREE_FETCHSIZE)); 86 } 87 catch (SQLException e) 88 { 89 pStmt.close(); 90 throw e; 91 } 92 } 94 95 public void getDocument(String ID) 96 throws SQLException 97 { 98 try 99 { 100 pStmt.setString(1, ID); 101 rs = pStmt.executeQuery(); 102 notExhausted = true; 103 } 104 catch (SQLException e) 105 { 106 pStmt.close(); 107 throw e; 108 } 109 } 110 111 114 public boolean fetchNextRow() throws SQLException 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 e) 136 { 137 close(); 138 throw e; 139 } 140 } 141 } 142 | Popular Tags |