annotate src/main/java/org/mpi/openmind/scripts/FixAttributeIdMissing.java @ 112:933d17f95016

new script MigratePrimeAliases to migrate is_prime_alias_X_of.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Wed, 14 Aug 2019 20:48:02 +0200
parents 1c034e2f7367
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 package org.mpi.openmind.scripts;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 import java.sql.Connection;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 import java.sql.ResultSet;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 import java.sql.SQLException;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 import java.sql.Statement;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
7 import java.util.ArrayList;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 import java.util.List;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
9
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 * Fixes attributes where the current version has no src_id (but older versions have).
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 * @author casties
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 public class FixAttributeIdMissing {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
17
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 * Print information about relations pointing to non-current entities to stdout.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 * Returns 0 if there are no such relations, 1 otherwise.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 * @param dbUser
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 * @param dbPw
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 public static int show(String dbUser, String dbPw) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 Connection conn = DBUtils.getConn(dbUser, dbPw);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 int fixableCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 int replacedCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 int missingSrcCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 int multiSrcCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 List<Long> brokenAttIds = getBrokenAttIds(conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 System.out.println(brokenAttIds.size() + " ATTRIBUTEs without source...");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 for (Long id : brokenAttIds) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 //System.out.println("ATTRIBUTE "+id+" source is missing");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 List<Long> srcIds = getAttSourceIds(id, conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
38 int ncv = srcIds.size();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
39 if (ncv == 1) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 fixableCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 System.out.println(" ATTRIBUTE "+id+" has source (in other version)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 List<Long> sameAttIds = getSameAttIds(id, srcIds.get(0), conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 if (sameAttIds.size() > 0) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 replacedCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 System.out.println(" ATTRIBUTE "+id+" has has been replaced");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 } else if (ncv == 0) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 missingSrcCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 multiSrcCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 System.out.println(" ERROR: ATTRIBUTE " + id + " has " + ncv + " sources!");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 System.out.println();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 System.out.println(brokenAttIds.size() + " ATTRIBUTES have no source_id");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 System.out.println(fixableCnt + " ATTRIBUTES are fixable (source_id in other version)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 System.out.println(replacedCnt + " ATTRIBUTES have been replaced");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 System.out.println(missingSrcCnt + " ATTRIBUTES are not fixable (no source_id)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 System.out.println(multiSrcCnt + " ATTRIBUTES have too many source ids");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 conn.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 if (brokenAttIds.size() > 0) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 return 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 return 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
68 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
69
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 * Repair relations pointing to non-current entities.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 * Sets the version (*_modif) of the source or target id to the current version of this entity.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 * Returns 0 if all relations were fixed, 1 otherwise.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 * @param dbUser
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 * @param dbPw
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 public static int repair(String dbUser, String dbPw) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 Connection conn = DBUtils.getConn(dbUser, dbPw);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 int fixableCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 int fixedCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 int unfixableCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 int replacedCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 int missingSrcCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 int multiSrcCnt = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 List<Long> brokenAttIds = getBrokenAttIds(conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 System.out.println(brokenAttIds.size() + " ATTRIBUTEs without source...");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 for (Long id : brokenAttIds) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 List<Long> srcIds = getAttSourceIds(id, conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 int ncv = srcIds.size();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
94 if (ncv == 1) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 fixableCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
96 Long srcId = srcIds.get(0);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 System.out.println(" ATTRIBUTE "+id+" has source (in other version)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
98 List<Long> sameAttIds = getSameAttIds(id, srcId, conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
99 if (sameAttIds.size() > 0) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
100 replacedCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 System.out.println(" ATTRIBUTE "+id+" has has been replaced");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
102 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 if (updateAttributeSrc(id, srcId, conn)) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
104 fixedCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 System.out.println(" ATTRIBUTE "+id+" source updated");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
106 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 unfixableCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
108 System.out.println(" ERROR: ATTRIBUTE "+id+" could not be fixed");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
109 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
111 } else if (ncv == 0) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 missingSrcCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 multiSrcCnt += 1;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 System.out.println(" ERROR: ATTRIBUTE " + id + " has " + ncv + " sources!");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
116 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 System.out.println();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
119 System.out.println(brokenAttIds.size() + " ATTRIBUTES had no source_id");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
120 System.out.println(fixableCnt + " ATTRIBUTES were fixable (source_id in other version)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 System.out.println(replacedCnt + " ATTRIBUTES have been replaced");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 System.out.println(missingSrcCnt + " ATTRIBUTES are not fixable (no source_id)");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 System.out.println(multiSrcCnt + " ATTRIBUTES have too many source ids");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 System.out.println();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 System.out.println(fixedCnt + " ATTRIBUTES have been fixed");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 System.out.println(unfixableCnt + " ATTRIBUTES could not be fixed");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
127
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
128
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
129 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
130 conn.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
131 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
132 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
133 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
134 return 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
135 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
136
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
137 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
138 * Return a list of ids of attributes with missing source_id.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
139 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
140 * @param conn
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
141 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
142 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
143 public static List<Long> getBrokenAttIds(Connection conn) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
144 List<Long> ids = new ArrayList<Long>();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
145 String query = "SELECT DISTINCT id FROM openmind.node"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
146 + " WHERE node_type = 'ATTRIBUTE'"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
147 + " AND system_status = 'CURRENT_VERSION'"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
148 + " AND source_id IS NULL";
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
149
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
150 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
151 Statement s = conn.createStatement();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
152 ResultSet r = s.executeQuery(query);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
153 while (r.next()) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
154 long id = r.getLong(1);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
155 ids.add(id);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
156 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
157 s.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
158 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
159 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
160 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
161 return ids;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
162 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
163
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
164 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
165 * Return a list of source_ids of an attribute.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
166 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
167 * @param attId
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
168 * @param conn
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
169 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
170 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
171 public static List<Long> getAttSourceIds(Long attId, Connection conn) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
172 List<Long> ids = new ArrayList<Long>();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
173 String query = "SELECT DISTINCT source_id FROM openmind.node "
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
174 + "WHERE node_type = 'ATTRIBUTE' "
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
175 + "AND source_id IS NOT NULL "
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
176 + "AND id = " + attId.toString();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
177
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
178 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
179 Statement s = conn.createStatement();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
180 ResultSet r = s.executeQuery(query);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
181 while (r.next()) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
182 long id = r.getLong(1);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
183 ids.add(id);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
184 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
185 s.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
186 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
187 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
188 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
189 return ids;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
190 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
191
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
192 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
193 * Check if another (current) attribute of the same type exists on the source.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
194 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
195 * @param attId
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
196 * @param srcId
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
197 * @param conn
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
198 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
199 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
200 public static List<Long> getSameAttIds(Long attId, Long srcId, Connection conn) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
201 List<Long> ids = new ArrayList<Long>();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
202 String query = "SELECT DISTINCT id FROM openmind.node"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
203 + " WHERE node_type = 'ATTRIBUTE'"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
204 + " AND system_status = 'CURRENT_VERSION'"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
205 + " AND id != " + attId.toString()
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
206 + " AND source_id = " + srcId.toString()
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
207 + " AND object_class IN ("
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
208 + " SELECT DISTINCT object_class FROM openmind.node"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
209 + " WHERE id = " + attId.toString() + ")";
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
210
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
211 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
212 Statement s = conn.createStatement();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
213 ResultSet r = s.executeQuery(query);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
214 while (r.next()) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
215 long id = r.getLong(1);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
216 ids.add(id);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
217 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
218 s.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
219 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
220 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
221 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
222 return ids;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
223 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
224
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
225 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
226 * Return the modification_date of the current version of the entity.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
227 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
228 * @param id
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
229 * @param conn
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
230 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
231 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
232 public static List<Long> getCurrentVersionTime(Long id, Connection conn) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
233 List<Long> times = new ArrayList<Long>();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
234 String query = "select modification_time from openmind.node "
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
235 + "where id = " + id.toString() + " "
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
236 + "and system_status = 'CURRENT_VERSION' ";
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
237 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
238 Statement statement = conn.createStatement();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
239 ResultSet results = statement.executeQuery(query);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
240 while (results.next()) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
241 long mtime = results.getLong(1);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
242 times.add(mtime);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
243 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
244 statement.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
245 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
246 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
247 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
248 return times;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
249 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
250
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
251 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
252 * Update the attribute with the source_id.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
253 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
254 * Returns true if the relation was fixed.
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
255 *
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
256 * @param id of the attribute
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
257 * @param id of the source
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
258 * @param conn
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
259 * @return
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
260 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
261 public static boolean updateAttributeSrc(Long attId, Long srcId, Connection conn) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
262 // get mtime of current version of target
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
263 List<Long> target_mtimes = getCurrentVersionTime(srcId, conn);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
264 if (target_mtimes.size() == 1) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
265 // update target_mtime of relation
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
266 long target_mtime = target_mtimes.get(0);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
267 String query = "UPDATE openmind.node"
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
268 + " SET source_id = " + srcId.toString()
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
269 + ", source_modif = " + target_mtime
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
270 + " WHERE id = " + attId.toString()
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
271 + " AND source_id IS NULL";
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
272 Statement s;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
273 try {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
274 s = conn.createStatement();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
275 s.executeUpdate(query);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
276 s.close();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
277 } catch (SQLException e) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
278 // TODO Auto-generated catch block
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
279 e.printStackTrace();
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
280 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
281 System.out.println(" ATTRIBUTE " + attId + " was updated to source " + srcId + "/"+ target_mtime);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
282 return true;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
283 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
284 System.out.println("ERROR: source " + srcId + " has " + target_mtimes.size() + " CURRENT_VERSIONs");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
285 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
286 return false;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
287 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
288
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
289 /**
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
290 * @param args
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
291 */
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
292 public static void main(String[] args) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
293 int rc = 0;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
294 if (args.length > 1 && args.length < 4) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
295 String user = args[1];
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
296 String pw = (args.length == 3) ? args[2] : null;
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
297 if (args[0].equalsIgnoreCase("fix")) {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
298 rc = repair(user, pw);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
299 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
300 rc = show(user, pw);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
301 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
302 } else {
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
303 System.out.println("Parameter/s not found! Should be: mode(SHOW/FIX), mysql_user, mysql_password");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
304 System.out.println(" got: "+args.toString() + "("+args.length+")");
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
305 System.exit(1);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
306 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
307 System.exit(rc);
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
308 }
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
309
1c034e2f7367 script that tries to fix attributes with missing source_id.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
310 }