Advertisement
Guest User

Untitled

a guest
Sep 8th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. package com.ts.web.rest;
  2.  
  3.  
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.util.Properties;
  12.  
  13. import org.apache.log4j.LogManager;
  14. import org.apache.log4j.Logger;
  15. import org.apache.log4j.PropertyConfigurator;
  16. import org.springframework.context.ApplicationContext;
  17. import org.springframework.context.support.ClassPathXmlApplicationContext;
  18.  
  19. import com.ncubo.browser.Ip;
  20. import com.ncubo.configuracion.Enviroment;
  21. import com.ts.configuracion.Api2ManagerREST;
  22. import com.ts.libraries.Browser;
  23. import com.ts.libraries.Canal.Tipo;
  24.  
  25. public class GerneradorDeLogDeComandos
  26. {
  27. private final static Logger logger = Logger.getLogger(GerneradorDeLogDeComandos.class);
  28.  
  29. public static void main(String[] args) throws IOException
  30. {
  31. Properties props = new Properties();
  32. InputStream configStream = GerneradorDeLogDeComandos.class.getResourceAsStream( "/log4jtestcases.properties");
  33. props.load(configStream);
  34. configStream.close();
  35. LogManager.resetConfiguration();
  36. PropertyConfigurator.configure(props);
  37. String compania = "",comando = "",respuesta= "" ;
  38.  
  39. Statement stmt = null;
  40. try
  41. {
  42. ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/testcasesaplication.xml");
  43. Comercios comerciosController = new Comercios();
  44. Enviroment env = (Enviroment)applicationContext.getBean("enviroment") ;
  45. comerciosController.setEnviroment( env );
  46.  
  47. Class.forName("com.mysql.jdbc.Driver");
  48. final Connection conexion = DriverManager.getConnection("jdbc:mysql://10.1.3.40:3306/testcases", "logwriter", "logwriter");
  49. stmt = conexion.createStatement();
  50. ResultSet rs = stmt.executeQuery("SHOW TABLES;");
  51.  
  52. boolean noprocesar = true;
  53.  
  54. Api2ManagerREST api2 = new Api2ManagerREST("");
  55. while (rs.next())
  56. {
  57. compania = rs.getString("Tables_in_testcases");
  58.  
  59. if( compania.equals("v_magdalenadiseampntildeocolombiano"))
  60. {
  61. noprocesar = false;
  62. }
  63.  
  64. if( noprocesar )
  65. {
  66. continue;
  67. }
  68.  
  69. props = new Properties();
  70. configStream = GerneradorDeLogDeComandos.class.getResourceAsStream( "/log4jtestcases.properties");
  71. props.load(configStream);
  72. props.setProperty("log4j.appender.tc.File", "${user.home}/.comercio/logs3.5/"+compania+".log");
  73. props.setProperty("log4j.appender.logfile.encoding", "UTF-8");
  74.  
  75. configStream.close();
  76. LogManager.resetConfiguration();
  77. PropertyConfigurator.configure(props);
  78.  
  79. final Connection conexion2 = DriverManager.getConnection(env.getConnectionMySQL(), env.getUsuarioMySQL(), env.getPasswordMySQL());
  80. Statement stmttrun = conexion2.createStatement();
  81. stmttrun.executeUpdate("DROP TABLE IF EXISTS "+compania);
  82.  
  83. Statement comandosStmt = conexion.createStatement();
  84. ResultSet comandosDeCompania = comandosStmt.executeQuery("SELECT id, Comando FROM "+compania+" order by id;");
  85.  
  86. api2.cargarInformacionDeContexto(new Ip(), new Browser(), "0000", Tipo.CONSOLA, compania);
  87.  
  88. System.out.println("Empieza " +compania);
  89. while (comandosDeCompania.next())
  90. {
  91. comando = comandosDeCompania.getString("Comando").trim();
  92. int id = comandosDeCompania.getInt("id");
  93.  
  94. String comandogenrado = api2.newCommand().add(comando).getCommandSustituido();
  95.  
  96. try
  97. {
  98. respuesta = comerciosController.atenderUnComercios(comandogenrado, compania);
  99. }
  100. catch(RuntimeException e)
  101. {
  102. System.err.println(compania+" | "+comando);
  103. respuesta = e.getMessage();
  104. e.printStackTrace();
  105. }
  106. logger.debug(compania+" | "+comando+" | "+respuesta );
  107. }
  108. }
  109.  
  110. rs.close();
  111. }
  112. catch (SQLException e)
  113. {
  114. throw new RuntimeException(e);
  115. }
  116. catch (ClassNotFoundException e)
  117. {
  118. throw new RuntimeException(e);
  119. }
  120. catch (Exception e)
  121. {
  122. System.err.println(compania+" | "+comando+" | "+respuesta );
  123. throw new RuntimeException(e);
  124. }
  125. finally
  126. {
  127. if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
  128. }
  129. }
  130.  
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement