Package com.knowgate.dataobjs

Examples of com.knowgate.dataobjs.DBBind


    DebugFile.writeln("End AdHocMailing.clone() : "+String.valueOf(getInt(DB.pg_mailing)));
  }
  } // clone 

  public boolean delete(JDCConnection oConn) throws SQLException {
    DBBind oDbb = (DBBind) oConn.getPool().getDatabaseBinding();
   
  final String sSep = oDbb.getProperty("fileprotocol","file://").startsWith("file:") ? File.separator : "/";
    String sSourceDir =  oDbb.getPropertyPath("workareasput") + getString(DB.gu_workarea) + sSep + "apps" + sSep + "Hipermail" + sSep + "html" + sSep + Gadgets.leftPad(String.valueOf(getInt(DB.pg_mailing)), '0', 5);
  try {
    FileSystem oFs = new FileSystem();
    oFs.rmdir(oDbb.getProperty("fileprotocol","file://")+sSourceDir);
  } catch (Exception xcpt) {
    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln(xcpt.getClass().getName()+" "+xcpt.getMessage());
    }
View Full Code Here


    if (req.getWindowState().equals(WindowState.MINIMIZED)) {
      sXML += "<calls/>";
    }
    else {

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

      DBSubset oCalls = new DBSubset (DB.k_phone_calls, DB.gu_phonecall + "," + DB.tp_phonecall + "," + DB.dt_start + "," + DB.dt_end + "," + DB.gu_contact + "," + DB.contact_person + "," + DB.tx_phone + "," + DB.tx_comments,
                                      DB.gu_workarea + "=? AND " + DB.gu_user + "=? AND " + DB.id_status + "=0 ORDER BY 3 DESC", 10);

      JDCConnection oCon = null;

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

        iCalls = oCalls.load (oCon, new Object[]{sWorkAreaId,sUserId});

        for (int c=0; c<iCalls; c++) {
          if (oCalls.isNull(2,c))
View Full Code Here

    if (bClickThrough && oSessionProps.getProperty("webserver")==null) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new NullPointerException("SendMail.send() If clickthrough property is true then webserver property is required");
    }

    DBBind oDbb;
    ArrayList<String> aWarnings = new ArrayList<String>();

    // *******************************************
    // Setup default values for missing parameters
        
    if (null==oSessionProps) oSessionProps=oMacc.getProperties();
     if (null==sEncoding) sEncoding = "UTF-8";
    if (null==sReplyAddr) sReplyAddr = sFromAddr;
    if (null==sRecipientType) sRecipientType = "to";
    if (null==sId) sId = Gadgets.generateUUID();
    if (null==sEnvCnfFileName) sEnvCnfFileName = "hipergate";
    if (null==sJobTl) sJobTl = "";

    final int nRecipients = aRecipients.length;

    if (DebugFile.trace) DebugFile.writeln("recipient count is "+String.valueOf(nRecipients));
   
    // Remove blank spaces, tabs and carriage return characters from e-mail address
    // end make a limited attempt to extract a sanitized email address
    // prefer text in <brackets>, ignore anything in (parentheses)
    for (int r=0; r<nRecipients; r++) {
    aRecipients[r] = MailMessage.sanitizeAddress(Gadgets.removeChars(aRecipients[r], " \t\r"));
    if (!Gadgets.checkEMail(aRecipients[r])) {
      if (DebugFile.trace) DebugFile.writeln("ERROR "+aRecipients[r]+" at line "+String.valueOf(r+1)+" is not a valid e-mail address");
      aWarnings.add(aRecipients[r]+" at line "+String.valueOf(r+1)+" is not a valid e-mail address");
    }
    }
           
    // Get mail from address
    if (!Gadgets.checkEMail(sFromAddr)) {
    aWarnings.add(sFromAddr+" is not a valid from e-mail address");
    }
   
    // Get mail reply-to address
    if (!Gadgets.checkEMail(sReplyAddr)) {
      aWarnings.add(sReplyAddr+" is not a valid reply-to e-mail address");
    }
   
    RecipientType oRecType;
    if (sRecipientType.equalsIgnoreCase("cc"))
      oRecType = RecipientType.CC;
    else if (sRecipientType.equalsIgnoreCase("bcc"))
      oRecType = RecipientType.BCC;
    else if (sRecipientType.equalsIgnoreCase("to"))
    oRecType = RecipientType.TO;
    else
      throw new MessagingException(sRecipientType+" is not a valid recipient type");

    if (sJobTl.length()>0) {
    if (null==oGlobalDbb)
      oDbb = new DBBind(sEnvCnfFileName);
    else
      oDbb = oGlobalDbb;
     
    JDCConnection oCon = null;
    try {

      Job oSnd;
      DBPersist oJob = new DBPersist(DB.k_jobs,"Job");
      oCon = oDbb.getConnection("SendMail",false);
      oCon.setAutoCommit(false);

      ACLUser oUsr = new ACLUser(oCon, oMacc.getString(DB.gu_user));

      String sJobId = Job.getIdFromTitle(oCon, sJobTl, oUsr.getString(DB.gu_workarea));

      if (null==sJobId) {
        if (DebugFile.trace) DebugFile.writeln("Job "+sJobTl+" not found, creating a new one...");
     
      if (oMacc.isNull(DB.gu_account)) {
        if (DebugFile.trace) DebugFile.decIdent();
          throw new SQLException("No MailAccount found for user "+oUsr.getString(DB.gu_user),"01S06");       
      }

        String sMBoxDir = DBStore.MBoxDirectory(oDbb.getProfileName(),oUsr.getInt(DB.id_domain),oUsr.getString(DB.gu_workarea));

        if (DebugFile.trace) DebugFile.writeln("mbox directory is "+sMBoxDir);

        SessionHandler oHndl = new SessionHandler(oMacc,sMBoxDir);
        DBStore oRDBMS = DBStore.open(oHndl.getSession(), oDbb.getProfileName(), sMBoxDir, oUsr.getString(DB.gu_user), oUsr.getString(DB.tx_pwd));
      DBFolder oOutbox = oRDBMS.openDBFolder("outbox",DBFolder.READ_WRITE);

      DBMimeMessage oMsg = DraftsHelper.draftMessage(oOutbox, oMacc.getString(DB.outgoing_server),
                               oUsr.getString(DB.gu_workarea),
                               oUsr.getString(DB.gu_user),
                               sTextHtml==null ? "plain" : "html");

      String sMsgId = oMsg.getContentID();

        if (null==sMsgId) throw new NullPointerException("MIME message identifier could not be set for message with GUID "+oMsg.getMessageGuid());

        DraftsHelper.draftUpdate(oCon, oUsr.getInt(DB.id_domain),
                     oUsr.getString(DB.gu_workarea),
                     oMsg.getMessageGuid(), sMsgId,
                                    sFromAddr,sReplyAddr,sFromPersonal,
                                    sSubject, "text/"+(sTextHtml==null ? "plain" : "html")+";charset="+sEncoding,
                                   (sTextHtml==null ? sTextPlain : sTextHtml), null, null, null);

      if (aAttachments!=null) {
          Integer oPart = DBCommand.queryMaxInt(oCon, DB.id_part, DB.k_mime_parts, DB.gu_mimemsg+"='"+oMsg.getMessageGuid()+"'");
          if (oPart==null) oPart = new Integer(1);
          PreparedStatement oStm = oCon.prepareStatement("INSERT INTO " + DB.k_mime_parts + "("+DB.gu_mimemsg+","+DB.id_message+","+DB.id_part+","+DB.id_disposition+","+DB.id_content+","+DB.id_type+","+DB.len_part+","+DB.de_part+","+DB.file_name+") VALUES ('"+oMsg.getMessageGuid()+"',?,?,'reference',?,?,?,?,?)");
        for (int p=0; p<aAttachments.length; p++) {
              String sFilePath = Gadgets.chomp(sUserDir,File.separator)+aAttachments[p];
              File oAttach = new File(sFilePath);
              if (oAttach.exists()) {
                oStm.setString(1, sMsgId);
                  oStm.setInt(2, oPart.intValue()+p);
              oStm.setString(3, DBMimePart.getMimeType(oCon,aAttachments[p]));       
              oStm.setString(4, DBMimePart.getMimeType(oCon,aAttachments[p]));       
              oStm.setInt(5, (int) oAttach.length());
              oStm.setString(6, aAttachments[p]);
              oStm.setString(7, sFilePath)
              oStm.executeUpdate();
              } // fi
        } // next
        oStm.close()
      } // fi

      sJobId = (sId.length()==32 ? sId : Gadgets.generateUUID());
        oJob.put(DB.gu_job, sJobId);
        oJob.put(DB.gu_workarea, oUsr.getString(DB.gu_workarea));
        oJob.put(DB.gu_writer, oUsr.getString(DB.gu_user));
        oJob.put(DB.id_command, Job.COMMAND_SEND);
        oJob.put(DB.id_status, bAutoRunJob ? Job.STATUS_SUSPENDED : Job.STATUS_PENDING);
        oJob.put(DB.tl_job, sJobTl);
        oJob.put(DB.tx_parameters, (bTestMode ? "testmode:true," : "")+
                                 "message:"+oMsg.getMessageGuid()+","+
                                 "id:"+sMsgId+","+
                                 "profile:"+oDbb.getProfileName()+","+
                                 "account:"+oMacc.getString(DB.gu_account)+","+
                                 "personalized:true"+","+
                                 "attachimages:"+(bAttachImages ? "true" : "false")+","+
                                 "clickthrough:"+(bClickThrough ? "true" : "false")+","+
                                 "webbeacon:"+(bWebBeacon ? "true" : "false")+","+
                                 "webserver:"+oSessionProps.getProperty("webserver")+","+
                                 "encoding:"+sEncoding);
        if (dtExecution!=null) oJob.put(DB.dt_execution, dtExecution);
        oJob.store(oCon);

      DBCommand.executeUpdate(oCon, "UPDATE "+DB.k_mime_msgs+" SET "+DB.gu_job+"='"+sJobId+"' WHERE "+DB.gu_mimemsg+"='"+oMsg.getMessageGuid()+"'");

        oSnd = Job.instantiate(oCon, sJobId, oDbb.getProperties());
       
        oSnd.insertRecipients(oCon, aRecipients, sRecipientType,
                              sTextHtml==null ? "text" : "html",
                              Job.STATUS_PENDING);
     
      } else {

        if (DebugFile.trace) DebugFile.writeln("Job "+sJobTl+" found with GUID "+sJobId);

        oSnd = Job.instantiate(oCon, sJobId, oDbb.getProperties());               

        oSnd.insertRecipients(oCon, aRecipients, sRecipientType,
                              sTextHtml==null ? "text" : "html",
                              Job.STATUS_PENDING);

      }
      oCon.commit();
      oCon.close("SendMail");
      oCon = null;
     
      if (bAutoRunJob) {
        SingleThreadExecutor oSte = new SingleThreadExecutor(oDbb, sJobId);
        oSte.registerCallback(SendMail.DEBUGLN);
        oSte.registerCallback(SendMail.PRINTLN);
        oSte.run();     
      } // bAutoRunJob
     
    } catch (SQLException sqle) {
      if (DebugFile.trace) DebugFile.writeln("SQLException "+sqle.getMessage());
        aWarnings.add("SQLException "+sqle.getMessage());
      if (null!=oCon) {
        if (!oCon.isClosed()) {
          if (!oCon.getAutoCommit()) oCon.rollback();
          oCon.close("SendMail");
        }
        oCon = null;
      }
      if (null==oGlobalDbb && null!=oDbb) oDbb.close();
      oDbb = null;
      }
    } else {
      SessionHandler oSssnHndlr = new SessionHandler(oSessionProps);
    ByteArrayOutputStream oByteOutStrm = new ByteArrayOutputStream();
View Full Code Here

                      sReplyAddr+">,"+(aRecipients==null ? null : "{"+Gadgets.join(aRecipients,";")+"}")+","+
                      sRecipientType+","+sId+","+sEnvCnfFileName+","+sJobTl+",[DBbind])");
      DebugFile.incIdent();
    } // fi (trace)

    DBBind oDbb;

    if (null==oGlobalDbb)
      oDbb = new DBBind(sEnvCnfFileName==null ? "hipergate" : sEnvCnfFileName);
    else
    oDbb = oGlobalDbb;

    JDCConnection oCon = oDbb.getConnection("SendMail_RO1", false);
   
    ACLUser oUsr = new ACLUser(oCon, ACLUser.getIdFromEmail(oCon,sFromAddr));
    if (!oUsr.exists(oCon)) {
      oCon.close("SendMail_RO1");
      if (DebugFile.trace) DebugFile.decIdent();
    throw new SQLException(sFromAddr+" e-mail address not found at k_users table","01S06");
    }

    MailAccount oMacc = MailAccount.forUser(oCon, oUsr.getString(DB.gu_user), oDbb.getProperties());
    if (null==oMacc) {
      oCon.close("SendMail_RO1");
      if (DebugFile.trace) DebugFile.decIdent();
    throw new SQLException("No default e-mail account found for user "+oUsr.getString(DB.gu_user),"01S06");
    }

    oCon.close("SendMail_RO1");
   
    if (DebugFile.trace) DebugFile.writeln("Ready to send message "+sSubject);
   
    ArrayList aWarnings = send(oMacc, oSessionProps,
                 sUserDir, sTextHtml, sTextPlain, sEncoding,
                   aAttachments, sSubject,
                   sFromAddr, sFromPersonal, sReplyAddr,
                   aRecipients, sRecipientType,
                     sId, oDbb.getProfileName(), sJobTl, true, oDbb);

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

    bContinue = true;

    oEnvProps = oProps;
   
    oGlobalDbb = new DBBind(oProps);

  sEnvProps = oGlobalDbb.getProfileName();

    oCallbacks = new LinkedList();
  } // SingleThreadExecutor
View Full Code Here

    String sSQL;
    String sJId;
    ResultSet oRst;
    ResultSetMetaData oMDt;

    DBBind oDBB = null;
    JDCConnection oCon = null;

  if (DebugFile.trace) {
    DebugFile.writeln("Begin SingleThreadExecutor.run("+String.valueOf(currentThread().getId())+")");
    DebugFile.writeln("environment is "+sEnvProps);
  }

    try {
      if (oGlobalDbb==null) {
        // Disable connection reaper to avoid connections being closed in the middle of job execution
        oDBB = new DBBind(sEnvProps);
        oDBB.connectionPool().setReaperDaemonDelay(0l);
      }
      else {
        oDBB = oGlobalDbb;
      }

      oCon = oDBB.getConnection("SingleThreadExecutor_"+String.valueOf(currentThread().getId()));
    oCon.setAutoCommit(true);

      bContinue = true;

      sLastError = "";

      oFdr = new AtomFeeder();

      while (bContinue) {

        if (oCon.isClosed()) {
          oCon = oDBB.getConnection("SingleThreadExecutor_"+String.valueOf(currentThread().getId()));
          oCon.setAutoCommit(true);
        }

        if (sJob==null)
          oDBS = oFdr.loadAtoms(oCon,1);
        else
          oDBS = oFdr.loadAtoms(oCon, sJob);

        if (oDBS.getRowCount()>0) {

          sJId = oDBS.getString(0,0);

          oJob = Job.instantiate(oCon, sJId, oEnvProps);

          oStm = oCon.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

          sSQL = "SELECT a.*, j." + DB.tx_parameters + " FROM " + DB.k_job_atoms + " a, " + DB.k_jobs + " j WHERE a." + DB.id_status + "=" + String.valueOf(Atom.STATUS_PENDING) + " AND j." + DB.gu_job + "=a." + DB.gu_job + " AND j." + DB.gu_job + "='" + sJId + "'";

        if (DebugFile.trace) {
          DebugFile.writeln("Statement.executeQuery("+sSQL+")");
        }

          oRst = oStm.executeQuery(sSQL);
          oMDt = oRst.getMetaData();

          while (oRst.next()) {

            oAtm = new Atom(oRst, oMDt);

        try {
              oJob.process(oAtm);
              oAtm.archive(oCon);           
              if (DebugFile.trace)
                DebugFile.writeln("Thread " + String.valueOf(currentThread().getId()) + " consumed Atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
            if (iCallbacks>0) callBack(WorkerThreadCallback.WT_ATOM_CONSUME, oJob.getString(DB.gu_job), null, oAtm.getString(DB.tx_email));
        }
            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 {
                oAtm.setStatus(oCon, Atom.STATUS_INTERRUPTED, e.getClass().getName() + " " + e.getMessage());
              } catch (SQLException sqle) {
                if (DebugFile.trace) DebugFile.writeln("Atom.setStatus() SQLException " + sqle.getMessage());
              }
              oJob.log(sLastError);

              if (iCallbacks>0) callBack(WorkerThreadCallback.WT_EXCEPTION, "Thread " + getName() + " " + sLastError, e, oJob);
            }

            if (oJob.pending()==0) {
              oJob.setStatus(oCon, Job.STATUS_FINISHED);
              if (iCallbacks>0) callBack(WorkerThreadCallback.WT_JOB_FINISH, "finish", null, oJob);
              if (sJob!=null) bContinue = false;
            }
          } // wend
          oRst.close();
          oStm.close();
        }
        else
          bContinue = false;
      } // wend

      if (!oCon.isClosed())
        oCon.close("SingleThreadExecutor_"+String.valueOf(currentThread().getId()));

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();
    }
    catch (SQLException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "SQLException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new SQLException(e.getMessage(), e.getSQLState(), e.getErrorCode()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");

    }
    catch (FileNotFoundException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "FileNotFoundException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new FileNotFoundException(e.getMessage()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");
    }
    catch (IOException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "IOException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new IOException(e.getMessage()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");
    }
    catch (ClassNotFoundException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "ClassNotFoundException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new ClassNotFoundException(e.getMessage()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");
    }
    catch (InstantiationException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "InstantiationException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new InstantiationException(e.getMessage()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");
    }
    catch (IllegalAccessException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "IllegalAccessException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new IllegalAccessException(e.getMessage()), null);

      if (oJob!=null) oJob.log(sLastError + "\n");
    }
    catch (NullPointerException e) {

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

      if (oGlobalDbb==null && oDBB!=null) oDBB.close();

      sLastError = "NullPointerException " + e.getMessage();

      if (iCallbacks>0) callBack(-1, sLastError, new NullPointerException(e.getMessage()), null);

View Full Code Here

    ServletConfig config = getServletConfig();

    String sProfile = config.getInitParameter("profile");

    if (sProfile==null) {
      oDbb = new DBBind();
    } else if (sProfile.trim().length()==0) {
      oDbb = new DBBind();
    } else {
      oDbb = new DBBind(sProfile);
    }

  oSecurityTokens = new HashMap<String,NameValuePair>();
    oWorkAreas = new HashMap<String,String>();
  } // init()
View Full Code Here

    }
    else {

      // Get database connection from desktop.jsp page

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

      JDCConnection oCon = null;

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

      String sFullName = DBCommand.queryStr(oCon, "SELECT "+DB.nm_user+",' ',"+DB.tx_surname1+" FROM "+DB.k_users+" WHERE '"+DB.gu_user+"='"+sUserId+"'");

        oCon.close("HelloWorld");
        oCon = null;
View Full Code Here

    }
    else {

      // 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;
View Full Code Here

    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");
 
View Full Code Here

TOP

Related Classes of com.knowgate.dataobjs.DBBind

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.