# HG changeset patch # User jurzua # Date 1424774745 0 # Node ID 478fd6f26ea8734a9db6d61033d75edc650c6f2d # Parent ac2fd7a4378d2b0fdf5e7b1bd8f50cb332c67be6 diff -r ac2fd7a4378d -r 478fd6f26ea8 src/main/java/org/mpi/openmind/scripts/DBUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/mpi/openmind/scripts/DBUtils.java Tue Feb 24 10:45:45 2015 +0000 @@ -0,0 +1,69 @@ +package org.mpi.openmind.scripts; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.naming.spi.DirStateFactory.Result; + + +public class DBUtils { + + private static String DB_URL = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8"; + + public static Connection getConn(String mysqlUser, String mysqlPwd){ + Connection conn = null; + try { + + Class.forName("com.mysql.jdbc.Driver").newInstance(); + conn = DriverManager.getConnection(DB_URL, mysqlUser, mysqlPwd); + + return conn; + } catch (ClassNotFoundException ex) { + System.err.println(ex.getMessage()); + } catch (IllegalAccessException ex) { + System.err.println(ex.getMessage()); + } catch (InstantiationException ex) { + System.err.println(ex.getMessage()); + } catch (SQLException ex) { + System.err.println(ex.getMessage()); + } + return conn; + } + + public static ResultSet getDefinition(Connection conn, String oc) throws SQLException{ + String query = "select * from node where node_type = 'ENTITY' and object_class = 'TBox' and own_value = '" + oc + "'"; + Statement stmt = conn.createStatement(); + return stmt.executeQuery(query); + } + + public static Long getDefId(Connection conn, String oc) throws SQLException{ + ResultSet rs = getDefinition(conn, oc); + if(rs != null && rs.next()) + return rs.getLong("id"); + return null; + } + + public static ResultSet getDefAtts(Connection conn, String oc, String attName) throws SQLException{ + Long defId = getDefId(conn, oc); + String query = + "select * from node where " + + "node_type = 'ATTRIBUTE' and " + + "object_class = 'TBox' and " + + "source_id = '" + defId + "' and " + + "own_value = '" + attName + "'"; + + Statement stmt = conn.createStatement(); + return stmt.executeQuery(query); + } + + public static void getAtt(String oc, String attName){ + + String query = + "select * from node where node_type = 'ATTRIBUTE' and source_obj_class = 'WITNESS' and object_class = 'notes'"; + + } + +} diff -r ac2fd7a4378d -r 478fd6f26ea8 src/main/java/org/mpi/openmind/scripts/NormalizeOW.java --- a/src/main/java/org/mpi/openmind/scripts/NormalizeOW.java Thu Oct 30 12:50:26 2014 +0000 +++ b/src/main/java/org/mpi/openmind/scripts/NormalizeOW.java Tue Feb 24 10:45:45 2015 +0000 @@ -23,7 +23,7 @@ Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8"; - conn = DriverManager.getConnection(url, "ismi", "ismipw"); + conn = DriverManager.getConnection(url, "root", "admin"); Map selectedMap = select(conn, type); @@ -93,13 +93,15 @@ } public static void main(String[] args) { + NormalizeOW.execute("all"); + /* String arg = args[0]; if(StringUtils.isNotEmpty(arg)){ if(arg.equals("ATTRIBUTE") || arg.equals("ENTITY") || arg.equals("all")){ NormalizeOW.execute(arg); System.exit(0); } - } + }*/ } } diff -r ac2fd7a4378d -r 478fd6f26ea8 src/main/java/org/mpi/openmind/scripts/RenameAttributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/mpi/openmind/scripts/RenameAttributes.java Tue Feb 24 10:45:45 2015 +0000 @@ -0,0 +1,67 @@ +package org.mpi.openmind.scripts; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class RenameAttributes { + + public static void execute(String oc, String oldAttName, String newAttName, String mysqlUser, String mysqlPwd){ + System.out.println("RenameAttributes " + oc + " [from: " + oldAttName + " to " + newAttName + "]"); + + try { + Connection conn = DBUtils.getConn(mysqlUser, mysqlPwd); + renameAtts(conn, oc, oldAttName, newAttName); + renameDefAtt(conn, oc, oldAttName, newAttName); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + public static void renameAtts(Connection conn, String oc, String oldAttName, String newAttName){ + System.out.println("Rename all Atts"); + try { + Statement st = conn.createStatement(); + String st0 = "UPDATE node " + + "SET object_class='" + newAttName + "' " + + "WHERE node_type = 'ATTRIBUTE' and source_obj_class = '" + oc + "' and object_class = '" + oldAttName + "'"; + System.out.println(st0); + int counter = st.executeUpdate(st0); + System.out.println(counter + " rows modfied!"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void renameDefAtt(Connection conn, String oc, String oldAttName, String newAttName) throws SQLException{ + System.out.println("Rename Definition Atts"); + ResultSet rs = DBUtils.getDefAtts(conn, oc, oldAttName); + + while(rs.next()){ + Long attRowId = rs.getLong("row_id"); + renameDefAtt(conn, attRowId, newAttName); + } + } + + public static void renameDefAtt(Connection conn, Long attRowId, String newAttName) throws SQLException{ + Statement st = conn.createStatement(); + String st0 = "UPDATE node " + + "SET own_value='" + newAttName + "' " + + "WHERE row_id = '" + attRowId + "'"; + System.out.println(st0); + int counter = st.executeUpdate(st0); + System.out.println(counter + " rows modfied!"); + } + + + public static void main(String[] args){ + execute("WITNESS", "notes", "notes_old", "root", "admin"); + execute("TEXT", "notes", "notes_old", "root", "admin"); + execute("CODEX", "notes", "notes_old", "root", "admin"); + execute("PERSON", "notes", "notes_old", "root", "admin"); + } + +}