Finish part 1

This commit is contained in:
Max O'Cull 2019-03-28 22:35:58 -04:00
parent 732977b4fa
commit a9a58d2cbd
4 changed files with 68 additions and 22 deletions

View File

@ -1,7 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5

View File

@ -12,7 +12,7 @@ public class FileScan extends Iterator {
private HeapFile file = null; // needed for restart(), getFile();
private HeapScan scan = null;
private RID rid = null;
private boolean isOpen;
private boolean isOpen = false;
/**
* Constructs a file scan, given the schema and heap file.

View File

@ -1,5 +1,7 @@
package relop;
import global.RID;
import index.BucketScan;
import global.SearchKey;
import heap.HeapFile;
import index.HashIndex;
@ -8,13 +10,21 @@ import index.HashIndex;
* Wrapper for bucket scan, an index access method.
*/
public class IndexScan extends Iterator {
private HeapFile file = null;
private BucketScan scan = null;
private HashIndex index = null;
private boolean isOpen = false;
/**
* Constructs an index scan, given the hash index and schema.
*/
public IndexScan(Schema schema, HashIndex index, HeapFile file) {
throw new UnsupportedOperationException("Not implemented");
this.file = file;
this.schema = schema;
this.index = index;
this.scan = this.index.openScan();
this.isOpen = true;
}
/**
@ -29,44 +39,65 @@ public class IndexScan extends Iterator {
* Restarts the iterator, i.e. as if it were just constructed.
*/
public void restart() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
scan.close();
this.isOpen = false;
}
this.scan = this.index.openScan();
this.isOpen = true;
}
/**
* Returns true if the iterator is open; false otherwise.
*/
public boolean isOpen() {
throw new UnsupportedOperationException("Not implemented");
return this.isOpen;
}
/**
* Closes the iterator, releasing any resources (i.e. pinned pages).
*/
public void close() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
this.scan.close();
this.scan = null;
this.isOpen = false;
}
}
/**
* Returns true if there are more tuples, false otherwise.
*/
public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
return this.scan.hasNext();
}
return false;
}
/**
* Gets the next tuple in the iteration.
*
*
* @throws IllegalStateException if no more tuples
*/
public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
RID rid = this.scan.getNext();
byte[] data = this.file.selectRecord(rid);
Tuple tuple = new Tuple(this.getSchema(), data);
return tuple;
}
return null;
}
/**
* Gets the key of the last tuple returned.
*/
public SearchKey getLastKey() {
throw new UnsupportedOperationException("Not implemented");
return this.scan.getLastKey();
}
/**
@ -74,7 +105,7 @@ public class IndexScan extends Iterator {
* number of buckets if none.
*/
public int getNextHash() {
throw new UnsupportedOperationException("Not implemented");
return this.scan.getNextHash();
}
} // public class IndexScan extends Iterator

View File

@ -1,5 +1,6 @@
package relop;
import global.RID;
import global.SearchKey;
import heap.HeapFile;
import index.HashIndex;
@ -39,35 +40,39 @@ public class KeyScan extends Iterator {
* Restarts the iterator, i.e. as if it were just constructed.
*/
public void restart() {
this.isOpen = false; // In case of errors maybe?
this.close();
this.scan = this.index.openScan(this.key);
this.isOpen = true;
this.isOpen = false; // In case of errors maybe?
this.close();
this.scan = this.index.openScan(this.key);
this.isOpen = true;
}
/**
* Returns true if the iterator is open; false otherwise.
*/
public boolean isOpen() {
return this.isOpen;
return this.isOpen;
}
/**
* Closes the iterator, releasing any resources (i.e. pinned pages).
*/
public void close() {
if (this.isOpen()) {
this.scan.close();
this.scan = null;
this.isOpen = false;
}
if (this.isOpen()) {
this.scan.close();
this.scan = null;
this.isOpen = false;
}
}
/**
* Returns true if there are more tuples, false otherwise.
*/
public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
return this.scan.hasNext();
}
return false;
}
/**
@ -76,7 +81,15 @@ public class KeyScan extends Iterator {
* @throws IllegalStateException if no more tuples
*/
public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented");
if (this.isOpen()) {
RID rid = scan.getNext();
byte[] data = this.file.selectRecord(rid);
Tuple tuple = new Tuple(this.getSchema(), data);
return tuple;
}
return null;
}
} // public class KeyScan extends Iterator