コード例 #1
0
 @Override
 public int registraOrdine(Ordine ordine) throws PersistenceException { // ok
   Connection connection = this.datasource.getConnection();
   PreparedStatement statement = null;
   int i;
   if (this.getOrdineByCodice(ordine.getCodiceOrdine()) != null)
     throw new PersistenceException("Ordine gia presente");
   try {
     String str = "insert into ordini (id,codice,data,stato,cliente) values (?,?,?,?,?)";
     statement = connection.prepareStatement(str);
     IdBroker id = new IdBrokerPostgres();
     i = id.getId();
     statement.setInt(1, i);
     statement.setString(
         2, new ClienteDAOImpl().getClienteById(ordine.getCliente().getId()).getNome() + i);
     statement.setDate(3, new java.sql.Date(ordine.getData().getTime()));
     statement.setString(4, ordine.getStato());
     statement.setInt(5, ordine.getCliente().getId());
     statement.executeUpdate();
   } catch (SQLException e) {
     throw new PersistenceException(e.getMessage());
   } finally {
     try {
       if (statement != null) statement.close();
       if (connection != null) connection.close();
     } catch (SQLException e) {
       throw new PersistenceException(e.getMessage());
     }
   }
   return i;
 }
コード例 #2
0
 @Override
 public void evadiOrdine(Ordine ordine) throws PersistenceException { // ok
   Connection connection = this.datasource.getConnection();
   PreparedStatement statement = null;
   try {
     String str = "update ordini set stato=? where codice=?";
     statement = connection.prepareStatement(str);
     statement.setString(1, ordine.getStato());
     statement.setString(2, ordine.getCodiceOrdine());
     statement.executeUpdate();
   } catch (SQLException e) {
     throw new PersistenceException(e.getMessage());
   } finally {
     try {
       if (statement != null) statement.close();
       if (connection != null) connection.close();
     } catch (SQLException e) {
       throw new PersistenceException(e.getMessage());
     }
   }
 }