1 22 23 package org.xquark.mapper.storage; 24 25 import java.sql.PreparedStatement ; 26 import java.sql.SQLException ; 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 RCSRevision = "$Revision: 1.2 $"; 45 private static final String RCSName = "$Name: $"; 46 47 private static Log log = LogFactory.getLog(DocumentTuple.class); 48 49 DocumentTuple(CollectionMappingInfo table) 50 { 51 super(table); 52 } 53 54 55 void init(AbstractConnection connection, CollectionMetadata collection) throws SQLException , 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 e) 66 { 67 selectStmt.close(); 68 throw e; 69 } 70 } 71 72 73 void execQuery(String ID) throws SQLException , RepositoryException 74 { 75 try 76 { 77 if (resultSet != null) 78 resultSet.close(); 79 ((PreparedStatement )selectStmt).setString(1, ID); 80 resultSet = ((PreparedStatement )selectStmt).executeQuery(); 81 notExhausted = true; 82 } 83 catch (SQLException e) 84 { 85 selectStmt.close(); 86 throw e; 87 } 88 } 89 90 boolean fetchNextRow() throws SQLException 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); pathoid = resultSet.getShort(getMapping().getPathIDIndex() + 1); 102 } 103 } 104 105 if (!notExhausted) 106 reset(); 107 return notExhausted; 108 } 109 catch (SQLException e) 110 { 111 selectStmt.close(); 112 throw e; 113 } 114 } 115 116 protected String fetchValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext) 117 throws SQLException , XMLDBCException 118 { 119 String ret = null; 120 try 121 { if (notExhausted) 123 { 124 if (getMapping().isClustered()) 125 ret = column.getTypeInfo().getParameter(resultSet, 126 column.getInsertColumnIndex() + 1, 127 decl, 128 nsContext); else 130 ret = column.getTypeInfo().getParameter(resultSet, 131 column.getInsertColumnIndex() + 3, 132 decl, 133 nsContext); } 135 } 136 catch (SQLException e) 137 { 138 selectStmt.close(); 139 throw e; 140 } 141 return ret; 142 } 143 144 } 145 146 | Popular Tags |