database - DB4O Insert winery that does not exist -


i'm doing test db4o. trying insert data. problem have is:

when insert name of winery , d.o. have insert if not exist in database.

how it?

this insert code:

scanner teclado=new scanner(system.in);          try{          objectcontainer db= db4oembedded.openfile("db4o.yap");         system.out.print("name of wine: ");         string nomvino = teclado.next();         system.out.print("name of cellar: ");         string nombodega = teclado.next();         system.out.print("d.o: ");         string = teclado.next();          system.out.print("type of wine: ");         string tipovino = teclado.next();         system.out.print("grad: ");         float gradosalch = teclado.nextfloat();         system.out.print("year of wine: ");         int fecha = teclado.nextint();          teclado.close();              vinos v = new vinos(nomvino,new bodega(nombodega,do),tipovino,gradosalch,fecha);             db.store(v); //guardar objetos             db.commit(); // valida los datos             //odb.rollback(); // deshace los datos             system.out.print("vino introducido\n");             db.close(); //cerrar la bd           }       catch(exception e){system.out.println (e);}      } 

thank in advance!

what problem (your question not clear) ?

do want avoid duplicating bodega() objects, i.e, when store new vinos object not want store bodega() object if 1 exists bodeganame änd do ?

if trying accomplish, need search bodega object in database before using vinos object; like:

scanner teclado=new scanner(system.in);  try{     objectcontainer db= db4oembedded.openfile("db4o.yap");     system.out.print("name of wine: ");     string nomvino = teclado.next();     system.out.print("name of cellar: ");     string nombodega = teclado.next();     system.out.print("d.o: ");     string = teclado.next();      system.out.print("type of wine: ");     string tipovino = teclado.next();     system.out.print("grad: ");     float gradosalch = teclado.nextfloat();     system.out.print("year of wine: ");     int fecha = teclado.nextint();      teclado.close();      objectset<bodega> foundbodegas = db.query(new predicate<bodega>() {                                         @override public  boolean match(bodega candidate) {                                              return candidate.getname().equals(nomebodega);                                         }});      bodega bodega = null;      if (foundbodegas.size() == 1) {         bodega = foundbodegas.next();     }     else {         bodega = new bodega(nombodega, do);     }      vinos v = new vinos(nomvino,  bodega  ,tipovino,gradosalch,fecha);      db.store(v); //guardar objetos     db.commit(); // valida los datos     //odb.rollback(); // deshace los datos     system.out.print("vino introducido\n");     db.close(); //cerrar la bd   } catch(exception e) {     system.out.println (e); } 

you can find more information here , here


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -