Skip to content

Commit

Permalink
Fixing wrong database configuration. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
vesavlad committed May 19, 2024
1 parent 7df28c7 commit b6c75c4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE export_table RENAME COLUMN first_name TO file_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- removing faulty constraints definitions
ALTER TABLE travel_times_for_trip_to_travel_times_for_path
DROP CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_stop_path;

ALTER TABLE travel_times_for_trip_to_travel_times_for_path
DROP CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_trip;

-- recreating new constraints
ALTER TABLE travel_times_for_trip_to_travel_times_for_path
ADD CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_stop_path FOREIGN KEY (for_path_id) REFERENCES travel_times_for_stop_paths (id);

ALTER TABLE travel_times_for_trip_to_travel_times_for_path
ADD CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_trip FOREIGN KEY (for_trip_id) REFERENCES travel_times_for_trips (id);
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ExportTable implements Serializable {
@Column(name = "export_status")
private int exportStatus;

@Column(name = "first_name")
@Column(name = "file_name")
private String fileName;

@Column(name = "file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

import com.querydsl.jpa.impl.JPAQuery;
import jakarta.persistence.*;
import lombok.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DynamicUpdate;
import org.transitclock.domain.structs.QTravelTimesForTrip;

import java.io.Serializable;
import java.util.*;
Expand All @@ -24,7 +23,7 @@
@Entity
@Slf4j
@DynamicUpdate
@Getter @Setter @ToString
@Data
@Table(
name = "travel_times_for_trips",
indexes = {
Expand Down Expand Up @@ -72,15 +71,13 @@ public class TravelTimesForTrip implements Serializable {
private final String tripCreatedForId;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "travel_times_for_trip_to_travel_times_for_path",
joinColumns = {
@JoinColumn(name = "for_path_id", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "for_trip_id", referencedColumnName = "id")
}
)
@JoinTable(name = "travel_times_for_trip_to_travel_times_for_path",
joinColumns = {
@JoinColumn(name = "for_trip_id", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "for_path_id", referencedColumnName = "id")
})
@Cascade({CascadeType.SAVE_UPDATE})
@OrderColumn(name = "list_index")
private final List<TravelTimesForStopPath> travelTimesForStopPaths = new ArrayList<>();
Expand Down Expand Up @@ -273,16 +270,4 @@ public TravelTimesForStopPath getTravelTimesForStopPath(int index) {
public int numberOfStopPaths() {
return travelTimesForStopPaths.size();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TravelTimesForTrip that)) return false;
return configRev == that.configRev && travelTimesRev == that.travelTimesRev && Objects.equals(id, that.id) && Objects.equals(tripPatternId, that.tripPatternId) && Objects.equals(tripCreatedForId, that.tripCreatedForId) && Objects.equals(travelTimesForStopPaths, that.travelTimesForStopPaths);
}

@Override
public int hashCode() {
return Objects.hash(id, configRev, travelTimesRev, tripPatternId, tripCreatedForId, travelTimesForStopPaths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ public boolean isStopAtOrAfterStop(String stopId1, String stopId2) {
* @return
*/
public List<String> getStopIds() {
List<String> list = new ArrayList<String>(stopPaths.size());
for (StopPath stopPath : stopPaths) list.add(stopPath.getStopId());
return list;
return stopPaths.stream()
.map(StopPath::getStopId)
.collect(Collectors.toList());
}

/**
Expand All @@ -539,7 +539,9 @@ public List<String> getStopIds() {
* @return ID of last stop
*/
public String getLastStopIdForTrip() {
return stopPaths.get(stopPaths.size() - 1).getStopId();
return Optional.ofNullable(getStopPath(stopPaths.size() - 1))
.map(StopPath::getStopId)
.orElse(null);
}

/**
Expand All @@ -560,7 +562,8 @@ public double getLength() {
* @return The specified StopPath or null if index out of range
*/
public StopPath getStopPath(int index) {
if (index < 0 || index >= stopPaths.size()) return null;
if (index < 0 || index >= stopPaths.size())
return null;

return stopPaths.get(index);
}
Expand Down

0 comments on commit b6c75c4

Please sign in to comment.