Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #70 from mohangandhiGH/constraint_violation
Browse files Browse the repository at this point in the history
Fix #65 - ConstraintViolationException while monitoring GTFS-rt feed
  • Loading branch information
barbeau committed Feb 21, 2017
2 parents c834c7d + ef2e796 commit 2da3769
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@XmlRootElement
@Entity
@Table(name="GtfsMessageLog")
@Table(name="MessageLog")
public class MessageLogModel implements Serializable {

public MessageLogModel(){};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@XmlRootElement
@Entity
@Table(name="GtfsOccurrence")
@Table(name="Occurrence")
public class OccurrenceModel implements Serializable {
public OccurrenceModel(String elementPath, String elementValue) {
this.elementPath = elementPath;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/edu/usf/cutr/gtfsrtvalidator/db/GTFSDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public static void InitializeDB() {
//Use reflection to get the list of rules from the ValidataionRules class
Field[] fields = ValidationRules.class.getDeclaredFields();

Session session = InitSessionBeginTrans();

List<ValidationRule> rulesInClass = new ArrayList<>();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers())) {
Expand All @@ -72,16 +74,18 @@ public static void InitializeDB() {
Object value = field.get(rule);
rule = (ValidationRule)value;
System.out.println(rule.getErrorDescription());
rulesInClass.add(rule);
ValidationRule validationRule = (ValidationRule) session.createQuery("FROM ValidationRule WHERE errorId = "
+ "'" + rule.getErrorId() + "'").uniqueResult();
if(validationRule == null) {
rulesInClass.add(rule);
}
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
}
}
}

Session session = InitSessionBeginTrans();
session.createQuery("DELETE FROM ValidationRule").executeUpdate(); //Deleting Error table
try {
for (ValidationRule rule : rulesInClass) {
session.save(rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class DBHelper {
public static void saveError(ErrorListHelperModel errorListHelperModel) {
Session session = GTFSDB.InitSessionBeginTrans();
int messageId = (int) session.save(errorListHelperModel.getErrorMessage());
GTFSDB.commitAndCloseSession(session);

session = GTFSDB.InitSessionBeginTrans();
for (OccurrenceModel occurrence : errorListHelperModel.getOccurrenceList()) {
occurrence.setMessageId(messageId);
session.save(occurrence);
Expand Down

0 comments on commit 2da3769

Please sign in to comment.