Advertisement
Guest User

AlianzaEvent.java

a guest
May 23rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.29 KB | None | 0 0
  1. package com.ligado.cmis.module.eventprocessor;
  2.  
  3.  
  4. import org.apache.logging.log4j.LogManager;
  5. import org.apache.logging.log4j.Logger;
  6.  
  7. import com.ligado.cmis.sys.util.AdminSysMsg;
  8. import com.ligado.cmis.sys.util.CmisConstants;
  9. import com.ligado.cmis.sys.util.GlobalCache;
  10. import com.ligado.cmis.sys.util.ManageableConsumer;
  11. import com.ligado.cmis.sys.util.ManagedTask;
  12. import com.ligado.cmis.sys.util.CmisConstants.EventType;
  13. import com.ligado.cmis.sys.util.sql.SqlCmis505Statements;
  14. import com.ligado.cmis.sys.util.sql.SqlEventManagerStatements;
  15. import com.ligado.cmis.util.misc.StringUtil;
  16.  
  17. import com.ligado.cmis.util.proc.Cmis_H_Proc;
  18. import com.ligado.cmis.util.proc.Parameter_List;
  19.  
  20. import java.sql.*;
  21. import java.util.LinkedHashMap;
  22. import java.util.Map;
  23. import java.util.Properties;
  24.  
  25. @SuppressWarnings("unused")
  26. public class AlianzaEvent { //extends ManagedTask {
  27.    
  28.  
  29.     //***********Local Variable ****************************************************************************************************/
  30.  
  31.     String DidNum   = null;
  32.     String TFN      = null;
  33.    
  34.     int verb;
  35.     int status;
  36.     int resp_code;
  37.    
  38.     Throwable thrown;
  39.    
  40.    
  41.     private final static            Logger  logger      = LogManager.getLogger("log4j.alianzaevent");
  42.    
  43.     private static                  Connection          dbConnection;
  44.     private final static String     messageHead         = "EMGR" ;
  45.  
  46.     //SQL queries
  47.     static String alianza_add =     ("SELECT * "
  48.              +"FROM ALIANZA_TELEPHONE_NUMBER_TXN "
  49.              +"WHERE  VERB = 0 ");
  50.     static String alianza_Update = ("Select * "
  51.             + "FROM ALIANZA_TELEPHONE_NUMBER TXN "
  52.             + "WHERE VERB = 3 ");
  53.     static String code = ("Select * "
  54.             + "FROM user_source "
  55.             + "WHERE name = 'ALIANZA_TELEPHONE-NUMBER_TXN_P' ");
  56.     static String init_qry = ("Select * "
  57.             + "FROM ALIANZA_TELEPHONE_NUMBER TXN ");
  58.            
  59.     private static final Map<String, Connection> dbConnectionMap = new LinkedHashMap<String, Connection>();
  60.    
  61.     //Constructor
  62.     public AlianzaEvent() {
  63.     //  super(CmisConstants.MNMSCLIENT_WORKER_NAME, 0, 600000L); // 0 - indicate it is normal Runnable task
  64.     //  Thread.currentThread().setName(CmisConstants.ALIANZA_WORKER_NAME);\
  65.         try {
  66.             String sql = "{call dbms_alert.register('ALIANZA_TELEPHONE_NUMBER_TXN')}";
  67.             CallableStatement cs1 = dbConnection.prepareCall(sql);
  68.             cs1.execute(); 
  69.         }
  70.        
  71.         catch (SQLException e) {
  72.             e.printStackTrace();
  73.             //throw e;
  74.         }
  75.     }
  76.        
  77.     /*****************************************************************************************************************************************************************************************/
  78.     static {
  79.     try {          
  80.         //dbConnection = GlobalCache.getInstance().getDbconnectionmap().get(CmisConstants.ALIANZA_WORKER_NAME);
  81.        
  82. //      Properties props = new Properties();
  83. //      props.setProperty("user", "cmis");
  84. //      props.setProperty("password", "cmis2dev");
  85. //      props.put("v$session.program", CmisConstants.ALIANZA_WORKER_NAME);
  86.  
  87.         dbConnection = DriverManager.getConnection("jdbc:oracle:thin:@" +
  88.                 "10.99.49.3" + ":" +
  89.                 "1531" + ":" +
  90.                 "cmisdev", "cmis", "cmis2dev");
  91.        
  92.     //  dbConnectionMap.put(CmisConstants.ALIANZA_WORKER_NAME, dbConnection);
  93.        
  94.         //dbConnectionMap.put(/*"cmis505"*/ CmisConstants.ALIANZA_WORKER_NAME, dbConnection);
  95.        
  96.        
  97.     //  registerAlerts();
  98.     }
  99.     catch (Exception e) {
  100.         logger.error("GlobalCache Initialization Failed, error message:" + e.getMessage());
  101.         throw new ExceptionInInitializerError(e);
  102.     }
  103.     }
  104.     /*****************************************************************************************************************************************************************************************/
  105.  
  106.    
  107.    
  108.  
  109.    
  110.     /*****************************************************************************************************************************************************************************************/
  111.     //Getters
  112.     //public Connection getDbConnection() { return dbConnection;}
  113.    
  114.     public String getDidNum() {return DidNum;}
  115.     public String getTFN() {return TFN;}
  116.    
  117.     public int getverb() {return verb;}
  118.     public int getstatus() { return status;}
  119.     public int getresp_code() {return resp_code;}
  120.    
  121.     /*****************************************************************************************************************************************************************************************/
  122.    
  123.     public void runQuery() throws InterruptedException, SQLException {
  124.         System.out.println("");
  125.        
  126.         String query = alianza_add;
  127.        
  128.         try (PreparedStatement selPrepStmt = dbConnection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  129.                 ResultSet RS = selPrepStmt.executeQuery()) {
  130.            
  131.             ResultSetMetaData rsmd = RS.getMetaData();
  132.             int columnCount = rsmd.getColumnCount();
  133.             int rows = 0;
  134.             String result = null;
  135.            
  136.                
  137.             String line = new String(new char[479]).replace('\0', '-');
  138.             System.out.println(line);
  139.            
  140.             String format = "%s %-20s %-1s  ";
  141.             String format1 = "%s %s %-20s";
  142.             String format2 = "%s %s %s";
  143.             boolean doit = true;
  144.                
  145.             while (true) {
  146.             while(RS.next()) {
  147.                 for(int i=1; i<=columnCount; i++) {
  148.                    
  149.                     String colname = rsmd.getColumnName(i);
  150.                     String data = RS.getNString(i);
  151.                     String vert ="|";
  152.  
  153.                     //System.out.printf("%-15s    %-15s %t", colname, data);
  154.                     //System.out.printf(format, colname,data);
  155.                     System.out.format(format,colname,data, vert);
  156.                     //System.out.format("%-20s  %5d\n", colname, data);
  157.                     //System.out.print(colname + ":" + data );
  158.                    
  159.                    
  160.                 }
  161.                 System.out.println("");
  162.                 doit=false;
  163.                 rows++;
  164.             }
  165.             RS.close();
  166.             break;
  167.            
  168.             }
  169.             System.out.println(line);
  170.         }
  171.  
  172.             catch (SQLException sqe) {
  173.                 logger.error("SQL error in call to MakeCPRCRTx for sequence " );
  174.                 logger.error("[makeCPRCRtx_PDU()] RollBack Failure. SQLException occured. Error Code: "+ sqe.getErrorCode()+" Error Message: " + sqe.getMessage()+ " SQLState: "+ sqe.getSQLState());
  175.             }
  176.  
  177.         /*
  178.         finally {
  179.             if(selCtrlGrpIDStmt !=null) { selCtrlGrpIDStmt.close();}
  180.            
  181.             if(dbConnection != null) {dbConnection.close();}
  182.             }*/
  183.         }
  184.    
  185.    
  186.  
  187.     public  Map<String, Connection> getDbconnectionmap() {
  188.         return dbConnectionMap;
  189.     }
  190.  
  191.     public static void registerAlerts() throws SQLException {
  192.        
  193.         try {
  194.             String sql = "{call dbms_alert.register('ALIANZA_TELEPHONE_NUMBER_TXN')}";
  195.             CallableStatement cs1 = dbConnection.prepareCall(sql);
  196.             cs1.execute(); 
  197.         }
  198.        
  199.         catch (SQLException e) {
  200.             e.printStackTrace();
  201.             throw e;
  202.         }
  203.        
  204.            
  205.     }
  206.                
  207.  
  208.     /*****************************************************************************************************************************************************************************************/
  209.  
  210.    
  211.     public void waitany() {
  212.     //  cancel.set(false);
  213.  
  214.         AdminSysMsg adminSysMsg = new AdminSysMsg();
  215.         adminSysMsg.getHeader().setOriginator("admin"); // admin---from ADMIN later on defined as CONSTANT
  216.         adminSysMsg.getHeader().setType(0); // 0---from ADMIN later on defined as CONSTANT
  217.  
  218.         try {
  219.             String sql = "{call dbms_alert.waitany(?, ?, ?,10)}"; // now let's go with no wait
  220.             CallableStatement cs2 = dbConnection.prepareCall(sql);
  221.             cs2.registerOutParameter(1, Types.VARCHAR);
  222.             cs2.registerOutParameter(2, Types.VARCHAR);
  223.             cs2.registerOutParameter(3, Types.INTEGER);
  224.  
  225.            
  226.             while (true) {
  227.                
  228.                 boolean signal_null = false;
  229.                 boolean msg_null = false;
  230.                 boolean int_null = false;
  231.  
  232.  
  233.                 cs2.execute();
  234.                
  235.                 String Result = cs2.getString(1);
  236.                 if (cs2.wasNull())
  237.                     signal_null = true;
  238.                 else
  239.                     signal_null = false;
  240.                 String Result2 = cs2.getString(2);
  241.                 if (cs2.wasNull())
  242.                     msg_null = true;
  243.                 else
  244.                     msg_null = false;
  245.                 int Result3 = cs2.getInt(3);
  246.                 if (cs2.wasNull())
  247.                     int_null = true;
  248.                 else
  249.                     int_null = false;
  250.                
  251.                 System.out.println("null");
  252.                 if (Result == null)    
  253.                     continue;
  254.                
  255.    
  256.                 else if (Result.equalsIgnoreCase("ALIANZA_INTERCONNECT_RATES")) {
  257.                     adminSysMsg.setSignal("RATES");
  258.                     System.out.println("here 1 ");
  259.                 }
  260.                
  261.                 else if (Result.equalsIgnoreCase("ALIANZA_TELEPHONE_NUMBER_TXN")) {
  262.                     adminSysMsg.setSignal("TXN");
  263.                     System.out.println("here 2 ");
  264.                 }
  265.                
  266.             } // while
  267.         }
  268.         catch (Throwable t) {
  269.             thrown = t;
  270.  
  271.         }
  272.         finally {
  273.         }
  274.        
  275.     }
  276.  
  277. //  @Override
  278. //  public void stopProcessing() {}
  279. // 
  280. //  @Override
  281. //  public void run() {
  282. //     
  283. //  }
  284.  
  285.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement