| 1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem; 2 3 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 4 import com.daffodilwoods.database.resource.*; 5 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 6 7 12 13 public class ClusterIterator { 14 15 18 19 private Cluster currentCluster; 20 21 24 25 private PersistentTable table; 26 27 public ClusterIterator(PersistentTable table0) { 28 table = table0; 29 } 30 31 35 36 boolean first()throws DException { 37 currentCluster = table.getFirstCluster(); 38 while (currentCluster!= null && currentCluster.activeRecordCount == 0) { 39 currentCluster = table.getNextCluster(currentCluster, null); 40 } 41 return (currentCluster) != null; 42 } 43 49 50 boolean next() throws DException { 51 try { 52 currentCluster = table.getNextCluster(currentCluster, null); 53 while (currentCluster!=null && currentCluster.activeRecordCount == 0) { 54 currentCluster = table.getNextCluster(currentCluster, null); 55 } 56 return (currentCluster) != null; 57 } 58 catch (NullPointerException ne) { 59 currentCluster = table.getClusterForRead(currentCluster. 60 clusterCharacteristics); 61 return (currentCluster = table.getNextCluster(currentCluster, null)) != null; 62 } 63 } 64 65 69 70 71 boolean last() throws DException { 72 currentCluster = table.getLastCluster(null); 73 while (currentCluster!= null && currentCluster.activeRecordCount == 0) { 74 currentCluster = table.getPreviousCluster(currentCluster, null); 75 } 76 return (currentCluster) != null; 77 } 78 79 84 85 boolean previous() throws DException { 86 try { 87 currentCluster = table.getPreviousCluster(currentCluster, null); 88 while (currentCluster!= null && currentCluster.activeRecordCount == 0) { 89 currentCluster = table.getPreviousCluster(currentCluster, null); 90 } 91 return (currentCluster) != null; 92 } 93 catch (NullPointerException ne) { 94 currentCluster = table.getClusterForRead(currentCluster. 95 clusterCharacteristics); 96 return (currentCluster = table.getPreviousCluster(currentCluster, null)) != null; 97 } 98 } 99 100 105 106 Cluster getCurrentCluster(){ 107 return currentCluster; 108 } 109 110 111 115 116 void move(Object key) throws DException{ 117 TableKey tk = (TableKey) key; 118 if (currentCluster != null && 119 currentCluster.clusterCharacteristics.getStartAddress() == 120 tk.getStartAddress()) { 121 return; 122 } 123 Cluster cls = (Cluster) tk.cluster.get(); 124 if (cls == null) { 125 cls = table.getClusterForRead(new ClusterCharacteristics(tk.getStartAddress(),false)); 126 } 127 currentCluster = cls; 128 } 129 130 public int getNumberOfClustersUsed() throws DException { 131 int count = 0; 132 if (first()) { 133 do { 134 count++; 135 } 136 while (next()); 137 } 138 return count; 139 } 140 141 142 } 143 | Popular Tags |