/kickup/trunk/src/ak/kickup/core/model/Participant.java |
---|
1,6 → 1,11 |
package ak.kickup.core.model; |
import java.util.Date; |
import java.util.Map; |
import java.util.HashMap; |
import java.util.Collections; |
import java.util.Collection; |
import java.util.Iterator; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
29,6 → 34,8 |
private Boolean payed; |
private String comment; |
private String privateComment; |
private Collection acts; // Collection(ParticipantAct) |
private Map actsMap = new HashMap(); // Map(Long id -> ParticipantAct) |
protected Participant() |
{ |
286,6 → 293,56 |
this.privateComment = privateComment; |
} |
/** |
* @return Collection(ParticipantAct) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="participant" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.ParticipantAct" |
*/ |
protected Collection getActs() |
{ |
return acts; |
} |
public Collection getActCollection() |
{ |
return Collections.unmodifiableCollection(acts); |
} |
/** |
* @param destinations Collection(ParticipantAct) |
*/ |
protected void setActs(Collection acts) |
{ |
this.acts = acts; |
actsMap.clear(); |
if(acts != null) { |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
ParticipantAct a = (ParticipantAct)i.next(); |
actsMap.put(a.getAct().getId(), a); |
} |
} |
} |
public ParticipantAct getAct(Long actId) |
{ |
return (ParticipantAct)actsMap.get(actId); |
} |
public void addAct(ParticipantAct act) |
{ |
acts.add(act); |
actsMap.put(act.getAct().getId(), act); |
} |
public void removeAct(ParticipantAct act) |
{ |
acts.remove(act); |
actsMap.remove(act.getAct().getId()); |
} |
public boolean equals(Object o) |
{ |
if(o == null || !(o instanceof Participant)) return false; |
/kickup/trunk/src/ak/kickup/core/model/ParticipantAct.java |
---|
0,0 → 1,64 |
package ak.kickup.core.model; |
import java.util.Date; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="participant_acts" |
*/ |
public class ParticipantAct |
extends GeneralModelObject |
{ |
private Participant participant; |
private Act act; |
private String comment; |
private Date modStamp; |
protected ParticipantAct() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Participant getParticipant() |
{ |
return participant; |
} |
public void setParticipant(Participant participant) |
{ |
this.participant = participant; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Act getAct() |
{ |
return act; |
} |
public void setAct(Act act) |
{ |
this.act = act; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
} |
/kickup/trunk/src/ak/kickup/core/model/ParticipantManager.java |
---|
27,6 → 27,8 |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Participant.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/ParticipantAct.hbm.xml"); |
participantManager = new ParticipantManager(); |
} |
82,6 → 84,30 |
} |
} |
public boolean emailExists(Participant participant, String email) |
throws ModelException |
{ |
try { |
if(participant.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant where email=? and event=?", |
new Object[] { email, participant.getEvent() }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Event.class) } ) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant p where email=? and event=? and p!=?", |
new Object[] { email, participant.getEvent(), participant }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Event.class), |
Hibernate.entity(Participant.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public String generateIdent() |
throws ModelException |
{ |
172,6 → 198,12 |
} |
} |
public ParticipantAct createAct() |
throws ModelException |
{ |
return new ParticipantAct(); |
} |
public static final Comparator NICK_COMPARATOR = new NickComparator(); |
private static class NickComparator |