view src/main/java/org/mpi/openmind/scripts/ChangeAllEntitiesPrivacity.java @ 90:4b6c0b368f46

new UpdateMpiwgDigitalizations script.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 29 May 2018 21:15:06 +0200
parents 979604ccc6db
children
line wrap: on
line source

package org.mpi.openmind.scripts;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.lang.StringUtils;

public class ChangeAllEntitiesPrivacity {

	public static void execute(boolean privacity) {
		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");
			
			
			Statement st = conn.createStatement();
			//((privacity)? "1" : "0") 
			String sql = "UPDATE node SET public =" + privacity + "";
			System.out.println("Executing:");
			System.out.println(sql);
			int n = st.executeUpdate(sql);
			//System.out.println(n + " rows were modified");
			
			conn.close();
		
		} catch (ClassNotFoundException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (InstantiationException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (SQLException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		String arg = args[0];
		System.out.println("arg: " + arg);
		boolean privacity = false;
		if(StringUtils.isNotEmpty(arg)){
			try{
				privacity = new Boolean(arg);
			}catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		ChangeAllEntitiesPrivacity.execute(privacity);
		System.exit(0);
	}
	
}