@Override public List<Customer> getList() throws SQLException { String sql; sql = "SELECT * FROM 'customer';"; System.out.println(sql); Statement stmt = dbConnection.getConn().createStatement(); ResultSet rs = stmt.executeQuery(sql); ArrayList<Customer> kundenarray = new ArrayList<Customer>(); while (rs.next()) { Customer kunde = new Customer( rs.getInt("customerId"), rs.getString("name"), rs.getString("firstName"), rs.getString("address"), rs.getString("zip"), rs.getString("city"), rs.getString("phoneNo"), rs.getString("eMail")); kunde.setPets(new PetDataMapper().getPetsFromCustomer(kunde.getCustomerId())); kundenarray.add(kunde); } return kundenarray; }
@Override public void save(Customer entry) throws SQLException, ValidationException { entry.validate(); if (entry.getCustomerId() <= 0) { entry.setCustomerId(insert(entry)); } else { update(entry); } }
@Override public void delete(Customer entry) throws SQLException { // Beziehungen zum Tier entfernen for (Pet t : entry.getPets()) { t.setFkCustomer(-1); try { new PetDataMapper().save(t); } catch (ValidationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } String sql; sql = "DELETE FROM 'customer' WHERE customerId = " + entry.getCustomerId() + ";"; System.out.println(sql); Statement stmt = dbConnection.getConn().createStatement(); stmt.executeUpdate(sql); }