1
|
1 package org.mpi.openmind.scripts;
|
|
2
|
|
3 import java.sql.Connection;
|
|
4 import java.sql.DriverManager;
|
|
5 import java.sql.ResultSet;
|
|
6 import java.sql.SQLException;
|
|
7 import java.sql.Statement;
|
|
8 import java.util.ArrayList;
|
|
9 import java.util.Arrays;
|
|
10 import java.util.HashMap;
|
|
11 import java.util.List;
|
|
12 import java.util.Map;
|
|
13
|
|
14 import org.apache.commons.lang.NotImplementedException;
|
|
15 import org.apache.commons.lang.StringUtils;
|
|
16 import org.mpi.openmind.repository.bo.Node;
|
|
17
|
|
18 /**
|
|
19 *
|
|
20 * This script find the relation that are mark as "CURRENT_VERSION",
|
|
21 * however the time_modification does not meet either the time modification of the source, of target or both.
|
|
22 *
|
|
23 * This script does not work well, when there is twice entities with the state "CURRENT_VERSION" and with the same id.
|
|
24 * This problem should be corrected before running this script. Use before class: DoubleEntity
|
|
25 *
|
|
26 *
|
|
27 * @author jurzua
|
|
28 *
|
|
29 */
|
|
30 public class TimeModification {
|
|
31
|
|
32 //selects
|
|
33 private static String queryEntListByClass = "select * from openmind.node where object_class = '##' and system_status = 'CURRENT_VERSION'";
|
|
34 private static String queryAllEntList = "select * from openmind.node where node_type = 'ENTITY' and system_status = 'CURRENT_VERSION' and type = 'ABox'";
|
|
35 private static String queryTarRels = "select * from openmind.node where target_id = '##' and system_status = 'CURRENT_VERSION'";
|
|
36 private static String querySrcRels = "select * from openmind.node where source_id = '##' and system_status = 'CURRENT_VERSION' and node_type = 'RELATION'";
|
|
37
|
|
38 //updates
|
|
39 private static String updateTarRel = "UPDATE openmind.node SET target_modif = '##' WHERE row_id = '**'";
|
|
40 private static String updateSrcRel = "UPDATE openmind.node SET source_modif = '##' WHERE row_id = '**'";
|
|
41
|
|
42 private static List<ClassRelation> classRelList = new ArrayList<ClassRelation>();
|
|
43
|
|
44 static{
|
|
45 classRelList.add(new ClassRelation("WITNESS", "src:is_part_of"));
|
|
46 classRelList.add(new ClassRelation("WITNESS", "src:is_exemplar_of"));
|
|
47 classRelList.add(new ClassRelation("CODEX", "src:is_part_of"));
|
|
48 classRelList.add(new ClassRelation("COLLECTION", "src:is_part_of"));
|
|
49 classRelList.add(new ClassRelation("REPOSITORY", "src:is_in"));
|
|
50 classRelList.add(new ClassRelation("CODEX", "tar:is_part_of"));
|
|
51 classRelList.add(new ClassRelation("COLLECTION", "tar:is_part_of"));
|
|
52 classRelList.add(new ClassRelation("REPOSITORY", "tar:is_part_of"));
|
|
53 classRelList.add(new ClassRelation("PLACE", "tar:is_in"));
|
|
54 classRelList.add(new ClassRelation("TEXT", "tar:is_exemplar_of"));
|
|
55 classRelList.add(new ClassRelation("TEXT", "src:was_created_by"));
|
|
56 classRelList.add(new ClassRelation("TEXT", "tar:is_prime_alias_title_of"));
|
|
57 classRelList.add(new ClassRelation("TEXT", "tar:is_alias_title_of"));
|
|
58 classRelList.add(new ClassRelation("TEXT", "tar:is_translation_of"));
|
|
59 classRelList.add(new ClassRelation("PERSON", "tar:was_created_by"));
|
|
60 classRelList.add(new ClassRelation("PERSON", "src:lived_in"));
|
|
61 classRelList.add(new ClassRelation("PERSON", "tar:is_reference_of"));
|
|
62 classRelList.add(new ClassRelation("PERSON", "tar:is_alias_name_of"));
|
|
63 classRelList.add(new ClassRelation("PERSON", "src:has_role"));
|
|
64 classRelList.add(new ClassRelation("PERSON", "tar:was_copied_by"));
|
|
65 classRelList.add(new ClassRelation("ALIAS", "src:is_prime_alias_title_of"));
|
|
66 classRelList.add(new ClassRelation("ALIAS", "src:is_alias_title_of"));
|
|
67 classRelList.add(new ClassRelation("ALIAS", "tar:has_title_written_as"));
|
|
68 }
|
|
69
|
|
70
|
|
71 /**
|
|
72 *
|
|
73 * @param conn
|
|
74 * @param entId
|
|
75 * @param entModif
|
|
76 * @param entOC
|
|
77 * @param action show/solve
|
|
78 * @throws SQLException
|
|
79 */
|
|
80 public static void executeEntity(Connection conn, Long entId, Long entModif, String entOC, String relacion, String action) throws Exception{
|
|
81
|
|
82 if(StringUtils.isEmpty(relacion)){
|
|
83 executeSources(conn, entId, entModif, entOC, null, action);
|
|
84 executeTargets(conn, entId, entModif, entOC, null, action);
|
|
85 }else{
|
|
86 String[] array = relacion.split(":");
|
|
87 String relLabel = array[1];
|
|
88 if(array[0].equals("src")){
|
|
89 executeSources(conn, entId, entModif, entOC, relLabel, action);
|
|
90 }else if(array[0].equals("tar")){
|
|
91 executeTargets(conn, entId, entModif, entOC, relLabel, action);
|
|
92 }else{
|
|
93 throw new Exception("The parameter relation is not valid: " + relacion);
|
|
94 }
|
|
95 }
|
|
96 }
|
|
97
|
|
98 public static boolean analyseSrcRels(Connection conn, List<Relation> rels, Long entId, Long entModif, String entOC, String relLabel, String action) throws Exception{
|
|
99
|
|
100 boolean ok = true;
|
|
101
|
|
102 for(Relation rel : rels){
|
|
103 if(!rel.srcModif.equals(entModif)){
|
|
104 ok = false;
|
|
105 break;
|
|
106 }
|
|
107 }
|
|
108
|
|
109 if(!ok){
|
|
110
|
|
111 printRels(entId, entOC, entModif, rels, "SRC");
|
|
112
|
|
113 if( StringUtils.equals(action, "solve") && (
|
|
114 (StringUtils.equals(entOC, "WITNESS") && (StringUtils.equals(relLabel, "is_part_of"))) ||
|
|
115 (StringUtils.equals(entOC, "WITNESS") && (StringUtils.equals(relLabel, "is_exemplar_of"))) ||
|
|
116 (StringUtils.equals(entOC, "COLLECTION") && (StringUtils.equals(relLabel, "is_part_of"))) ||
|
|
117 (StringUtils.equals(entOC, "TEXT") && (StringUtils.equals(relLabel, "was_created_by"))) ||
|
|
118 (StringUtils.equals(entOC, "ALIAS") && (StringUtils.equals(relLabel, "is_prime_alias_title_of"))) ||
|
|
119 (StringUtils.equals(entOC, "ALIAS") && (StringUtils.equals(relLabel, "is_alias_title_of")))
|
|
120 )
|
|
121 ){
|
|
122 solveUniqueSourceRel(conn, rels, entId, entModif);
|
|
123 }
|
|
124
|
|
125
|
|
126 if( StringUtils.equals(action, "solve") && (
|
|
127 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "lived_in"))) ||
|
|
128 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "has_role")))
|
|
129 )
|
|
130 ){
|
|
131 solveMultipleSourceRels(conn, rels, entId, entModif);
|
|
132 removeDoubleRelations(conn, rels);
|
|
133 }
|
|
134
|
|
135 }
|
|
136 return ok;
|
|
137 }
|
|
138
|
|
139 public static boolean analyseTarRels(Connection conn, List<Relation> rels, Long entId, Long entModif, String entOC, String relLabel, String action) throws Exception{
|
|
140
|
|
141 boolean ok = true;
|
|
142
|
|
143 for(Relation rel : rels){
|
|
144 if(!rel.tarModif.equals(entModif)){
|
|
145 ok = false;
|
|
146 break;
|
|
147 }
|
|
148 }
|
|
149
|
|
150 if(!ok){
|
|
151
|
|
152 printRels(entId, entOC, entModif, rels, "TAR");
|
|
153
|
|
154
|
|
155 if( StringUtils.equals(action, "solve") && (
|
|
156 (StringUtils.equals(entOC, "CODEX") && (StringUtils.equals(relLabel, "is_part_of"))) ||
|
|
157 (StringUtils.equals(entOC, "TEXT") && (StringUtils.equals(relLabel, "is_exemplar_of"))) ||
|
|
158 (StringUtils.equals(entOC, "TEXT") && (StringUtils.equals(relLabel, "is_alias_title_of"))) ||
|
|
159 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "was_created_by"))) ||
|
|
160 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "is_reference_of"))) ||
|
|
161 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "is_alias_name_of"))) ||
|
|
162 (StringUtils.equals(entOC, "PERSON") && (StringUtils.equals(relLabel, "was_copied_by"))) ||
|
|
163 (StringUtils.equals(entOC, "COLLECTION") && (StringUtils.equals(relLabel, "is_part_of"))) ||
|
|
164 (StringUtils.equals(entOC, "REPOSITORY") && (StringUtils.equals(relLabel, "is_part_of"))) ||
|
|
165 (StringUtils.equals(entOC, "PLACE") && (StringUtils.equals(relLabel, "is_in")))
|
|
166 )
|
|
167 ){
|
|
168 solveMultipleTargetRels(conn, rels, entId, entModif);
|
|
169 removeDoubleRelations(conn, rels);
|
|
170 }
|
|
171
|
|
172 if( StringUtils.equals(action, "solve") && (
|
|
173 (StringUtils.equals(entOC, "TEXT") && (StringUtils.equals(relLabel, "is_prime_alias_title_of"))) ||
|
|
174 (StringUtils.equals(entOC, "TEXT") && (StringUtils.equals(relLabel, "is_translation_of"))) ||
|
|
175 (StringUtils.equals(entOC, "ALIAS") && (StringUtils.equals(relLabel, "has_title_written_as")))
|
|
176 )
|
|
177 ){
|
|
178 solveUniqueTargetRel(conn, rels, entId, entModif);
|
|
179 }
|
|
180 }
|
|
181 return ok;
|
|
182 }
|
|
183
|
|
184 private static void printRels(Long entId, String entOC, Long entModif, List<Relation> rels, String direction){
|
|
185 System.out.println("\n" + direction + ") Entity [id=" + entId + ", oc=" + entOC + ", modif=" + entModif + "] - Relation " + rels.get(0).label);
|
|
186 System.out.println("\trowId\tid\tlabel\tsrcModif\ttarModif");
|
|
187 for(Relation rel : rels){
|
|
188 System.out.println("\t" + rel.toString());
|
|
189 }
|
|
190 }
|
|
191
|
|
192 /**
|
|
193 * This method should be used only when the entity is WITNESS and from the source domain.
|
|
194 * @param conn
|
|
195 * @param rels
|
|
196 * @param entId
|
|
197 * @param entModif
|
|
198 * @throws SQLException
|
|
199 */
|
|
200 private static void solveUniqueSourceRel(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
201 System.out.println("\t-----------------------");
|
|
202 Statement stmt = conn.createStatement() ;
|
|
203
|
|
204
|
|
205 Relation correctRel = null;
|
|
206
|
|
207 for(Relation rel : rels){
|
|
208 if(rel.srcModif.equals(entModif)){
|
|
209 correctRel = rel;
|
|
210 break;
|
|
211 }
|
|
212 }
|
|
213
|
|
214 // if correctRel is not null, it means that there is at least one relation with the right modification time.
|
|
215 // if correctRel is not, we will use the last modified relation
|
|
216
|
|
217 if(correctRel == null){
|
|
218 correctRel = getLastModifiedRel(rels);
|
|
219 String update = updateSrcRel.replace("##", entModif.toString()).replace("**", correctRel.rowId.toString());
|
|
220 System.out.println("\t" + update);
|
|
221 int rows = stmt.executeUpdate( update ) ;
|
|
222 }
|
|
223
|
|
224
|
|
225 // All other relations will be made Node.SYS_STATUS_PREVIOUS_VERSION
|
|
226 if(correctRel != null){
|
|
227 for(Relation rel : rels){
|
|
228 if(!rel.equals(correctRel)){
|
|
229
|
|
230 String update = "UPDATE openmind.node SET system_status = '" + Node.SYS_STATUS_PREVIOUS_VERSION + "' WHERE row_id = '" + rel.rowId + "'";
|
|
231 System.out.println("\t" + update);
|
|
232 int rows = stmt.executeUpdate( update ) ;
|
|
233
|
|
234 }
|
|
235 }
|
|
236 }
|
|
237
|
|
238 stmt.close();
|
|
239 System.out.println("\t-----------------------\n");
|
|
240 }
|
|
241
|
|
242 private static void solveUniqueTargetRel(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
243
|
|
244 System.out.println("\t-----------------------");
|
|
245 Statement stmt = conn.createStatement() ;
|
|
246
|
|
247 Relation correctRel = null;
|
|
248
|
|
249 for(Relation rel : rels){
|
|
250 if(rel.tarModif.equals(entModif)){
|
|
251 correctRel = rel;
|
|
252 break;
|
|
253 }
|
|
254 }
|
|
255 // if correctRel is not null, it means that there is at least one relation with the right modification time.
|
|
256 // if correctRel is not, we will use the last modified relation
|
|
257 if(correctRel == null){
|
|
258 correctRel = getLastModifiedRel(rels);
|
|
259 String update = updateTarRel.replace("##", entModif.toString()).replace("**", correctRel.rowId.toString());
|
|
260 System.out.println("\t" + update);
|
|
261 int rows = stmt.executeUpdate( update ) ;
|
|
262 }
|
|
263
|
|
264 // All other relations will be made Node.SYS_STATUS_PREVIOUS_VERSION
|
|
265 if(correctRel != null){
|
|
266 for(Relation rel : rels){
|
|
267 if(!rel.equals(correctRel)){
|
|
268
|
|
269 String update = "UPDATE openmind.node SET system_status = '" + Node.SYS_STATUS_PREVIOUS_VERSION + "' WHERE row_id = '" + rel.rowId + "'";
|
|
270 System.out.println("\t" + update);
|
|
271 int rows = stmt.executeUpdate( update ) ;
|
|
272
|
|
273 }
|
|
274 }
|
|
275 }
|
|
276
|
|
277 stmt.close();
|
|
278 System.out.println("\t-----------------------\n");
|
|
279 }
|
|
280
|
|
281 private static void removeDoubleRelations(Connection conn, List<Relation> rels) throws Exception{
|
|
282 Map<String, List<Relation>> doubleRelMal = new HashMap<String, List<Relation>>();
|
|
283
|
|
284 for(Relation rel : rels){
|
|
285 String key = rel.srcId + "-" + rel.tarId;
|
|
286 if(!doubleRelMal.containsKey(key)){
|
|
287 doubleRelMal.put(key, new ArrayList<Relation>());
|
|
288 }
|
|
289 doubleRelMal.get(key).add(rel);
|
|
290 }
|
|
291
|
|
292 for(String key : doubleRelMal.keySet()){
|
|
293
|
|
294 List<Relation> list = doubleRelMal.get(key);
|
|
295
|
|
296 //found double relations
|
|
297
|
|
298 if(list.size() > 1){
|
|
299 Statement stmt = conn.createStatement() ;
|
|
300 System.out.println("\t-----------------------");
|
|
301 System.out.println("\tFound double relations:");
|
|
302
|
|
303 Relation correctRel = getLastModifiedRel(list);
|
|
304 for(Relation rel : list){
|
|
305 System.out.println("\t" + rel.toString());
|
|
306 if(!rel.equals(correctRel)){
|
|
307 String update = "UPDATE openmind.node SET system_status = '" + Node.SYS_STATUS_PREVIOUS_VERSION + "' WHERE row_id = '" + rel.rowId + "'";
|
|
308 System.out.println("\t" + update);
|
|
309 int rows = stmt.executeUpdate( update ) ;
|
|
310 }
|
|
311 }
|
|
312 stmt.close();
|
|
313 System.out.println("\t-----------------------\n");
|
|
314 }
|
|
315
|
|
316 }
|
|
317
|
|
318 }
|
|
319
|
|
320 private static Relation getLastModifiedRel(List<Relation> rels){
|
|
321 Relation lastModified = null;
|
|
322
|
|
323 for(Relation rel : rels){
|
|
324 if(lastModified == null || lastModified.modifTime < rel.modifTime){
|
|
325 lastModified = rel;
|
|
326 }
|
|
327 }
|
|
328 return lastModified;
|
|
329 }
|
|
330
|
|
331 private static void solveMultipleTargetRels(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
332 System.out.println("\t-----------------------");
|
|
333 Statement stmt = conn.createStatement() ;
|
|
334
|
|
335
|
|
336 for(Relation rel : rels){
|
|
337 String update = updateTarRel.replace("##", entModif.toString()).replace("**", rel.rowId.toString());
|
|
338 System.out.println("\t" + update);
|
|
339 int rows = stmt.executeUpdate( update ) ;
|
|
340 }
|
|
341
|
|
342 stmt.close();
|
|
343 System.out.println("\t-----------------------\n");
|
|
344 }
|
|
345
|
|
346 private static void solveMultipleSourceRels(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
347 System.out.println("\t-----------------------");
|
|
348 Statement stmt = conn.createStatement() ;
|
|
349
|
|
350
|
|
351 for(Relation rel : rels){
|
|
352 String update = updateSrcRel.replace("##", entModif.toString()).replace("**", rel.rowId.toString());
|
|
353 System.out.println("\t" + update);
|
|
354 int rows = stmt.executeUpdate( update ) ;
|
|
355 }
|
|
356
|
|
357 stmt.close();
|
|
358 System.out.println("\t-----------------------\n");
|
|
359 }
|
|
360
|
|
361
|
|
362 private static void executeSources(Connection conn, Long entId, Long entModif, String entOC, String relLabel, String action) throws Exception{
|
|
363 Map<String, List<Relation>> srcRelMap = new HashMap<String, List<Relation>>();
|
|
364
|
|
365 ResultSet srcRels = getSrcRels(conn, entId);
|
|
366 try {
|
|
367 while (srcRels.next()) {
|
|
368 Relation rel = new Relation(srcRels);
|
|
369 if(!srcRelMap.containsKey(rel.label)){
|
|
370 srcRelMap.put(rel.label, new ArrayList<Relation>());
|
|
371 }
|
|
372 srcRelMap.get(rel.label).add(rel);
|
|
373 }
|
|
374 } finally {
|
|
375 srcRels.close();
|
|
376 }
|
|
377
|
|
378 if(StringUtils.isEmpty(relLabel)){
|
|
379 for(String rel : srcRelMap.keySet()){
|
|
380 analyseSrcRels(conn, srcRelMap.get(rel), entId, entModif, entOC, rel, action);
|
|
381 }
|
|
382 }else if(srcRelMap.containsKey(relLabel)){
|
|
383 analyseSrcRels(conn, srcRelMap.get(relLabel), entId, entModif, entOC, relLabel, action);
|
|
384 }
|
|
385 }
|
|
386
|
|
387 private static void executeTargets(Connection conn, Long entId, Long entModif, String entOC, String relLabel, String action) throws Exception{
|
|
388 Map<String, List<Relation>> tarRelMap = new HashMap<String, List<Relation>>();
|
|
389
|
|
390 ResultSet tarRels = getTarRels(conn, entId);
|
|
391 try {
|
|
392 while (tarRels.next()) {
|
|
393 Relation rel = new Relation(tarRels);
|
|
394 if(!tarRelMap.containsKey(rel.label)){
|
|
395 tarRelMap.put(rel.label, new ArrayList<Relation>());
|
|
396 }
|
|
397 tarRelMap.get(rel.label).add(rel);
|
|
398 }
|
|
399 } finally {
|
|
400 tarRels.close();
|
|
401 }
|
|
402
|
|
403 if(StringUtils.isEmpty(relLabel)){
|
|
404 for(String rel : tarRelMap.keySet()){
|
|
405 analyseTarRels(conn, tarRelMap.get(rel), entId, entModif, entOC, rel, action);
|
|
406 }
|
|
407 }else if(tarRelMap.containsKey(relLabel)){
|
|
408 analyseTarRels(conn, tarRelMap.get(relLabel), entId, entModif, entOC, relLabel, action);
|
|
409 }
|
|
410 }
|
|
411
|
|
412 /*
|
|
413 public static void solveTarRels(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
414 Statement stmt = conn.createStatement() ;
|
|
415 for(Relation rel : rels){
|
|
416 String update = updateTarRel.replace("##", entModif.toString()).replace("**", rel.rowId.toString());
|
|
417 System.out.println(update);
|
|
418 int rows = stmt.executeUpdate( update ) ;
|
|
419 }
|
|
420 stmt.close();
|
|
421 System.out.println("Problem solved!");
|
|
422 }
|
|
423
|
|
424 public static void solveSrcRels(Connection conn, List<Relation> rels, Long entId, Long entModif) throws SQLException{
|
|
425 Statement stmt = conn.createStatement() ;
|
|
426 for(Relation rel : rels){
|
|
427 String update = updateSrcRel.replace("##", entModif.toString()).replace("**", rel.rowId.toString());
|
|
428 System.out.println(update);
|
|
429 int rows = stmt.executeUpdate( update ) ;
|
|
430 }
|
|
431 stmt.close();
|
|
432 System.out.println("Problem solved!");
|
|
433 }*/
|
|
434
|
|
435 public static ResultSet getTarRels(Connection conn, Long entId)
|
|
436 throws SQLException {
|
|
437 String query = queryTarRels.replace("##", entId.toString());
|
|
438 Statement st = conn.createStatement();
|
|
439 ResultSet rs = st.executeQuery(query);
|
|
440 return rs;
|
|
441 }
|
|
442
|
|
443 public static ResultSet getSrcRels(Connection conn, Long entId)
|
|
444 throws SQLException {
|
|
445 String query = querySrcRels.replace("##", entId.toString());
|
|
446 Statement st = conn.createStatement();
|
|
447 ResultSet rs = st.executeQuery(query);
|
|
448 return rs;
|
|
449 }
|
|
450
|
|
451 /**
|
|
452 * TODO reduces double entities
|
|
453 * @param conn
|
|
454 * @param objectClass
|
|
455 * @return
|
|
456 * @throws SQLException
|
|
457 */
|
|
458 public static ResultSet getEntitiesByClass(Connection conn,
|
|
459 String objectClass) throws SQLException {
|
|
460
|
|
461 String query = null;
|
|
462
|
|
463 if(StringUtils.isEmpty(objectClass)){
|
|
464 query = queryAllEntList;
|
|
465 }else{
|
|
466 query = queryEntListByClass.replace("##", objectClass);
|
|
467 }
|
|
468
|
|
469 Statement st = conn.createStatement();
|
|
470 ResultSet rs = st.executeQuery(query);
|
|
471 System.out.println("Entities had been loaded...");
|
|
472 return rs;
|
|
473 }
|
|
474
|
|
475 public static void execute(String mysqlUser,
|
|
476 String mysqlPass, String action, String objectClass, String relation) {
|
|
477 try {
|
|
478 Connection conn;
|
|
479
|
|
480 Class.forName("com.mysql.jdbc.Driver").newInstance();
|
|
481 String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8";
|
|
482 conn = DriverManager.getConnection(url, mysqlUser, mysqlPass);
|
|
483
|
|
484 if(StringUtils.equals("solve", action) && StringUtils.isEmpty(objectClass) && StringUtils.isEmpty(relation)){
|
|
485
|
|
486 for(ClassRelation classRel : classRelList){
|
|
487 System.out.println("#######################################");
|
|
488 System.out.println(classRel.toString());
|
|
489 ResultSet ents = getEntitiesByClass(conn, classRel.objectClass);
|
|
490 int count = 0;
|
|
491
|
|
492 try {
|
|
493 while (ents.next()) {
|
|
494 executeEntity(conn, ents.getLong("id"), ents.getLong("modification_time"), ents.getString("object_class"), classRel.relName, action);
|
|
495 count++;
|
|
496
|
|
497 if(count % 50 == 0){
|
|
498 System.out.print("*");
|
|
499 }
|
|
500 if(count % 300 == 0){
|
|
501 System.out.println(count);
|
|
502 }
|
|
503 }
|
|
504 } finally {
|
|
505 ents.close();
|
|
506 }
|
|
507 System.out.println();
|
|
508 }
|
|
509
|
|
510
|
|
511 }else{
|
|
512 ResultSet ents = getEntitiesByClass(conn, objectClass);
|
|
513 int count = 0;
|
|
514
|
|
515 try {
|
|
516 while (ents.next()) {
|
|
517 executeEntity(conn, ents.getLong("id"), ents.getLong("modification_time"), ents.getString("object_class"), relation, action);
|
|
518 count++;
|
|
519
|
|
520 if(count % 50 == 0){
|
|
521 System.out.print("*");
|
|
522 }
|
|
523 if(count % 300 == 0){
|
|
524 System.out.println(count);
|
|
525 }
|
|
526 }
|
|
527 } finally {
|
|
528 ents.close();
|
|
529 }
|
|
530 }
|
|
531
|
|
532
|
|
533 System.out.println("#### Finished ####");
|
|
534
|
|
535 conn.close();
|
|
536 } catch (Exception ex) {
|
|
537 ex.printStackTrace();
|
|
538 }
|
|
539 }
|
|
540
|
|
541 public static void test(){
|
|
542 try {
|
|
543 Connection conn;
|
|
544
|
|
545 Class.forName("com.mysql.jdbc.Driver").newInstance();
|
|
546 String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8";
|
|
547 conn = DriverManager.getConnection(url, "ismi", "ismipw");
|
|
548
|
|
549 executeEntity(conn, Long.parseLong("297238"), Long.parseLong("1405366164815"), "WITNESS", "show", null);
|
|
550
|
|
551 conn.close();
|
|
552 } catch (Exception ex) {
|
|
553 ex.printStackTrace();
|
|
554 }
|
|
555 }
|
|
556
|
|
557 /**
|
|
558 *
|
|
559 * @param args
|
|
560 * objectClass, mysqlUser, mysqlPassword, action
|
|
561 *
|
|
562 * action:
|
|
563 * - show: show all
|
|
564 * - showExemplarOf: for witnesses, it shows the relation "is_exemplar_of" with problems
|
|
565 * - solveExemplarOf: for witnesses, it solves the relation "is_exemplar_of" with problems
|
|
566 * - showPartOf
|
|
567 * - solvePartOf
|
|
568 */
|
|
569 public static void main(String[] args) {
|
|
570
|
|
571 //test();
|
|
572 if (args.length == 3) {
|
|
573 execute(args[0], args[1], args[2], null, null);
|
|
574 }else if(args.length == 4){
|
|
575 execute(args[0], args[1], args[2], args[3], null);
|
|
576 }else if(args.length == 5){
|
|
577 execute(args[0], args[1], args[2], args[3], args[4]);
|
|
578 } else {
|
|
579 System.out
|
|
580 .println("Parameter/s no found: They should be: mode(SHOW/REDUCE), mysql_user, mysql_password");
|
|
581 System.out.println("args.length= " + args.length);
|
|
582 System.out.println(Arrays.toString(args));
|
|
583
|
|
584 }
|
|
585
|
|
586 System.exit(0);
|
|
587 }
|
|
588
|
|
589 public static class ClassRelation{
|
|
590 public String objectClass;
|
|
591 public String relName;
|
|
592
|
|
593 public ClassRelation(String objectClass, String relName){
|
|
594 this.objectClass = objectClass;
|
|
595 this.relName = relName;
|
|
596 }
|
|
597
|
|
598 @Override
|
|
599 public String toString(){
|
|
600 return this.objectClass + " [" + relName + "]";
|
|
601 }
|
|
602 }
|
|
603
|
|
604 public static class Relation{
|
|
605
|
|
606 public Long id;
|
|
607 public Long rowId;
|
|
608 public Long srcModif;
|
|
609 public Long tarModif;
|
|
610 public Long srcId;
|
|
611 public Long tarId;
|
|
612 public String label;
|
|
613 public Long modifTime;
|
|
614
|
|
615 public Relation(ResultSet rs) throws SQLException{
|
|
616 this.id = rs.getLong("id");
|
|
617 this.rowId = rs.getLong("row_id");
|
|
618 this.srcModif = rs.getLong("source_modif");
|
|
619 this.tarModif = rs.getLong("target_modif");
|
|
620 this.srcId = rs.getLong("source_id");
|
|
621 this.tarId = rs.getLong("target_id");
|
|
622 this.label = rs.getString("object_class");
|
|
623 this.modifTime = rs.getLong("modification_time");
|
|
624 }
|
|
625
|
|
626 @Override
|
|
627 public String toString(){
|
|
628 return this.rowId + "\t" + this.id + "\t" + this.label + "\t" + this.srcId + "\t" + this.tarId + "\t" + this.srcModif + "\t" + this.tarModif;
|
|
629 }
|
|
630 }
|
|
631 }
|