Mercurial > hg > openmind
view src/main/java/org/mpi/openmind/scripts/CurrentVersionForRelations.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 | 615d27dce9b3 |
children |
line wrap: on
line source
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; public class CurrentVersionForRelations { private static String querySrc; private static String queryTar; static{ querySrc = "select " + "entity.id as entId, entity.own_value as entOW, entity.modification_time as entModif, entity.version as entVersion, " + "relation.id as relId, relation.modification_time as relModif, relation.version as relVersion, relation.own_value as relOW " + "from node as entity, node as relation " + "where " + "relation.node_type = 'RELATION' AND " + "entity.node_type = 'RELATION' AND " + "relation.system_status = 'CURRENT_VERSION' AND " + "entity.system_status = 'CURRENT_VERSION' AND " + "relation.source_id != entity.id " + "group by entity.id"; } public static ResultSet select(Connection conn, String arg){ ResultSet rs = null; try{ System.out.println("EntId \tentOW \tentModif \tentVersion \trelId \trelOW \trelModif \trelVersion"); Statement st = conn.createStatement(); rs = st.executeQuery(querySrc); int count =0; while (rs.next()) { StringBuilder sb = new StringBuilder(); sb.append( rs.getString("entId") + "\t"); sb.append( rs.getString("entOW") + "\t"); sb.append( rs.getString("entModif") + "\t"); sb.append( rs.getString("entVersion") + "\t"); sb.append( rs.getString("relId") + "\t"); sb.append( rs.getString("relOW") + "\t"); sb.append( rs.getString("relModif") + "\t"); sb.append( rs.getString("relVersion") + "\t"); System.out.println(sb.toString()); } }catch (Exception e) { e.printStackTrace(); } return rs; } public static void execute(String arg) { try { Connection conn; Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8"; conn = DriverManager.getConnection(url, "ismi", "ismipw"); ResultSet rs = select(conn, arg); conn.close(); } 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()); } } public static void main(String[] args) { String arg = args[0]; CurrentVersionForRelations.execute(arg); System.exit(0); } }