Implement Trip model in XML
This commit is contained in:
parent
be87269876
commit
c2988d5a8e
@ -0,0 +1,20 @@
|
|||||||
|
package dst.ass1.jpa.listener;
|
||||||
|
|
||||||
|
import dst.ass1.jpa.model.ITrip;
|
||||||
|
|
||||||
|
import javax.persistence.PrePersist;
|
||||||
|
import javax.persistence.PreUpdate;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class TripListener {
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist(ITrip trip) {
|
||||||
|
trip.setCreated(new Date());
|
||||||
|
trip.setUpdated(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
public void preUpdate(ITrip trip) {
|
||||||
|
trip.setUpdated(new Date());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,40 +7,17 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static dst.ass1.jpa.util.Constants.*;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Trip implements ITrip {
|
public class Trip implements ITrip {
|
||||||
@Id @GeneratedValue
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private Date created;
|
private Date created;
|
||||||
|
|
||||||
private Date updated;
|
private Date updated;
|
||||||
|
|
||||||
private TripState state;
|
private TripState state;
|
||||||
|
|
||||||
@OneToOne(targetEntity = Location.class, optional = false)
|
|
||||||
private ILocation pickup;
|
private ILocation pickup;
|
||||||
|
|
||||||
@OneToOne(targetEntity = Location.class, optional = false)
|
|
||||||
private ILocation destination;
|
private ILocation destination;
|
||||||
|
|
||||||
@ManyToMany(targetEntity = Location.class)
|
|
||||||
@JoinTable(
|
|
||||||
name = J_TRIP_LOCATION,
|
|
||||||
joinColumns = @JoinColumn(name = I_TRIP),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = I_LOCATION)
|
|
||||||
)
|
|
||||||
private Collection<ILocation> stops = new ArrayList<>();
|
private Collection<ILocation> stops = new ArrayList<>();
|
||||||
|
|
||||||
@OneToOne(targetEntity = TripInfo.class)
|
|
||||||
private ITripInfo tripInfo;
|
private ITripInfo tripInfo;
|
||||||
|
|
||||||
@OneToOne(targetEntity = Match.class)
|
|
||||||
private IMatch match;
|
private IMatch match;
|
||||||
|
|
||||||
@OneToOne(targetEntity = Rider.class)
|
|
||||||
private IRider rider;
|
private IRider rider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class TripInfo implements ITripInfo {
|
|||||||
|
|
||||||
private Integer riderRating;
|
private Integer riderRating;
|
||||||
|
|
||||||
@OneToOne(targetEntity = Trip.class)
|
@OneToOne(targetEntity = Trip.class, optional = false)
|
||||||
private ITrip trip;
|
private ITrip trip;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user