OIM API To Get Scheduler Job Details From BLOB


  1. package com.oimacademy.scheduleJobs;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.ObjectInputStream;
  5. import java.io.Serializable;
  6. import java.sql.Blob;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.text.SimpleDateFormat;
  11. import java.util.HashMap;
  12. import oracle.iam.scheduler.vo.JobDetails;
  13. import oracle.iam.scheduler.vo.JobParameter;
  14. import org.quartz.JobDataMap;
  15. import com.oimacademy.connection.DataSource;
  16. /**
  17.  *
  18.  * @author jaij
  19.  */
  20. public class GetSchedulerJobDetailsFromBLOB  {  
  21.  public void execute() throws Exception {
  22.   String mname = "execute()";
  23.   String jname = "*Disable*";//Job Name  which is having issue.
  24.   jname=jname.replaceAll("\\*", "%");
  25.   if (null == jname)
  26.    throw new NullPointerException("JobName is null.");
  27.   jname = jname.replace('*', '%');
  28.   String query = "select job_data from qrtz92_job_details where job_name like '" + jname + "'";
  29.   try {
  30.             PreparedStatement prepStmt = DataSource.getConnection().prepareStatement(query);           
  31.    ResultSet rs = prepStmt.executeQuery(query);   
  32.    boolean found = false;
  33.    while(rs.next()) {
  34.     found = true;
  35.     Blob b = rs.getBlob("job_data");
  36.     InputStream bis = b.getBinaryStream();
  37.     ObjectInputStream ois = new ObjectInputStream(bis);
  38.     Object obj = ois.readObject();
  39.     if(obj instanceof JobDataMap) {
  40.      print((JobDataMap) obj);
  41.     }
  42.     ois.close();
  43.     bis.close();
  44.    }
  45.    rs.close();
  46.             prepStmt.close();
  47.    if(!found) {
  48.     System.out.println("Job Not found : " + jname);
  49.    }
  50.   } catch (SQLException ex) {
  51.    ex.printStackTrace();
  52.   } catch (IOException ex) {
  53.    ex.printStackTrace();
  54.   } finally {
  55.    DataSource.closeConnection();
  56.         }
  57.  } 
  58.  private void print(JobDataMap jdm) {
  59.   String mname = "print(JobDataMap)";  
  60.   String[] keys = jdm.getKeys();
  61.   for(String key : keys) {
  62.    Object ov = jdm.get(key);
  63.    if(ov instanceof JobDetails[]) {
  64.     System.out.println( key + " : ");
  65.     JobDetails[] jds = (JobDetails[]) ov;
  66.     for(JobDetails jd : jds) {
  67.      System.out.println( "  name               : " + jd.getName());
  68.      System.out.println( "  class name         : " + jd.getTaskClassName());
  69.      System.out.println( "  task key           : " + jd.getTaskKey());
  70.      System.out.println( "  task name          : " + jd.getTaskName());
  71.      System.out.println( "  method             : " + jd.getMethod());
  72.      System.out.println( "  job schedule type  : " + jd.getJobScheduleType());
  73.      System.out.println( "  job listener       : " + jd.getJobListener());
  74.      System.out.println( "  cron schedule type : " + jd.getCronScheduleType());
  75.      System.out.println( "  last modify date   : " + dateFormat().format(jd.getLastModifyDate()));
  76.      System.out.println( "  retry count        : " + jd.getRetrycount());
  77.      HashMap<String,JobParameter> hmattr = jd.getAttributes();
  78.      System.out.println( "  Attributes : ");
  79.      if(null != hmattr)
  80.      for(String attr : hmattr.keySet()) {
  81.       System.out.println( "    attr : " + attr);
  82.       JobParameter av = hmattr.get(attr);
  83.       System.out.println( "      data type     : " + av.getDataType());
  84.       System.out.println( "      name          : " + av.getName());
  85.       System.out.println( "      parameter key : " + av.getParameterKey());
  86.       Serializable val = av.getValue();
  87.       System.out.println( "      value         : " + val);
  88.      }
  89.      if(jd.getTaskName()!=null){
  90.       jd.setTaskName(null);
  91.      }
  92.      /*HashMap<String,JobParameter> hmparam = jd.getParams();
  93.      if(null != hmparam)
  94.      for(String param : hmparam.keySet()) {
  95.       System.out.println("    param : " + param);
  96.       JobParameter av = hmparam.get(param);
  97.       System.out.println( "      data type     : " + av.getDataType());
  98.       System.out.println( "      name          : " + av.getName());
  99.       System.out.println( "      parameter key : " + av.getParameterKey());
  100.       Serializable val = av.getValue();
  101.       System.out.println( "      value         : " + val);
  102.      }*/
  103.     }
  104.    } else {
  105.     System.out.println( key + " = " + ov);
  106.    }
  107.   }  
  108.  } 
  109.  public SimpleDateFormat dateFormat(){
  110.   SimpleDateFormat simpleDate = new SimpleDateFormat("DDMMYY");  
  111.   return simpleDate;
  112.  } 
  113.  public static void main(String[] args) throws Exception{
  114.   new GetSchedulerJobDetailsFromBLOB().execute();
  115.  } 
  116. }

No comments:

Post a Comment