Package com.knowgate.jdc

Examples of com.knowgate.jdc.JDCConnection


      // Get database connection from desktop.jsp page

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

      JDCConnection oCon = null;

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

    // *** Place database access code here

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

        sXML += "<Nodes></Nodes>";
      }
      catch (SQLException e) {
        sXML += "<Nodes/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("Invoicing");
        } catch (SQLException ignore) { }
      }
    } // fi (WindowState)

    try {
View Full Code Here


    }
    else {

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

      JDCConnection oCon = null;
      PreparedStatement oStm = null;
      String sSQL, sInterval;

      try  {
        int iOprtnCount = 0;
        StringBuffer oXML = new StringBuffer();
        String[][] aOprtns = new String[6][iMaxRecent];

        oCon = oDBB.getConnection("OportunitiesTab");

        if (oCon.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL)
          sInterval = "interval '10 years'";
        else
          sInterval = "3650";

        sSQL = "SELECT "+
               DB.gu_oportunity+","+DB.tl_oportunity+","+DB.gu_company+","+DB.gu_contact+","+DB.tx_company+","+DB.tx_contact+","+DB.dt_modified+","+DB.dt_next_action+","+
               DBBind.Functions.GETDATE+"-"+DB.dt_modified+ " AS nu_elapsed FROM "+DB.k_oportunities+" WHERE "+DB.id_status+" NOT IN ('PERDIDA','GANADA','ABANDONADA') AND "+
               DB.dt_modified+" IS NOT NULL AND " + DB.gu_workarea+"=? AND "+DB.gu_writer+"=? UNION SELECT "+
               DB.gu_oportunity+","+DB.tl_oportunity+","+DB.gu_company+","+DB.gu_contact+","+DB.tx_company+","+DB.tx_contact+","+DB.dt_modified+","+DB.dt_next_action+","+
               DBBind.Functions.ISNULL+"("+DB.dt_next_action+","+DBBind.Functions.GETDATE+"+" + sInterval + ")-"+DBBind.Functions.GETDATE+" AS nu_elapsed "+
               "FROM "+DB.k_oportunities+" WHERE "+DB.id_status+" NOT IN ('PERDIDA','GANADA','ABANDONADA') AND "+
               DB.gu_workarea+"=? AND "+DB.gu_writer+"=?";

        if (oCon.getDataBaseProduct()!=JDCConnection.DBMS_MYSQL) {
          sSQL = "(" + sSQL + ")";
        }
        sSQL += " ORDER BY "+DB.nu_elapsed;

        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");

        oStm = oCon.prepareStatement(sSQL,ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

        oStm.setString (1,sWorkAreaId);
        oStm.setString (2,sUserId);
        oStm.setString (3,sWorkAreaId);
        oStm.setString (4,sUserId);

        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeQuery()");

        ResultSet oRSet = oStm.executeQuery();

        while (oRSet.next() && iOprtnCount<iMaxRecent) {

          boolean bListed = false;
          for (int n=0; n<iOprtnCount && !bListed; n++)
            bListed = oRSet.getString(1).equals(aOprtns[0][n]);

          if (!bListed) {
            aOprtns[0][iOprtnCount] = oRSet.getString(1);
            aOprtns[1][iOprtnCount] = oRSet.getString(2);
            aOprtns[2][iOprtnCount] = oRSet.getString(3);
            aOprtns[3][iOprtnCount] = oRSet.getString(4);
            aOprtns[4][iOprtnCount] = oRSet.getString(5);
            aOprtns[5][iOprtnCount] = oRSet.getString(6);

            iOprtnCount++;
          }
        } // wend

        oRSet.close();
        oRSet = null;

        oStm.close();
        oStm = null;

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

        for (int o=0; o<iOprtnCount; o++)
          for (int f=0; f<6; f++)
            if (aOprtns[f][o]==null) aOprtns[f][o]="";

        oXML.append("<oportunities>\n");
        for (int q=0; q<iOprtnCount; q++) {
          oXML.append("<oportunity>\n");

          oXML.append("<gu_oportunity>"+aOprtns[0][q]+"</gu_oportunity>");
          oXML.append("<tl_oportunity><![CDATA["+aOprtns[1][q]+"]]></tl_oportunity>");
          oXML.append("<gu_company>"+aOprtns[2][q]+"</gu_company>");
          oXML.append("<gu_contact>"+aOprtns[3][q]+"</gu_contact>");
          oXML.append("<tx_company><![CDATA["+aOprtns[4][q]+"]]></tx_company>");
          oXML.append("<tx_contact><![CDATA["+aOprtns[5][q]+"]]></tx_contact>");
          oXML.append("<tx_contact_esc><![CDATA["+Gadgets.URLEncode(aOprtns[5][q])+"]]></tx_contact_esc>");
          oXML.append("<where><![CDATA["+Gadgets.URLEncode(" AND gu_contact='" + aOprtns[3][q] + "'")+"]]></where>");

          oXML.append("</oportunity>\n");
        }

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

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

        if (DebugFile.trace) DebugFile.writeln("SQLException " + e.getMessage());
        try {
          if (null != oStm)
              oStm.close();
        } catch (SQLException ignore) { }

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

    try {
View Full Code Here

    ResultSet oRSet;
    int iJobCount;
    int nThreads;
    String sSQL;
    AtomConsumer oCsr = null;
    JDCConnection oJcn = null;
   
    if (DebugFile.trace) DebugFile.writeln("Begin SchedulerDaemon.run()");

  try  {
    nThreads = Integer.parseInt(oEnvProps.getProperty("maxschedulerthreads","1"));
  } catch (Exception xcpt) { nThreads = 1; }
 
    try {

    if (null==oDbb) oDbb = new DBBind(sProfile);

    oJcn = oDbb.getConnection("SchedulerDaemon",true);
  Event.trigger(oJcn, 1024, "startschedulerdaemon", new HashMap(), oEnvProps);
  oJcn.close("SchedulerDaemon");
 
  oDbb.connectionPool().setPoolSize(4*nThreads);
  // No more that ten times the number of threads allowed for connections
  oDbb.connectionPool().setMaxPoolSize(10*nThreads);

    // Create Atom queue.
    if (DebugFile.trace) DebugFile.writeln("new AtomQueue()");

    oQue = new AtomQueue();

    // This object feeds the queue with new atoms
    // extracted from the database.
    if (DebugFile.trace) DebugFile.writeln("new AtomFeeder()");

    AtomFeeder oFdr = new AtomFeeder();

    // This is the queue consumer object
    // it grants that only one atom is
    // poped from the queue at a time.
    if (DebugFile.trace) DebugFile.writeln("new AtomConsumer([JDCconnection], [AtomQueue])");

    oCsr = new AtomConsumer(oDbb, oQue);

    // Create WorkerThreadPool

    if (DebugFile.trace) DebugFile.writeln("new WorkerThreadPool([AtomConsumer], [Properties])");

    oThreadPool = new WorkerThreadPool(oCsr, oEnvProps);

    // Register callbacks on each worker thread

    ListIterator oIter = oCallbacks.listIterator();
    while (oIter.hasNext())
      oThreadPool.registerCallback((WorkerThreadCallback) oIter.next());

    dtStartDate = new Date();

    do {
      try {

        while (bContinue) {

          oJcn = oDbb.getConnection("SchedulerDaemon");
          oJcn.setAutoCommit(true);
         
          // Count how many atoms are pending of processing at the database
          oStmt = oJcn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

          // ***************************************************
          // Finish all the jobs that have no more pending atoms
          sSQL = "SELECT j.gu_job FROM k_jobs j WHERE ("+
                 "j.id_status="+String.valueOf(Job.STATUS_PENDING)+" OR "+
                 "j.id_status="+String.valueOf(Job.STATUS_RUNNING)+") AND "+
                 "NOT EXISTS (SELECT a.pg_atom FROM k_job_atoms a WHERE "+
                 "j.gu_job=a.gu_job AND a.id_status IN ("+
                 String.valueOf(Atom.STATUS_PENDING)+","+
                 String.valueOf(Atom.STATUS_RUNNING)+","+
                 String.valueOf(Atom.STATUS_SUSPENDED)+"))";

          if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery("+sSQL+") on connection with process id. "+oJcn.pid());

          oRSet = oStmt.executeQuery(sSQL);
          LinkedList<String> oFinished = new LinkedList<String>();
          while (oRSet.next()) {
            oFinished.add(oRSet.getString(1));
          } // wend
          oRSet.close();
      oStmt.close();

          if (DebugFile.trace) DebugFile.writeln("Already finished jobs "+String.valueOf(oFinished.size()));

          if (oFinished.size()>0) {
            sSQL = "UPDATE k_jobs SET id_status="+String.valueOf(Job.STATUS_FINISHED)+",dt_finished="+DBBind.Functions.GETDATE+" WHERE gu_job=?";
            if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+") on connection with process id. "+oJcn.pid());
            PreparedStatement oUpdt = oJcn.prepareStatement(sSQL);
            oIter = oFinished.listIterator();
            while (oIter.hasNext()) {
              oUpdt.setObject(1, oIter.next(), java.sql.Types.CHAR);
              oUpdt.executeUpdate();
            } // wend
            oUpdt.close();
          } // fi

          // ***************************************************
          // Count jobs running or pending of begining execution

          if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT COUNT(*) FROM k_jobs WHERE id_status=" + String.valueOf(Job.STATUS_PENDING) + " AND ("+DB.dt_execution+" IS NULL OR "+DB.dt_execution+"<="+DBBind.Functions.GETDATE+")) on connection with process id. "+oJcn.pid());

      iJobCount = DBCommand.queryCount(oJcn, "*", DB.k_jobs, DB.id_status + "=" + String.valueOf(Job.STATUS_RUNNING) + " OR (" + DB.id_status + "=" + String.valueOf(Job.STATUS_PENDING)+" AND ("+DB.dt_execution+" IS NULL OR "+DB.dt_execution+"<="+DBBind.Functions.GETDATE+"))");

      oJcn.close("SchedulerDaemon");

          if (DebugFile.trace) DebugFile.writeln(String.valueOf(iJobCount) + " pending jobs");

          if (0==iJobCount) {
            if (DebugFile.trace) DebugFile.writeln("sleep (10000)");
            sleep (10000);
          }
          else {
            break;
          }
        } // wend

        if (bContinue) {

      try {
        oJcn = oDbb.getConnection("SchedulerDaemon.AtomFeeder");
            oJcn.setAutoCommit(true);
            oFdr.loadAtoms(oJcn, oThreadPool.size());
            oFdr.feedQueue(oJcn, oQue);
        oJcn.close("SchedulerDaemon.AtomFeeder");
        oJcn=null;
      } finally {
        try { if (null!=oJcn) oJcn.close("SchedulerDaemon.AtomFeeder"); } catch (Exception ignore) { }
      }

      if (DebugFile.trace) {
        DebugFile.writeln("Queue has "+String.valueOf(oQue.size())+" atoms");
      }

          if (oQue.size()>0) {
            oThreadPool.launchAll();
          }

          do {

            if (DebugFile.trace) DebugFile.writeln("sleep (10000)");

            sleep(10000);

            if (DebugFile.trace) DebugFile.writeln(String.valueOf(oThreadPool.livethreads()) + " live threads");

          } while(oThreadPool.livethreads()==oThreadPool.size());
        } // fi (bContinue)
      }
      catch (InterruptedException e) {
        if (DebugFile.trace)
          DebugFile.writeln("SchedulerDaemon InterruptedException " + e.getMessage());
      }
    } while (bContinue) ;

    if (DebugFile.trace) DebugFile.writeln(" exiting SchedulerDaemon");

    oThreadPool.haltAll();
    oThreadPool = null;

  oCsr.close();
    oCsr = null;

    oFdr = null;
    oQue = null;

    if (DebugFile.trace) DebugFile.writeln("JDConnection.close()");

  if (oJcn!=null) { if (!oJcn.isClosed()) { oJcn.close("SchedulerDaemon"); } oJcn = null; }

    oJcn = oDbb.getConnection("SchedulerDaemon",true);
  Event.trigger(oJcn, 1024, "stopschedulerdaemon", new HashMap(), oEnvProps);
  oJcn.close("SchedulerDaemon");

    oDbb.close();
    oDbb=null;
    }
    catch (Exception e) {
     
      if (DebugFile.trace) {
        DebugFile.writeln("SchedulerDaemon " + e.getClass().getName() + " " + e.getMessage());
        try {
          DebugFile.writeln(StackTraceUtil.getStackTrace(e));
        } catch (IOException ignore) {}
       
        DebugFile.writeln("SchedulerDaemon.run() abnormal termination");
      }
     
      try {
        System.err.println("Hipergate SchedulerDaemon fatal error " + e.getClass().getName() + " " + e.getMessage());
        System.err.println(StackTraceUtil.getStackTrace(e));
      } catch (IOException ignore) {}

      try { oThreadPool.haltAll(); oThreadPool=null; } catch (Exception ignore) {}
      try {
        if (oJcn!=null) if (!oJcn.isClosed()) oJcn.close("SchedulerDaemon");
      } catch (SQLException sqle) {
        if (DebugFile.trace) DebugFile.writeln("SchedulerDaemon SQLException on close() " + sqle.getMessage());
      }
      if (null!=oDbb) { try { oDbb.close(); } catch (Exception ignore) {} }
      oJcn = null;
View Full Code Here

    if (null==oDbb)
      oDb2 = new DBBind(sProfile);
    else
      oDb2 = oDbb;
     
    JDCConnection oCon = oDb2.getConnection("SchedulerDaemon.abortJob");
  oCon.setAutoCommit(true);

  atomQueue().remove(sGuJob);

  Job.instantiate(oCon, sGuJob, oEnvProps).abort(oCon);

  oCon.close("SchedulerDaemon.abortJob");

  if (oDb2!=oDbb) oDb2.close();

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

    oThreadPool.haltAll();
    String[] aStillRunningJobs = oThreadPool.runningJobs();

    if (null!=oDbb) {
      try {
        JDCConnection oCon = oDbb.getConnection("SchedulerDaemonHaltAll");
        oCon.setAutoCommit(true);
        if (null!=aInitRunningJobs) {
          if (null!=aStillRunningJobs) {
            int nInitRunningJobs = aInitRunningJobs.length;
            int nStillRunningJobs= aStillRunningJobs.length;
            for (int i=0; i<nInitRunningJobs; i++) {
              boolean bStillRunning = false;
              for (int j=0; j<nStillRunningJobs && !bStillRunning; j++) {
                bStillRunning = aStillRunningJobs[j].equals(aInitRunningJobs[i]);
              } // next
              if (bStillRunning) aInitRunningJobs[i]=null;
            } // next
          } // fi
          suspendJobs(oCon, aInitRunningJobs);
        } // fi
        oCon.close("SchedulerDaemonHaltAll");
      } catch (SQLException sqle) {
        throw new IllegalStateException("SchedulerDaemon.haltAll() SQLException "+sqle.getMessage());
      }
      oDbb.close();
      oDbb=null;
View Full Code Here

  // call oThreadPool.haltAll() and clean-up atom consumer

    try { sleep(lDelayMilis); } catch (InterruptedException ignore) { }

    if (null!=oDbb) {
      JDCConnection oCon = oDbb.getConnection("SchedulerDaemonStopAll");
      oCon.setAutoCommit(true);
      oThreadPool.stopAll(oCon);
      interruptJobs(oCon, oThreadPool.runningJobs());
      oCon.close("SchedulerDaemonStopAll");
      oDbb.close();
      oDbb=null;
    } else {
      oThreadPool.stopAll();
    }
View Full Code Here

   * @throws IllegalStateException if despatch advice 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 despatch advice 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 despatch advice 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

      DebugFile.writeln("Connection.prepareStatement("+sSQL+")");
    }

    oUpdt = oConn.prepareStatement(sSQL);

    jConn = new JDCConnection(oConn, null);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End TableLoader.prepare()");
    }
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.