import java.io.*; import java.util.*; // This class support the creation of database relations, several // relational algebra operators and basic data manipulation operators. public class Relation implements Serializable { // F I E L D S // Name of the relation. private String relName=null; // Attribute names for the relation private Vector attributes=null; // Domain classes (types of attributes) private Vector domains=null; // Actual data storage (list of tuples) for the relation. private Vector table=null; // Counter to facilitate iterator on tuples private int counter=0; // Map associating relation names with relation memory images. private static Map catalogMap; // Static block to load the system catalog and all relations listed // in the catalog. static { catalogMap=new HashMap(); FileInputStream fin,fin2 = null; BufferedReader infile,infile2 = null; try { fin = new FileInputStream("catalog.dat"); infile = new BufferedReader(new InputStreamReader(fin)); int numRelations=0; String s = infile.readLine(); try { numRelations = Integer.parseInt(s); } catch (NumberFormatException e) { System.out.println("Invalid number"); } for (int i=0; i (counter+1)) return null; Comparable [] tup = (Comparable []) table.elementAt(counter); Tuple t = new Tuple(tup,attributes,domains); return t; } public void setRelationName(String rn) { relName = rn; } public boolean existsTuples() { return (table.size() > 0); } public Relation cartesianProduct(Relation r2) { Vector attr = new Vector(); Vector dom = new Vector(); int numAttr = attributes.size(); for (int i=0; i