1 22 23 package org.xquark.mapper.storage; 24 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 import java.util.Arrays ; 29 30 import org.xquark.mapper.mapping.ColumnMapping; 31 import org.xquark.mapper.mapping.TableMapping; 32 import org.xquark.mapper.metadata.CollectionMappingInfo; 33 import org.xquark.schema.Declaration; 34 import org.xquark.schema.validation.ValidationContextProvider; 35 import org.xquark.xml.xdbc.XMLDBCException; 36 37 public abstract class Tuple 38 { 39 40 private static final String RCSRevision = "$Revision: 1.1 $"; 41 42 private static final String RCSName = "$Name: $"; 43 44 protected Statement selectStmt = null; 45 46 protected ResultSet resultSet = null; 47 48 protected boolean notExhausted = false; 49 50 protected CollectionMappingInfo table; 51 52 protected long uoid = -1; 53 54 protected String [] values = null; protected boolean[] fetched = null; 56 57 58 protected short pathoid = -2; 59 60 Tuple(CollectionMappingInfo table) 61 { 62 this.table = table; 63 values = new String [getMapping().getColumnMappingCount()]; 64 fetched = new boolean[getMapping().getColumnMappingCount()]; 65 } 66 67 boolean queryPending() 68 { 69 return notExhausted; 70 } 71 72 73 boolean resultActive() 74 { 75 return notExhausted; 76 } 77 78 boolean isClosed() 79 { 80 return (resultSet == null); 81 } 82 83 public boolean isInRange(long first, long last, short path) 84 { 85 return resultActive() && (uoid >= first) && (uoid <= last) && (pathoid == path); 86 } 87 88 public boolean isInRangeAbs(long first, long last, short path) 89 { 90 return resultActive() && (uoid >= first) && (uoid <= last) && ((short)Math.abs(pathoid) == path); 91 } 92 93 public boolean isInRange(long first, long last) 94 { 95 return resultActive() && (uoid >= first) && (uoid <= last); 96 } 97 98 long getUOID() 99 { 100 return uoid; 101 } 102 103 TableMapping getMapping() 104 { 105 return table.getTableMapping(); 106 } 107 108 short getPathID() 109 { 110 return (short)Math.abs(pathoid); 111 } 112 113 boolean fetchNextRow() throws SQLException 114 { 115 Arrays.fill(fetched, false); 116 return true; 117 } 118 119 String getValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext) 120 throws SQLException , XMLDBCException 121 { 122 int index = column.getInsertColumnIndex(); 123 124 if (!fetched[index]) 125 { 126 values[index] = fetchValue(column, decl, nsContext); 127 fetched[index] = true; 128 } 129 130 return values[index]; 131 } 132 133 protected abstract String fetchValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext) 134 throws SQLException , XMLDBCException; 135 136 void close() throws SQLException 137 { 138 reset(); 139 if (selectStmt != null) { 141 selectStmt.close(); 142 selectStmt = null; 143 } 144 } 145 146 void reset() throws SQLException 147 { 148 if (!isClosed()) { 150 resultSet.close(); 151 resultSet = null; 152 uoid = -1; 153 pathoid = -2; 154 notExhausted = false; 155 } 156 } 157 158 } 159 160
| Popular Tags
|