# HG changeset patch # User casties # Date 1428657592 0 # Node ID 3c28ecafafc1d1c3c1f912a1c682675542be60ee # Parent d71f28dac165184478e19910eb9baaa6ffdae744 more comments for FixRelationNonCurrent. diff -r d71f28dac165 -r 3c28ecafafc1 src/main/java/org/mpi/openmind/scripts/FixRelationNonCurrent.java --- a/src/main/java/org/mpi/openmind/scripts/FixRelationNonCurrent.java Thu Apr 09 20:03:51 2015 +0000 +++ b/src/main/java/org/mpi/openmind/scripts/FixRelationNonCurrent.java Fri Apr 10 09:19:52 2015 +0000 @@ -16,6 +16,15 @@ */ public class FixRelationNonCurrent { + /** + * Print information about relations pointing to non-current entities to stdout. + * + * Returns 0 if there are no such relations, 1 otherwise. + * + * @param dbUser + * @param dbPw + * @return + */ public static int show(String dbUser, String dbPw) { Connection conn = DBUtils.getConn(dbUser, dbPw); List sourceRelIds = getRelIds("source", conn); @@ -23,7 +32,7 @@ System.out.println("RELATION "+id+" source is not CURRENT_VERSION"); int ncv = getCurrentVersionTime(id, conn).size(); if (ncv == 1) { - System.out.println(" RELATION "+id+" can be fixed"); + System.out.println(" RELATION "+id+" has current version"); } else { System.out.println(" ERROR: RELATION " + id + " has " + ncv + " CURRENT_VERSIONs"); } @@ -34,7 +43,7 @@ System.out.println("RELATION "+id+" target is not CURRENT_VERSION"); int ncv = getCurrentVersionTime(id, conn).size(); if (ncv == 1) { - System.out.println(" RELATION "+id+" can be fixed"); + System.out.println(" RELATION "+id+" has current version"); } else { System.out.println(" ERROR: RELATION "+id+" has " + ncv + " CURRENT_VERSIONs"); } @@ -52,6 +61,17 @@ return 0; } + /** + * Repair relations pointing to non-current entities. + * + * Sets the version (*_modif) of the source or target id to the current version of this entity. + * + * Returns 0 if all relations were fixed, 1 otherwise. + * + * @param dbUser + * @param dbPw + * @return + */ public static int repair(String dbUser, String dbPw) { Connection conn = DBUtils.getConn(dbUser, dbPw); List relSourceIds = getRelIds("source", conn); @@ -76,8 +96,8 @@ System.out.println(" ERROR: RELATION "+id+" was not fixed!"); } } - System.out.println(relSourceIds.size() + " RELATION sources are not CURRENT_VERSION"); - System.out.println(relTargetIds.size() + " RELATION targets are not CURRENT_VERSION"); + System.out.println(relSourceIds.size() + " RELATION sources were not CURRENT_VERSION"); + System.out.println(relTargetIds.size() + " RELATION targets were not CURRENT_VERSION"); System.out.println(fixedSs + " RELATION sources were fixed."); System.out.println(fixedTs + " RELATION targets were fixed."); try { @@ -90,6 +110,13 @@ return 0; } + /** + * Return a list of ids of relations pointing to non-current entitites. + * + * @param type either "source" or "target" + * @param conn + * @return + */ public static List getRelIds(String type, Connection conn) { List relIds = new ArrayList(); String qTargetRels = "select rel.id from openmind.node rel, openmind.node ent " @@ -113,6 +140,13 @@ return relIds; } + /** + * Return the modification_date of the current version of the entity. + * + * @param id + * @param conn + * @return + */ public static List getCurrentVersionTime(Long id, Connection conn) { List times = new ArrayList(); String query = "select modification_time from openmind.node " @@ -132,6 +166,16 @@ return times; } + /** + * Update the relation to point to the current version of the entity. + * + * Returns true if the relation was fixed. + * + * @param id of the relation + * @param type either "source" or "target" + * @param conn + * @return + */ public static boolean updateCurrentRelation(Long id, String type, Connection conn) { // get target_id of relation String qTargetId = "select " + type + "_id from openmind.node "