annotate src/main/java/org/mpi/openmind/scripts/FixRelationNonCurrent.java @ 127:3e772f7f43e0 default tip

ismi-date with long month names in xml dump.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Thu, 11 May 2023 18:15:45 +0200
parents 034df8d5c923
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
1 package org.mpi.openmind.scripts;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
2
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
3 import java.sql.Connection;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
4 import java.sql.ResultSet;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
5 import java.sql.SQLException;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
6 import java.sql.Statement;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
7 import java.util.ArrayList;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
8 import java.util.List;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
9
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
10 /**
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
11 * Fixes relations with sources or targets that do not point to the current
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
12 * versions of the respective entities.
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
13 *
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
14 * @author casties
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
15 *
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
16 */
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
17 public class FixRelationNonCurrent {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
18
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
19 /**
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
20 * Print information about relations pointing to non-current entities to stdout.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
21 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
22 * Returns 0 if there are no such relations, 1 otherwise.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
23 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
24 * @param dbUser
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
25 * @param dbPw
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
26 * @return
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
27 */
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
28 public static int show(String dbUser, String dbPw) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
29 Connection conn = DBUtils.getConn(dbUser, dbPw);
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
30 List<Long> sourceRelIds = getRelIds("source", conn);
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
31 for (Long id : sourceRelIds) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
32 System.out.println("RELATION "+id+" source is not CURRENT_VERSION");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
33 int ncv = getCurrentVersionTime(id, conn).size();
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
34 if (ncv == 1) {
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
35 System.out.println(" RELATION "+id+" has current version");
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
36 } else {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
37 System.out.println(" ERROR: RELATION " + id + " has " + ncv + " CURRENT_VERSIONs");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
38 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
39 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
40 System.out.println();
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
41 List<Long> targetRelIds = getRelIds("target", conn);
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
42 for (Long id : targetRelIds) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
43 System.out.println("RELATION "+id+" target is not CURRENT_VERSION");
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
44 int ncv = getCurrentVersionTime(id, conn).size();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
45 if (ncv == 1) {
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
46 System.out.println(" RELATION "+id+" has current version");
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
47 } else {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
48 System.out.println(" ERROR: RELATION "+id+" has " + ncv + " CURRENT_VERSIONs");
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
49 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
50 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
51 System.out.println();
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
52 System.out.println(sourceRelIds.size() + " RELATION sources are not CURRENT_VERSION");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
53 System.out.println(targetRelIds.size() + " RELATION targets are not CURRENT_VERSION");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
54 try {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
55 conn.close();
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
56 } catch (SQLException e) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
57 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
58 if (sourceRelIds.size() > 0 || targetRelIds.size() > 0) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
59 return 1;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
60 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
61 return 0;
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
62 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
63
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
64 /**
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
65 * Repair relations pointing to non-current entities.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
66 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
67 * Sets the version (*_modif) of the source or target id to the current version of this entity.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
68 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
69 * Returns 0 if all relations were fixed, 1 otherwise.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
70 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
71 * @param dbUser
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
72 * @param dbPw
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
73 * @return
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
74 */
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
75 public static int repair(String dbUser, String dbPw) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
76 Connection conn = DBUtils.getConn(dbUser, dbPw);
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
77 List<Long> relSourceIds = getRelIds("source", conn);
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
78 int fixedSs = 0;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
79 for (Long id : relSourceIds) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
80 System.out.println("RELATION "+id+" source is not CURRENT_VERSION");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
81 if (updateCurrentRelation(id, "source", conn)) {
14
034df8d5c923 output better information.
casties
parents: 13
diff changeset
82 System.out.println(" RELATION "+id+" source updated to current version");
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
83 fixedSs += 1;
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
84 } else {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
85 System.out.println(" ERROR: RELATION "+id+" was not fixed!");
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
86 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
87 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
88 List<Long> relTargetIds = getRelIds("target", conn);
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
89 int fixedTs = 0;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
90 for (Long id : relTargetIds) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
91 System.out.println("RELATION "+id+" target is not CURRENT_VERSION");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
92 if (updateCurrentRelation(id, "target", conn)) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
93 System.out.println(" RELATION "+id+" target updated to current version");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
94 fixedTs += 1;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
95 } else {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
96 System.out.println(" ERROR: RELATION "+id+" was not fixed!");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
97 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
98 }
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
99 System.out.println(relSourceIds.size() + " RELATION sources were not CURRENT_VERSION");
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
100 System.out.println(relTargetIds.size() + " RELATION targets were not CURRENT_VERSION");
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
101 System.out.println(fixedSs + " RELATION sources were fixed.");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
102 System.out.println(fixedTs + " RELATION targets were fixed.");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
103 try {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
104 conn.close();
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
105 } catch (SQLException e) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
106 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
107 if (relSourceIds.size() > fixedSs || relTargetIds.size() > fixedTs) {
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
108 return 1;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
109 }
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
110 return 0;
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
111 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
112
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
113 /**
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
114 * Return a list of ids of relations pointing to non-current entitites.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
115 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
116 * @param type either "source" or "target"
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
117 * @param conn
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
118 * @return
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
119 */
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
120 public static List<Long> getRelIds(String type, Connection conn) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
121 List<Long> relIds = new ArrayList<Long>();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
122 String qTargetRels = "select rel.id from openmind.node rel, openmind.node ent "
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
123 + "where rel." + type + "_id = ent.id "
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
124 + "and rel." + type + "_modif = ent.modification_time "
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
125 + "and rel.node_type = 'RELATION' "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
126 + "and rel.system_status = 'CURRENT_VERSION' "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
127 + "and ent.system_status != 'CURRENT_VERSION' ";
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
128
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
129 try {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
130 Statement sTargetRels = conn.createStatement();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
131 ResultSet rTargetRels = sTargetRels.executeQuery(qTargetRels);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
132 while (rTargetRels.next()) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
133 long id = rTargetRels.getLong(1);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
134 relIds.add(id);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
135 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
136 sTargetRels.close();
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
137 } catch (SQLException e) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
138 e.printStackTrace();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
139 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
140 return relIds;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
141 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
142
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
143 /**
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
144 * Return the modification_date of the current version of the entity.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
145 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
146 * @param id
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
147 * @param conn
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
148 * @return
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
149 */
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
150 public static List<Long> getCurrentVersionTime(Long id, Connection conn) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
151 List<Long> times = new ArrayList<Long>();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
152 String query = "select modification_time from openmind.node "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
153 + "where id = " + id.toString() + " "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
154 + "and system_status = 'CURRENT_VERSION' ";
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
155 try {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
156 Statement statement = conn.createStatement();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
157 ResultSet results = statement.executeQuery(query);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
158 while (results.next()) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
159 long mtime = results.getLong(1);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
160 times.add(mtime);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
161 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
162 statement.close();
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
163 } catch (SQLException e) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
164 e.printStackTrace();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
165 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
166 return times;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
167 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
168
12
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
169 /**
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
170 * Update the relation to point to the current version of the entity.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
171 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
172 * Returns true if the relation was fixed.
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
173 *
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
174 * @param id of the relation
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
175 * @param type either "source" or "target"
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
176 * @param conn
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
177 * @return
3c28ecafafc1 more comments for FixRelationNonCurrent.
casties
parents: 11
diff changeset
178 */
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
179 public static boolean updateCurrentRelation(Long id, String type, Connection conn) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
180 // get target_id of relation
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
181 String qTargetId = "select " + type + "_id from openmind.node "
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
182 + "where id = " + id.toString() + " "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
183 + "and system_status = 'CURRENT_VERSION' ";
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
184 try {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
185 Statement sTargetId = conn.createStatement();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
186 ResultSet rTargetId = sTargetId.executeQuery(qTargetId);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
187 if (rTargetId.next()) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
188 long target_id = rTargetId.getLong(1);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
189 // get mtime of current version of target
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
190 List<Long> target_mtimes = getCurrentVersionTime(target_id, conn);
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
191 if (target_mtimes.size() == 1) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
192 // update target_mtime of relation
13
85dddb9d54ef output more information.
casties
parents: 12
diff changeset
193 long target_mtime = target_mtimes.get(0);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
194 String qUpdate = "update openmind.node "
13
85dddb9d54ef output more information.
casties
parents: 12
diff changeset
195 + "set " + type + "_modif = " + target_mtime + " "
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
196 + "where id = " + id.toString() + " "
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
197 + "and system_status = 'CURRENT_VERSION' ";
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
198 Statement sUpdate = conn.createStatement();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
199 int rUpdate = sUpdate.executeUpdate(qUpdate);
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
200 sUpdate.close();
14
034df8d5c923 output better information.
casties
parents: 13
diff changeset
201 System.out.println(" relation " + type + " " + target_id + " was updated to " + target_mtime);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
202 return true;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
203 } else {
13
85dddb9d54ef output more information.
casties
parents: 12
diff changeset
204 System.out.println("ERROR: relation " + type + " " + target_id + " has " + target_mtimes.size() + " CURRENT_VERSIONs");
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
205 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
206 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
207 sTargetId.close();
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
208 } catch (SQLException e) {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
209 e.printStackTrace();
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
210 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
211 return false;
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
212 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
213
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
214 /**
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
215 * @param args
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
216 */
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
217 public static void main(String[] args) {
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
218 int rc = 0;
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
219 if (args.length > 1 && args.length < 4) {
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
220 String user = args[1];
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
221 String pw = (args.length == 3) ? args[2] : null;
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
222 if (args[0].equalsIgnoreCase("fix")) {
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
223 rc = repair(user, pw);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
224 } else {
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
225 rc = show(user, pw);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
226 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
227 } else {
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
228 System.out.println("Parameter/s not found! Should be: mode(SHOW/FIX), mysql_user, mysql_password");
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
229 System.out.println(" got: "+args.toString() + "("+args.length+")");
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
230 System.exit(1);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
231 }
11
d71f28dac165 FixRelationNonCurrent now fixes relations with non-current sources.
casties
parents: 10
diff changeset
232 System.exit(rc);
10
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
233 }
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
234
dc458969f479 added script to fix relations with non-current targets.
casties
parents:
diff changeset
235 }