Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public class Prenotazione {
  2.  
  3. private int id;
  4. private Date data;
  5. private Cliente cliente;
  6. private Mezzo mezzo;
  7. private int numPostiOccupati;
  8. private Stazione partenza;
  9. private Stazione arrivo;
  10. private Localita localita;
  11.  
  12. //getters and setters
  13. }
  14. public class PrenotazioneDAO implements IPrenotazioneDAO {
  15. @Override
  16. public Prenotazione findById(int id) {
  17.  
  18. Prenotazione p = null;
  19.  
  20. ArrayList<String[]> res = DbConnection.getInstance().eseguiQuery("SELECT * FROM prenotazione WHERE idprenotazione =" + id + ";");
  21. if (res.size() == 1) {
  22. String[] riga = res.get(0);
  23. p.setId(Integer.parseInt(riga[0]));
  24. p.setNumPostiOccupati(Integer.parseInt(riga[4]));
  25. p.setData(DateUtil.dateTimeFromString(riga[1]));
  26.  
  27. ILocalitaDAO lDao = new LocalitaDAO();
  28. IStazioneDAO sDao = new StazioneDAO();
  29. IClienteDAO cDao = new ClienteDAO();
  30. IMezzoDAO mDao = new MezzoDAO();
  31.  
  32. Localita l = lDao.findById(Integer.parseInt(riga[7]));
  33. Stazione partenza = sDao.findById(Integer.parseInt(riga[5]));
  34. Stazione arrivo = sDao.findById(Integer.parseInt(riga[6]));
  35. Cliente cliente = cDao.findById(Integer.parseInt(riga[2]));
  36. Mezzo mezzo = mDao.findById(Integer.parseInt(riga[3]));
  37.  
  38. p.setLocalita(l);
  39. p.setArrivo(arrivo);
  40. p.setPartenza(partenza);
  41. p.setMezzo(mezzo);
  42. p.setCliente(cliente);
  43. //dobbiamo fare i DAO di stazione
  44. }
  45. return p;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement