1 22 23 27 28 package org.xquark.mapper.storage; 29 30 import java.sql.SQLException ; 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 34 import org.xquark.mapper.RepositoryException; 35 import org.xquark.mapper.mapping.ColumnMapping; 36 import org.xquark.mapper.mapping.RepositoryMapping; 37 import org.xquark.mapper.mapping.TableMapping; 38 import org.xquark.mapper.metadata.PathSet; 39 import org.xquark.schema.Declaration; 40 import org.xquark.schema.SchemaException; 41 import org.xquark.schema.validation.ValidationContextProvider; 42 import org.xquark.xml.xdbc.XMLDBCException; 43 44 48 public abstract class TableExplorer 49 { 50 private static final String RCSRevision = "$Revision: 1.1 $"; 51 private static final String RCSName = "$Name: $"; 52 53 public final static int NOT_FOUND = -3; 54 public final static int STRUCT_TUPLE = -2; 55 public final static int EXTRA_TUPLE = -1; 56 public final static int MIN_DATA = 0; 57 58 protected PathSet pathSet; 59 protected Tuple[] tuples; 60 protected StructExplorer wNode; 61 protected ExtraDataExplorer extraNode; 62 protected _RepositoryCollection collection; 64 65 TableExplorer(_RepositoryCollection collection) 66 throws SQLException , XMLDBCException 67 { 68 this.collection = collection; 69 pathSet = collection.getMetadata().getPathSet(); 70 RepositoryMapping collectionMapping = collection.getMetadata().getMapping(); 71 } 72 73 74 76 Tuple get(int index) throws SQLException 77 { 78 return tuples[index]; 79 } 80 81 StructExplorer getStructNode() throws SQLException 82 { 83 return wNode; 84 } 85 86 ExtraDataExplorer getExtraNode() throws SQLException 87 { 88 return extraNode; 89 } 90 91 Tuple pollData(Collection tableMappings, long first, long last) throws SQLException 92 { 93 int minIndex = NOT_FOUND, i; 94 long minOID = Long.MAX_VALUE; if (tableMappings == null) 96 return null; 97 Iterator it = tableMappings.iterator(); 98 99 while (it.hasNext()) 100 { 101 i = ((TableMapping)it.next()).getTableIndex(); 102 if ((tuples[i] != null) 103 && tuples[i].queryPending() 104 && (tuples[i].getUOID() <= minOID) && (tuples[i].isInRange(first, last))) 106 { 107 minIndex= i; 108 minOID = tuples[i].getUOID(); 109 } 110 } 111 if (minIndex == NOT_FOUND) 112 return null; 113 else 114 return get(minIndex); 115 } 116 117 118 int poll(long first, long last) 119 throws SQLException 120 { 121 int minIndex = NOT_FOUND; 122 long minOID = Long.MAX_VALUE; 124 if ((getStructNode().getUOID() < minOID) && getStructNode().isInRange(first, last)) 126 { 127 minIndex= STRUCT_TUPLE; 128 minOID = getStructNode().getUOID(); 129 } 130 int defaultMappingIndex = collection.getMetadata().getDefaultMappingIndex(); 131 if ((tuples[defaultMappingIndex] != null) 132 && tuples[defaultMappingIndex].queryPending() 133 && (tuples[defaultMappingIndex].getUOID() < minOID) && tuples[defaultMappingIndex].isInRange(first, last)) 135 minIndex= defaultMappingIndex; 136 return minIndex; 137 } 138 139 140 boolean lookup() throws SQLException 141 { 142 boolean rows = wNode.fetchNextRow(); 143 rows |= extraNode.fetchNextRow(); 144 for (int i = 0; i < tuples.length; i++) 145 { 146 if (tuples[i] != null) 147 { 148 if (tuples[i].queryPending()) 149 tuples[i].fetchNextRow(); 150 rows |= tuples[i].queryPending(); 151 } 152 } 153 return rows; 154 } 155 156 void close() throws SQLException , RepositoryException 157 { 158 wNode.close(); 159 extraNode.close(); 160 161 162 for (int i = 0; i < tuples.length; i++) 163 { 164 if (tuples[i] != null) 165 tuples[i].close(); 166 } 167 } 168 169 171 void reset() throws SQLException , RepositoryException 172 { 173 wNode.reset(); 174 extraNode.reset(); 175 176 for (int i = 0; i < tuples.length; i++) 178 { 179 if (tuples[i] != null) 180 tuples[i].reset(); 181 } 182 } 183 184 String getValue(ColumnMapping column, Declaration decl, ValidationContextProvider nsContext) 185 throws SQLException , SchemaException, XMLDBCException 186 { 187 return get(column.getTableIndex()).getValue(column, decl, nsContext); 188 } 189 } 190 | Popular Tags |