home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / GuerriniG / dispense / corso-oodb / progetti-99 / progetto1 / Top.java < prev   
Text File  |  1999-10-19  |  3KB  |  104 lines

  1. package progetto1;
  2.  
  3. import com.odi.*;
  4. import com.odi.util.*;
  5. import java.util.*;
  6.  
  7. final public class Top
  8. {
  9.   public static Database db=null;
  10.  
  11.   public static void main(String argv[]) throws java.io.IOException
  12.   {
  13.     String dbName="db.odb";
  14.     ObjectStore.initialize(null, null);
  15.     try{
  16.     db = createDatabase(dbName);
  17.     readDatabase(db);
  18.        }
  19.     catch(Exception e){
  20.         System.out.println(e);
  21.     }
  22.     finally{
  23.         ObjectStore.shutdown(true);
  24.     }
  25.   }
  26.  
  27. static Database createDatabase(String dbName) 
  28.   {
  29.    try{
  30.        db = Database.open(dbName,  ObjectStore.OPEN_UPDATE);
  31.       }
  32.       catch (DatabaseNotFoundException e){
  33.        db = Database.create(dbName,ObjectStore.ALL_READ | ObjectStore.ALL_WRITE);
  34.        }
  35.    Transaction t = Transaction.begin(ObjectStore.UPDATE);
  36.  
  37.    Squadra s1 = new Squadra("Genoa","rosso blu",null,null,null,"Levante",null);
  38.    Giocatore g1 = new Giocatore(1969,"portiere","Martina",400,2000,s1);
  39.    Giocatore g2 = new Giocatore(1980,"attaccante","Aguilera",700,2001,s1);
  40.    Allenatore a1 = new Allenatore("Scoglio",200,2001,s1);
  41.    Giocatore giocatori[] = {g1,g2};
  42.    s1.giocatori = giocatori;
  43.    s1.capitano = g2;
  44.    s1.allenatore = a1;
  45.    // db.createRoot("Genoa",s1);
  46.  
  47.    Squadra s2 = new Squadra("Samp","blucerchiato",null,null,null,"Barilla",null);
  48.    Giocatore g21 = new Giocatore(1968,"portiere","Pagliuca",400,2000,s2);
  49.    Giocatore g22 = new Giocatore(1985,"attaccante","Montella",700,2001,s2);
  50.    Allenatore a2 = new Allenatore("Boskov",200,2001,s2);
  51.    Giocatore giocatori2[] = {g21,g22};
  52.    s2.giocatori = giocatori2;
  53.    s2.capitano = g21;
  54.    s2.allenatore = a2;
  55.    //db.createRoot("Samp",s2);
  56.  
  57.    Arbitro arb = new Arbitro("Lucci","Torino");
  58.    Goal goal1 = new Goal(20,false,g2);
  59.    Goal goal2 = new Goal(40,false,g2);
  60.    Goal cart[] = {goal1,goal2};
  61.    Partita p1 = new Partita(1,s1,s2,arb,cart,2,0);
  62.    try{db.createRoot("derby",p1);
  63.       } catch(DatabaseRootAlreadyExistsException e){}
  64.  
  65.    Goal emptycart[] = {};
  66.    Partita p2 = new Partita(2,s2,s1,arb,emptycart,0,0);
  67.    Partita camp[] = {p1, p2};
  68.    s1.partite = camp;
  69.    s2.partite = camp;
  70.                 
  71.    t.commit();
  72.    return db;
  73.   }
  74.  
  75.  
  76. static void readDatabase(Database db) 
  77.   {
  78.    Transaction tr = Transaction.begin(ObjectStore.READONLY);
  79.  
  80.    Partita p = (Partita)db.getRoot("derby");
  81.    System.out.println(p.toString());
  82.    System.out.println(p.squadracasa.toString());
  83.    System.out.println(p.squadratrasferta.toString());
  84.    System.out.println("La vincitrice e' " + p.vincitrice().nome);
  85.  
  86.    System.out.println("Il punteggio di " + p.squadracasa.nome + " e' "
  87.                         + p.squadracasa.punteggio());
  88.    System.out.println("La media inglese di " + p.squadracasa.nome + " e' "
  89.                         + p.squadracasa.mediaingl());
  90.  
  91.  
  92.    System.out.println("Il punteggio di " + p.squadratrasferta.nome + " e' "
  93.                         + p.squadratrasferta.punteggio());
  94.    System.out.println("La media inglese di " + p.squadratrasferta.nome + " e' "
  95.                         + p.squadratrasferta.mediaingl());
  96.  
  97.     
  98.    tr.commit();
  99.  
  100.    db.close();
  101.   }
  102.  
  103. }
  104.