import java.io.*; import java.util.*; import COM.odi.*; import COM.odi.util.OSTreeSet; import COM.odi.util.*; public class createData{ public static void main(String argv[]){ String dbName = argv[0]; try { ObjectStore.initialize(null,null); } catch(Throwable throwable) { java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream(); java.io.PrintWriter writer = new java.io.PrintWriter(stream); throwable.printStackTrace(writer); writer.flush(); System.err.println("An unhandled throw occurred while" + " executing the Movie program :\n" + stream); System.exit(1); } Database db = createDatabase(dbName); ObjectStore.shutdown(true); } public static Database createDatabase(String dbName) { Database db; try { db = Database.open(dbName,ObjectStore.OPEN_UPDATE); db.destroy(); // destroy past content } catch(DatabaseNotFoundException e) { } db = Database.create(dbName,ObjectStore.ALL_READ|ObjectStore.ALL_WRITE); Transaction tr = Transaction.begin(ObjectStore.UPDATE); Studio d1 = new Studio("MGM","Hollywood Blvd"); Studio d2 = new Studio("Paramount","Pine Blvd"); Movie m1 = new Movie("bugs life", 1998, 120, 'c',d1); Movie m2 = new Movie("seven days in tibet", 1995,150,'c',d1); Movie m3 = new Movie("top gun", 1980,200,'c',d1); Movie m4 = new Movie("prince of egypt", 1998, 300,'b',d2); Star s1 = new Star("tina", "222 ridge wood, NJ 29150"); Star s2 = new Star("jim", "444 shallowford, Ga 30303"); Star s3 = new Star("tim", "323 north avenus, ga 30313"); Star s4 = new Star("jack", "434 abc drive, Ga 30318"); Star s5 = new Star("jerry","333 xyz drive, NY 30303"); Star s6 = new Star("buffy", "120 North Avenue, GA 30313"); d1.addMovie(m1); d1.addMovie(m2); d1.addMovie(m3); d2.addMovie(m4); m1.addStar(s1); m1.addStar(s2); m1.addStar(s3); m1.addStar(s4); m2.addStar(s1); m2.addStar(s3); m2.addStar(s5); m3.addStar(s5); m3.addStar(s6); m4.addStar(s1); m4.addStar(s6); s1.addMovie(m1); s1.addMovie(m2); s1.addMovie(m4); s2.addMovie(m1); s3.addMovie(m1); s3.addMovie(m2); s4.addMovie(m1); s5.addMovie(m2); s5.addMovie(m3); s6.addMovie(m3); s6.addMovie(m4); db.createRoot("allMovies", new OSTreeSet(db)); db.createRoot("allStars", new OSTreeSet(db)); db.createRoot("allStudios", new OSTreeSet(db)); tr.current().commit(); tr.begin(ObjectStore.UPDATE); OSTreeSet allMovies = (OSTreeSet) db.getRoot("allMovies"); OSTreeSet allStars = (OSTreeSet) db.getRoot("allStars"); OSTreeSet allStudios = (OSTreeSet) db.getRoot("allStudios"); allMovies.add(m1); allMovies.add(m2); allMovies.add(m3); allMovies.add(m4); allStars.add(s1); allStars.add(s2); allStars.add(s3); allStars.add(s4); allStars.add(s5); allStars.add(s6); allStudios.add(d1); allStudios.add(d2); tr.current().commit(); db.close(); return db; } public int hashCode() { return super.hashCode(); } }