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
|
|
9 import org.mpi.openmind.cache.WrapperService;
|
|
10 import org.mpi.openmind.repository.bo.Entity;
|
|
11 import org.mpi.openmind.repository.services.ServiceRegistry;
|
|
12
|
|
13 public class SicilyCase {
|
|
14
|
|
15 //public static String USER = "script-repo-name";
|
|
16
|
|
17 /*
|
|
18
|
|
19 select pl1.source_id as PL1, pl1.id, pl2.id, pl1.own_value from openmind.`node` as pl1, openmind.`node` as pl2
|
|
20 where
|
|
21
|
|
22 pl1.node_type = 'RELATION' and
|
|
23 pl2.node_type = 'RELATION' and
|
|
24 pl1.system_status = 'CURRENT_VERSION' and
|
|
25 pl2.system_status = 'CURRENT_VERSION' and
|
|
26 pl1.source_obj_class = 'PLACE' and
|
|
27 pl2.source_obj_class = 'PLACE' and
|
|
28 pl1.target_obj_class = 'PLACE' and
|
|
29 pl2.target_obj_class = 'PLACE' and
|
|
30 pl1.source_id = pl2.source_id and
|
|
31 pl1.id != pl2.id
|
|
32
|
|
33 */
|
|
34
|
|
35
|
|
36 private WrapperService ontology;
|
|
37 private static String sql =
|
|
38 "select " +
|
|
39 "pl1.source_id as srcId, " +
|
|
40 "pl1.id as rel1Id, " +
|
|
41 "pl2.id as rel2Id, " +
|
|
42 "pl1.own_value, " +
|
|
43 "pl1.target_id as tar1Id, " +
|
|
44 "pl2.target_id as tar2Id " +
|
|
45 "from openmind.`node` as pl1, openmind.`node` as pl2 " +
|
|
46 "where " +
|
|
47 "pl1.node_type = 'RELATION' and " +
|
|
48 "pl2.node_type = 'RELATION' and " +
|
|
49 "pl1.system_status = 'CURRENT_VERSION' and " +
|
|
50 "pl2.system_status = 'CURRENT_VERSION' and " +
|
|
51 "pl1.source_obj_class = 'PLACE' and " +
|
|
52 "pl2.source_obj_class = 'PLACE' and " +
|
|
53 "pl1.target_obj_class = 'PLACE' and " +
|
|
54 "pl2.target_obj_class = 'PLACE' and " +
|
|
55 "pl1.source_id = pl2.source_id and " +
|
|
56 "pl1.id != pl2.id";
|
|
57
|
|
58 public SicilyCase(WrapperService ot){
|
|
59 this.ontology = ot;
|
|
60 }
|
|
61
|
|
62 public void execute(){
|
|
63 try {
|
|
64
|
|
65 Connection conn;
|
|
66
|
|
67 Class.forName("com.mysql.jdbc.Driver").newInstance();
|
|
68 String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8";
|
|
69 conn = DriverManager.getConnection(url, "ismi", "ismipw");
|
|
70
|
|
71
|
|
72 Statement st = conn.createStatement();
|
|
73
|
|
74
|
|
75
|
|
76
|
|
77 System.out.println("Executing:");
|
|
78 System.out.println(sql);
|
|
79 ResultSet rs = st.executeQuery(sql);
|
|
80
|
|
81 System.out.println("srcId\ttar1\ttar2");
|
|
82
|
|
83 while(rs.next()){
|
|
84 Long srcId = rs.getLong("srcId");
|
|
85 Long tar1Id = rs.getLong("tar1Id");
|
|
86 Long tar2Id = rs.getLong("tar2Id");
|
|
87 Long rel1Id = rs.getLong("rel1Id");
|
|
88 Long rel2Id = rs.getLong("rel2Id");
|
|
89
|
|
90 Entity src = ontology.getEntityByIdReadOnly(srcId);
|
|
91 Entity tar1 = ontology.getEntityByIdReadOnly(tar1Id);
|
|
92 Entity tar2 = ontology.getEntityByIdReadOnly(tar2Id);
|
|
93
|
|
94 System.out.println(src.getOwnValue() + " [" +srcId + "]\t" + tar1.getOwnValue() + " [" + tar1Id + "]\t" + tar2.getOwnValue() + " [" + tar2Id + "]");
|
|
95 }
|
|
96
|
|
97
|
|
98 conn.close();
|
|
99
|
|
100 } catch (ClassNotFoundException ex) {
|
|
101 System.err.println(ex.getMessage());
|
|
102 ex.printStackTrace();
|
|
103 } catch (IllegalAccessException ex) {
|
|
104 System.err.println(ex.getMessage());
|
|
105 ex.printStackTrace();
|
|
106 } catch (InstantiationException ex) {
|
|
107 System.err.println(ex.getMessage());
|
|
108 ex.printStackTrace();
|
|
109 } catch (SQLException ex) {
|
|
110 System.err.println(ex.getMessage());
|
|
111 ex.printStackTrace();
|
|
112 }
|
|
113 }
|
|
114
|
|
115
|
|
116 public static void main(String[] args) {
|
|
117 ServiceRegistry services = new ServiceRegistry();
|
|
118 SicilyCase script = new SicilyCase(services.getWrapper());
|
|
119 script.execute();
|
|
120 System.exit(0);
|
|
121 }
|
|
122 }
|