import java.util.*; import java.text.DecimalFormat; import java.io.*; class TAtable { private String Abbrev; private String Name; private Vector Rows; private int Rowcount; private int Maxver; protected Database TheSchema; TAtable(Database mySchema) { Abbrev = "TA"; Name = "TableAttributes"; Rowcount = 0; Rows = new Vector(1); TheSchema = mySchema; } public String getName() { return Name; } public String getAbbrev() { return Abbrev; } public int getRowcount() { return Rowcount; } public TA getFirstRow() { if( Rows.isEmpty() ) return null; return (TA)Rows.firstElement(); } public TA getLastRow() { if( Rows.isEmpty() ) return null; return (TA)Rows.lastElement(); } public TA getNextRow(TA thisrow) { if( Rows.isEmpty() ) return null; if( Rows.indexOf( thisrow ) == ( Rows.size() - 1 ) ) return null; return (TA)Rows.elementAt( Rows.indexOf( thisrow ) + 1 ); } public TA getPrevRow(TA thisrow) { if( Rows.isEmpty() ) return null; if( Rows.indexOf( thisrow ) == 0 ) return null; return (TA)Rows.elementAt( Rows.indexOf( thisrow ) - 1 ); } public void insertRow(TA 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 ) { TA currRow = (TA)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( TA 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) { // TAtable theTable = new TAtable(); // TA row1 = new TA(); // Populate rows here // theTable.insertRow(row1); // for( TA curr = theTable.getFirstRow(); // curr != null; // curr = theTable.getNextRow(curr)) { // System.out.println(curr); // } } }