Package com.knowgate.dataobjs

Examples of com.knowgate.dataobjs.DBPersist


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


    for (int l=0; l<iLists; l++) {
      DistributionList.delete(oConn, oLists.getString(0,l));
    } // next

    DBPersist oDBP = new DBPersist(DB.k_queries, "QueryByForm");

    oDBP.put(DB.gu_query, sQBFGUID);

    boolean bRetVal = oDBP.delete(oConn);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End QueryByForm.delete() : " + String.valueOf(bRetVal));
    }
View Full Code Here

  /**
   * Create an empty Project Snapshot
   */
  public ProjectSnapshot() {
    oProjct = new Project();
    oRecord = new DBPersist(DB.k_project_snapshots, "ProjectSnapshot");
  }
View Full Code Here

   * Create empty Snapshot for a given Project
   */

  public ProjectSnapshot(JDCConnection oConn, Project oProj) throws SQLException {
    oProjct = oProj;
    oRecord = new DBPersist(DB.k_project_snapshots, "ProjectSnapshot");
  oRecord.load(oConn, new Object[]{oProj.getString(DB.gu_project)});
  }
View Full Code Here

  private DBPersist oAddr;

  public DBInetAddr(String sMsgGUID, int iPart) {

    oAddr = new DBPersist(DB.k_inet_addrs, "InetAddrDB");

    oAddr.put(DB.gu_mimemsg, sMsgGUID);
    oAddr.put(DB.id_part, iPart);
  }
View Full Code Here

    if (null==sTpRecipient) throw new NullPointerException("DBInetAddr recipient type cannot be null");

    if (!sTpRecipient.equals("from") && !sTpRecipient.equals("to") && !!sTpRecipient.equals("cc") && !!sTpRecipient.equals("bcc"))
      throw new java.lang.IllegalArgumentException("Recipient type must be either from, to, cc or bcc");

    oAddr = new DBPersist(DB.k_inet_addrs, "InetAddrDB");

    oAddr.put(DB.gu_mimemsg, sMsgGUID);
    oAddr.put(DB.id_message, sMsgId);
    oAddr.put(DB.tx_email, sTxEMail);
    oAddr.put(DB.tp_recipient, sTpRecipient);
View Full Code Here

public class SalePoint extends Address {

  private DBPersist oSalePoint;

  public SalePoint() {
    oSalePoint = new DBPersist(DB.k_sale_points, "SalePoint");
  }
View Full Code Here

  public SalePoint() {
    oSalePoint = new DBPersist(DB.k_sale_points, "SalePoint");
  }

  public SalePoint(JDCConnection oConn, String sGuid) throws SQLException {
    oSalePoint = new DBPersist(DB.k_sale_points, "SalePoint");
  load(oConn, sGuid);
  }
View Full Code Here

      if (!isNull(DB.gu_contact)) {
        oStmt = oConn.prepareStatement("SELECT "+DB.gu_address+ " FROM "+DB.k_x_contact_addr+" WHERE "+DB.gu_contact+"=?",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
        oStmt.setString(1, getString(DB.gu_contact));
        oRSet = oStmt.executeQuery();
        if (oRSet.next()) {
          oBuyer = new DBPersist(DB.k_member_address, "Buyer");
          oBuyer.load(oConn, new Object[]{oRSet.getString(1)});
        }
        oRSet.close();
        oStmt.close();
      } else if (!isNull(DB.gu_company)) {
        oStmt = oConn.prepareStatement("SELECT "+DB.gu_address+ " FROM "+DB.k_x_company_addr+" WHERE "+DB.gu_company+"=?",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
        oStmt.setString(1, getString(DB.gu_company));
        oRSet = oStmt.executeQuery();
        if (oRSet.next()) {
          oBuyer = new DBPersist(DB.k_member_address, "Buyer");
          oBuyer.load(oConn, new Object[]{oRSet.getString(1)});
        }
        oRSet.close();
        oStmt.close();
      }
View Full Code Here

       }
     }
     else if (sCmd.equalsIgnoreCase("update")) {
       if (DebugFile.trace) DebugFile.writeln("command is update");
       Enumeration oParamNames = request.getParameterNames();
       DBPersist oDbp;
       Class oCls;

       if (null==sCls) {
         oDbp = new DBPersist(sTbl, "DBPersist");
         try {
           oCls = Class.forName("com.knowgate.dataobjs.DBPersist");
         } catch (ClassNotFoundException neverthrown) { oCls=null; }

       } else {
         try {
           oCls = Class.forName(sCls);
           oDbp = (DBPersist) oCls.newInstance();
         } catch (ClassNotFoundException nfe) {
           if (DebugFile.trace) DebugFile.decIdent();
           throw new ServletException("ClassNotFoundException "+nfe.getMessage()+" "+sCls);
         } catch (InstantiationException ine) {
           if (DebugFile.trace) DebugFile.decIdent();
           throw new ServletException("InstantiationException "+ine.getMessage()+" "+sCls);
         } catch (IllegalAccessException iae) {
           if (DebugFile.trace) DebugFile.decIdent();
           throw new ServletException("IllegalAccessException "+iae.getMessage()+" "+sCls);
         } catch (ClassCastException cce) {
           if (DebugFile.trace) DebugFile.decIdent();
           throw new ServletException("ClassCastException "+cce.getMessage()+" "+sCls);
         }

         if (sCls.equals("com.knowgate.hipergate.InvoicePayment") &&
            request.getParameter("gu_invoice")!=null & request.getParameter("pg_payment")!=null) {
           if (request.getParameter("gu_invoice").length()>0 &&
               request.getParameter("pg_payment").length()>0) {
             try {
               oCon = oBnd.getConnection("HttpDataObjsServlet.InvoicePayment", true);
               oDbp.load(oCon, new Object[]{request.getParameter("gu_invoice"), new Integer(request.getParameter("pg_payment"))});
               oCon.close("HttpDataObjsServlet.InvoicePayment");
               oCon=null;
             } catch (Exception xcpt) {
               if (DebugFile.trace) {
                  DebugFile.writeln(xcpt.getClass().getName()+" "+xcpt.getMessage());
                 DebugFile.decIdent();
               }
               throw new ServletException(xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
             }
             finally {
               if (oCon!=null) { try { if (!oCon.isClosed()) { oCon.close("HttpDataObjsServlet.InvoicePayment"); } } catch (Exception ignore) { } }
             } // finally
           } // fi (gu_invoice && pg_payment)
         } // fi (sCls==InvoicePayment)
       } // fi

       if (DebugFile.trace) DebugFile.writeln("class "+oDbp.getClass().getName()+" instantiated");

       while (oParamNames.hasMoreElements()) {
         String sKey = (String) oParamNames.nextElement();
         if (DebugFile.trace) DebugFile.writeln("reading parameter "+sKey);
         sKey = sKey.trim();
         int iSpc = sKey.indexOf(' ');
         if (iSpc>0) {
           String sKeyName = sKey.substring(0, iSpc);
           iSpc++;
           if (iSpc<sKey.length()-1) {
             String sSQLType = sKey.substring(iSpc);
             if (DebugFile.trace) DebugFile.writeln("sqltype is "+sSQLType);
             if (sSQLType.toUpperCase().startsWith("DATE") || sSQLType.toUpperCase().startsWith("DATETIME") || sSQLType.toUpperCase().startsWith("TIMESTAMP")) {
               iSpc = sSQLType.indexOf(' ');
               String sDtFmt = "";
               try {
                 if (iSpc > 0) {
                   sDtFmt = sSQLType.substring(++iSpc);
                   if (DebugFile.trace) DebugFile.writeln("date format is "+sDtFmt);
                   oDbp.replace(sKeyName, request.getParameter(sKey), new SimpleDateFormat(sDtFmt));
                 } else {
                   oDbp.replace(sKeyName, request.getParameter(sKey), DBColumn.getSQLType(sSQLType));
                 }
               } catch (ParseException pe) {
                 if (DebugFile.trace) DebugFile.decIdent();
                 throw new ServletException("ERROR ParseException "+sKey+"|"+sDtFmt+"|"+request.getParameter(sKey)+" "+pe.getMessage());
               } catch (IllegalArgumentException ia) {
                 if (DebugFile.trace) DebugFile.decIdent();
                 throw new ServletException("ERROR IllegalArgumentException "+sKey+"|"+sDtFmt+"|"+request.getParameter(sKey)+ia.getMessage());
               }
             } else {
               try {
                 oDbp.replace(sKeyName, request.getParameter(sKey), DBColumn.getSQLType(sSQLType));
               } catch (NumberFormatException nfe) {
                 if (DebugFile.trace) DebugFile.decIdent();
                 throw new ServletException("ERROR NumberFormatException "+sKey+" "+" "+request.getParameter(sKey)+" "+nfe.getMessage());
               }
             }
           } else {
             oDbp.replace(sKeyName, request.getParameter(sKey));
           }
         } else {
           oDbp.replace(sKey, request.getParameter(sKey));
         }
       } // wend
       try {
         oCon = oBnd.getConnection("HttpDataObjsServlet");
         if (null==oCon) {
           if (DebugFile.trace) DebugFile.decIdent();
           throw new ServletException("ERROR Unable to get database connection from pool "+sDbb);
         }
         if (oBnd.exists(oCon, DB.k_users, "U")) {
           if (Gadgets.checkEMail(sUsr)) {
             sUsr = ACLUser.getIdFromEmail(oCon, sUsr);
             if (null==sUsr)
               iAuth = ACL.USER_NOT_FOUND;
             else
               iAuth = ACL.autenticate(oCon, sUsr, sPwd, ACL.PWD_CLEAR_TEXT);
           } else {
               iAuth = ACL.autenticate(oCon, sUsr, sPwd, ACL.PWD_CLEAR_TEXT);
           } // fi (checkEMail(sUsr))
         } else {
           iAuth = 0;
         } // fi (exists(DBk_users))
         if (iAuth<0) {
           response.sendError(HttpServletResponse.SC_FORBIDDEN, ACL.getErrorMessage(iAuth));
         } else {
           if (oDbp.isNull(DB.gu_workarea))
             bAllowed = true;
           else
             bAllowed = isUserAllowed(oCon, sUsr, oDbp.getString(DB.gu_workarea));
           if (bAllowed) {
               oCon.setAutoCommit(true);
               if (null==sCls) {
                 oDbp.store(oCon);
               } else {
                 if (DebugFile.trace) DebugFile.writeln(oCls.getName()+".getMethod(\"store\", new Class[]{Class.forName(\"com.knowgate.jdc.JDCConnection\")}).invoke(...)");
                 oCls.getMethod("store", new Class[]{Class.forName("com.knowgate.jdc.JDCConnection")}).invoke(oDbp, new Object[]{oCon});
               } // fi (sCls)
               response.setContentType("text/plain");
View Full Code Here

TOP

Related Classes of com.knowgate.dataobjs.DBPersist

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.