//package edu.gsu.cs.dbengine; 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 { // 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; public static void initializeDatabase(String dir) { catalogMap=new HashMap(); FileInputStream fin,fin2 = null; BufferedReader infile,infile2 = null; try { fin = new FileInputStream(dir+"/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 union(Relation r2) { Vector attr = new Vector(); Vector dom = new Vector(); int numAttr = attributes.size(); for (int i=0; i