import simpledb.server.SimpleDB; import simpledb.tx.Transaction; import simpledb.record.*; import simpledb.metadata.MetadataMgr; public class MetadataMgrTest { public static void main(String[] args) throws Exception { SimpleDB.init("testdb"); Transaction tx = new Transaction(); MetadataMgr mdmgr = SimpleDB.mdMgr(); // we assume that some other program has created // table "junk" by executing the following statements: // Schema sch = new Schema(); // sch.addIntField("A"); // sch.addStringField("B", 8); // mdmgr.createTable("junk", sch, tx2); TableInfo ti = mdmgr.getTableInfo("junk", tx); // The rest of the code is identical to RecordMgrTest RecordFile rf = new RecordFile(ti, tx); for (int i=0; i<500; i++) { rf.insert(); int n = (int) Math.round(Math.random() * 200); rf.setInt("A", n); rf.setString("B", "test"+n); } int count = 0; rf.beforeFirst(); while (rf.next()) { if (rf.getInt("A") < 10) { count++; System.out.println(rf.getString("B")); rf.delete(); } } System.out.println(count + " values under 10 were deleted"); rf.close(); tx.commit(); } }