Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ts.web.rest;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- import org.apache.log4j.LogManager;
- import org.apache.log4j.Logger;
- import org.apache.log4j.PropertyConfigurator;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.ncubo.browser.Ip;
- import com.ncubo.configuracion.Enviroment;
- import com.ts.configuracion.Api2ManagerREST;
- import com.ts.libraries.Browser;
- import com.ts.libraries.Canal.Tipo;
- public class GerneradorDeLogDeComandos
- {
- private final static Logger logger = Logger.getLogger(GerneradorDeLogDeComandos.class);
- public static void main(String[] args) throws IOException
- {
- Properties props = new Properties();
- InputStream configStream = GerneradorDeLogDeComandos.class.getResourceAsStream( "/log4jtestcases.properties");
- props.load(configStream);
- configStream.close();
- LogManager.resetConfiguration();
- PropertyConfigurator.configure(props);
- String compania = "",comando = "",respuesta= "" ;
- Statement stmt = null;
- try
- {
- ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/testcasesaplication.xml");
- Comercios comerciosController = new Comercios();
- Enviroment env = (Enviroment)applicationContext.getBean("enviroment") ;
- comerciosController.setEnviroment( env );
- Class.forName("com.mysql.jdbc.Driver");
- final Connection conexion = DriverManager.getConnection("jdbc:mysql://10.1.3.40:3306/testcases", "logwriter", "logwriter");
- stmt = conexion.createStatement();
- ResultSet rs = stmt.executeQuery("SHOW TABLES;");
- boolean noprocesar = true;
- Api2ManagerREST api2 = new Api2ManagerREST("");
- while (rs.next())
- {
- compania = rs.getString("Tables_in_testcases");
- if( compania.equals("v_magdalenadiseampntildeocolombiano"))
- {
- noprocesar = false;
- }
- if( noprocesar )
- {
- continue;
- }
- props = new Properties();
- configStream = GerneradorDeLogDeComandos.class.getResourceAsStream( "/log4jtestcases.properties");
- props.load(configStream);
- props.setProperty("log4j.appender.tc.File", "${user.home}/.comercio/logs3.5/"+compania+".log");
- props.setProperty("log4j.appender.logfile.encoding", "UTF-8");
- configStream.close();
- LogManager.resetConfiguration();
- PropertyConfigurator.configure(props);
- final Connection conexion2 = DriverManager.getConnection(env.getConnectionMySQL(), env.getUsuarioMySQL(), env.getPasswordMySQL());
- Statement stmttrun = conexion2.createStatement();
- stmttrun.executeUpdate("DROP TABLE IF EXISTS "+compania);
- Statement comandosStmt = conexion.createStatement();
- ResultSet comandosDeCompania = comandosStmt.executeQuery("SELECT id, Comando FROM "+compania+" order by id;");
- api2.cargarInformacionDeContexto(new Ip(), new Browser(), "0000", Tipo.CONSOLA, compania);
- System.out.println("Empieza " +compania);
- while (comandosDeCompania.next())
- {
- comando = comandosDeCompania.getString("Comando").trim();
- int id = comandosDeCompania.getInt("id");
- String comandogenrado = api2.newCommand().add(comando).getCommandSustituido();
- try
- {
- respuesta = comerciosController.atenderUnComercios(comandogenrado, compania);
- }
- catch(RuntimeException e)
- {
- System.err.println(compania+" | "+comando);
- respuesta = e.getMessage();
- e.printStackTrace();
- }
- logger.debug(compania+" | "+comando+" | "+respuesta );
- }
- }
- rs.close();
- }
- catch (SQLException e)
- {
- throw new RuntimeException(e);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(e);
- }
- catch (Exception e)
- {
- System.err.println(compania+" | "+comando+" | "+respuesta );
- throw new RuntimeException(e);
- }
- finally
- {
- if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement