Instantiate Collections to ArrayList

This commit is contained in:
Tobias Eidelpes 2021-04-02 18:46:16 +02:00
parent fd9b742026
commit f639e25392
12 changed files with 66 additions and 26 deletions

View File

@ -3,7 +3,6 @@ package dst.ass1.jpa.model.impl;
import dst.ass1.jpa.model.*;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@ -16,7 +15,7 @@ public class Driver extends PlatformUser implements IDriver {
private IVehicle vehicle;
@OneToMany(targetEntity = Employment.class)
private Collection<IEmployment> employments;
private Collection<IEmployment> employments = new ArrayList<>();
@Override
public Collection<IEmployment> getEmployments() {

View File

@ -14,8 +14,11 @@ import static dst.ass1.jpa.util.Constants.T_ORGANIZATION;
@Entity
public class Employment implements IEmployment {
@EmbeddedId @Target(EmploymentKey.class) private IEmploymentKey id;
@EmbeddedId @Target(EmploymentKey.class)
private IEmploymentKey id;
private Date since;
private Boolean active;
@MapsId(T_ORGANIZATION)

View File

@ -4,16 +4,20 @@ import dst.ass1.jpa.model.ILocation;
import dst.ass1.jpa.model.ITrip;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
@Entity
public class Location implements ILocation {
@Id @GeneratedValue private Long id;
@Id @GeneratedValue
private Long id;
private String name;
private Long locationId;
@ManyToMany(targetEntity = Trip.class)
private Collection<ITrip> trips;
private Collection<ITrip> trips = new ArrayList<>();
@Override
public Long getId() {

View File

@ -7,9 +7,13 @@ import java.util.Date;
@Entity
public class Match implements IMatch {
@Id @GeneratedValue private Long id;
@Id @GeneratedValue
private Long id;
private Date date;
@Embedded private IMoney fare;
@Embedded
private IMoney fare;
@OneToOne(targetEntity = Trip.class)
private ITrip trip;

View File

@ -6,7 +6,6 @@ import dst.ass1.jpa.model.*;
* Creates new instances of your model implementations.
*/
public class ModelFactory implements IModelFactory {
@Override
public IModelFactory createModelFactory() {
return new ModelFactory();

View File

@ -8,6 +8,7 @@ import java.math.BigDecimal;
@Embeddable
public class Money implements IMoney {
private String currency;
private BigDecimal value;
@Override

View File

@ -5,13 +5,16 @@ import dst.ass1.jpa.model.IOrganization;
import dst.ass1.jpa.model.IVehicle;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import static dst.ass1.jpa.util.Constants.*;
@Entity
public class Organization implements IOrganization {
@Id @GeneratedValue private Long id;
@Id @GeneratedValue
private Long id;
private String name;
@ManyToMany(targetEntity = Organization.class)
@ -20,16 +23,16 @@ public class Organization implements IOrganization {
joinColumns = @JoinColumn(name = I_ORGANIZATION_PART_OF),
inverseJoinColumns = @JoinColumn(name = I_ORGANIZATION_PARTS)
)
private Collection<IOrganization> parts;
private Collection<IOrganization> parts = new ArrayList<>();
@ManyToMany(mappedBy = "parts", targetEntity = Organization.class)
private Collection<IOrganization> partOf;
private Collection<IOrganization> partOf = new ArrayList<>();
@ManyToMany(targetEntity = Vehicle.class)
private Collection<IVehicle> vehicles;
private Collection<IVehicle> vehicles = new ArrayList<>();
@OneToMany(targetEntity = Employment.class)
private Collection<IEmployment> employments;
private Collection<IEmployment> employments = new ArrayList<>();
public Organization() {
}

View File

@ -4,17 +4,22 @@ import dst.ass1.jpa.model.IPreferences;
import dst.ass1.jpa.model.IRider;
import javax.persistence.*;
import java.util.HashMap;
import java.util.Map;
import static dst.ass1.jpa.util.Constants.*;
@Entity
public class Preferences implements IPreferences {
@Id
@Id @GeneratedValue
private Long id;
@ElementCollection
private Map<String, String> data;
@OneToOne(fetch = FetchType.LAZY)
@MapsId
@ElementCollection(fetch = FetchType.LAZY)
@OrderColumn
@JoinTable(name = J_PREFERENCES_DATA)
private Map<String, String> data = new HashMap<>();
@OneToOne(targetEntity = Rider.class, fetch = FetchType.LAZY)
private IRider rider;
@Override

View File

@ -6,6 +6,7 @@ import dst.ass1.jpa.model.ITrip;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import static dst.ass1.jpa.util.Constants.M_RIDER_ACCOUNT;

View File

@ -3,6 +3,7 @@ package dst.ass1.jpa.model.impl;
import dst.ass1.jpa.model.*;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@ -10,11 +11,19 @@ import static dst.ass1.jpa.util.Constants.*;
@Entity
public class Trip implements ITrip {
@Id @GeneratedValue private Long id;
@Id @GeneratedValue
private Long id;
private Date created;
private Date updated;
private TripState state;
@OneToOne(targetEntity = Location.class, optional = false)
private ILocation pickup;
@OneToOne(targetEntity = Location.class, optional = false)
private ILocation destination;
@ManyToMany(targetEntity = Location.class)
@ -23,10 +32,15 @@ public class Trip implements ITrip {
joinColumns = @JoinColumn(name = I_TRIP),
inverseJoinColumns = @JoinColumn(name = I_LOCATION)
)
private Collection<ILocation> stops;
private Collection<ILocation> stops = new ArrayList<>();
@OneToOne(targetEntity = TripInfo.class)
private ITripInfo tripInfo;
@OneToOne(targetEntity = Match.class)
private IMatch match;
@OneToOne(targetEntity = Rider.class)
private IRider rider;
@Override

View File

@ -4,21 +4,23 @@ import dst.ass1.jpa.model.IMoney;
import dst.ass1.jpa.model.ITrip;
import dst.ass1.jpa.model.ITripInfo;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.*;
import java.util.Date;
@Entity
public class TripInfo implements ITripInfo {
@Id
@Id @GeneratedValue
private Long id;
private Date completed;
private Double distance;
@Embedded
private IMoney total;
private Integer driverRating;
private Integer riderRating;
@OneToOne(targetEntity = Trip.class)

View File

@ -10,17 +10,22 @@ import java.util.Collection;
@Entity
public class Vehicle implements IVehicle {
@Id
@Id @GeneratedValue
private Long id;
@Column(unique = true)
private String license;
private String color;
private String type;
@OneToMany(targetEntity = Driver.class)
private Collection<IDriver> driver;
@OneToMany(targetEntity = Match.class)
private Collection<IMatch> match;
@ManyToMany(mappedBy = "vehicles", targetEntity = Organization.class)
private Collection<IOrganization> organization;