import java.util.*; import java.text.DecimalFormat; import java.io.*; class RRtable { private String Abbrev; private String Name; private Vector Rows; private int Rowcount; private int Maxver; protected Database TheSchema; RRtable(Database mySchema) { Abbrev = "RR"; Name = "RowRelations"; Rowcount = 0; Rows = new Vector(1); TheSchema = mySchema; } public String getName() { return Name; } public String getAbbrev() { return Abbrev; } public int getRowcount() { return Rowcount; } public RR getFirstRow() { if( Rows.isEmpty() ) return null; return (RR)Rows.firstElement(); } public RR getLastRow() { if( Rows.isEmpty() ) return null; return (RR)Rows.lastElement(); } public RR getNextRow(RR thisrow) { if( Rows.isEmpty() ) return null; if( Rows.indexOf( thisrow ) == ( Rows.size() - 1 ) ) return null; return (RR)Rows.elementAt( Rows.indexOf( thisrow ) + 1 ); } public RR getPrevRow(RR thisrow) { if( Rows.isEmpty() ) return null; if( Rows.indexOf( thisrow ) == 0 ) return null; return (RR)Rows.elementAt( Rows.indexOf( thisrow ) - 1 ); } public void insertRow(RR newRow) { int i; Enumeration enum = Rows.elements(); newRow.setTable(this); if( newRow.getPkid() == null ) { String keystr; DecimalFormat twoDigits = new DecimalFormat( "00" ); DecimalFormat fourDigits = new DecimalFormat( "0000" ); keystr = getAbbrev(); keystr += twoDigits.format(1); keystr += fourDigits.format(Rowcount + 1); Key newRowKey = new Key(keystr, TheSchema); newRow.setPkid(newRowKey); } for( i = 0; i < Rows.size(); ++i ) { RR currRow = (RR)Rows.elementAt(i); if( currRow.getPkid().getValue() >= newRow.getPkid().getValue() ) break; } Rows.insertElementAt(newRow, i); Rowcount++; if( newRow.getPkid().getVersion() > Maxver ) Maxver = newRow.getPkid().getVersion(); } public void removeRow(RC oldrow) { Rows.removeElement(oldrow); } public void dumpTable(BufferedWriter output) throws IOException { for( RR curr = getFirstRow(); curr != null; curr = getNextRow(curr)) { curr.dumpRow(output); } } public Database getTheSchema() { return TheSchema; } public void setTheSchema(Database value) { TheSchema = value; } public static void main(String[] args) { // RRtable theTable = new RRtable(); // RR row1 = new RR(); // Populate rows here // theTable.insertRow(row1); // for( RR curr = theTable.getFirstRow(); // curr != null; // curr = theTable.getNextRow(curr)) { // System.out.println(curr); // } } }