public static void save(Iterable<CarOption> options, Session session) { for (CarOption option : options) { Criteria criteria = session.createCriteria(CarOption.class); criteria.add(Restrictions.eq("description", option.getDescription())); criteria.setMaxResults(1); CarOption savedCar = (CarOption) criteria.uniqueResult(); if (savedCar != null) { option.setId(savedCar.getId()); } else { session.save(option); } } }
@SuppressWarnings("unchecked") public void returnOptions(ReturnEvent event) { Object value = event.getReturnValue(); StringBuffer buffer = new StringBuffer(); int addedPrice = 0; if (value instanceof List) { for (CarOption option : (List<CarOption>) value) { addedPrice = addedPrice + option.getPrice(); if (buffer.length() != 0) buffer.append(", "); buffer.append(option.getName()); } } _options.setValue(buffer.toString()); Integer price = (Integer) _price.getValue(); _price.setValue(new Integer(price.intValue() + addedPrice)); }