Package com.knowgate.jdc

Examples of com.knowgate.jdc.JDCConnection


                                          DBBind.Functions.LENGTH+"("+DBBind.Functions.ISNULL+"(m."+DB.tx_subject+",''))=0 AND " +
                                          "m."+DB.len_mimemsg + "=0 AND NOT EXISTS (SELECT p." + DB.gu_mimemsg + " FROM " +
                                          DB.k_mime_parts + " p WHERE m." + DB.gu_mimemsg + "=p." + DB.gu_mimemsg + ")" , 10);
    int iEmptyDrafts = 0;
   
    JDCConnection oConn = null;
    try {
      oConn = getConnection();
      iEmptyDrafts = oEmptyDrafts.load(oConn, new Object[]{getCategoryGuid(),((DBStore)getStore()).getUser().getString(DB.gu_workarea)});
    } catch (SQLException sqle) {
    throw new MessagingException(sqle.getMessage(), sqle);
    }
   
    if (iEmptyDrafts>0) {
    sSQL = "UPDATE " + DB.k_mime_msgs + " SET " + DB.bo_deleted + "=1 WHERE " + DB.gu_mimemsg + "=?";
   
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");
   
      try {
        oUpdt = oConn.prepareStatement(sSQL);
        for (int d=0; d<iEmptyDrafts; d++) {
          oUpdt.setString(1,oEmptyDrafts.getString(0,d));
        oUpdt.executeUpdate();
        } // next
      oUpdt.close();
      } catch (SQLException sqle) {
      throw new MessagingException(sqle.getMessage(), sqle);
      }
    } // fi

    // ***********************************************
    // Get the list of deleted and not purged messages

    MboxFile oMBox = null;
    DBSubset oDeleted = new DBSubset(DB.k_mime_msgs,
                                     DB.gu_mimemsg+","+DB.pg_message,
                                     DB.bo_deleted+"=1 AND "+DB.gu_category+"='"+oCatg.getString(DB.gu_category)+"'", 100);

    try {
      int iDeleted = oDeleted.load(getConnection());

      File oFile = getFile();

      // *************************************
      // Purge deleted messages from MBOX file

      if (oFile.exists() && iDeleted>0) {
        oMBox = new MboxFile(oFile, MboxFile.READ_WRITE);
        int[] msgnums = new int[iDeleted];
        for (int m=0; m<iDeleted; m++)
          msgnums[m] = oDeleted.getInt(1, m);
        oMBox.purge(msgnums);
        oMBox.close();
      }

      // *********************************************************
      // Remove from disk the files referenced by deleted messages

      oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     
      if (DebugFile.trace) DebugFile.writeln("Connection.executeQuery(SELECT p." + DB.file_name + " FROM " + DB.k_mime_parts + " p," + DB.k_mime_msgs + " m WHERE p." + DB.gu_mimemsg + "=m."+ DB.gu_mimemsg + " AND m." + DB.id_disposition + "='reference' AND m." + DB.bo_deleted + "=1 AND m." + DB.gu_category +"='"+oCatg.getString(DB.gu_category)+"')");

      oRSet = oStmt.executeQuery("SELECT p." + DB.id_part + ",p." + DB.id_type + ",p." + DB.file_name + " FROM " + DB.k_mime_parts + " p," + DB.k_mime_msgs + " m WHERE p." +
                                 DB.gu_mimemsg + "=m."+ DB.gu_mimemsg + " AND m." + DB.id_disposition + "='reference' AND m." +
                                 DB.bo_deleted + "=1 AND m." + DB.gu_category +"='"+oCatg.getString(DB.gu_category)+"'");

      while (oRSet.next()) {
        if (DebugFile.trace) DebugFile.writeln("processing part "+String.valueOf(oRSet.getInt(1))+" "+oRSet.getString(2));
        String sFileName = oRSet.getString(3);
        if (!oRSet.wasNull()) {
          if (DebugFile.trace) DebugFile.writeln("trying to delete file "+sFileName);
          try {
            File oRef = new File(sFileName);
            if (oRef.exists())
              oRef.delete();
            else if (DebugFile.trace)
              DebugFile.writeln("file "+sFileName+" not found");           
          }
          catch (SecurityException se) {
            if (DebugFile.trace) DebugFile.writeln("SecurityException deleting file " + sFileName + " " + se.getMessage());
          }
        }
      } // wend

      oRSet.close();
      oRSet = null;
      oStmt.close();
      oStmt = null;

      // ****************************************************
      // Set Category size to length of MBOX file after purge

      oFile = getFile();
      oStmt = oConn.createStatement();
      oStmt.executeUpdate("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+String.valueOf(oFile.length())+" WHERE "+DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"'");
      oStmt.close();
      oStmt=null;

      // *********************************************
      // Actually delete messages from database tables

      if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
        oStmt = oConn.createStatement();
        for (int d=0; d<iDeleted; d++)
          oStmt.executeQuery("SELECT k_sp_del_mime_msg('" + oDeleted.getString(0,d) + "')");
        oStmt.close();
        oStmt=null;
      }
      else {
        oCall = oConn.prepareCall("{ call k_sp_del_mime_msg(?) }");

        for (int d=0; d<iDeleted; d++) {
          oCall.setString(1, oDeleted.getString(0,d));
          oCall.execute();
        } // next
        oCall.close();
        oCall=null;
      }

      if (oFile.exists() && iDeleted>0) {

        // ***********************************************************************
        // Temporary move all messages at k_mime_msgs, k_mime_parts & k_inet_addrs
        // beyond its maximum so they do not clash when progressive identifiers
        // are re-assigned

        BigDecimal oUnit = new BigDecimal(1);
        oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        oRSet = oStmt.executeQuery("SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"'");
        oRSet.next();
        BigDecimal oMaxPg = oRSet.getBigDecimal(1);
        if (oRSet.wasNull()) oMaxPg = new BigDecimal(0);
        oRSet.close();
        oRSet = null;
        oStmt.close();
        oStmt = null;
        oMaxPg = oMaxPg.add(oUnit);

        String sCat = getCategory().getString(DB.gu_category);
        oStmt = oConn.createStatement();
        oStmt.executeUpdate("UPDATE "+DB.k_mime_msgs+" SET "+DB.pg_message+"="+DB.pg_message+"+"+oMaxPg.toString()+" WHERE "+DB.gu_category+"='"+sCat+"'");
        oStmt.close();
        oStmt = null;

        // *********************************************************************************
        // Re-assign ordinal position and byte offset for all messages remaining after purge

        DBSubset oMsgSet = new DBSubset(DB.k_mime_msgs, DB.gu_mimemsg+","+DB.pg_message, DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"' ORDER BY "+DB.pg_message, 1000);
        int iMsgCount = oMsgSet.load(oConn);

        oMBox = new MboxFile(oFile, MboxFile.READ_ONLY);
        long[] aPositions = oMBox.getMessagePositions();
        oMBox.close();

        oMaxPg = new BigDecimal(0);
        oUpdt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.pg_message+"=?,"+DB.nu_position+"=? WHERE "+DB.gu_mimemsg+"=?");
        oPart = oConn.prepareStatement("UPDATE "+DB.k_mime_parts+" SET "+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
        oAddr = oConn.prepareStatement("UPDATE "+DB.k_inet_addrs+" SET "+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
        for (int m=0; m<iMsgCount; m++) {
          String sGuMsg = oMsgSet.getString(0,m);
          oUpdt.setBigDecimal(1, oMaxPg);
          oUpdt.setBigDecimal(2, new BigDecimal(aPositions[m]));
          oUpdt.setString(3, sGuMsg);
          oUpdt.executeUpdate();
          oPart.setBigDecimal(1, oMaxPg);
          oPart.setString(2, sGuMsg);
          oPart.executeUpdate();
          oAddr.setBigDecimal(1, oMaxPg);
          oAddr.setString(2, sGuMsg);
          oAddr.executeUpdate();
          oMaxPg = oMaxPg.add(oUnit);
        }
        oUpdt.close();
        oPart.close();
        oAddr.close();
      }
      oConn.commit();
    } catch (SQLException sqle) {
      try { if (oMBox!=null) oMBox.close(); } catch (Exception e) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
      try { if (oCall!=null) oCall.close(); } catch (Exception e) {}
      try { if (oConn!=null) oConn.rollback(); } catch (Exception e) {}
      throw new MessagingException (sqle.getMessage(), sqle);
    }
    catch (IOException sqle) {
      try { if (oMBox!=null) oMBox.close(); } catch (Exception e) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
      try { if (oCall!=null) oCall.close(); } catch (Exception e) {}
      try { if (oConn!=null) oConn.rollback(); } catch (Exception e) {}
      throw new MessagingException (sqle.getMessage(), sqle);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
View Full Code Here


    }
    else {

      DBBind oDBB = (DBBind) getPortletContext().getAttribute("GlobalDBBind");

      JDCConnection oCon = null;

      try  {
        oCon = oDBB.getConnection("RecentContactsTab");

        PreparedStatement oStm = oCon.prepareStatement("(SELECT dt_last_visit,gu_company,NULL AS gu_contact,nm_company,'' AS full_name,work_phone,tx_email FROM k_companies_recent WHERE gu_user=? UNION SELECT dt_last_visit,NULL AS gu_company,gu_contact,nm_company,full_name,work_phone,tx_email FROM k_contacts_recent WHERE gu_user=?) ORDER BY dt_last_visit DESC", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        oStm.setString (1, sUserId);
        oStm.setString (2, sUserId);
        ResultSet oRSet = oStm.executeQuery();

        int iRecentCount = 0;
        StringBuffer oXML = new StringBuffer();
        String sStr;

        while (oRSet.next() && iRecentCount<iMaxRecent) {
          oXML.append("<contact>");

          sStr = oRSet.getString(2);
          if (oRSet.wasNull()) oXML.append("<gu_company/>"); else oXML.append("<gu_company>"+oRSet.getString(2)+"</gu_company>");

          sStr = oRSet.getString(3);
          if (oRSet.wasNull()) oXML.append("<gu_contact/>"); else oXML.append("<gu_contact>"+oRSet.getString(3)+"</gu_contact>");

          sStr = oRSet.getString(4);
          if (oRSet.wasNull()) oXML.append("<nm_company/>"); else oXML.append("<nm_company><![CDATA["+oRSet.getString(4)+"]]></nm_company>");

          sStr = oRSet.getString(5);
          if (oRSet.wasNull()) oXML.append("<full_name/>"); else oXML.append("<full_name><![CDATA["+oRSet.getString(5)+"]]></full_name>");

          sStr = oRSet.getString(6);
          if (oRSet.wasNull()) oXML.append("<work_phone/>"); else oXML.append("<work_phone><![CDATA["+oRSet.getString(6)+"]]></work_phone>");

          sStr = oRSet.getString(7);
          if (oRSet.wasNull()) oXML.append("<tx_email/>"); else oXML.append("<tx_email>"+oRSet.getString(7)+"</tx_email>");

          oXML.append("</contact>");

          iRecentCount++;
        } // wend

        oCon.close("RecentContactsTab");
        oCon = null;

        sXML += "<contacts>\n"+oXML.toString()+"</contacts>";
      }
      catch (SQLException e) {
        sXML += "<contacts/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("RecentContactsTab");
        } catch (SQLException ignore) { }
      }
    }

    try {
View Full Code Here

    }

    if (null==oConn)
      throw new IllegalStateException("Not connected to database");

  JDCConnection oJDC;
    // Get a JDC Connection Wrapper
    if (oConn instanceof JDCConnection)
      oJDC = (JDCConnection) oConn;
    else
      oJDC = new JDCConnection(oConn, null);

  String sContactXml = null;
  String sCompanyXml = null;
 
  if (oJDC.getPool()==null) {
      switch (oJDC.getDataBaseProduct()) {
        case JDCConnection.DBMS_MSSQL:
          sContactXml = getResourceAsString("scripts/mssql/contact_clon.xml", sEncoding);
          sCompanyXml = getResourceAsString("scripts/mssql/company_clon.xml", sEncoding);
          break;
        case JDCConnection.DBMS_MYSQL:
          sContactXml = getResourceAsString("scripts/mysql/contact_clon.xml", sEncoding);
          sCompanyXml = getResourceAsString("scripts/mysql/company_clon.xml", sEncoding);
          break;
      case JDCConnection.DBMS_ORACLE:
        sContactXml = getResourceAsString("scripts/oracle/contact_clon.xml", sEncoding);
        sCompanyXml = getResourceAsString("scripts/oracle/company_clon.xml", sEncoding);
        break;
      case JDCConnection.DBMS_POSTGRESQL:
        sContactXml = getResourceAsString("scripts/postgresql/contact_clon.xml", sEncoding);
        sCompanyXml = getResourceAsString("scripts/postgresql/company_clon.xml", sEncoding);
        break;
      default:
        if (DebugFile.trace) {
          DebugFile.writeln("Unsupported database");
          DebugFile.decIdent();
        }
        throw new SQLException ("Unsupported database");
      }
  }
  else {
    FileSystemWorkArea oFsw = new FileSystemWorkArea(((DBBind)oJDC.getPool().getDatabaseBinding()).getProperties());
      try {
        switch (oJDC.getDataBaseProduct()) {
          case JDCConnection.DBMS_MSSQL:
            sContactXml = oFsw.readstorfilestr("datacopy/mssql/contact_clon.xml", sEncoding);
            sCompanyXml = oFsw.readstorfilestr("datacopy/mssql/company_clon.xml", sEncoding);
            break;
          case JDCConnection.DBMS_MYSQL:
            sContactXml = oFsw.readstorfilestr("datacopy/mysql/contact_clon.xml", sEncoding);
            sCompanyXml = oFsw.readstorfilestr("datacopy/mysql/company_clon.xml", sEncoding);
            break;
          case JDCConnection.DBMS_ORACLE:
            sContactXml = oFsw.readstorfilestr("datacopy/oracle/contact_clon.xml", sEncoding);
            sCompanyXml = oFsw.readstorfilestr("datacopy/oracle/company_clon.xml", sEncoding);
            break;
          case JDCConnection.DBMS_POSTGRESQL:
            sContactXml = oFsw.readstorfilestr("datacopy/postgresql/contact_clon.xml", sEncoding);
            sCompanyXml = oFsw.readstorfilestr("datacopy/postgresql/company_clon.xml", sEncoding);
            break;
          default:
            if (DebugFile.trace) {
              DebugFile.writeln("Unsupported database "+oJDC.getMetaData().getDatabaseProductName());
              DebugFile.decIdent();
            }
            throw new SQLException ("Unsupported database "+oJDC.getMetaData().getDatabaseProductName());
        }
      } catch (com.enterprisedt.net.ftp.FTPException neverthrown) { }
  } // fi
 
    Properties oParams = new Properties();
View Full Code Here

  Integer oCodError = new Integer(0);
 
    Interpreter oInterpreter = new Interpreter();
    try {
      oInterpreter.set ("UserId", sUserId);
      oInterpreter.set ("DefaultConnection", new JDCConnection(oConn,null));
      if (DebugFile.trace) DebugFile.writeln("Interpreter.eval(getResourceAsString(scripts/user_categories_create.js,"+sEncoding);
      oInterpreter.eval(getResourceAsString("scripts/user_categories_create.js", sEncoding));
      Object obj = oInterpreter.get("ErrorCode");
      oCodError = (Integer) oInterpreter.get("ErrorCode");
      if (oCodError.intValue()==0) {
View Full Code Here

   * @throws IllegalStateException if order lines are not loaded or buyer is not set or seller is not set
   * @see <a href="http://docs.oasis-open.org/ubl/cd-UBL-1.0/">OASIS Universal Business Language 1.0</a>
   */

  public String toXML() throws IllegalStateException {
    JDCConnection oConn = null;
    return toXML (oConn, null);
  }
View Full Code Here

   * @throws IllegalStateException if order lines are not loaded or buyer is not set or seller is not set
   * @see <a href="http://docs.oasis-open.org/ubl/cd-UBL-1.0/">OASIS Universal Business Language 1.0</a>
   */

  public String toXML(String sIdent, String sDelim) throws IllegalStateException {
    JDCConnection oConn = null;
    return toXML (oConn, null);
  }
View Full Code Here

   * @throws IllegalStateException if order lines are not loaded or buyer is not set or seller is not set
   * @see <a href="http://docs.oasis-open.org/ubl/cd-UBL-1.0/">OASIS Universal Business Language 1.0</a>
   */

  public String toXML(String sIdent) throws IllegalStateException {
    JDCConnection oConn = null;
    return toXML (oConn, null);
  }
View Full Code Here

           getDataBaseBind().getProperty("smspassword"),
           oPrp);
  SMSResponse oRsp = oPsh.push (oMsg);
  oPsh.close();

    JDCConnection oCon = getDataBaseBind().getConnection("SMSSender");
    oCon.setAutoCommit (true);
  PreparedStatement oStm = oCon.prepareStatement("INSERT INTO "+DB.k_sms_audit+" (id_sms,gu_workarea,pg_part,nu_msisdn,id_msg,gu_batch,bo_success,nu_error,id_status,dt_sent,gu_writer,gu_address,gu_contact,gu_company,tx_msg,tx_err) "+
                                               "VALUES ('"+oRsp.messageId()+"','"+getString(DB.gu_workarea)+"',1,'"+oAtm.getString(DB.mov_phone)+"',NULL,'"+getString(DB.gu_job)+"',?,?,?,?,'"+getString(DB.gu_writer)+"',?,?,?,?,?)");

  oStm.setShort(1, (short) (oRsp.errorCode()==SMSResponse.ErrorCode.NONE ? 1 : 0));
  oStm.setInt(2, (int) oRsp.errorCode().intValue());
  oStm.setInt(3, (int) oRsp.notificationStatusCode().intValue());
  oStm.setTimestamp(4, new Timestamp(oRsp.dateStamp().getTime()));
    oStm.setNull(5, Types.CHAR);
  if (oAtm.isNull(DB.gu_contact))
      oStm.setNull(6, Types.CHAR);
    else
      oStm.setString(6, oAtm.getString(DB.gu_contact));
  if (oAtm.isNull(DB.gu_company))
      oStm.setNull(7, Types.CHAR);
    else
    oStm.setString(7, oAtm.getString(DB.gu_company));
    oStm.setString(8, getParameter("txt"));
    if (oRsp.errorCode()==SMSResponse.ErrorCode.NONE)
      oStm.setNull(9, Types.VARCHAR);
    else
      oStm.setString(9, Gadgets.left(oRsp.errorMessage(),254));
    oStm.executeUpdate();
    oStm.close();
    oCon.close("SMSSender");

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End SMSSender.process()");
    }
View Full Code Here

     throws SQLException, org.xml.sax.SAXException, java.io.IOException,
     ClassNotFoundException, IllegalAccessException, InstantiationException {

     DBPersist oJob;
     DBBind oDBB;
     JDCConnection oCon;

     if (argv.length!=4 && argv.length!=5)
       printUsage();
     else
       if (!argv[0].equals("create"))
         printUsage();

      else if (!argv[1].equalsIgnoreCase("MAIL") && !argv[1].equalsIgnoreCase("FAX") &&
                !argv[1].equalsIgnoreCase("SAVE") && !argv[1].equalsIgnoreCase("FTP") &&
                !argv[1].equalsIgnoreCase("SEND") )
        printUsage();

      else {
         oDBB = new DBBind(argv[2]);

         oCon = oDBB.getConnection("job_main");
         oCon.setAutoCommit(true);

         oJob = new DBPersist(DB.k_jobs, argv[1]);

         oJob.parseXML(argv[3]);

         if (argv.length==5)
           oJob.replace (DB.gu_job, argv[4]);

         else if (!oJob.getItemMap().containsKey(DB.gu_job))
           oJob.put (DB.gu_job, com.knowgate.misc.Gadgets.generateUUID());

         oJob.store(oCon);

         oCon.close();

         oDBB.close();

         System.out.println("gu_job:"+oJob.getString(DB.gu_job));
      } // fi
View Full Code Here

   * If an exception is thrown while creating of processing atoms the workerthread
   * will be aborted.
   */
  public void run() {
    String sJob = ""; // Current Job Unique Id.
    JDCConnection oCsrConn = null;

    if (DebugFile.trace) {
       DebugFile.writeln("Begin WorkerThread.run()");
       DebugFile.incIdent();
       DebugFile.writeln("thread=" + getName());
     }

    bContinue = true;

    sLastError = "";

    while (bContinue) {

      try {
        if (delay>0) sleep(delay);

        long lStartRun = new Date().getTime();

        if (DebugFile.trace) DebugFile.writeln(getName() + " getting next atom...");

        oAtm = oConsumer.next();

        if (oAtm==null) {
          // No more atoms to consume
          if (DebugFile.trace) DebugFile.writeln(getName() + " no more atoms.");

          if (iCallbacks>0) callBack (WorkerThreadCallback.WT_ATOMCONSUMER_NOMORE, "Thread " + getName() + " no more Atoms", null, oConsumer);

          break;
        }

        if (iCallbacks>0) callBack (WorkerThreadCallback.WT_ATOM_GET, "Thread " + getName() + " got Atom " + String.valueOf(oAtm.getInt(DB.pg_atom)), null, oAtm);

        // ***********************************
        // Instantiate the proper Job subclass

        if (!sJob.equals(oAtm.getString(DB.gu_job))) {

          // The Job is only re-loaded if it is different from the previous job at this thread
          // this is a Job instance reuse policy for better performance.

          sJob = oAtm.getString(DB.gu_job);

          try {
      if (oJob==null) {
              // Dynamically instantiate the job subclass specified at k_lu_job_commands table
              oCsrConn = oConsumer.getDatabaseBind().getConnection("WorkerThread."+String.valueOf(getId()), true);
              oJob = Job.instantiate(oCsrConn, sJob, oPool.getProperties());
        oCsrConn.close("WorkerThread."+String.valueOf(getId()));
        oCsrConn = null;
              if (iCallbacks>0) callBack(WorkerThreadCallback.WT_JOB_INSTANTIATE, "instantiate job " + sJob + " command " + oJob.getString(DB.id_command), null, oJob);
      } else if (!oJob.getString(DB.gu_job).equals(sJob)) {
        oJob.free();
              // Dynamically instantiate the job subclass specified at k_lu_job_commands table
              oCsrConn = oConsumer.getDatabaseBind().getConnection("WorkerThread."+String.valueOf(getId()), true);
              oJob = Job.instantiate(oCsrConn, sJob, oPool.getProperties());
        oCsrConn.close("WorkerThread."+String.valueOf(getId()));
        oCsrConn = null;       
              if (iCallbacks>0) callBack(WorkerThreadCallback.WT_JOB_INSTANTIATE, "instantiate job " + sJob + " command " + oJob.getString(DB.id_command), null, oJob);
      }

          }
          catch (ClassNotFoundException e) {
            sJob = "";
            oJob = null;
            sLastError = "Job.instantiate(" + sJob + ") ClassNotFoundException " + e.getMessage();

            if (DebugFile.trace) DebugFile.writeln(getName() + " " + sLastError);

            if (iCallbacks>0) callBack(-1, sLastError, e, null);

            bContinue = false;
          }
          catch (IllegalAccessException e) {
            sJob = "";
            oJob = null;
            sLastError = "Job.instantiate(" + sJob + ") IllegalAccessException " + e.getMessage();

            if (DebugFile.trace) DebugFile.writeln(getName() + " " + sLastError);

            if (iCallbacks>0) callBack(-1, sLastError, e, null);

            bContinue = false;
          }
          catch (InstantiationException e) {
            sJob = "";
            oJob = null;
            sLastError = "Job.instantiate(" + sJob + ") InstantiationException " + e.getMessage();

            if (DebugFile.trace) DebugFile.writeln(getName() + " " + sLastError);

            if (iCallbacks>0) callBack(-1, sLastError, e, null);

            bContinue = false;
          }
          catch (SQLException e) {
            sJob = "";
            oJob = null;
            sLastError = " Job.instantiate(" + sJob + ") SQLException " + e.getMessage();

            if (DebugFile.trace) DebugFile.writeln(getName() + " " + sLastError);

            if (iCallbacks>0) callBack(-1, sLastError, e, null);

            bContinue = false;
          } finally {
            if (null!=oCsrConn) { try { oCsrConn.close("WorkerThread."+String.valueOf(getId())); } catch (Exception ignore) { } }
          }
        } // fi(Previous_Job == CurrentAtom->Job)

        // ---------------------------------------------------------------------

        if (null!=oJob) {

          // -------------------------------------------------------------------
          // Actual Atom processing call here!
     
      try {

            oJob.process(oAtm);

            oCsrConn = oConsumer.getDatabaseBind().getConnection("WorkerThread."+String.valueOf(getId()));
        oCsrConn.setAutoCommit(true);

            oAtm.archive(oCsrConn);           
     
            if (DebugFile.trace)
              DebugFile.writeln("Thread " + getName() + " consumed Atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));

            if (DebugFile.trace) DebugFile.writeln("job " + oJob.getString(DB.gu_job) + " pending " + String.valueOf(oJob.pending()));

            if (oJob.pending()==0) {
              oJob.setStatus(oCsrConn, Job.STATUS_FINISHED);

              if (iCallbacks>0) callBack(WorkerThreadCallback.WT_JOB_FINISH, "finish", null, oJob);
            }

            oCsrConn.close("WorkerThread."+String.valueOf(getId()));
      oCsrConn = null;
      }
          catch (Exception e) {
            if (DebugFile.trace) {
              DebugFile.writeln(getName() + " " + e.getClass().getName() + " job " + oJob.getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)) + e.getMessage());
              DebugFile.writeln(StackTraceUtil.getStackTrace(e));
            }

            sLastError = e.getClass().getName() + ", job " + oJob.getString(DB.gu_job) + " ";
            sLastError = "atom " + String.valueOf(oAtm.getInt(DB.pg_atom)) + " ";
            sLastError += e.getMessage() + "\n" + StackTraceUtil.getStackTrace(e) + "\n";
            try {
              if (null!=oCsrConn) {
                oAtm.setStatus(oCsrConn, Atom.STATUS_INTERRUPTED, e.getClass().getName() + " " + e.getMessage());
              } else {
              oCsrConn = oConsumer.getDatabaseBind().getConnection("WorkerThread."+String.valueOf(getId()));
          oCsrConn.setAutoCommit(true);
                oAtm.setStatus(oCsrConn, Atom.STATUS_INTERRUPTED, e.getClass().getName() + " " + e.getMessage());
                oCsrConn.close("WorkerThread."+String.valueOf(getId()));
          oCsrConn = null;
              }
            } catch (SQLException sqle) {
              if (DebugFile.trace) DebugFile.writeln("Atom.setStatus() SQLException " + sqle.getMessage());
            }
            oJob.log(sLastError);

            if (iCallbacks>0) callBack(WorkerThreadCallback.WT_ATOM_CONSUME, "Thread " + getName() + " " + sLastError, e, oJob);
          } finally {
            if (null!=oCsrConn) oCsrConn.close("WorkerThread."+String.valueOf(getId()));
      oCsrConn = null;
          }
         
          if (iCallbacks>0) callBack(WorkerThreadCallback.WT_ATOM_CONSUME, "Thread " + getName() + " consumed Atom " + String.valueOf(oAtm.getInt(DB.pg_atom)), null, oAtm);

          oAtm = null;

          // -------------------------------------------------------------------

        } // fi (oJob)
        else {
          oAtm = null;
          sLastError = "Job.instantiate(" + sJob + ") returned null";
          if (DebugFile.trace) DebugFile.writeln("ERROR: " + sLastError);

          if (iCallbacks>0) callBack(-1, sLastError, new NullPointerException("Job.instantiate(" + sJob + ")"), null);

          bContinue = false;
        }
        lRunningTime += new Date().getTime()-lStartRun;
      }
      catch (Exception e) {

        if (DebugFile.trace)
          DebugFile.writeln(getName() + " " + e.getClass().getName() + " " + e.getMessage());

        if (null!=oJob) {
          sLastError = e.getClass().getName() + ", job " + oJob.getString(DB.gu_job) + " ";
          if (null!=oAtm) {
            sLastError = "atom " + String.valueOf(oAtm.getInt(DB.pg_atom)) + " ";
            try {
              if (null==oCsrConn) {
                oCsrConn = oConsumer.getDatabaseBind().getConnection("WorkerThread.Exception."+String.valueOf(getId()));
                oCsrConn.setAutoCommit(true);
              }
              oAtm.setStatus(oCsrConn, Atom.STATUS_INTERRUPTED, e.getClass().getName() + " " + e.getMessage());
              oCsrConn.close("WorkerThread.Exception."+String.valueOf(getId()));
              oCsrConn=null;
            } catch (Exception sqle) {
              if (DebugFile.trace) DebugFile.writeln("Atom.setStatus() " + sqle.getClass().getName() + " " + sqle.getMessage());
            } finally {
              if (null!=oCsrConn) try { oCsrConn.close("WorkerThread.Exception."+String.valueOf(getId())); } catch (Exception ignore) { }
              oCsrConn=null;
            }
          } // fi
          sLastError += e.getMessage();

View Full Code Here

TOP

Related Classes of com.knowgate.jdc.JDCConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.