changeset 12:3c28ecafafc1

more comments for FixRelationNonCurrent.
author casties
date Fri, 10 Apr 2015 09:19:52 +0000
parents d71f28dac165
children 85dddb9d54ef
files src/main/java/org/mpi/openmind/scripts/FixRelationNonCurrent.java
diffstat 1 files changed, 48 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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<Long> 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<Long> 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<Long> getRelIds(String type, Connection conn) {
         List<Long> relIds = new ArrayList<Long>();
         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<Long> getCurrentVersionTime(Long id, Connection conn) {
         List<Long> times = new ArrayList<Long>();
         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 "