Example #1
0
 /** {@inheritDoc} */
 @Override
 public void create(Contratto entity) {
   ResultSet rs =
       connection.executeReadQuery(
           "SELECT AUTO_INCREMENT FROM  INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "
               + "'carloan' AND   TABLE_NAME = 'contratto'");
   try {
     while (rs.next()) entity.setId(rs.getInt(1));
   } catch (SQLException e) {
     e.printStackTrace();
   }
   connection.executeUpdateQuery(
       "INSERT INTO contratto(operatore, cliente, vettura, agenzianoleggio, agenziaconsegna, datastipula, "
           + "datainizionoleggio, datafinenoleggio, chilometraggiolimitato, chilometriprevisti, rifornimento, acconto, "
           + "costo, assicurazioneavanzata) values("
           + "'"
           + entity.getOperatore().getUsername()
           + "', "
           + "'"
           + entity.getCliente().getCodicePatente()
           + "', "
           + "'"
           + entity.getVettura().getTarga()
           + "', "
           + entity.getAgenziaNoleggio().getId()
           + ", "
           + entity.getAgenziaConsegna().getId()
           + ", "
           + "'"
           + entity.getDataStipula()
           + "', "
           + "'"
           + entity.getDataInizioNoleggio()
           + "', "
           + "'"
           + entity.getDataFineNoleggio()
           + "', "
           + entity.isChilometraggioLimitato()
           + ", "
           + entity.getChilometriPrevisti()
           + ", "
           + entity.getRifornimento().getIndex()
           + ", "
           + entity.getAcconto()
           + ", "
           + entity.getCosto()
           + ", "
           + entity.isAssicurazioneAvanzata()
           + ");");
   for (Optional o : entity.getOptionals()) {
     connection.executeUpdateQuery(
         "insert into optional_contratto values (" + entity.getId() + ", " + o.getId() + ");");
   }
 }
Example #2
0
 /** {@inheritDoc} */
 @Override
 public void update(Contratto entity) {
   connection.executeUpdateQuery(
       "UPDATE contratto SET "
           + "Operatore = '"
           + entity.getOperatore().getUsername()
           + "', "
           + "Cliente = '"
           + entity.getCliente().getCodicePatente()
           + "', "
           + "Vettura = '"
           + entity.getVettura().getTarga()
           + "', "
           + "AgenziaNoleggio = "
           + entity.getAgenziaNoleggio().getId()
           + ", "
           + "AgenziaConsegna = "
           + entity.getAgenziaConsegna().getId()
           + ", "
           + "DataStipula = '"
           + entity.getDataStipula()
           + "', "
           + "DataInizioNoleggio = '"
           + entity.getDataInizioNoleggio()
           + "', "
           + "ChilometraggioLimitato = "
           + entity.isChilometraggioLimitato()
           + ", "
           + "ChilometriPrevisti = "
           + entity.getChilometriPrevisti()
           + ", "
           + "Rifornimento = "
           + entity.getRifornimento().getIndex()
           + ", "
           + "Acconto = "
           + entity.getAcconto()
           + ", "
           + "Chiuso = "
           + entity.isChiuso()
           + ", "
           + "Costo = "
           + entity.getCosto()
           + ", "
           + "AssicurazioneAvanzata = "
           + entity.isAssicurazioneAvanzata()
           + " "
           + "WHERE id = "
           + entity.getId()
           + "; ");
   connection.executeUpdateQuery(
       "delete from optional_contratto where idcontratto = " + entity.getId() + ";");
   for (Optional o : entity.getOptionals()) {
     connection.executeUpdateQuery(
         "insert into optional_contratto values (" + entity.getId() + ", " + o.getId() + ");");
   }
   if (entity.getDataChiusura() != null) {
     connection.executeUpdateQuery(
         "update contratto set datachiusura = '"
             + entity.getDataChiusura()
             + "', chilometriPercorsi = "
             + entity.getChilometriPercorsi()
             + " where id = "
             + entity.getId()
             + ";");
   }
 }