Examples of JDCConnection


Examples of com.knowgate.jdc.JDCConnection

    // For each first line of a despatch, get data from order and insert row into k_despatch_advices and k_x_orders_despatch

  if (bIsNewDespacth) {
    sLastDespatchAdviceIdentifier = (String) get("id_ref");
    sLastDespatchAdviceGUID = Gadgets.generateUUID();
    iLastDespatchAdviceNumber = DespatchAdvice.nextVal(new JDCConnection(oConn, null), sWorkArea);
    iLastDespatchLineNumber = 1;

    // Get data for the previous order corresponding to this despatch advice
    ResultSet rOrderData = oLoadOrder.queryResultSet(oConn, "SELECT gu_order,gu_shop,id_legal,id_currency,gu_warehouse,gu_company,gu_contact,nm_client,gu_ship_addr,gu_bill_addr FROM k_orders WHERE gu_workarea='"+sWorkArea+"' AND id_ref='"+sLastDespatchAdviceIdentifier+"'");
    if (rOrderData.next()) {
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

      try {
        File[] aDirs = oBase.listFiles();
        if (aDirs!=null) {
          DBBind oDbbd = new DBBind(argv[0]);
          Contact oCont = new Contact();
          JDCConnection oConn = oDbbd.getConnection("AttachmentUploader");
          PreparedStatement oStmt = oConn.prepareStatement("SELECT "+DB.gu_contact+","+DB.gu_workarea+" FROM "+DB.k_contacts+" WHERE "+DB.gu_contact+"=? OR "+DB.id_ref+"=? OR "+DB.sn_passport+"=?",
                                                           ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oConn.setAutoCommit(false);
          int nDirs = aDirs.length;
          for (int d=0; d<nDirs; d++) {
            if (aDirs[d].isDirectory()) {
              String sDirName = aDirs[d].getName();
              oStmt.setString(1, sDirName);
              oStmt.setString(2, sDirName);
              oStmt.setString(3, sDirName);
              ResultSet oRSet = oStmt.executeQuery();
              if (oRSet.next()) {
                oCont.replace(DB.gu_contact , oRSet.getString(1));
                oCont.replace(DB.gu_workarea, oRSet.getString(2));
                oRSet.close();
                oCont.addAttachments(oConn, argv[2], aDirs[d].getAbsolutePath(), true);
                oConn.commit();
                aDirs[d].delete();
              } else {
                DebugFile.writeln("AttachmentUploader.main() SQLException: No data found for Contact "+sDirName);
                oRSet.close();
              } // fi (next)
            } // fi (isDirectory)
          } // next
          oStmt.close();
          oConn.close("AttachmentUploader");
          oDbbd.close();
        } // fi (aDirs)
      } catch (Exception xcpt) {
        if (DebugFile.trace) {
          DebugFile.writeln(xcpt.getClass().getName()+" "+xcpt.getMessage());
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    if (DebugFile.trace) {
      DebugFile.writeln("Begin DraftsHelper.draftMessage("+sMailHost+","+sGuWorkArea+","+sUserId+","+sContentType+")");
      DebugFile.incIdent();
    }

    JDCConnection oConn = oDraftsFldr.getConnection();

    java.sql.PreparedStatement oStmt;
    java.sql.ResultSet oRSet;

    com.knowgate.acl.ACLUser oUsr = new com.knowgate.acl.ACLUser();
    if (!oUsr.load(oConn, new Object[]{sUserId})) {
     
      if (DebugFile.trace) {
        DebugFile.writeln("ERROR: User "+sUserId+" not found");
        DebugFile.decIdent();
      }   
    throw new SQLException("DraftsHelper.draftMessage() User "+sUserId+" not found");
    } // fi

    String sGuMsg = Gadgets.generateUUID();
    String sGuFldr= oDraftsFldr.getCategoryGuid();
    String sFrom  = oUsr.getStringNull(DB.nm_user,"")+" "+oUsr.getStringNull(DB.tx_surname1,"")+" "+oUsr.getStringNull(DB.tx_surname2,"");
    String sIdMsg = "<"+sGuMsg+"."+oUsr.getStringNull(DB.tx_nickname,"")+"@"+sMailHost+">";

    oConn.setAutoCommit(false);

    if (DebugFile.trace) {
      DebugFile.writeln("Creating message "+sGuMsg+" "+sIdMsg+" at folder "+oDraftsFldr.getName()+" "+sGuFldr);
      DebugFile.writeln("JDCConnection.prepareStatement(SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"='"+sGuFldr+"')");
    }

    oStmt = oConn.prepareStatement("SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"=?");
    oStmt.setString (1,sGuFldr);
    oRSet = oStmt.executeQuery();
    oRSet.next();
    java.math.BigDecimal oMax = oRSet.getBigDecimal(1);
    if (oRSet.wasNull()) oMax = new java.math.BigDecimal(0);
    oRSet.close();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.writeln("JDCConnection.prepareStatement(INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES('"+sGuMsg+"',"+oMax.add(new java.math.BigDecimal(1)).toString()+",'"+sGuWorkArea+"','"+sGuFldr+"','text/"+sContentType+"; charset=utf-8','"+sIdMsg+"','','"+oUsr.getString(DB.tx_main_email)+"','"+oUsr.getString(DB.tx_main_email)+"','"+sFrom.trim()+"',0,1,0))");
    }

    oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES(?,?,?,?,?,?,?,?,?,?,0,1,0)");
    oStmt.setString (1,sGuMsg);
    oStmt.setBigDecimal (2,oMax.add(new java.math.BigDecimal(1)));
    oStmt.setString (3,sGuWorkArea);
    oStmt.setString (4,sGuFldr);
    oStmt.setString (5,"text/"+sContentType+"; charset=utf-8");
    oStmt.setString (6,sIdMsg);
    oStmt.setString (7,"");
    oStmt.setString (8,oUsr.getString(DB.tx_main_email));
    oStmt.setString (9,oUsr.getString(DB.tx_main_email));
    oStmt.setString (10,sFrom.trim());

    if (DebugFile.trace) {
      DebugFile.writeln("JDCConnection.executeUpdate(INSERT INTO "+DB.k_mime_msgs+" ("+DB.gu_mimemsg+","+DB.pg_message+","+DB.gu_workarea+","+DB.gu_category+","+DB.id_type+","+DB.id_message+","+DB.tx_subject+","+DB.tx_email_from+","+DB.tx_email_reply+","+DB.nm_from+","+DB.len_mimemsg+","+DB.bo_draft+","+DB.bo_deleted+") VALUES('"+sGuMsg+"',?,'"+sGuWorkArea+"','"+sGuFldr+"','text/"+sContentType+"; charset=utf-8','"+sIdMsg+"','','"+oUsr.getString(DB.tx_main_email)+"','"+oUsr.getString(DB.tx_main_email)+"','"+sFrom.trim()+"',0,1,0))");
    }   

    nAffected = oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.writeln(String.valueOf(nAffected)+" affected rows");
    }   
       
    oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+") VALUES (?,?,?,?,?,?)");
    oStmt.setString (1,sGuMsg);
    oStmt.setString (2,sIdMsg);
    oStmt.setString (3,oUsr.getString(DB.tx_main_email));
    oStmt.setString (4,"from");
    oStmt.setString (5,sFrom.trim());
    oStmt.setString (6,sUserId);

    if (DebugFile.trace) {
      DebugFile.writeln("JDCConnection.executeUpdate(INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+") VALUES ('"+sGuMsg+"','"+sIdMsg+"','"+oUsr.getString(DB.tx_main_email)+"','from','"+sFrom.trim()+"','"+sUserId+"'))");
    }

    nAffected = oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.writeln(String.valueOf(nAffected)+" affected rows");
    }   

    if (!oConn.getAutoCommit()) {
      if (DebugFile.trace)
        DebugFile.writeln("Connection.commit()");
      oConn.commit();
    }

  DBMimeMessage oRetVal = oDraftsFldr.getMessageByGuid(sGuMsg);
       
    if (DebugFile.trace) {
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    }

  String sSQL;
    PreparedStatement oStmt;

    JDCConnection oConn = oDraftsFldr.getConnection();

    DBMimeMessage oDraft = draftMessage(oDraftsFldr, sMailHost, sGuWorkArea, sUserId, sContentType);

    com.knowgate.acl.ACLUser oUsr = new com.knowgate.acl.ACLUser();
    oUsr.load(oConn, new Object[]{sUserId});

    String sIdMsg = "<"+oDraft.getMessageGuid()+"."+oUsr.getStringNull(DB.tx_nickname,"")+"@"+sMailHost+">";

    DBMimeMessage oOrMsg = new DBMimeMessage(oOriginalFldr, sGuOriginalMsg);
    DBInetAddr oFrom = (DBInetAddr) oOrMsg.getFromRecipient();

    String sText;
    if (sContentType.equals("html"))
      sText = oOrMsg.tagBodyHtml();
    else
      sText = oOrMsg.tagBodyPlain();

    MimeBodyPart oText = new MimeBodyPart();
    oText.setContent(sText, "text/html");
    java.io.ByteArrayOutputStream oBaStrm = new java.io.ByteArrayOutputStream(sText.length()*2+2);
    oText.writeTo(oBaStrm);

    oStmt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.len_mimemsg+"=?"+","+DB.tx_subject+"=?,"+DB.by_content+"=? WHERE "+DB.gu_mimemsg+"=?");
    oStmt.setInt(1, oBaStrm.size());
    oStmt.setString(2, oOrMsg.getSubject());
    oStmt.setBinaryStream(3, new java.io.ByteArrayInputStream(oBaStrm.toByteArray()), oBaStrm.size());
    oStmt.setString(4, oDraft.getMessageGuid());
    oStmt.executeUpdate();
    oStmt.close();

  sSQL = "INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+") (SELECT '"+oDraft.getMessageGuid()+"','"+sIdMsg+"',"+DB.tx_email+",'to',"+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+" FROM "+DB.k_inet_addrs+" WHERE "+DB.gu_mimemsg+"=? AND "+DB.tp_recipient+"='from')";

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

    oStmt = oConn.prepareStatement(sSQL);
    oStmt.setString (1, sGuOriginalMsg );
    oStmt.executeUpdate();
    oStmt.close();
   
    if (oFrom!=null) {
      if (DebugFile.trace)
        DebugFile.writeln("DBMimeMessage.addRecipient(RecipientType.TO, "+oFrom.getAddress()+")");
      oDraft.addRecipient(RecipientType.TO, oFrom);
    }

    if (bReplyAll) {
      sSQL = "INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+") (SELECT '"+oDraft.getMessageGuid()+"','"+sIdMsg+"',"+DB.tx_email+",'to',"+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+" FROM "+DB.k_inet_addrs+" WHERE "+DB.gu_mimemsg+"=? AND "+DB.tp_recipient+"='to')";
      if (DebugFile.trace) DebugFile.writeln("JDCConnection.prepareStatement("+sSQL+")");
      oStmt = oConn.prepareStatement(sSQL);
      oStmt.setString (1,sGuOriginalMsg);
      oStmt.executeUpdate();
      oStmt.close();

      oDraft.addRecipients(RecipientType.TO, oOrMsg.getRecipients(RecipientType.TO));

    sSQL = "INSERT INTO "+DB.k_inet_addrs+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.tx_email+","+DB.tp_recipient+","+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+") (SELECT '"+oDraft.getMessageGuid()+"','"+sIdMsg+"',"+DB.tx_email+",'cc',"+DB.tx_personal+","+DB.gu_user+","+DB.gu_contact+","+DB.gu_company+" FROM "+DB.k_inet_addrs+" WHERE "+DB.gu_mimemsg+"=? AND "+DB.tp_recipient+"='cc')";
      if (DebugFile.trace) DebugFile.writeln("JDCConnection.prepareStatement("+sSQL+")");
      oStmt = oConn.prepareStatement(sSQL);
      oStmt.setString (1,sGuOriginalMsg);
      oStmt.executeUpdate();
      oStmt.close();

      oDraft.addRecipients(RecipientType.CC, oOrMsg.getRecipients(RecipientType.CC));
    } // bReplyAll

    if (!oConn.getAutoCommit()) oConn.commit();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DraftsHelper.draftMessageForReply() : "+oDraft.getMessageGuid());
    }
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    }

    PreparedStatement oStmt;
    ResultSet oRSet;

    JDCConnection oConn = oDraftsFldr.getConnection();

    DBMimeMessage oDraft = draftMessage(oDraftsFldr, sMailHost, sGuWorkArea, sUserId, sContentType);

    // Compose message id by concatenating guid, user nickname and mail host
    com.knowgate.acl.ACLUser oUsr = new com.knowgate.acl.ACLUser();
    oUsr.load(oConn, new Object[]{sUserId});

    String sIdMsg = "<"+oDraft.getMessageGuid()+"."+oUsr.getStringNull(DB.tx_nickname,"")+"@"+sMailHost+">";

    DBMimeMessage oOrMsg = new DBMimeMessage(oOriginalFldr, sGuOriginalMsg);
    DBInetAddr oFrom = (DBInetAddr) oOrMsg.getFromRecipient();

    String sText;
    if (sContentType.equals("html"))
      sText = oOrMsg.tagBodyHtml();
    else
      sText = oOrMsg.tagBodyPlain();

    MimeBodyPart oText = new MimeBodyPart();
    oText.setContent(sText, "text/html");
    java.io.ByteArrayOutputStream oBaStrm = new java.io.ByteArrayOutputStream(sText.length()*2+2);
    oText.writeTo(oBaStrm);

    java.math.BigDecimal oPosition;
    oStmt = oConn.prepareStatement("SELECT "+DB.nu_position+" FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_mimemsg+"=?");
    oStmt.setString(1, sGuOriginalMsg);
    oRSet = oStmt.executeQuery();
    if (oRSet.next())
      oPosition = oRSet.getBigDecimal(1);
    else
      oPosition = null;
    oRSet.close();
    oRSet = null;
    oStmt.close();
    oStmt = null;

    if (com.knowgate.debug.DebugFile.trace)
      com.knowgate.debug.DebugFile.writeln("Connection.prepareStatement(UPDATE "+DB.k_mime_msgs+" SET "+DB.nu_position+"=?,"+DB.len_mimemsg+"=?"+","+DB.by_content+"=? WHERE "+DB.gu_mimemsg+"='"+oDraft.getMessageGuid()+"')");

    oStmt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.nu_position+"=?,"+DB.len_mimemsg+"=?,"+DB.tx_subject+"=?,"+DB.by_content+"=? WHERE "+DB.gu_mimemsg+"=?");
    oStmt.setBigDecimal(1, oPosition);
    oStmt.setInt(2, oBaStrm.size());
    oStmt.setString(3, oOrMsg.getSubject());
    oStmt.setBinaryStream(4, new java.io.ByteArrayInputStream(oBaStrm.toByteArray()), oBaStrm.size());
    oStmt.setString(5, oDraft.getMessageGuid());
    oStmt.executeUpdate();
    oStmt.close();

    if (com.knowgate.debug.DebugFile.trace)
      com.knowgate.debug.DebugFile.writeln("Connection.prepareStatement(INSERT INTO "+DB.k_mime_parts+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.pg_message+","+DB.nu_offset+","+DB.id_part+","+DB.id_content+","+DB.id_type+","+DB.id_disposition+","+DB.id_encoding+","+DB.len_part+","+DB.de_part+","+DB.tx_md5+","+DB.file_name+","+DB.id_compression+","+DB.by_content+") (SELECT '"+oDraft.getMessageGuid()+"','"+sIdMsg+"',NULL,"+DB.nu_offset+","+DB.id_part+","+DB.id_content+","+DB.id_type+",'pointer',"+DB.id_encoding+","+DB.len_part+","+DB.file_name+","+DB.tx_md5+",'"+oOriginalFldr.getFilePath()+"',"+DB.id_compression+",NULL FROM "+DB.k_mime_parts+" WHERE "+DB.gu_mimemsg+"='"+sGuOriginalMsg+"'))");
    oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_mime_parts+" ("+DB.gu_mimemsg+","+DB.id_message+","+DB.pg_message+","+DB.nu_offset+","+DB.id_part+","+DB.id_content+","+DB.id_type+","+DB.id_disposition+","+DB.id_encoding+","+DB.len_part+","+DB.de_part+","+DB.tx_md5+","+DB.file_name+","+DB.id_compression+","+DB.by_content+") (SELECT '"+oDraft.getMessageGuid()+"','"+sIdMsg+"',NULL,"+DB.nu_offset+","+DB.id_part+","+DB.id_content+","+DB.id_type+",'pointer',"+DB.id_encoding+","+DB.len_part+","+DB.file_name+","+DB.tx_md5+",?,"+DB.id_compression+",NULL FROM "+DB.k_mime_parts+" WHERE "+DB.gu_mimemsg+"=? AND "+DB.id_disposition+"='attachment')");
    oStmt.setString (1,sGuOriginalMsg);
    oStmt.setString (2,oOriginalFldr.getFilePath());     
    oStmt.executeUpdate();
    oStmt.close();

    if (!oConn.getAutoCommit()) oConn.commit();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DraftsHelper.draftMessageForForward() : "+oDraft.getMessageGuid());
    }
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    return (DBBind) oDbbs.get(sDefaultBindingName);
  }

  public JDCConnection getConnection(String sCaller)
    throws SQLException {
    JDCConnection oRetObj;
    oRetObj = getDefaultDataBaseBind().getConnection(sCaller);
    return oRetObj;
  }
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    else if (!argv[1].equalsIgnoreCase("list") || !argv[1].equalsIgnoreCase("emails")) {
      printUsage();
    }
    else {
      DBBind oDBB = new DBBind();
      JDCConnection oCon = oDBB.getConnection("ACLDomain_main");
      Statement oStm = oCon.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      ResultSet oRst = oStm.executeQuery("SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.id_domain + "=" + argv[2] + " AND " + DB.bo_active + "<>0");

      while (oRst.next()) {
        System.out.println(oRst.getString(1));
      } // wend

      oRst.close();
      oStm.close();
      oCon.close("ACLDomain_main");

      oDBB.connectionPool().close();
      oDBB = null;
    }
  } // main
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

      DebugFile.incIdent();
    }
    DBKeySet oKeySet = new DBKeySet(DB.k_mime_msgs,
                                    DB.id_message,
                                    DB.id_message+" IS NOT NULL AND "+DB.gu_category+"=? AND "+DB.bo_deleted+"<>1 AND "+DB.gu_parent_msg+" IS NULL",0);
    JDCConnection oCnn = null;
    try {
      oCnn = getConnection();
    } catch (MessagingException msge) {
      throw new SQLException(msge.getMessage(), msge);
    }
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    String sCatGuid = null;

    boolean bWasOpen = isOpen();
    if (!bWasOpen) open(Folder.READ_WRITE);

  JDCConnection oConn = null;
 
    try {
      oConn = getConnection();

      sCatGuid = getCategory().getString(DB.gu_category);
     
      if (null==sCatGuid) throw new SQLException("Could not find category for folder");

      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT "+DB.pg_message+","+DB.nu_position+","+DB.len_mimemsg+" FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_mimemsg+"='"+oSrcMsg.getMessageGuid()+"')");
      oStmt = oConn.prepareStatement("SELECT "+DB.pg_message+","+DB.nu_position+","+DB.len_mimemsg+" FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_mimemsg+"=?");
      oStmt.setString(1, oSrcMsg.getMessageGuid());
      oRSet = oStmt.executeQuery();
      if (oRSet.next()) {
        oPg = oRSet.getBigDecimal(1);
        oPos = oRSet.getBigDecimal(2);
        iLen = oRSet.getInt(3);
        bNullLen = oRSet.wasNull();
      }
      oRSet.close();
      oRSet=null;
      oStmt.close();
      oStmt=null;

      if (DebugFile.trace) {
        if (oPg!=null) DebugFile.writeln("message number is "+oPg.toString()); else DebugFile.writeln("message number is null");
        if (oPos!=null) DebugFile.writeln("message position is "+oPos.toString()); else DebugFile.writeln("message position is null");
        if (!bNullLen) DebugFile.writeln("message length is "+String.valueOf(iLen)); else DebugFile.writeln("message length is null");
      }

      oConn.setAutoCommit(false);

      String sSrcCatg = null;
      if (DebugFile.trace) {
        DBFolder oSrcFldr = (DBFolder) oSrcMsg.getFolder();
        if (null==oSrcFldr)
          DebugFile.writeln("Source message folder is null");
        else {
          Category oSrcCatg = oSrcFldr.getCategory();
          if (null==oSrcCatg)
            DebugFile.writeln("Source message category is null");
          else {
            sSrcCatg = oSrcCatg.getStringNull(DB.gu_category,null);
          }
        }
        if (null==sSrcCatg) {
          DebugFile.decIdent();
          throw new MessagingException("Could not find folder for source message");
        }
        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"-"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"='"+sSrcCatg+"')");
      }
      sSrcCatg = ((DBFolder)(oSrcMsg.getFolder())).getCategory().getString(DB.gu_category);
      oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"-"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"=?");
      oStmt.setString(1, sSrcCatg);
      oStmt.executeUpdate();
      oStmt.close();
      oStmt=null;
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"='"+getCategory().getStringNull(DB.gu_category,"null")+"')");
      oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"=?");
      oStmt.setString(1, getCategory().getString(DB.gu_category));
      oStmt.executeUpdate();
      oStmt.close();
      oStmt=null;

      if (DebugFile.trace) DebugFile.writeln("JDCConnection.commit()");

      oConn.commit();
    }
    catch (SQLException sqle) {
      if (DebugFile.trace) {
        DebugFile.writeln("SQLException "+sqle.getMessage());
        DebugFile.writeStackTrace(sqle);
      }
      if (null!=oRSet) { try {oRSet.close(); } catch (Exception ignore) {} }
      if (null!=oStmt) { try {oStmt.close(); } catch (Exception ignore) {} }
      if (null!=oConn) { try {oConn.rollback(); } catch (Exception ignore) {} }
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
      throw new MessagingException(sqle.getMessage(), sqle);
    }

    if (null==oPg) {
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
      throw new MessagingException("Source message "+oSrcMsg.getMessageGuid()+" not found");
    }

    // If position is null then message is only at the database and not also at
    // an MBOX file so skip moving from one MBOX file to another
    if (null!=oPos) {

      DBFolder oSrcFldr = (DBFolder) oSrcMsg.getFolder();

      MboxFile oMboxSrc = null, oMboxThis = null;
     
      try {
        if (DebugFile.trace) DebugFile.writeln("new MboxFile("+oSrcFldr.getFile().getPath()+", MboxFile.READ_WRITE)");
         
        oMboxSrc = new MboxFile(oSrcFldr.getFile(), MboxFile.READ_WRITE);

        if (DebugFile.trace) DebugFile.writeln("new MboxFile("+getFile().getPath()+", MboxFile.READ_WRITE)");

        oMboxThis = new MboxFile(getFile(), MboxFile.READ_WRITE);

        if (DebugFile.trace) DebugFile.writeln("MboxFile.appendMessage([MboxFile], "+oPos.toString()+","+String.valueOf(iLen)+")");

        oMboxThis.appendMessage(oMboxSrc, oPos.longValue(), iLen);

        oMboxThis.close();
        oMboxThis=null;

        oMboxSrc.purge (new int[]{oPg.intValue()});

        oMboxSrc.close();
        oMboxSrc=null;
      }
      catch (Exception e) {
        if (DebugFile.trace) {
          DebugFile.writeln(e.getClass()+" "+e.getMessage());
          DebugFile.writeStackTrace(e);
        }
        if (oMboxThis!=null) { try { oMboxThis.close(); } catch (Exception ignore) {} }
        if (oMboxSrc!=null)  { try { oMboxSrc.close()} catch (Exception ignore) {} }
        if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
        throw new MessagingException(e.getMessage(), e);
      }
    } // fi (oPos)

    try {
      oConn = getConnection();
      oConn.setAutoCommit(false);

      BigDecimal dNext = getNextMessage();

      if (DebugFile.trace)
        DebugFile.writeln("JDCConnection.prepareStatement(UPDATE "+DB.k_mime_msgs+" SET "+DB.gu_category+"='"+sCatGuid+"',"+DB.pg_message+"="+dNext.toString()+" WHERE "+DB.gu_mimemsg+"='"+oSrcMsg.getMessageGuid()+"')");

      oStmt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.gu_category+"=?,"+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
      oStmt.setString(1, sCatGuid);
      oStmt.setBigDecimal(2, dNext);
      oStmt.setString(3, oSrcMsg.getMessageGuid());
      int iAffected = oStmt.executeUpdate();     
      if (DebugFile.trace) DebugFile.writeln(String.valueOf(iAffected)+" updated rows");     
      oStmt.close();
      oStmt=null;

      if (DebugFile.trace) DebugFile.writeln("JDCConnection.commit()");

      oConn.commit();
    }
    catch (SQLException sqle) {

      if (DebugFile.trace) {
        DebugFile.writeln("MessagingException "+sqle.getMessage());
        DebugFile.writeStackTrace(sqle);
      }

      if (null!=oStmt) { try { oStmt.close(); } catch (Exception ignore) {}}
      if (null!=oConn) { try { oConn.rollback(); } catch (Exception ignore) {} }
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }

      throw new MessagingException(sqle.getMessage(), sqle);
    }
View Full Code Here

Examples of com.knowgate.jdc.JDCConnection

    } else {
      if ((0==(mode&MODE_MBOX)) && (0==(mode&MODE_BLOB)))
        mode |= MODE_MBOX;

      iOpenMode = mode;
      JDCConnection oConn = null;
      try {
        oConn = getConnection();
      } catch (SQLException sqle) {
        throw new MessagingException(sqle.getMessage(), sqle);
      }
      if ((iOpenMode&MODE_MBOX)!=0) {
        String sFolderUrl;
        try {
          sFolderUrl = Gadgets.chomp(getStore().getURLName().getFile(), File.separator) + oCatg.getPath(oConn);
          if (DebugFile.trace) DebugFile.writeln("mail folder directory is " + sFolderUrl);
          if (sFolderUrl.startsWith("file://"))
            sFolderDir = sFolderUrl.substring(7);
          else
            sFolderDir = sFolderUrl;
          if (File.separator.equals("\\")) sFolderDir = sFolderDir.replace('/','\\');
        } catch (SQLException sqle) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (sqle.getMessage(), sqle);
        }
        try {
          File oDir = new File (sFolderDir);
          if (!oDir.exists()) {
            FileSystem oFS = new FileSystem();
            oFS.mkdirs(sFolderUrl);
          }
        } catch (IOException ioe) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (ioe.getMessage(), ioe);
        } catch (SecurityException se) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (se.getMessage(), se);
        } catch (Exception je) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (je.getMessage(), je);
        }

        // Create a ProductLocation pointing to the MBOX file if it does not exist
        try {
          oConn = getConnection();
        } catch (SQLException sqle) {
          throw new MessagingException(sqle.getMessage(), sqle);
        }
        PreparedStatement oStmt = null;
        ResultSet oRSet = null;
        boolean bHasFilePointer;
        try {
          oStmt = oConn.prepareStatement("SELECT NULL FROM "+DB.k_x_cat_objs+ " WHERE "+DB.gu_category+"=? AND "+DB.id_class+"=15",
                                         ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oStmt.setString(1, getCategory().getString(DB.gu_category));
          oRSet = oStmt.executeQuery();
          bHasFilePointer = oRSet.next();
          oRSet.close();
          oRSet = null;
          oStmt.close();
          oStmt = null;

          if (!bHasFilePointer) {
            oConn.setAutoCommit(false);

            Product oProd = new Product();
            oProd.put(DB.gu_owner, oCatg.getString(DB.gu_owner));
            oProd.put(DB.nm_product, oCatg.getString(DB.nm_category));
            oProd.store(oConn);

            ProductLocation oLoca = new ProductLocation();
            oLoca.put(DB.gu_product, oProd.getString(DB.gu_product));
            oLoca.put(DB.gu_owner, oCatg.getString(DB.gu_owner));
            oLoca.put(DB.pg_prod_locat, 1);
            oLoca.put(DB.id_cont_type, 1);
            oLoca.put(DB.id_prod_type, "MBOX");
            oLoca.put(DB.len_file, 0);
            oLoca.put(DB.xprotocol, "file://");
            oLoca.put(DB.xhost, "localhost");
            oLoca.put(DB.xpath, Gadgets.chomp(sFolderDir, File.separator));
            oLoca.put(DB.xfile, oCatg.getString(DB.nm_category)+".mbox");
            oLoca.put(DB.xoriginalfile, oCatg.getString(DB.nm_category)+".mbox");
            oLoca.store(oConn);

            oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_x_cat_objs+" ("+DB.gu_category+","+DB.gu_object+","+DB.id_class+") VALUES (?,?,15)");
            oStmt.setString(1, oCatg.getString(DB.gu_category));
            oStmt.setString(2, oProd.getString(DB.gu_product));
            oStmt.executeUpdate();
            oStmt.close();
            oStmt = null;

            oConn.commit();
          }
        }
        catch (SQLException sqle) {
          if (DebugFile.trace) {
            DebugFile.writeln("SQLException " + sqle.getMessage());
            DebugFile.decIdent();
          }
          if (oStmt!=null) { try { oStmt.close(); } catch (SQLException ignore) {} }
          if (oConn!=null) { try { oConn.rollback(); } catch (SQLException ignore) {} }
          throw new MessagingException(sqle.getMessage(), sqle);
        }
      }
      else {
        sFolderDir = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.