/** * Search index file for a primary key value * * @param pkvalue the primary key value to search for * @param position [0] = index entry, [1] = table row * @throws Exception */ public boolean searchIndex(String pkvalue, Positions pos) throws Exception { boolean found = false; boolean end = false; if (!indexExists(def.getPK())) { throw new Exception("No index created"); } int pkindex = def.getColPosition(def.getPK()); if (pkindex == -1) { throw new Exception("Primary key does not exist"); } // calculate index = hash value String s_value = pkvalue.trim(); int index = hash(s_value); Integer[] size = def.getSizes(); int recordSize = idxFixedRecordLength() + size[pkindex]; indexFile.seek(index * recordSize); String line = indexFile.readLine(); if (line.substring(0, 1).equals(" ")) { // Empty record, end of search found = false; return found; } String[] parts = line.split("#"); String s_part = parts[2].trim(); if (s_part.equals(pkvalue) && !(parts[1].equals("D"))) { found = true; pos.index = Integer.parseInt(parts[0].trim()); pos.table = Integer.parseInt(parts[3].trim()); } while (!found && !end) { if (parts[4].substring(0, 4).equals("null")) { // end of linked list end = true; found = false; } else { index = Integer.parseInt(parts[4].trim()); indexFile.seek(index * recordSize); line = indexFile.readLine(); parts = line.split("#"); if (parts[2].trim().equals(pkvalue) && !(parts[1].equals("D"))) { found = true; pos.index = Integer.parseInt(parts[0].trim()); pos.table = Integer.parseInt(parts[3].trim()); } } } return found; }
public CheckLimitOn(Positions positions, Filter filter, Check check) { valid = positions.isEmpty() ? false : check.check(positions.ratioOn(filter)); }