Mercurial > hg > openmind
comparison src/main/java/org/mpi/openmind/scripts/RenameAttributes.java @ 8:478fd6f26ea8
(none)
author | jurzua |
---|---|
date | Tue, 24 Feb 2015 10:45:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:ac2fd7a4378d | 8:478fd6f26ea8 |
---|---|
1 package org.mpi.openmind.scripts; | |
2 | |
3 import java.sql.Connection; | |
4 import java.sql.ResultSet; | |
5 import java.sql.SQLException; | |
6 import java.sql.Statement; | |
7 | |
8 public class RenameAttributes { | |
9 | |
10 public static void execute(String oc, String oldAttName, String newAttName, String mysqlUser, String mysqlPwd){ | |
11 System.out.println("RenameAttributes " + oc + " [from: " + oldAttName + " to " + newAttName + "]"); | |
12 | |
13 try { | |
14 Connection conn = DBUtils.getConn(mysqlUser, mysqlPwd); | |
15 renameAtts(conn, oc, oldAttName, newAttName); | |
16 renameDefAtt(conn, oc, oldAttName, newAttName); | |
17 conn.close(); | |
18 } catch (SQLException e) { | |
19 e.printStackTrace(); | |
20 } | |
21 | |
22 } | |
23 | |
24 public static void renameAtts(Connection conn, String oc, String oldAttName, String newAttName){ | |
25 System.out.println("Rename all Atts"); | |
26 try { | |
27 Statement st = conn.createStatement(); | |
28 String st0 = "UPDATE node " + | |
29 "SET object_class='" + newAttName + "' " + | |
30 "WHERE node_type = 'ATTRIBUTE' and source_obj_class = '" + oc + "' and object_class = '" + oldAttName + "'"; | |
31 System.out.println(st0); | |
32 int counter = st.executeUpdate(st0); | |
33 System.out.println(counter + " rows modfied!"); | |
34 } catch (SQLException e) { | |
35 e.printStackTrace(); | |
36 } | |
37 } | |
38 | |
39 public static void renameDefAtt(Connection conn, String oc, String oldAttName, String newAttName) throws SQLException{ | |
40 System.out.println("Rename Definition Atts"); | |
41 ResultSet rs = DBUtils.getDefAtts(conn, oc, oldAttName); | |
42 | |
43 while(rs.next()){ | |
44 Long attRowId = rs.getLong("row_id"); | |
45 renameDefAtt(conn, attRowId, newAttName); | |
46 } | |
47 } | |
48 | |
49 public static void renameDefAtt(Connection conn, Long attRowId, String newAttName) throws SQLException{ | |
50 Statement st = conn.createStatement(); | |
51 String st0 = "UPDATE node " + | |
52 "SET own_value='" + newAttName + "' " + | |
53 "WHERE row_id = '" + attRowId + "'"; | |
54 System.out.println(st0); | |
55 int counter = st.executeUpdate(st0); | |
56 System.out.println(counter + " rows modfied!"); | |
57 } | |
58 | |
59 | |
60 public static void main(String[] args){ | |
61 execute("WITNESS", "notes", "notes_old", "root", "admin"); | |
62 execute("TEXT", "notes", "notes_old", "root", "admin"); | |
63 execute("CODEX", "notes", "notes_old", "root", "admin"); | |
64 execute("PERSON", "notes", "notes_old", "root", "admin"); | |
65 } | |
66 | |
67 } |