Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ligado.cmis.module.eventprocessor;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import com.ligado.cmis.sys.util.AdminSysMsg;
- import com.ligado.cmis.sys.util.CmisConstants;
- import com.ligado.cmis.sys.util.GlobalCache;
- import com.ligado.cmis.sys.util.ManageableConsumer;
- import com.ligado.cmis.sys.util.ManagedTask;
- import com.ligado.cmis.sys.util.CmisConstants.EventType;
- import com.ligado.cmis.sys.util.sql.SqlCmis505Statements;
- import com.ligado.cmis.sys.util.sql.SqlEventManagerStatements;
- import com.ligado.cmis.util.misc.StringUtil;
- import com.ligado.cmis.util.proc.Cmis_H_Proc;
- import com.ligado.cmis.util.proc.Parameter_List;
- import java.sql.*;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Properties;
- @SuppressWarnings("unused")
- public class AlianzaEvent { //extends ManagedTask {
- //***********Local Variable ****************************************************************************************************/
- String DidNum = null;
- String TFN = null;
- int verb;
- int status;
- int resp_code;
- Throwable thrown;
- private final static Logger logger = LogManager.getLogger("log4j.alianzaevent");
- private static Connection dbConnection;
- private final static String messageHead = "EMGR" ;
- //SQL queries
- static String alianza_add = ("SELECT * "
- +"FROM ALIANZA_TELEPHONE_NUMBER_TXN "
- +"WHERE VERB = 0 ");
- static String alianza_Update = ("Select * "
- + "FROM ALIANZA_TELEPHONE_NUMBER TXN "
- + "WHERE VERB = 3 ");
- static String code = ("Select * "
- + "FROM user_source "
- + "WHERE name = 'ALIANZA_TELEPHONE-NUMBER_TXN_P' ");
- static String init_qry = ("Select * "
- + "FROM ALIANZA_TELEPHONE_NUMBER TXN ");
- private static final Map<String, Connection> dbConnectionMap = new LinkedHashMap<String, Connection>();
- //Constructor
- public AlianzaEvent() {
- // super(CmisConstants.MNMSCLIENT_WORKER_NAME, 0, 600000L); // 0 - indicate it is normal Runnable task
- // Thread.currentThread().setName(CmisConstants.ALIANZA_WORKER_NAME);\
- try {
- String sql = "{call dbms_alert.register('ALIANZA_TELEPHONE_NUMBER_TXN')}";
- CallableStatement cs1 = dbConnection.prepareCall(sql);
- cs1.execute();
- }
- catch (SQLException e) {
- e.printStackTrace();
- //throw e;
- }
- }
- /*****************************************************************************************************************************************************************************************/
- static {
- try {
- //dbConnection = GlobalCache.getInstance().getDbconnectionmap().get(CmisConstants.ALIANZA_WORKER_NAME);
- // Properties props = new Properties();
- // props.setProperty("user", "cmis");
- // props.setProperty("password", "cmis2dev");
- // props.put("v$session.program", CmisConstants.ALIANZA_WORKER_NAME);
- dbConnection = DriverManager.getConnection("jdbc:oracle:thin:@" +
- "10.99.49.3" + ":" +
- "1531" + ":" +
- "cmisdev", "cmis", "cmis2dev");
- // dbConnectionMap.put(CmisConstants.ALIANZA_WORKER_NAME, dbConnection);
- //dbConnectionMap.put(/*"cmis505"*/ CmisConstants.ALIANZA_WORKER_NAME, dbConnection);
- // registerAlerts();
- }
- catch (Exception e) {
- logger.error("GlobalCache Initialization Failed, error message:" + e.getMessage());
- throw new ExceptionInInitializerError(e);
- }
- }
- /*****************************************************************************************************************************************************************************************/
- /*****************************************************************************************************************************************************************************************/
- //Getters
- //public Connection getDbConnection() { return dbConnection;}
- public String getDidNum() {return DidNum;}
- public String getTFN() {return TFN;}
- public int getverb() {return verb;}
- public int getstatus() { return status;}
- public int getresp_code() {return resp_code;}
- /*****************************************************************************************************************************************************************************************/
- public void runQuery() throws InterruptedException, SQLException {
- System.out.println("");
- String query = alianza_add;
- try (PreparedStatement selPrepStmt = dbConnection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
- ResultSet RS = selPrepStmt.executeQuery()) {
- ResultSetMetaData rsmd = RS.getMetaData();
- int columnCount = rsmd.getColumnCount();
- int rows = 0;
- String result = null;
- String line = new String(new char[479]).replace('\0', '-');
- System.out.println(line);
- String format = "%s %-20s %-1s ";
- String format1 = "%s %s %-20s";
- String format2 = "%s %s %s";
- boolean doit = true;
- while (true) {
- while(RS.next()) {
- for(int i=1; i<=columnCount; i++) {
- String colname = rsmd.getColumnName(i);
- String data = RS.getNString(i);
- String vert ="|";
- //System.out.printf("%-15s %-15s %t", colname, data);
- //System.out.printf(format, colname,data);
- System.out.format(format,colname,data, vert);
- //System.out.format("%-20s %5d\n", colname, data);
- //System.out.print(colname + ":" + data );
- }
- System.out.println("");
- doit=false;
- rows++;
- }
- RS.close();
- break;
- }
- System.out.println(line);
- }
- catch (SQLException sqe) {
- logger.error("SQL error in call to MakeCPRCRTx for sequence " );
- logger.error("[makeCPRCRtx_PDU()] RollBack Failure. SQLException occured. Error Code: "+ sqe.getErrorCode()+" Error Message: " + sqe.getMessage()+ " SQLState: "+ sqe.getSQLState());
- }
- /*
- finally {
- if(selCtrlGrpIDStmt !=null) { selCtrlGrpIDStmt.close();}
- if(dbConnection != null) {dbConnection.close();}
- }*/
- }
- public Map<String, Connection> getDbconnectionmap() {
- return dbConnectionMap;
- }
- public static void registerAlerts() throws SQLException {
- try {
- String sql = "{call dbms_alert.register('ALIANZA_TELEPHONE_NUMBER_TXN')}";
- CallableStatement cs1 = dbConnection.prepareCall(sql);
- cs1.execute();
- }
- catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- }
- /*****************************************************************************************************************************************************************************************/
- public void waitany() {
- // cancel.set(false);
- AdminSysMsg adminSysMsg = new AdminSysMsg();
- adminSysMsg.getHeader().setOriginator("admin"); // admin---from ADMIN later on defined as CONSTANT
- adminSysMsg.getHeader().setType(0); // 0---from ADMIN later on defined as CONSTANT
- try {
- String sql = "{call dbms_alert.waitany(?, ?, ?,10)}"; // now let's go with no wait
- CallableStatement cs2 = dbConnection.prepareCall(sql);
- cs2.registerOutParameter(1, Types.VARCHAR);
- cs2.registerOutParameter(2, Types.VARCHAR);
- cs2.registerOutParameter(3, Types.INTEGER);
- while (true) {
- boolean signal_null = false;
- boolean msg_null = false;
- boolean int_null = false;
- cs2.execute();
- String Result = cs2.getString(1);
- if (cs2.wasNull())
- signal_null = true;
- else
- signal_null = false;
- String Result2 = cs2.getString(2);
- if (cs2.wasNull())
- msg_null = true;
- else
- msg_null = false;
- int Result3 = cs2.getInt(3);
- if (cs2.wasNull())
- int_null = true;
- else
- int_null = false;
- System.out.println("null");
- if (Result == null)
- continue;
- else if (Result.equalsIgnoreCase("ALIANZA_INTERCONNECT_RATES")) {
- adminSysMsg.setSignal("RATES");
- System.out.println("here 1 ");
- }
- else if (Result.equalsIgnoreCase("ALIANZA_TELEPHONE_NUMBER_TXN")) {
- adminSysMsg.setSignal("TXN");
- System.out.println("here 2 ");
- }
- } // while
- }
- catch (Throwable t) {
- thrown = t;
- }
- finally {
- }
- }
- // @Override
- // public void stopProcessing() {}
- //
- // @Override
- // public void run() {
- //
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement