1 32 33 package com.knowgate.crm; 34 35 import java.io.File ; 36 import java.io.FileNotFoundException ; 37 38 import java.util.Date ; 39 import java.util.HashMap ; 40 import java.util.ListIterator ; 41 42 import java.sql.Connection ; 43 import java.sql.SQLException ; 44 import java.sql.Statement ; 45 import java.sql.PreparedStatement ; 46 import java.sql.CallableStatement ; 47 import java.sql.ResultSet ; 48 49 import com.knowgate.debug.DebugFile; 50 import com.knowgate.misc.Environment; 51 import com.knowgate.misc.Gadgets; 52 import com.knowgate.jdc.JDCConnection; 53 import com.knowgate.acl.ACLDomain; 54 import com.knowgate.dataobjs.DB; 55 import com.knowgate.dataobjs.DBBind; 56 import com.knowgate.dataobjs.DBSubset; 57 import com.knowgate.dataobjs.DBPersist; 58 59 import com.knowgate.hipergate.Product; 60 import com.knowgate.hipergate.Address; 61 import com.knowgate.hipergate.DBLanguages; 62 import com.knowgate.hipergate.Product; 63 import com.knowgate.hipergate.ProductLocation; 64 import com.knowgate.workareas.FileSystemWorkArea; 65 66 72 73 public class Contact extends DBPersist { 74 75 78 public Contact() { 79 super(DB.k_contacts, "Contact"); 80 } 81 82 87 public Contact(String sIdContact) throws SQLException { 88 super(DB.k_contacts,"Contact"); 89 put(DB.gu_contact, sIdContact); 90 } 91 92 97 public Contact(JDCConnection oConn, String sIdContact) throws SQLException { 98 super(DB.k_contacts,"Contact"); 99 100 Object aCont[] = { sIdContact }; 101 102 load (oConn,aCont); 103 } 104 105 107 115 public boolean store(JDCConnection oConn) throws SQLException { 116 PreparedStatement oStmt; 117 ResultSet oRSet; 118 119 if (DebugFile.trace) { 120 DebugFile.writeln("Begin Contact.store([Connection])"); 121 DebugFile.incIdent(); 122 } 123 124 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 125 126 if (!AllVals.containsKey(DB.gu_contact)) 127 put(DB.gu_contact, Gadgets.generateUUID()); 128 129 if (!AllVals.containsKey(DB.gu_company) && AllVals.containsKey(DB.nm_legal)) { 130 131 if (DebugFile.trace) 132 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_company + " FROM " + DB.k_companies + " WHERE " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea, "null") + "' AND " + DB.nm_legal + "='" + getStringNull(DB.nm_legal, "null") + "')"); 133 134 oStmt = oConn.prepareStatement("SELECT " + DB.gu_company + " FROM " + DB.k_companies + " WHERE " + DB.gu_workarea + "=? AND " + DB.nm_legal + "=?", 135 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 136 137 oStmt.setString(1, getStringNull(DB.gu_workarea, null)); 138 oStmt.setString(2, getStringNull(DB.nm_legal, null)); 139 oRSet = oStmt.executeQuery(); 140 141 if (oRSet.next()) { 142 if (DebugFile.trace) DebugFile.writeln("gu_company=" + oRSet.getString(1)); 143 144 AllVals.put(DB.gu_company, oRSet.getString(1)); 145 } 146 else 147 if (DebugFile.trace) DebugFile.writeln("no company guid found for " + getStringNull(DB.nm_legal, null)); 148 149 oRSet.close(); 150 oStmt.close(); 151 } 153 replace(DB.dt_modified, dtNow); 154 155 boolean bRetVal = super.store(oConn); 156 157 if (DebugFile.trace) { 158 DebugFile.decIdent(); 159 DebugFile.writeln("End Contact.store() : " + String.valueOf(bRetVal)); 160 } 161 162 return bRetVal; 163 } 165 167 171 public boolean delete(JDCConnection oConn) throws SQLException { 172 return Contact.delete(oConn, getString(DB.gu_contact)); 173 } 174 175 177 184 public boolean addAddress(JDCConnection oConn, String sAddrGUID) throws SQLException { 185 PreparedStatement oStmt = null; 186 boolean bRetVal; 187 188 try { 189 oStmt = oConn.prepareStatement("INSERT INTO " + DB.k_x_contact_addr + " (" + DB.gu_contact + "," + DB.gu_address + ") VALUES (?,?)"); 190 oStmt.setString(1, getStringNull(DB.gu_contact, null)); 191 oStmt.setString(2, sAddrGUID); 192 int iAffected = oStmt.executeUpdate(); 193 oStmt.close(); 194 oStmt = null; 195 bRetVal = (iAffected > 0); 196 } catch (SQLException sqle) { 197 bRetVal = false; 198 try { if (oStmt!=null) oStmt.close(); } catch (Exception ignore) {} 199 } 200 return bRetVal; 201 } 203 205 212 public boolean addBankAccount(JDCConnection oConn, String sFullBankAccount) throws SQLException { 213 PreparedStatement oStmt = null; 214 boolean bRetVal; 215 216 try { 217 oStmt = oConn.prepareStatement("INSERT INTO " + DB.k_x_contact_bank + " (" + DB.gu_contact + "," + DB.nu_bank_acc + "," + DB.gu_workarea + ") VALUES (?,?,?)"); 218 oStmt.setString(1, getStringNull(DB.gu_contact, null)); 219 oStmt.setString(2, sFullBankAccount); 220 oStmt.setString(3, getStringNull(DB.gu_workarea, null)); 221 int iAffected = oStmt.executeUpdate(); 222 oStmt.close(); 223 oStmt = null; 224 bRetVal = (iAffected > 0); 225 } catch (SQLException sqle) { 226 bRetVal = false; 227 try { if (oStmt!=null) oStmt.close(); } catch (Exception ignore) {} 228 } 229 return bRetVal; 230 } 233 241 public Address getAddress(JDCConnection oConn, int iIndex) throws SQLException { 242 String sGuAddr; 243 PreparedStatement oStmt = oConn.prepareStatement("SELECT a."+DB.gu_address+" FROM "+DB.k_addresses+" a,"+DB.k_x_contact_addr+" x WHERE a."+DB.gu_address+"=x."+DB.gu_address+" AND x."+DB.gu_contact+"=? AND a."+DB.ix_address+"=?",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY); 244 oStmt.setString(1, getStringNull(DB.gu_contact,null)); 245 oStmt.setInt(2, iIndex); 246 ResultSet oRSet = oStmt.executeQuery(); 247 if (oRSet.next()) 248 sGuAddr = oRSet.getString(1); 249 else 250 sGuAddr = null; 251 oRSet.close(); 252 oStmt.close(); 253 if (null!=sGuAddr) 254 return new Address(oConn, sGuAddr); 255 else 256 return null; 257 } 258 259 261 269 public Address getAddress(JDCConnection oConn, String sTpLocation) throws SQLException { 270 String sGuAddr; 271 PreparedStatement oStmt = oConn.prepareStatement("SELECT a."+DB.gu_address+" FROM "+DB.k_addresses+" a,"+DB.k_x_contact_addr+" x WHERE a."+DB.gu_address+"=x."+DB.gu_address+" AND x."+DB.gu_contact+"=? AND a."+DB.tp_location+"=?",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY); 272 oStmt.setString(1, getStringNull(DB.gu_contact,null)); 273 oStmt.setString(2, sTpLocation); 274 ResultSet oRSet = oStmt.executeQuery(); 275 if (oRSet.next()) 276 sGuAddr = oRSet.getString(1); 277 else 278 sGuAddr = null; 279 oRSet.close(); 280 oStmt.close(); 281 if (null!=sGuAddr) 282 return new Address(oConn, sGuAddr); 283 else 284 return null; 285 } 286 287 289 296 public DBSubset getAddresses(JDCConnection oConn) throws SQLException { 297 if (DebugFile.trace) { 298 DebugFile.writeln("Begin Contact.getAddresses([Connection])" ); 299 DebugFile.incIdent(); 300 } 301 302 if (isNull(DB.gu_contact)) throw new NullPointerException ("gu_contact not set"); 303 304 Address oAddr = new Address(); 305 306 DBSubset oAddrs = new DBSubset (DB.k_addresses, 307 oAddr.getTable(oConn).getColumnsStr(), 308 DB.gu_address + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_x_contact_addr + " WHERE " + DB.gu_contact + "='" + getString(DB.gu_contact) + "')", 10); 309 int iAddrs = oAddrs.load (oConn); 310 311 oAddr = null; 312 313 if (DebugFile.trace) { 314 DebugFile.decIdent(); 315 DebugFile.writeln("End Contact.getAddresses() : " + String.valueOf(iAddrs)); 316 } 317 318 return oAddrs; 319 } 321 323 331 public DBSubset getAllBankAccounts(JDCConnection oConn) 332 throws SQLException ,IllegalStateException { 333 if (isNull(DB.gu_contact)) 334 throw new IllegalStateException ("Contact.getAllBankAccounts() gu_contact property is not set"); 335 if (isNull(DB.gu_workarea)) 336 throw new IllegalStateException ("Contact.getAllBankAccounts() gu_workarea property is not set"); 337 338 DBSubset oAccs = new DBSubset (DB.k_bank_accounts, 339 DB.nu_bank_acc+","+DB.dt_created+","+DB.bo_active+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc, 340 DB.gu_workarea+"=? AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_contact_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_contact+"=?)",10); 341 342 oAccs.load(oConn, new Object []{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_contact)}); 343 return oAccs; 344 } 346 348 356 public DBSubset getActiveBankAccounts(JDCConnection oConn) 357 throws SQLException ,IllegalStateException { 358 if (isNull(DB.gu_contact)) 359 throw new IllegalStateException ("Contact.getActiveBankAccounts() gu_contact property is not set"); 360 if (isNull(DB.gu_workarea)) 361 throw new IllegalStateException ("Contact.getActiveBankAccounts() gu_workarea property is not set"); 362 363 DBSubset oAccs = new DBSubset (DB.k_bank_accounts, 364 DB.nu_bank_acc+","+DB.dt_created+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc, 365 DB.gu_workarea+"=? AND "+DB.bo_active+"<>0 AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_contact_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_contact+"=?)",10); 366 367 oAccs.load(oConn, new Object []{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_contact)}); 368 return oAccs; 369 } 371 373 381 public DBSubset getUnactiveBankAccounts(JDCConnection oConn) 382 throws SQLException ,IllegalStateException { 383 if (isNull(DB.gu_company)) 384 throw new IllegalStateException ("Contact.getUnactiveBankAccounts() gu_company property is not set"); 385 if (isNull(DB.gu_workarea)) 386 throw new IllegalStateException ("Contact.getUnactiveBankAccounts() gu_contact property is not set"); 387 388 DBSubset oAccs = new DBSubset (DB.k_bank_accounts, 389 DB.nu_bank_acc+","+DB.dt_created+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc, 390 DB.gu_workarea+"=? AND "+DB.bo_active+"=0 AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_contact_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_company+"=?)",10); 391 392 oAccs.load(oConn, new Object []{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_contact)}); 393 return oAccs; 394 } 396 398 412 public Attachment addAttachment(JDCConnection oConn, String sGuWriter, 413 String sDirPath, String sFileName, 414 boolean bDeleteOriginalFile) 415 throws SQLException ,NullPointerException ,FileNotFoundException ,Exception { 416 417 if (DebugFile.trace) { 418 DebugFile.writeln("Begin Contact.addAttachment([Connection],"+sGuWriter+","+ 419 sDirPath+","+sFileName+","+String.valueOf(bDeleteOriginalFile)+")" ); 420 DebugFile.incIdent(); 421 } 422 423 Date dtNow = new Date (); 424 PreparedStatement oStmt; 425 ResultSet oRSet; 426 String sNmLegal; 427 String sProfile; 428 429 if (isNull(DB.gu_contact) || isNull(DB.gu_workarea)) 431 throw new NullPointerException ("Contact.addAttachment() Contact not loaded"); 432 433 if (null==sDirPath) 434 throw new NullPointerException ("Contact.addAttachment() File path may not be null"); 435 436 if (null==sFileName) 437 throw new NullPointerException ("Contact.addAttachment() File name may not be null"); 438 439 File oDir = new File (sDirPath); 440 if (!oDir.isDirectory()) 441 throw new FileNotFoundException ("Contact.addAttachment() "+sDirPath+" is not a directory"); 442 443 if (!oDir.exists()) 444 throw new FileNotFoundException ("Contact.addAttachment() Directory "+sDirPath+" not found"); 445 446 File oFile = new File (Gadgets.chomp(sDirPath,File.separatorChar)+sFileName); 447 if (!oFile.exists()) 448 throw new FileNotFoundException ("Contact.addAttachment() File "+Gadgets.chomp(sDirPath,File.separatorChar)+sFileName+" not found"); 449 450 Integer iDom = ACLDomain.forWorkArea(oConn, getString(DB.gu_workarea)); 452 453 if (DebugFile.trace) DebugFile.writeln("id_domain="+iDom); 454 455 switch (oConn.getDataBaseProduct()) { 456 case JDCConnection.DBMS_ORACLE: 457 oStmt = oConn.prepareStatement("SELECT k." + DB.nm_legal + " FROM " + DB.k_contacts + " c, " + DB.k_companies + " k WHERE c." + DB.gu_company + "=k." + DB.gu_company + "(+) AND c." + DB.gu_contact + "=? AND c." + DB.gu_company + " IS NOT NULL", 458 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 459 break; 460 default: 461 oStmt = oConn.prepareStatement("SELECT k." + DB.nm_legal + " FROM " + DB.k_contacts + " c LEFT OUTER JOIN " + DB.k_companies + " k ON c." + DB.gu_company + "=k." + DB.gu_company + " WHERE c." + DB.gu_contact + "=? AND c." + DB.gu_company + " IS NOT NULL", 462 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 463 } 464 oStmt.setString(1, getString(DB.gu_contact)); 465 oRSet = oStmt.executeQuery(); 466 if (oRSet.next()) 467 sNmLegal = Gadgets.ASCIIEncode(oRSet.getString(1)); 468 else 469 sNmLegal = "_NOCOMPANY"; 470 oRSet.close(); 471 oStmt.close(); 472 473 String sCatPath = "apps/Sales/"+sNmLegal+"/"+getString(DB.gu_contact)+"/"; 474 475 if (DebugFile.trace) DebugFile.writeln("category path = "+sCatPath); 476 477 if (null==oConn.getPool()) 478 sProfile = "hipergate"; 479 else 480 sProfile = ((DBBind) oConn.getPool().getDatabaseBinding()).getProfileName(); 481 482 if (DebugFile.trace) DebugFile.writeln("profile = "+sProfile); 483 484 FileSystemWorkArea oFileSys = new FileSystemWorkArea(Environment.getProfile(sProfile)); 485 oFileSys.mkstorpath(iDom.intValue(), getString(DB.gu_workarea), sCatPath); 486 487 String sStorage = Environment.getProfilePath(sProfile, "storage"); 488 String sFileProtocol = Environment.getProfileVar(sProfile, "fileprotocol", "file://"); 489 String sFileServer = Environment.getProfileVar(sProfile, "fileserver", "localhost"); 490 491 String sWrkAHome = sStorage + "domains" + File.separator + iDom.toString() + File.separator + "workareas" + File.separator + getString(DB.gu_workarea) + File.separator; 492 if (DebugFile.trace) DebugFile.writeln("workarea home = "+sWrkAHome); 493 494 Product oProd = new Product(); 495 oProd.put(DB.nm_product,Gadgets.left(sFileName, 128)); 496 oProd.put(DB.gu_owner, sGuWriter); 497 oProd.put(DB.dt_uploaded, dtNow); 498 oProd.store(oConn); 499 500 ProductLocation oLoca = new ProductLocation(); 501 oLoca.put(DB.gu_owner, sGuWriter); 502 oLoca.put(DB.gu_product, oProd.get(DB.gu_product)); 503 oLoca.put(DB.dt_uploaded, dtNow); 504 oLoca.setPath (sFileProtocol, sFileServer, sWrkAHome + sCatPath, sFileName, sFileName); 505 oLoca.setLength(oFile.length()); 506 oLoca.replace(DB.id_cont_type, oLoca.getContainerType()); 507 oLoca.store(oConn); 508 509 if (sFileProtocol.equalsIgnoreCase("ftp://")) 510 oLoca.upload(oConn, oFileSys, "file://" + sDirPath, sFileName, "ftp://" + sFileServer + sWrkAHome + sCatPath, sFileName); 511 else 512 oLoca.upload(oConn, oFileSys, "file://" + sDirPath, sFileName, sFileProtocol + sWrkAHome + sCatPath, sFileName); 513 514 Attachment oAttach = new Attachment(); 515 oAttach.put(DB.gu_contact, getString(DB.gu_contact)); 516 oAttach.put(DB.gu_product, oProd.getString(DB.gu_product)); 517 oAttach.put(DB.gu_location, oLoca.getString(DB.gu_location)); 518 oAttach.put(DB.gu_writer, sGuWriter); 519 oAttach.store(oConn); 520 521 if (bDeleteOriginalFile) { 522 if (DebugFile.trace) DebugFile.writeln("deleting file "+oFile.getAbsolutePath()); 523 oFile.delete(); 524 if (DebugFile.trace) DebugFile.writeln("deleting file "+sFileName+" deleted"); 525 } 526 527 if (DebugFile.trace) { 528 DebugFile.decIdent(); 529 DebugFile.writeln("End Contact.addAttachment() : " + String.valueOf(oAttach.getInt(DB.pg_product))); 530 } 531 532 return oAttach; 533 } 535 537 549 public void addAttachments(JDCConnection oConn, String sGuWriter, 550 String sDirPath, boolean bDeleteOriginalFiles) 551 throws SQLException ,NullPointerException ,FileNotFoundException ,Exception { 552 553 File oDir = new File (sDirPath); 554 555 if (!oDir.exists()) 556 throw new FileNotFoundException ("Contact.addAttachment() Directory "+sDirPath+" not found"); 557 558 if (!oDir.isDirectory()) 559 throw new FileNotFoundException ("Contact.addAttachment() "+sDirPath+" is not a directory"); 560 561 if (!oDir.exists()) 562 throw new FileNotFoundException ("Contact.addAttachment() Directory "+sDirPath+" not found"); 563 564 File [] aFiles = oDir.listFiles(); 565 if (null!=aFiles) { 566 int nFiles = aFiles.length; 567 for (int f=0; f<nFiles; f++) 568 addAttachment(oConn, sGuWriter, sDirPath, aFiles[f].getName(), false); 569 if (bDeleteOriginalFiles) { 570 for (int f=0; f<nFiles; f++) 571 aFiles[f].delete(); 572 } } } 576 578 587 public boolean removeAttachment(JDCConnection oConn, int iPgAttachment) 588 throws SQLException { 589 Attachment oAttach = new Attachment(); 590 if (oAttach.load(oConn, new Object []{get(DB.gu_contact),new Integer (iPgAttachment)})) 591 return oAttach.delete(oConn); 592 else 593 return false; 594 } 596 598 606 public Attachment[] getAttachments(JDCConnection oConn) 607 throws SQLException ,NullPointerException { 608 609 if (isNull(DB.gu_contact)) 610 throw new NullPointerException ("Contact.getAttachments() Contact not loaded"); 611 612 Attachment oAttach = new Attachment(); 613 Attachment[] aAttachs; 614 DBSubset oAttachs = new DBSubset(DB.k_contact_attachs, 615 oAttach.getTable(oConn).getColumnsStr(), 616 DB.gu_contact+"=?", 10); 617 int iAttachs = oAttachs.load(oConn, new Object []{get(DB.gu_contact)}); 618 if (0==iAttachs) { 619 aAttachs = null; 620 } else { 621 aAttachs = new Attachment[iAttachs]; 622 ListIterator oCols = oAttach.getTable(oConn).getColumns().listIterator(); 623 while (oCols.hasNext()) { 624 String sKey = (String ) oCols.next(); 625 if (!sKey.equalsIgnoreCase(DB.dt_created)) { 626 for (int a=0; a<iAttachs; a++) { 627 aAttachs[a].put(sKey, oAttachs.get(sKey,a)); 628 } } } } return aAttachs; 633 } 635 637 644 public WelcomePack getWelcomePack(JDCConnection oConn) throws SQLException { 645 return WelcomePack.forContact(oConn, getString(DB.gu_contact)); 646 } 647 648 651 662 663 public static boolean delete(JDCConnection oConn, String sContactGUID) throws SQLException { 664 boolean bRetVal; 665 Statement oUpdt; 666 PreparedStatement oDlte; 667 668 if (DebugFile.trace) { 669 DebugFile.writeln("Begin Contact.delete([Connection], " + sContactGUID + ")"); 670 DebugFile.incIdent(); 671 } 672 673 674 if (DBBind.exists(oConn, DB.k_inet_addrs, "U")) { 675 oUpdt = oConn.createStatement(); 676 677 if (DebugFile.trace) 678 DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_contact + "=NULL WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 679 680 oUpdt.executeUpdate("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_contact + "=NULL WHERE " + DB.gu_contact + "='" + sContactGUID + "'"); 681 682 oUpdt.close(); 683 } 684 685 686 if (DBBind.exists(oConn, DB.k_projects, "U")) { 687 oUpdt = oConn.createStatement(); 688 689 if (DebugFile.trace) 690 DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_projects + " SET " + DB.gu_contact + "=NULL WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 691 692 oUpdt.executeUpdate("UPDATE " + DB.k_projects + " SET " + DB.gu_contact + "=NULL WHERE " + DB.gu_contact + "='" + sContactGUID + "'"); 693 oUpdt.close(); 694 oUpdt = null; 695 } 696 697 698 if (DBBind.exists(oConn, DB.k_orders, "U")) { 699 DBSubset oOrders = new DBSubset(DB.k_orders, DB.gu_order, DB.gu_contact + "='" + sContactGUID + "'", 1000); 700 701 int iOrders = oOrders.load(oConn); 702 703 for (int o=0; o<iOrders; o++) 704 com.knowgate.hipergate.Order.delete (oConn, oOrders.getString(0,o)); 705 } 707 708 if (DBBind.exists(oConn, DB.k_x_meeting_contact, "U")) { 709 if (DebugFile.trace) 710 DebugFile.writeln("Connection.prepareStatement(DELETE FROM " + DB.k_x_meeting_contact + " WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 711 712 oDlte = oConn.prepareStatement("DELETE FROM " + DB.k_x_meeting_contact + " WHERE " + DB.gu_contact + "=?"); 713 714 oDlte.setString(1, sContactGUID); 715 716 oDlte.executeUpdate(); 717 718 oDlte.close(); 719 720 oDlte = null; 721 } 723 724 if (DBBind.exists(oConn, DB.k_phone_calls, "U")) { 725 if (DebugFile.trace) 726 DebugFile.writeln("Connection.prepareStatement(DELETE FROM " + DB.k_phone_calls + " WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 727 728 oDlte = oConn.prepareStatement("DELETE FROM " + DB.k_phone_calls + " WHERE " + DB.gu_contact + "=?"); 729 730 oDlte.setString(1,sContactGUID); 731 732 oDlte.executeUpdate(); 733 734 oDlte.close(); 735 } 737 738 if (DBBind.exists(oConn, DB.k_x_course_bookings, "U")) { 739 if (DebugFile.trace) 740 DebugFile.writeln("Connection.prepareStatement(DELETE FROM " + DB.k_x_course_bookings + " WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 741 742 oDlte = oConn.prepareStatement("DELETE FROM " + DB.k_x_course_bookings + " WHERE " + DB.gu_contact + "=?"); 743 744 oDlte.setString(1,sContactGUID); 745 746 oDlte.executeUpdate(); 747 748 oDlte.close(); 749 } 751 DBSubset oAttachs = new DBSubset(DB.k_contact_attachs, DB.gu_product, DB.gu_contact + "='" + sContactGUID + "'" , 64); 752 int iAttachs = oAttachs.load(oConn); 753 754 if (DebugFile.trace) DebugFile.writeln("new Product()"); 755 756 Product oProd = new Product(); 757 758 for (int a=0;a<iAttachs; a++) { 759 oProd.replace(DB.gu_product, oAttachs.getString(0,a)); 760 oProd.delete(oConn); 761 } 763 oProd = null; 764 765 oAttachs = null; 766 767 Statement oStmt = oConn.createStatement(); 768 769 if (DebugFile.trace) 770 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_contact_attachs + " WHERE " + DB.gu_contact + "='" + sContactGUID + "')"); 771 772 oStmt.executeUpdate("DELETE FROM " + DB.k_contact_attachs + " WHERE " + DB.gu_contact + "='" + sContactGUID + "'"); 773 oStmt.close(); 774 775 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 776 oStmt = oConn.createStatement(); 777 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT k_sp_del_contact ('" + sContactGUID + "')"); 778 oStmt.executeQuery("SELECT k_sp_del_contact ('" + sContactGUID + "')"); 779 oStmt.close(); 780 bRetVal = true; 781 } 782 else { 783 if (DebugFile.trace) 784 DebugFile.writeln("Connection.prepareCall({ call k_sp_del_contact ('" + sContactGUID + "') }"); 785 786 CallableStatement oCall = oConn.prepareCall("{ call k_sp_del_contact ('" + sContactGUID + "') }"); 787 bRetVal = oCall.execute(); 788 oCall.close(); 789 } 790 791 if (DebugFile.trace) { 792 DebugFile.decIdent(); 793 DebugFile.writeln("End Contact.delete() : " + String.valueOf(bRetVal)); 794 } 795 796 return bRetVal; 797 } 799 809 public static boolean addLookupPassportType (Connection oConn, String sGuWorkArea, String sTpPassport, HashMap oTranslations) 810 throws SQLException { 811 return DBLanguages.addLookup(oConn,DB.k_contacts_lookup, sGuWorkArea, DB.tp_passport, sTpPassport, oTranslations); 812 } 813 814 824 public static boolean addLookupJobTitle (Connection oConn, String sGuWorkArea, String sDeTitle, HashMap oTranslations) 825 throws SQLException { 826 return DBLanguages.addLookup(oConn,DB.k_contacts_lookup, sGuWorkArea, DB.de_title, sDeTitle, oTranslations); 827 } 828 829 832 public static final short ClassId = 90; 833 } 834 | Popular Tags |