try { int participantNumber = runHome.getNextAvailableParticipantNumber(runner.getDistance().getPrimaryKey(), getMinParticipantNumber(runner.getDistance().getName(), runner.getRun().getName()), getMaxParticipantNumber(runner.getDistance().getName(), runner.getRun().getName())); if (participantNumber == 0) { participantNumber = getMinParticipantNumber(runner.getDistance().getName(), runner.getRun().getName()); } else { participantNumber++; } participant.setParticipantNumber(participantNumber); } catch (IDOException ie) { ie.printStackTrace(); }
participant.setParticipantNumber(getNextAvailableParticipantNumber(runner.getRun(), runner.getDistance()));
	public Collection saveParticipants(Collection runners, String email, String hiddenCardNumber, double amount, IWTimestamp date, Locale locale) throws IDOCreateException {		Collection participants = new ArrayList();		UserTransaction trans = getSessionContext().getUserTransaction();		try {			trans.begin();			Iterator iter = runners.iterator();			while (iter.hasNext()) {				Runner runner = (Runner) iter.next();				User user = runner.getUser();				if (user == null) {					user = saveUser(runner.getName(), runner.getPersonalID(), new IWTimestamp(runner.getDateOfBirth()), runner.getGender(), runner.getAddress(), runner.getPostalCode(), runner.getCity(), runner.getCountry());				}								Group ageGenderGroup = getAgeGroup(user, runner.getRun(), runner.getDistance());				ageGenderGroup.addGroup(user);				Group yearGroup = (Group) runner.getDistance().getParentNode();				Group run = runner.getRun();				Group distance = runner.getDistance();								try {					ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);					Participant participant = runHome.create();					participant.setUser(user);					participant.setRunTypeGroup(run);					participant.setRunDistanceGroup(distance);					participant.setRunYearGroup(yearGroup);					participant.setRunGroupGroup(ageGenderGroup);					if (runner.getAmount() > 0) {						participant.setPayedAmount(String.valueOf(runner.getAmount()));					}										participant.setTShirtSize(runner.getShirtSize());					if (runner.isOwnChip()) {						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_OWN);					}					else if (runner.isRentChip()) {						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_RENT);					}					else if (runner.isBuyChip()) {						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_BUY);					}					participant.setChipNumber(runner.getChipNumber());					participant.setUserNationality(runner.getNationality().getName());					if (runner.getDistance() != null) {						try {							int participantNumber = runHome.getNextAvailableParticipantNumber(runner.getDistance().getPrimaryKey(), getMinParticipantNumber(runner.getDistance().getName(), runner.getRun().getName()), getMaxParticipantNumber(runner.getDistance().getName(), runner.getRun().getName()));							if (participantNumber == 0) {								participantNumber = getMinParticipantNumber(runner.getDistance().getName(), runner.getRun().getName());							}							else {								participantNumber++;							}							participant.setParticipantNumber(participantNumber);						}						catch (IDOException ie) {							ie.printStackTrace();						}					}					participant.store();					participants.add(participant);										getUserBiz().updateUserHomePhone(user, runner.getHomePhone());					getUserBiz().updateUserMobilePhone(user, runner.getMobilePhone());					getUserBiz().updateUserMail(user, runner.getEmail());					if (runner.getEmail() != null) {						IWResourceBundle iwrb = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(locale);						Object[] args = { user.getName(), iwrb.getLocalizedString(run.getName(),run.getName()), iwrb.getLocalizedString(distance.getName(),distance.getName()), iwrb.getLocalizedString("shirt_size." + runner.getShirtSize(), runner.getShirtSize()), String.valueOf(participant.getParticipantNumber()) };						String subject = iwrb.getLocalizedString("registration_received_subject_mail", "Your registration has been received.");						String body = MessageFormat.format(iwrb.getLocalizedString("registration_received_body_mail", "Your registration has been received."), args);						sendMessage(runner.getEmail(), subject, body);					}				}				catch (CreateException ce) {					ce.printStackTrace();				}				catch (RemoteException re) {					throw new IBORuntimeException(re);				}			}			if (email != null) {				IWResourceBundle iwrb = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(locale);				Object[] args = { hiddenCardNumber, String.valueOf(amount), date.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT) };				String subject = iwrb.getLocalizedString("receipt_subject_mail", "Your receipt for registration on Marathon.is");				String body = MessageFormat.format(iwrb.getLocalizedString("receipt_body_mail", "Your registration has been received."), args);				sendMessage(email, subject, body);			}			trans.commit();		}		catch (Exception ex) {			try {				trans.rollback();			}			catch (javax.transaction.SystemException e) {				throw new IDOCreateException(e.getMessage());			}			ex.printStackTrace();			throw new IDOCreateException(ex);		}				return participants;	}