/kickup/tags/release-1.0/src/ak/kickup/core/model/ParticipantManager.java |
---|
0,0 → 1,344 |
package ak.kickup.core.model; |
import java.util.*; |
import java.io.UnsupportedEncodingException; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.kickup.util.HibernateUtil; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
public class ParticipantManager |
{ |
private static ParticipantManager participantManager = null; |
private static boolean registered = false; |
public static ParticipantManager getInstance() |
{ |
return participantManager; |
} |
protected static void register() |
{ |
synchronized(ParticipantManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Participant.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/ParticipantAct.hbm.xml"); |
participantManager = new ParticipantManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private ParticipantManager() |
{ |
} |
public Participant create() |
throws ModelException |
{ |
Participant p = new Participant(); |
p.init(); |
return p; |
} |
public Participant get(Long id) |
throws ModelException |
{ |
try { |
return (Participant)HibernateUtil.currentSession().load(Participant.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Participant findForIdent(String ident) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from Participant where ident = ?", |
ident, Hibernate.STRING ); |
if(list.size() == 0) |
return null; |
else |
return (Participant)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Participant findForEmail(String email) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from Participant where email = ?", |
email, Hibernate.STRING ); |
if(list.size() == 0) |
return null; |
else |
return (Participant)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
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 |
{ |
String ident; |
do { |
byte[] buf = new byte[6]; |
for(int i = 0; i < buf.length; i++) { |
buf[i] = (byte)(Math.random() * 10 + 48); |
} |
try { |
ident = new String(buf, "ascii"); |
} |
catch(UnsupportedEncodingException ex) { |
throw new ModelException(ex); |
} |
} while(identExists(ident)); |
return ident; |
} |
public boolean identExists(String ident) |
throws ModelException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant where ident = ?", |
ident, Hibernate.STRING) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Participant participant) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(participant); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Participant participant) |
throws ModelException |
{ |
try { |
participant.getEvent().removeParticipant(participant); |
HibernateUtil.currentSession().delete(participant); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listFreeTransport(Event event) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from Participant where event = ? and free_transport > 0", |
event, Hibernate.entity(Event.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listFreeSleep(Event event) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from Participant where event = ? and free_sleep > 0", |
event, Hibernate.entity(Event.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listForAct(EventAct act) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select pa from Participant as p, ParticipantAct as pa" |
+ " where p.event = ? and pa.participant = p and pa.act = ?", |
new Object[] { act.getEvent(), act.getAct() }, |
new Type[] { Hibernate.entity(Event.class), Hibernate.entity(Act.class) } ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public ParticipantAct createAct() |
throws ModelException |
{ |
return new ParticipantAct(); |
} |
public boolean allowDeleteAct(Act act) |
throws ModelException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from ParticipantAct where act=?", |
act, Hibernate.entity(Act.class)) |
.next()).intValue() == 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public static final Comparator NICK_COMPARATOR = new NickComparator(); |
public static final Comparator ACT_NICK_COMPARATOR = new ActNickComparator(); |
public static final Comparator FROM_ZIP_COMPARATOR = new FromZipComparator(); |
private static class NickComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Participant) || !(o2 instanceof Participant)) |
throw new ClassCastException("not a Participant"); |
Participant a1 = (Participant)o1; |
Participant a2 = (Participant)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getNick().compareToIgnoreCase(a2.getNick()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NickComparator); |
} |
} |
private static class ActNickComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof ParticipantAct) || !(o2 instanceof ParticipantAct)) |
throw new ClassCastException("not a ParticipantAct"); |
ParticipantAct a1 = (ParticipantAct)o1; |
ParticipantAct a2 = (ParticipantAct)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getParticipant().getNick().compareToIgnoreCase(a2.getParticipant().getNick()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof ActNickComparator); |
} |
} |
private static class FromZipComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Participant) || !(o2 instanceof Participant)) |
throw new ClassCastException("not a Participant"); |
Participant a1 = (Participant)o1; |
Participant a2 = (Participant)o2; |
if((a1 == null || a1.getFromZip() == null) && (a2 == null || a2.getFromZip() == null)) |
return 0; |
else if((a1 == null || a1.getFromZip() == null) && (a2 != null && a2.getFromZip() != null)) |
return -1; |
else if((a1 != null && a1.getFromZip() == null) && (a2 == null || a2.getFromZip() == null)) |
return 1; |
else |
return a1.getFromZip().compareToIgnoreCase(a2.getFromZip()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof FromZipComparator); |
} |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/Event.java |
---|
0,0 → 1,453 |
package ak.kickup.core.model; |
import java.math.BigDecimal; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Date; |
import java.util.Map; |
import java.util.HashMap; |
import java.util.Calendar; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="events" |
*/ |
public class Event |
extends GeneralModelObject |
{ |
private String name; |
private String email; |
private String admins; |
private String phones; |
private String place; |
private String address; |
private String transportDesc; |
private Date start; |
private Date stop; |
private Date lastRegister; |
private Date lastUnregister; |
private BigDecimal price; |
private String moneyAccount; |
private Boolean enabled; |
private String comment; |
private Collection acts; // Collection(EventAct) |
private Map actsMap = new HashMap(); // Map(Long id -> EventAct) |
private Collection apartments; // Collection(EventApartment) |
private Map apartmentsMap = new HashMap(); // Map(Long id -> EventApartment) |
private Collection participants; // Collection(EventAct) |
protected Event() |
{ |
} |
protected void init() |
{ |
acts = new ArrayList(); |
apartments = new ArrayList(); |
participants = new ArrayList(); |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
public void setEmail(String email) |
{ |
this.email = email; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAdmins() |
{ |
return admins; |
} |
public void setAdmins(String admins) |
{ |
this.admins = admins; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getPhones() |
{ |
return phones; |
} |
public void setPhones(String phones) |
{ |
this.phones = phones; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getPlace() |
{ |
return place; |
} |
public void setPlace(String place) |
{ |
this.place = place; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAddress() |
{ |
return address; |
} |
public void setAddress(String address) |
{ |
this.address = address; |
} |
/** |
* |
* @hibernate.property column="transport_desc" |
*/ |
public String getTransportDesc() |
{ |
return transportDesc; |
} |
public void setTransportDesc(String transportDesc) |
{ |
this.transportDesc = transportDesc; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Date getStart() |
{ |
return start; |
} |
public void setStart(Date start) |
{ |
this.start = start; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Date getStop() |
{ |
return stop; |
} |
public void setStop(Date stop) |
{ |
this.stop = stop; |
} |
/** |
* |
* @hibernate.property column="last_register" |
*/ |
public Date getLastRegister() |
{ |
return lastRegister; |
} |
public void setLastRegister(Date lastRegister) |
{ |
this.lastRegister = lastRegister; |
} |
/** |
* |
* @hibernate.property column="last_unregister" |
*/ |
public Date getLastUnregister() |
{ |
return lastUnregister; |
} |
public void setLastUnregister(Date lastUnregister) |
{ |
this.lastUnregister = lastUnregister; |
} |
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getPrice() |
{ |
return price; |
} |
public void setPrice(BigDecimal price) |
{ |
this.price = price; |
} |
/** |
* |
* @hibernate.property column="money_account" |
*/ |
public String getMoneyAccount() |
{ |
return moneyAccount; |
} |
public void setMoneyAccount(String moneyAccount) |
{ |
this.moneyAccount = moneyAccount; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getEnabled() |
{ |
return enabled; |
} |
public void setEnabled(Boolean enabled) |
{ |
this.enabled = enabled; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
/** |
* @return Collection(EventAct) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="event" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.EventAct" |
*/ |
protected Collection getActs() |
{ |
return acts; |
} |
public Collection getActCollection() |
{ |
return Collections.unmodifiableCollection(acts); |
} |
/** |
* @param destinations Collection(EventAct) |
*/ |
protected void setActs(Collection acts) |
{ |
this.acts = acts; |
actsMap.clear(); |
if(acts != null) { |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
EventAct a = (EventAct)i.next(); |
if(a.getAct() != null) |
actsMap.put(a.getAct().getId(), a); |
} |
} |
} |
public EventAct getAct(Long actId) |
{ |
return (EventAct)actsMap.get(actId); |
} |
public void addAct(EventAct act) |
{ |
acts.add(act); |
actsMap.put(act.getAct().getId(), act); |
} |
public void removeAct(EventAct act) |
{ |
acts.remove(act); |
actsMap.remove(act.getAct().getId()); |
} |
/** |
* @return Collection(EventApartment) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="event" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.EventApartment" |
*/ |
protected Collection getApartments() |
{ |
return apartments; |
} |
public Collection getApartmentCollection() |
{ |
return Collections.unmodifiableCollection(apartments); |
} |
/** |
* @param destinations Collection(EventApartment) |
*/ |
protected void setApartments(Collection apartments) |
{ |
this.apartments = apartments; |
apartmentsMap.clear(); |
if(apartments != null) { |
for(Iterator i = apartments.iterator(); i.hasNext(); ) { |
EventApartment a = (EventApartment)i.next(); |
if(a.getApartment() != null) |
apartmentsMap.put(a.getApartment().getId(), a); |
} |
} |
} |
public EventApartment getApartment(Long apartmentId) |
{ |
return (EventApartment)apartmentsMap.get(apartmentId); |
} |
public void addApartment(EventApartment apartment) |
{ |
apartments.add(apartment); |
apartmentsMap.put(apartment.getApartment().getId(), apartment); |
} |
public void removeApartment(EventApartment apartment) |
{ |
apartments.remove(apartment); |
apartmentsMap.remove(apartment.getApartment().getId()); |
} |
public boolean isRegistrationAvailable() |
{ |
if(enabled == null || !enabled.booleanValue()) return false; |
Calendar cal = Calendar.getInstance(); |
cal.set(Calendar.HOUR_OF_DAY, 0); |
cal.set(Calendar.MINUTE, 0); |
cal.set(Calendar.SECOND, 0); |
cal.set(Calendar.MILLISECOND, 0); |
Date now = cal.getTime(); |
if(lastRegister == null) { |
return (start == null || !start.before(now)); |
} |
else { |
return !lastRegister.before(now); |
} |
} |
public boolean isUnregistrationAvailable() |
{ |
if(enabled == null || !enabled.booleanValue()) return false; |
Calendar cal = Calendar.getInstance(); |
cal.set(Calendar.HOUR_OF_DAY, 0); |
cal.set(Calendar.MINUTE, 0); |
cal.set(Calendar.SECOND, 0); |
cal.set(Calendar.MILLISECOND, 0); |
Date now = cal.getTime(); |
if(lastUnregister == null) { |
return (start == null || !start.before(now)); |
} |
else { |
return !lastUnregister.before(now); |
} |
} |
public int getParticipantCount() |
{ |
return participants.size(); |
} |
public int getPersonCount() |
{ |
int count = 0; |
for(Iterator i = participants.iterator(); i.hasNext(); ) { |
Participant p = (Participant)i.next(); |
if(p.getPersons() != null) |
count += p.getPersons().intValue(); |
} |
return count; |
} |
/** |
* @return Collection(Participant) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="event" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.Participant" |
*/ |
protected Collection getParticipants() |
{ |
return participants; |
} |
public Collection getParticipantCollection() |
{ |
return Collections.unmodifiableCollection(participants); |
} |
/** |
* @param destinations Collection(Participant) |
*/ |
protected void setParticipants(Collection participants) |
{ |
this.participants = participants; |
} |
protected void removeParticipant(Participant participant) |
{ |
participants.remove(participant); |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/Participant.java |
---|
0,0 → 1,387 |
package ak.kickup.core.model; |
import java.math.BigDecimal; |
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 java.util.ArrayList; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="participants" |
*/ |
public class Participant |
extends GeneralModelObject |
{ |
public static final int PAYED_NULL = 0; // event price is nto defined |
public static final int PAYED_NONE = 1; // noit yet payed |
public static final int PAYED_LESS = 2; // payed but less then needed |
public static final int PAYED_EXACTLY = 3; // payed exactly as needed |
public static final int PAYED_MORE = 4; // payed more then needed |
private String ident; |
private String nick; |
private String email; |
private Boolean emailPublic; |
private String name; |
private String phone; |
private Event event; |
private Integer persons; |
private String fromZip; |
private String fromCity; |
private Date departure; |
private Integer freeTransport; |
private String transportComment; |
private Integer freeSleep; |
private String sleepComment; |
private BigDecimal payed; |
private String comment; |
private String privateComment; |
private Collection acts; // Collection(ParticipantAct) |
private Map actsMap = new HashMap(); // Map(Long id -> ParticipantAct) |
protected Participant() |
{ |
} |
protected void init() |
{ |
acts = new ArrayList(); |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getIdent() |
{ |
return ident; |
} |
public void setIdent(String ident) |
{ |
this.ident = ident; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getNick() |
{ |
return nick; |
} |
public void setNick(String nick) |
{ |
this.nick = nick; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
public void setEmail(String email) |
{ |
this.email = email; |
} |
/** |
* |
* @hibernate.property column="email_public" |
*/ |
public Boolean getEmailPublic() |
{ |
return emailPublic; |
} |
public void setEmailPublic(Boolean emailPublic) |
{ |
this.emailPublic = emailPublic; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getPhone() |
{ |
return phone; |
} |
public void setPhone(String phone) |
{ |
this.phone = phone; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Event getEvent() |
{ |
return event; |
} |
public void setEvent(Event event) |
{ |
this.event = event; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Integer getPersons() |
{ |
return persons; |
} |
public void setPersons(Integer persons) |
{ |
this.persons = persons; |
} |
/** |
* |
* @hibernate.property column="from_zip" |
*/ |
public String getFromZip() |
{ |
return fromZip; |
} |
public void setFromZip(String fromZip) |
{ |
this.fromZip = fromZip; |
} |
/** |
* |
* @hibernate.property column="from_city" |
*/ |
public String getFromCity() |
{ |
return fromCity; |
} |
public void setFromCity(String fromCity) |
{ |
this.fromCity = fromCity; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Date getDeparture() |
{ |
return departure; |
} |
public void setDeparture(Date departure) |
{ |
this.departure = departure; |
} |
/** |
* |
* @hibernate.property column="free_transport" |
*/ |
public Integer getFreeTransport() |
{ |
return freeTransport; |
} |
public void setFreeTransport(Integer freeTransport) |
{ |
this.freeTransport = freeTransport; |
} |
/** |
* |
* @hibernate.property column="transport_comment" |
*/ |
public String getTransportComment() |
{ |
return transportComment; |
} |
public void setTransportComment(String transportComment) |
{ |
this.transportComment = transportComment; |
} |
/** |
* |
* @hibernate.property column="free_sleep" |
*/ |
public Integer getFreeSleep() |
{ |
return freeSleep; |
} |
public void setFreeSleep(Integer freeSleep) |
{ |
this.freeSleep = freeSleep; |
} |
/** |
* |
* @hibernate.property column="sleep_comment" |
*/ |
public String getSleepComment() |
{ |
return sleepComment; |
} |
public void setSleepComment(String sleepComment) |
{ |
this.sleepComment = sleepComment; |
} |
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getPayed() |
{ |
return payed; |
} |
public void setPayed(BigDecimal payed) |
{ |
this.payed = payed; |
} |
public BigDecimal getMustPay() |
{ |
if(event == null || event.getPrice() == null || persons == null) return null; |
return new BigDecimal(event.getPrice().doubleValue() * persons.intValue()); |
} |
public int getPayedStatus() |
{ |
if(event == null || event.getPrice() == null || persons == null) return PAYED_NULL; |
if(payed == null) return PAYED_NONE; |
double needed = event.getPrice().doubleValue() * persons.intValue(); |
double p = payed.doubleValue(); |
if(Math.abs(needed - p) < 0.001) return PAYED_EXACTLY; |
else if(needed < p) return PAYED_MORE; |
else return PAYED_LESS; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
/** |
* |
* @hibernate.property column="private_comment" |
*/ |
public String getPrivateComment() |
{ |
return privateComment; |
} |
public void setPrivateComment(String privateComment) |
{ |
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(); |
if(a.getAct() != null) |
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; |
Participant p = (Participant)o; |
return (getId() != null) && (p.getId() != null) && (getId().equals(p.getId())); |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/EventManager.java |
---|
0,0 → 1,313 |
package ak.kickup.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.kickup.util.HibernateUtil; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
public class EventManager |
{ |
private static EventManager eventManager = null; |
private static boolean registered = false; |
public static EventManager getInstance() |
{ |
return eventManager; |
} |
protected static void register() |
{ |
synchronized(EventManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Event.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/EventAct.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/EventApartment.hbm.xml"); |
eventManager = new EventManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private EventManager() |
{ |
} |
public Event create() |
throws ModelException |
{ |
Event e = new Event(); |
e.init(); |
return e; |
} |
public Event get(Long id, boolean enabledOnly) |
throws ModelException |
{ |
Event event; |
try { |
event = (Event)HibernateUtil.currentSession().load(Event.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
if(enabledOnly && (event.getEnabled() == null || !event.getEnabled().booleanValue())) |
throw new ModelSecurityException(); |
return event; |
} |
public boolean nameExists(Event event, String name) |
throws ModelException |
{ |
try { |
if(event.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Event where name = ?", |
name, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Event e where name = ? and e != ?", |
new Object[] { name, event }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Event.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Event event) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(event); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Event event) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(event); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listEvents(boolean enabledOnly) |
throws ModelException |
{ |
try { |
if(enabledOnly) { |
return HibernateUtil.currentSession().find( |
"from Event where enabled=?", |
Boolean.TRUE, Hibernate.BOOLEAN); |
} |
else { |
return HibernateUtil.currentSession().find("from Event"); |
} |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public EventAct createAct() |
throws ModelException |
{ |
return new EventAct(); |
} |
public boolean allowDeleteAct(Act act) |
throws ModelException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from EventAct where act=?", |
act, Hibernate.entity(Act.class)) |
.next()).intValue() == 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public EventApartment createApartment() |
throws ModelException |
{ |
return new EventApartment(); |
} |
public boolean allowDeleteApartment(Apartment apartment) |
throws ModelException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from EventApartment where apartment=?", |
apartment, Hibernate.entity(Apartment.class)) |
.next()).intValue() == 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
protected void deleteApartments(Apartment apartment) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete( |
"from EventApartment where apartment=?", |
apartment, Hibernate.entity(Apartment.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
public static final Comparator START_COMPARATOR = new StartComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Event) || !(o2 instanceof Event)) |
throw new ClassCastException("not a Event"); |
Event a1 = (Event)o1; |
Event a2 = (Event)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
private static class StartComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Event) || !(o2 instanceof Event)) |
throw new ClassCastException("not a Event"); |
Event a1 = (Event)o1; |
Event a2 = (Event)o2; |
if((a1 == null || a1.getStart() == null) && (a2 == null || a2.getStart() == null)) |
return 0; |
else if((a1 == null || a1.getStart() == null) && (a2 != null && a2.getStart() != null)) |
return -1; |
else if((a1 != null && a1.getStart() != null) && (a2 == null || a2.getStart() == null)) |
return 1; |
else |
return a1.getStart().compareTo(a2.getStart()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof StartComparator); |
} |
} |
public static final Comparator ACT_NAME_COMPARATOR = new ActNameComparator(); |
private static class ActNameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof EventAct) || !(o2 instanceof EventAct)) |
throw new ClassCastException("not a EventAct"); |
EventAct a1 = (EventAct)o1; |
EventAct a2 = (EventAct)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getAct().getName().compareToIgnoreCase(a2.getAct().getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof ActNameComparator); |
} |
} |
public static final Comparator APARTMENT_NAME_COMPARATOR = new ApartmentNameComparator(); |
private static class ApartmentNameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof EventApartment) || !(o2 instanceof EventApartment)) |
throw new ClassCastException("not a EventApartment"); |
EventApartment a1 = (EventApartment)o1; |
EventApartment a2 = (EventApartment)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getApartment().getName().compareToIgnoreCase(a2.getApartment().getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof ApartmentNameComparator); |
} |
} |
} |
/kickup/tags/release-1.0/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/tags/release-1.0/src/ak/kickup/core/model/ActManager.java |
---|
0,0 → 1,151 |
package ak.kickup.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.kickup.util.HibernateUtil; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
public class ActManager |
{ |
private static ActManager actManager = null; |
private static boolean registered = false; |
public static ActManager getInstance() |
{ |
return actManager; |
} |
protected static void register() |
{ |
synchronized(ActManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Act.hbm.xml"); |
actManager = new ActManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private ActManager() |
{ |
} |
public Act create() |
throws ModelException |
{ |
return new Act(); |
} |
public Act get(Long id) |
throws ModelException |
{ |
try { |
return (Act)HibernateUtil.currentSession().load(Act.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public boolean nameExists(Act act, String name) |
throws ModelException |
{ |
try { |
if(act.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Act where name = ?", |
name, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Act a where name = ? and a != ?", |
new Object[] { name, act }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Act.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Act act) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(act); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Act act) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(act); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listActs() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from Act"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Act) || !(o2 instanceof Act)) |
throw new ClassCastException("not a Act"); |
Act a1 = (Act)o1; |
Act a2 = (Act)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/GeneralModelObject.java |
---|
0,0 → 1,37 |
package ak.kickup.core.model; |
import java.util.Date; |
public abstract class GeneralModelObject |
{ |
private Long id; |
private Date modStamp; |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
protected void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/ApartmentManager.java |
---|
0,0 → 1,151 |
package ak.kickup.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.kickup.util.HibernateUtil; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
public class ApartmentManager |
{ |
private static ApartmentManager apartmentManager = null; |
private static boolean registered = false; |
public static ApartmentManager getInstance() |
{ |
return apartmentManager; |
} |
protected static void register() |
{ |
synchronized(ApartmentManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Apartment.hbm.xml"); |
apartmentManager = new ApartmentManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private ApartmentManager() |
{ |
} |
public Apartment create() |
throws ModelException |
{ |
return new Apartment(); |
} |
public Apartment get(Long id) |
throws ModelException |
{ |
try { |
return (Apartment)HibernateUtil.currentSession().load(Apartment.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public boolean nameExists(Apartment apartment, String name) |
throws ModelException |
{ |
try { |
if(apartment.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Apartment where name = ?", |
name, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Apartment a where name = ? and a != ?", |
new Object[] { name, apartment }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Apartment.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Apartment apartment) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(apartment); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Apartment apartment) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(apartment); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listApartments() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from Apartment"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Apartment) || !(o2 instanceof Apartment)) |
throw new ClassCastException("not a Apartment"); |
Apartment a1 = (Apartment)o1; |
Apartment a2 = (Apartment)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/Act.java |
---|
0,0 → 1,56 |
package ak.kickup.core.model; |
import java.util.Date; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="acts" |
*/ |
public class Act |
extends GeneralModelObject |
{ |
private String name; |
private String comment; |
protected Act() |
{ |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
public boolean equals(Object o) |
{ |
if(o == null || !(o instanceof Act)) return false; |
Act a = (Act)o; |
return (getId() != null) && (a.getId() != null) && (getId().equals(a.getId())); |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/EventAct.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="event_acts" |
*/ |
public class EventAct |
extends GeneralModelObject |
{ |
private Event event; |
private Act act; |
private String comment; |
private Date modStamp; |
protected EventAct() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Event getEvent() |
{ |
return event; |
} |
public void setEvent(Event event) |
{ |
this.event = event; |
} |
/** |
* |
* @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/tags/release-1.0/src/ak/kickup/core/model/Apartment.java |
---|
0,0 → 1,101 |
package ak.kickup.core.model; |
import java.math.BigDecimal; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="apartments" |
*/ |
public class Apartment |
extends GeneralModelObject |
{ |
private String name; |
private String address; |
private BigDecimal price; |
private String url; |
private String comment; |
protected Apartment() |
{ |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAddress() |
{ |
return address; |
} |
public void setAddress(String address) |
{ |
this.address = address; |
} |
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getPrice() |
{ |
return price; |
} |
public void setPrice(BigDecimal price) |
{ |
this.price = price; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getUrl() |
{ |
return url; |
} |
public void setUrl(String url) |
{ |
this.url = url; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
public boolean equals(Object o) |
{ |
if(o == null || !(o instanceof Apartment)) return false; |
Apartment a = (Apartment)o; |
return (getId() != null) && (a.getId() != null) && (getId().equals(a.getId())); |
} |
} |
/kickup/tags/release-1.0/src/ak/kickup/core/model/EventApartment.java |
---|
0,0 → 1,80 |
package ak.kickup.core.model; |
import java.math.BigDecimal; |
import java.util.Date; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="event_apartments" |
*/ |
public class EventApartment |
extends GeneralModelObject |
{ |
private Event event; |
private Apartment apartment; |
private BigDecimal distance; |
private String comment; |
private Date modStamp; |
protected EventApartment() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Event getEvent() |
{ |
return event; |
} |
public void setEvent(Event event) |
{ |
this.event = event; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Apartment getApartment() |
{ |
return apartment; |
} |
public void setApartment(Apartment apartment) |
{ |
this.apartment = apartment; |
} |
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getDistance() |
{ |
return distance; |
} |
public void setDistance(BigDecimal distance) |
{ |
this.distance = distance; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
} |