Skip to content

Commit

Permalink
Partial changes to the model:
Browse files Browse the repository at this point in the history
- renamed Row;
- removed show-venue dependency (accessible through venuelayout)
  • Loading branch information
mbogoevici authored and pmuir committed May 28, 2012
1 parent 9e7c61c commit 97bb24e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 37 deletions.
Expand Up @@ -28,7 +28,7 @@ public class Allocation implements Serializable {
private Performance performance;

@ManyToOne
private SectionRow row;
private Row row;

@ManyToOne
private Booking booking;
Expand All @@ -55,11 +55,11 @@ public void setPerformance(Performance performance) {
this.performance = performance;
}

public SectionRow getRow() {
public Row getRow() {
return row;
}

public void setRow(SectionRow row) {
public void setRow(Row row) {
this.row = row;
}

Expand Down
Expand Up @@ -30,14 +30,13 @@ public class Event implements Serializable {

private String description;


/**
* TODO: revise this, consider whether the Event owns the picture or media items can be shared between events
*/
@ManyToOne
@JoinColumn(name = "PICTURE_ID")
private MediaItem picture;


@ManyToOne
@JoinColumn(name = "CATEGORY_ID")
private EventCategory category;

private boolean major;
Expand Down
Expand Up @@ -15,9 +15,10 @@
* Seat allocations within the row are given a number, starting with 1.
*
* @author Shane Bryzak
* @author Marius Bogoevici
*/
@Entity
public class SectionRow implements Serializable {
public class Row implements Serializable {
private static final long serialVersionUID = 8180924487630451004L;

@Id
Expand All @@ -29,7 +30,6 @@ public class SectionRow implements Serializable {


@ManyToOne
@JoinColumn(name = "SECTION_ID")
private Section section;

public Long getId() {
Expand Down
@@ -1,12 +1,13 @@
package org.jboss.jdf.example.ticketmonster.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.codehaus.jackson.annotate.JsonIgnore;

Expand Down Expand Up @@ -43,10 +44,13 @@ public class Section implements Serializable {
* The layout to which this section belongs
*/
@ManyToOne
@JoinColumn(name = "LAYOUT_ID")
@JsonIgnore
private VenueLayout layout;

@OneToMany(mappedBy = "section")
@JsonIgnore
private List<Row> sectionRows;

public Long getId() {
return id;
}
Expand Down Expand Up @@ -86,4 +90,12 @@ public VenueLayout getLayout() {
public void setLayout(VenueLayout layout) {
this.layout = layout;
}

public List<Row> getSectionRows() {
return sectionRows;
}

public void setSectionRows(List<Row> sectionRows) {
this.sectionRows = sectionRows;
}
}
21 changes: 2 additions & 19 deletions src/main/java/org/jboss/jdf/example/ticketmonster/model/Show.java
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand All @@ -29,20 +30,12 @@ public class Show implements Serializable {
private Long id;

@ManyToOne
@JoinColumn(name = "EVENT_ID")
private Event event;


@ManyToOne
@JoinColumn(name = "VENUE_ID")
private Venue venue;

@ManyToOne
@JoinColumn(name = "LAYOUT_ID")
private VenueLayout venueLayout;

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "SHOW_ID")
@OneToMany(fetch = FetchType.EAGER, mappedBy = "show", cascade = {CascadeType.ALL})
private Set<Performance> performances;

public Long getId() {
Expand All @@ -62,16 +55,6 @@ public void setEvent(Event event) {
this.event = event;
}

public Venue getVenue() {
return venue;
}


public void setVenue(Venue venue) {
this.venue = venue;
}


public Set<Performance> getPerformances() {
return performances;
}
Expand Down
Expand Up @@ -16,7 +16,6 @@
public class Venue implements Serializable {
private static final long serialVersionUID = -6588912817518967721L;


@Id
@GeneratedValue
private Long id;
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.jboss.jdf.example.ticketmonster.model.Performance;
import org.jboss.jdf.example.ticketmonster.model.PriceCategory;
import org.jboss.jdf.example.ticketmonster.model.AllocationTicketCategoryCount;
import org.jboss.jdf.example.ticketmonster.model.SectionRow;
import org.jboss.jdf.example.ticketmonster.model.Row;

/**
* @author Marius Bogoevici
Expand Down Expand Up @@ -91,9 +91,9 @@ public Response createBooking(@FormParam("email") String email,
if (ticketCount == 0) {
continue;
}
List<SectionRow> rows = (List<SectionRow>) getEntityManager().createQuery("select r from SectionRow r where r.section.id = :id").setParameter("id", sectionId).getResultList();
List<Row> rows = (List<Row>) getEntityManager().createQuery("select r from SectionRow r where r.section.id = :id").setParameter("id", sectionId).getResultList();
Allocation createdAllocation = null;
for (SectionRow row : rows) {
for (Row row : rows) {
List<Allocation> allocations = (List<Allocation>) getEntityManager().createQuery("select a from Allocation a where a.performance.id = :perfId and a.row.id = :rowId").setParameter("perfId", performanceId).setParameter("rowId", row.getId()).getResultList();
if (allocations.size() > 0) {
int confirmedCandidate = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/import.sql
Expand Up @@ -337,11 +337,11 @@ insert into eventcategory (id, description) values (5, 'Comedy');
insert into event (id, name, description, picture_id, category_id, major) values (1, 'Rock concert of the decade', 'Get ready to rock your night away with this megaconcert extravaganza from 10 of the biggest rock stars of the 80''s', 100, 1, true);
insert into event (id, name, description, picture_id, category_id, major) values (2, 'Shane''s Sock Puppets', 'This critically acclaimed masterpiece will take you on an emotional rollercoaster the likes of which you''ve never experienced.', 101, 2, true);

insert into show (id, event_id, venue_id, layout_id) values (1, 1, 1, 1);
insert into show (id, event_id, venuelayout_id) values (1, 1, 1);
insert into performance (id, show_id, date) values (1, 1, '2011-01-01 19:00:00');
insert into performance (id, show_id, date) values (2, 1, '2011-01-02 19:00:00');

insert into show (id, event_id, venue_id, layout_id) values (2, 1, 2, 2);
insert into show (id, event_id, venuelayout_id) values (2, 1, 2);
insert into performance (id, show_id, date) values (3, 2, '2011-01-03 19:30:00');
insert into performance (id, show_id, date) values (4, 2, '2011-01-04 19:30:00');

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/events.html
Expand Up @@ -33,7 +33,7 @@
loadedShows = new Object()
$("#venueSelectorDiv").empty().append("<select id='venueSelector' />")
$.each(shows, function (i, show) {
$("#venueSelector").append("<option value='" + show.id + "'>" + show.venue.name + "</option>")
$("#venueSelector").append("<option value='" + show.id + "'>" + show.venuelayout.venue.name + "</option>")
loadedShows[show.id] = show
})
$("#venueSelector").change(function (selectElement) {
Expand Down

0 comments on commit 97bb24e

Please sign in to comment.