1 32 33 package com.knowgate.crm; 34 35 import java.sql.SQLException ; 36 import java.sql.CallableStatement ; 37 import java.sql.PreparedStatement ; 38 import java.sql.Statement ; 39 import java.sql.ResultSet ; 40 import java.sql.Types ; 41 42 import com.knowgate.debug.DebugFile; 43 import com.knowgate.jdc.JDCConnection; 44 import com.knowgate.misc.Gadgets; 45 import com.knowgate.dataobjs.DB; 46 import com.knowgate.dataobjs.DBCommand; 47 import com.knowgate.dataobjs.DBPersist; 48 49 import com.knowgate.hipergate.QueryByForm; 50 51 56 public class DistributionList extends DBPersist { 57 58 public DistributionList() { 59 super(DB.k_lists, "DistributionList"); 60 } 61 62 68 public DistributionList(JDCConnection oConn, String sListGUID) throws SQLException { 69 super(DB.k_lists, "DistributionList"); 70 load(oConn, new Object []{sListGUID}); 71 } 72 73 75 82 public DistributionList(JDCConnection oConn, String sListDesc, String sWorkAreaGUID) throws SQLException { 83 super(DB.k_lists, "DistributionList"); 84 85 String sListGUID; 86 PreparedStatement oStmt = oConn.prepareStatement("SELECT "+DB.gu_list+" FROM "+DB.k_lists+" WHERE "+DB.gu_workarea+"=? AND "+DB.de_list+"=?", 87 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 88 oStmt.setString(1, sWorkAreaGUID); 89 oStmt.setString(2, sListDesc); 90 ResultSet oRSet = oStmt.executeQuery(); 91 if (oRSet.next()) 92 sListGUID = oRSet.getString(1); 93 else 94 sListGUID = null; 95 oRSet.close(); 96 oStmt.close(); 97 98 if (null!=sListGUID) 99 load(oConn, new Object []{sListGUID}); 100 } 101 102 104 110 public int memberCount(JDCConnection oConn) throws SQLException { 111 112 if (DebugFile.trace) { 113 DebugFile.writeln("Begin DistributionList.memberCount([Connection])"); 114 DebugFile.incIdent(); 115 } 116 117 String sSQL; 118 String sTableName; 119 String sWhere; 120 Statement oStmt; 121 ResultSet oRSet; 122 int iCount; 123 124 String sBlackList = blackList(oConn); 125 126 if (getShort(DB.tp_list)==TYPE_DYNAMIC) { 127 sTableName = DB.k_member_address; 128 129 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "m", getString(DB.gu_query)); 130 131 sWhere = "m." + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "' AND "; 132 sWhere+= "(" + oQBF.composeSQL() + ") AND "; 133 sWhere+= " NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 134 135 oQBF = null; 136 } 137 else { 138 sTableName = DB.k_x_list_members; 139 sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND "; 140 sWhere+= "m." + DB.bo_active + "<>0 "; 141 142 if (getShort(DB.tp_list)!=TYPE_BLACK) 143 sWhere+= " AND NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 144 } 145 146 sSQL = "SELECT COUNT(*) FROM " + sTableName + " m WHERE " + sWhere; 147 148 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 149 150 try { oStmt.setQueryTimeout(120); } catch (SQLException sqle) { } 151 152 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 153 154 oRSet = oStmt.executeQuery(sSQL); 155 156 oRSet.next(); 157 158 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_ORACLE) 159 iCount = oRSet.getBigDecimal(1).intValue(); 160 else 161 iCount = oRSet.getInt(1); 162 163 oRSet.close(); 164 oStmt.close(); 165 166 if (DebugFile.trace) { 167 DebugFile.decIdent(); 168 DebugFile.writeln("End DistributionList.memberCount()"); 169 } 170 171 return iCount; 172 } 174 176 183 public String activeMembers(JDCConnection oConn) 184 throws SQLException ,IllegalStateException { 185 186 if (DebugFile.trace) { 187 DebugFile.writeln("Begin DistributionList.activeMembers([Connection])"); 188 if (isNull(DB.tp_list)) 189 throw new IllegalStateException ("DistributionList.activeMembers() list type not set"); 190 DebugFile.incIdent(); 191 } 192 193 String sSQL; 194 String sTableName; 195 String sWhere; 196 StringBuffer oBuffer; 197 Statement oStmt; 198 ResultSet oRSet; 199 200 String sBlackList = blackList(oConn); 201 202 if (getShort(DB.tp_list)==TYPE_DYNAMIC) { 203 sTableName = DB.k_member_address; 204 205 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "m", getString(DB.gu_query)); 206 207 sWhere = "m." + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "' AND "; 208 sWhere+= "(" + oQBF.composeSQL() + ") AND "; 209 sWhere+= " NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 210 211 oQBF = null; 212 } 213 else { 214 sTableName = DB.k_x_list_members; 215 sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND "; 216 sWhere+= "m." + DB.bo_active + "<>0 "; 217 218 if (getShort(DB.tp_list)!=TYPE_BLACK) 219 sWhere+= " AND NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 220 } 221 222 sSQL = "SELECT " + DB.tx_email + " FROM " + sTableName + " m WHERE " + sWhere; 223 224 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 225 226 try { oStmt.setQueryTimeout(120); } catch (SQLException sqle) { } 227 228 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 229 230 oRSet = oStmt.executeQuery(sSQL); 231 232 try { oRSet.setFetchSize(500); } catch (SQLException sqle) { } 233 234 oBuffer = new StringBuffer (4096); 235 236 if (oRSet.next()) 237 oBuffer.append(oRSet.getString(1)); 238 239 while (oRSet.next()) { 240 oBuffer.append(","); 241 oBuffer.append(oRSet.getString(1)); 242 } 244 oRSet.close(); 245 oStmt.close(); 246 247 if (DebugFile.trace) { 248 DebugFile.decIdent(); 249 DebugFile.writeln("End DistributionList.activeMembers()"); 250 } 251 252 return oBuffer.toString(); 253 } 255 257 263 264 public String activeContacts(JDCConnection oConn) throws SQLException { 265 266 if (getShort(DB.tp_list)==TYPE_DIRECT) 267 throw new SQLException ("Contacts cannot be directly retrived for DIRECT lists"); 268 269 if (DebugFile.trace) { 270 DebugFile.writeln("Begin DistributionList.activeContacts([Connection])"); 271 DebugFile.incIdent(); 272 } 273 274 String sSQL; 275 String sTableName = null; 276 String sWhere = null; 277 StringBuffer oBuffer; 278 Statement oStmt; 279 ResultSet oRSet; 280 281 String sBlackList = blackList(oConn); 282 283 if (getShort(DB.tp_list)==TYPE_DYNAMIC) { 284 sTableName = DB.k_member_address; 285 286 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "m", getString(DB.gu_query)); 287 288 sWhere = "m." + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "' AND "; 289 sWhere+= "(" + oQBF.composeSQL() + ") AND " + DB.gu_contact + " IS NOT NULL AND "; 290 sWhere+= " NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 291 292 oQBF = null; 293 } 294 else if (getShort(DB.tp_list)!=TYPE_DIRECT) { 295 sTableName = DB.k_x_list_members; 296 sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND "; 297 sWhere+= "m." + DB.bo_active + "<>0 AND " + DB.gu_contact + " IS NOT NULL "; 298 299 if (getShort(DB.tp_list)!=TYPE_BLACK) 300 sWhere+= " AND NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 301 } 302 303 sSQL = "SELECT " + DB.gu_contact + " FROM " + sTableName + " m WHERE " + sWhere; 304 305 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 306 307 try { oStmt.setQueryTimeout(120); } catch (SQLException sqle) { } 308 309 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 310 311 oRSet = oStmt.executeQuery(sSQL); 312 313 try { oRSet.setFetchSize(500); } catch (SQLException sqle) { } 314 315 oBuffer = new StringBuffer (4096); 316 317 if (oRSet.next()) 318 oBuffer.append(oRSet.getString(1)); 319 320 while (oRSet.next()) { 321 oBuffer.append(","); 322 oBuffer.append(oRSet.getString(1)); 323 } 325 oRSet.close(); 326 oStmt.close(); 327 328 if (DebugFile.trace) { 329 DebugFile.decIdent(); 330 DebugFile.writeln("End DistributionList.activeContacts()"); 331 } 332 333 return oBuffer.toString(); 334 } 335 336 338 344 345 public String activeCompanies(JDCConnection oConn) throws SQLException { 346 347 if (getShort(DB.tp_list)==TYPE_DIRECT) 348 throw new SQLException ("Companies cannot be directly retrived for DIRECT lists"); 349 350 if (DebugFile.trace) { 351 DebugFile.writeln("Begin DistributionList.activeCompanies([Connection])"); 352 DebugFile.incIdent(); 353 } 354 355 String sBlackList = blackList(oConn); 356 357 String sSQL; 358 String sTableName; 359 String sWhere; 360 StringBuffer oBuffer; 361 Statement oStmt; 362 ResultSet oRSet; 363 364 if (getShort(DB.tp_list)==TYPE_DYNAMIC) { 365 sTableName = DB.k_member_address; 366 367 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "m", getString(DB.gu_query)); 368 369 sWhere = "m." + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "' AND "; 370 sWhere+= "(" + oQBF.composeSQL() + ") AND " + DB.gu_company + " IS NOT NULL AND "; 371 sWhere+= " NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 372 373 oQBF = null; 374 } 375 else { 376 sTableName = DB.k_x_list_members; 377 sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND "; 378 sWhere+= "m." + DB.bo_active + "<>0 AND " + DB.gu_company + " IS NOT NULL "; 379 380 if (getShort(DB.tp_list)!=TYPE_BLACK) 381 sWhere+= " AND NOT EXISTS (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " b WHERE b." + DB.gu_list + "='" + sBlackList + "' AND b." + DB.tx_email + "=m." + DB.tx_email + ")"; 382 } 383 384 sSQL = "SELECT " + DB.gu_company + " FROM " + sTableName + " m WHERE " + sWhere; 385 386 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 387 388 try { oStmt.setQueryTimeout(120); } catch (SQLException sqle) { } 389 390 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 391 392 oRSet = oStmt.executeQuery(sSQL); 393 394 try { oRSet.setFetchSize(500); } catch (SQLException sqle) { } 395 396 oBuffer = new StringBuffer (4096); 397 398 if (oRSet.next()) 399 oBuffer.append(oRSet.getString(1)); 400 401 while (oRSet.next()) { 402 oBuffer.append(","); 403 oBuffer.append(oRSet.getString(1)); 404 } 406 oRSet.close(); 407 oStmt.close(); 408 409 if (DebugFile.trace) { 410 DebugFile.decIdent(); 411 DebugFile.writeln("End DistributionList.activeCompanies()"); 412 } 413 414 return oBuffer.toString(); 415 } 417 419 432 public boolean contains (JDCConnection oConn, String sMember) throws SQLException { 433 boolean bRetVal; 434 PreparedStatement oStmt; 435 ResultSet oRSet; 436 QueryByForm oQBF; 437 438 if (DebugFile.trace) { 439 DebugFile.writeln("Begin DistributionList.contains([Connection], " + sMember + ")"); 440 DebugFile.incIdent(); 441 } 442 443 switch (getShort(DB.tp_list)) { 444 445 case TYPE_DYNAMIC: 446 oQBF = new QueryByForm(oConn, DB.k_member_address, "ma", getString (DB.gu_query)); 447 448 if (DebugFile.trace) 449 DebugFile.writeln("Connection.prepareStatement(SELECT NULL FROM " + DB.k_member_address + " ma WHERE ma." + DB.gu_workarea + "=? AND (ma." + DB.gu_contact + "='" + sMember + "' OR ma." + DB.gu_company + "='" + sMember + "') AND (" + oQBF.composeSQL() + "))"); 450 451 oStmt = oConn.prepareStatement("SELECT NULL FROM " + DB.k_member_address + " ma WHERE ma." + DB.gu_workarea + "=? AND (ma." + DB.gu_contact + "=? OR ma." + DB.gu_company + "=?) AND (" + oQBF.composeSQL() + ")", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 452 453 oStmt.setString(1, getString(DB.gu_workarea)); 454 oStmt.setString(2, sMember); 455 oStmt.setString(3, sMember); 456 oRSet = oStmt.executeQuery(); 457 bRetVal = oRSet.next(); 458 oRSet.close(); 459 oStmt.close(); 460 461 oQBF = null; 462 break; 463 464 case TYPE_STATIC: 465 466 if (DebugFile.trace) 467 DebugFile.writeln("Connection.prepareStatement(SELECT NULL FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "' AND (" + DB.gu_contact + "='" + sMember + "' OR " + DB.gu_company + "='" + sMember + "'))"); 468 469 oStmt = oConn.prepareStatement("SELECT NULL FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "=? AND (" + DB.gu_contact + "=? OR " + DB.gu_company + "=?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 470 oStmt.setString(1, getString(DB.gu_list)); 471 oStmt.setString(2, sMember); 472 oStmt.setString(3, sMember); 473 oRSet = oStmt.executeQuery(); 474 bRetVal = oRSet.next(); 475 oRSet.close(); 476 oStmt.close(); 477 break; 478 479 case TYPE_DIRECT: 480 case TYPE_BLACK: 481 482 if (DebugFile.trace) 483 DebugFile.writeln("Connection.prepareStatement(SELECT NULL FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "=? AND " + DB.tx_email + "='" + sMember + "')"); 484 485 oStmt = oConn.prepareStatement("SELECT NULL FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "=? AND " + DB.tx_email + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 486 oStmt.setString(1, getString(DB.gu_list)); 487 oStmt.setString(2, sMember); 488 oRSet = oStmt.executeQuery(); 489 bRetVal = oRSet.next(); 490 oRSet.close(); 491 oStmt.close(); 492 break; 493 494 default: 495 throw new java.lang.IllegalArgumentException ("DistributionList.contains() invalid value of tp_list property"); 496 } 497 498 if (DebugFile.trace) { 499 DebugFile.decIdent(); 500 DebugFile.writeln("End DistributionList.contains() : " + String.valueOf(bRetVal)); 501 } 502 return bRetVal; 503 } 504 505 507 513 public boolean store(JDCConnection oConn) throws SQLException { 514 515 if (!AllVals.containsKey(DB.gu_list)) 516 put(DB.gu_list, Gadgets.generateUUID()); 517 518 return super.store(oConn); 519 } 521 523 public boolean delete(JDCConnection oConn) throws SQLException { 524 return DistributionList.delete(oConn, getString(DB.gu_list)); 525 } 527 529 537 public String blackList(JDCConnection oConn) throws SQLException , IllegalStateException { 538 PreparedStatement oStmt; 539 ResultSet oRSet; 540 String sBlackListId; 541 542 if (DebugFile.trace) { 543 DebugFile.writeln("Begin DistributionList.blackList([Connection])"); 544 if (isNull(DB.gu_workarea)) 545 throw new IllegalStateException ("DistributionList.blackList() workarea is not set"); 546 if (isNull(DB.gu_list)) 547 throw new IllegalStateException ("DistributionList.blackList() list GUID is not set"); 548 DebugFile.incIdent(); 549 } 550 551 oStmt = oConn.prepareStatement("SELECT " + DB.gu_list + " FROM " + DB.k_lists + " WHERE " + DB.gu_workarea + "=? AND " + DB.tp_list + "=" + String.valueOf(TYPE_BLACK) + " AND " + DB.gu_query + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 552 553 try { oStmt.setQueryTimeout(10); } catch (SQLException e) { } 554 555 oStmt.setString(1, getString(DB.gu_workarea)); 556 oStmt.setString(2, getString(DB.gu_list)); 557 558 try { oStmt.setQueryTimeout(20); } catch (SQLException sqle) { } 559 560 oRSet = oStmt.executeQuery(); 561 562 if (oRSet.next()) 563 sBlackListId = oRSet.getString(1); 564 else 565 sBlackListId = null; 566 567 oRSet.close(); 568 oStmt.close(); 569 570 if (DebugFile.trace) { 571 DebugFile.decIdent(); 572 DebugFile.writeln("End DistributionList.blackList() : " + (sBlackListId!=null ? sBlackListId : "null")); 573 } 574 575 return sBlackListId; 576 } 578 580 591 public void append(JDCConnection oConn, String sListGUID) throws SQLException ,IllegalArgumentException ,IllegalStateException ,ClassCastException { 592 Statement oInsrt; 593 String sSQL; 594 String sColumnList; 595 DistributionList oAppendedList; 596 597 if (DebugFile.trace) { 598 DebugFile.writeln("Begin DistributionList.append([Connection], " + (sListGUID!=null ? sListGUID : "null") + ")"); 599 DebugFile.incIdent(); 600 } 601 602 if (null==sListGUID) 603 throw new IllegalArgumentException ("list id cannot be null"); 604 605 if (null==get(DB.gu_list)) 606 throw new IllegalStateException ("list id not set"); 607 608 if (getShort(DB.tp_list)==DistributionList.TYPE_DYNAMIC) 609 throw new ClassCastException ("append operation not supported for Dynamic lists"); 610 611 if (sListGUID.equals(getString(DB.gu_list))) return; 612 613 oAppendedList = new DistributionList(oConn, sListGUID); 614 615 618 oInsrt = oConn.createStatement(); 619 620 try { oInsrt.setQueryTimeout(120); } catch (SQLException sqle) { } 621 622 if (oAppendedList.getShort(DB.tp_list)==TYPE_DYNAMIC) { 623 624 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "ma", oAppendedList.getString(DB.gu_query)); 626 sColumnList = DB.tx_email + "," + DB.tx_name + "," + DB.tx_surname + "," + DB.tx_salutation + "," + DB.gu_company + "," + DB.gu_contact; 627 628 sSQL = "INSERT INTO " + DB.k_x_list_members + " ("+DB.gu_list+"," + sColumnList + ") " + 629 "SELECT '" + getString(DB.gu_list) + "'," + sColumnList + " FROM " + DB.k_member_address + " ma WHERE ma.gu_workarea='" + oAppendedList.getString(DB.gu_workarea) + "' AND (" + oQBF.composeSQL() + ") AND " + 630 "ma." + DB.tx_email + " NOT IN (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "')"; 631 } 632 633 else { 634 635 sColumnList = DB.tx_email + "," + DB.tx_name + "," + DB.tx_surname + "," + DB.tx_salutation + "," + DB.bo_active + "," + DB.gu_company + "," + DB.gu_contact + "," + DB.id_format; 636 637 sSQL = "INSERT INTO " + DB.k_x_list_members + " ("+DB.gu_list+"," + sColumnList + ") " + 638 "SELECT '" + getString(DB.gu_list) + "'," + sColumnList + " FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + sListGUID + "' AND " + 639 DB.tx_email + " NOT IN (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "')"; 640 641 } 642 643 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 644 645 oInsrt.execute(sSQL); 646 oInsrt.close(); 647 648 if (DebugFile.trace) { 649 DebugFile.decIdent(); 650 DebugFile.writeln("End DistributionList.append()"); 651 } 652 } 654 656 665 public void overwrite(JDCConnection oConn, String sListGUID) throws SQLException ,IllegalArgumentException ,ClassCastException ,IllegalStateException { 666 Statement oInsrt; 667 PreparedStatement oUpdt; 668 ResultSet oRSet; 669 String sSQL; 670 String sColumnList; 671 DistributionList oAppendedList; 672 673 if (DebugFile.trace) { 674 DebugFile.writeln("Begin DistributionList.overwrite([Connection], " + (sListGUID!=null ? sListGUID : "null") + ")"); 675 DebugFile.incIdent(); 676 } 677 678 if (null==sListGUID) 679 throw new IllegalArgumentException ("list id cannot be null"); 680 681 if (null==get(DB.gu_list)) 682 throw new IllegalStateException ("list id not set"); 683 684 if (getShort(DB.tp_list)==DistributionList.TYPE_DYNAMIC) 685 throw new ClassCastException ("overwrite operation not supported for Dynamic lists"); 686 687 if (sListGUID.equals(getString(DB.gu_list))) return; 688 689 oAppendedList = new DistributionList(oConn, sListGUID); 690 691 sColumnList = DB.tx_email + "," + DB.tx_name + "," + DB.tx_surname + "," + DB.tx_salutation + "," + DB.bo_active + "," + DB.gu_company + "," + DB.gu_contact + "," + DB.id_format; 692 693 696 sSQL = "UPDATE " + DB.k_x_list_members + " SET " + DB.tx_name + "=?," + DB.tx_surname + "=?," + DB.tx_salutation + "=?," + DB.bo_active + "=?," + DB.gu_company + "=?," + DB.gu_contact + "=?," + DB.id_format + "=? WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "' AND " + DB.tx_email + "=?"; 698 699 if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")"); 700 701 oUpdt = oConn.prepareStatement(sSQL); 702 703 oInsrt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 705 706 try { oInsrt.setQueryTimeout(60); } catch (SQLException sqle) { } 707 708 if (oAppendedList.getShort(DB.tp_list)==TYPE_DYNAMIC) { 709 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "b", oAppendedList.getString(DB.gu_query)); 710 711 sSQL = "SELECT b." + DB.tx_name + ",b." + DB.tx_surname + ",b." + DB.tx_salutation + ",1,b." + DB.gu_company + ",b." + DB.gu_contact + ",'TXT', a." + DB.tx_email + " FROM " + DB.k_x_list_members + " a, " + DB.k_member_address + " b WHERE a." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND b." + DB.gu_workarea + "='" + oAppendedList.getString(DB.gu_workarea) + "' AND (" + oQBF.composeSQL() + ") AND a." + DB.tx_email + "=b." + DB.tx_email; 712 } 713 else 714 sSQL = "SELECT b." + DB.tx_name + ",b." + DB.tx_surname + ",b." + DB.tx_salutation + ",b." + DB.bo_active + ",b." + DB.gu_company + ",b." + DB.gu_contact + ",b." + DB.id_format + ", a." + DB.tx_email + " FROM " + DB.k_x_list_members + " a, " + DB.k_x_list_members + " b WHERE a." + DB.gu_list + "='" + getString(DB.gu_list) + "' AND b." + DB.gu_list + "='" + sListGUID + "' AND a." + DB.tx_email + "=b." + DB.tx_email; 715 716 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 717 718 oRSet = oInsrt.executeQuery(sSQL); 719 720 while (oRSet.next()) { 723 oUpdt.setObject(1, oRSet.getObject(1), Types.VARCHAR); oUpdt.setObject(2, oRSet.getObject(2), Types.VARCHAR); oUpdt.setObject(3, oRSet.getObject(3), Types.VARCHAR); oUpdt.setObject(4, oRSet.getObject(4), Types.SMALLINT); oUpdt.setObject(5, oRSet.getObject(5), Types.VARCHAR); oUpdt.setObject(6, oRSet.getObject(6), Types.VARCHAR); oUpdt.setObject(7, oRSet.getObject(7), Types.VARCHAR); oUpdt.setObject(8, oRSet.getObject(8), Types.VARCHAR); oUpdt.executeUpdate(); 732 } 734 oInsrt.close(); 735 oUpdt.close(); 736 737 if (DebugFile.trace) { 738 DebugFile.decIdent(); 739 DebugFile.writeln("End DistributionList.overwrite()"); 740 } 741 } 743 745 753 public void substract(JDCConnection oConn, String sListGUID) throws SQLException ,IllegalArgumentException ,IllegalStateException ,ClassCastException { 754 String sSQL; 755 Statement oDlte; 756 DistributionList oAppendedList; 757 758 if (DebugFile.trace) { 759 DebugFile.writeln("Begin DistributionList.substract([Connection], " + (sListGUID!=null ? sListGUID : "null") + ")"); 760 DebugFile.incIdent(); 761 } 762 763 if (null==sListGUID) 764 throw new IllegalArgumentException ("list id cannot be null"); 765 766 if (null==get(DB.gu_list)) 767 throw new IllegalStateException ("list id not set"); 768 769 if (getShort(DB.tp_list)==DistributionList.TYPE_DYNAMIC) 770 throw new ClassCastException ("substract operation not supported for Dynamic lists"); 771 772 oAppendedList = new DistributionList(oConn, sListGUID); 773 774 if (sListGUID.equals(getString(DB.gu_list))) 775 776 sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "'"; 777 778 else if (oAppendedList.getShort(DB.tp_list)==TYPE_DYNAMIC) { 779 780 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "ma", oAppendedList.getString(DB.gu_query)); 781 782 sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "' AND " + DB.tx_email + " IN (SELECT " + DB.tx_email + " FROM " + DB.k_member_address + " ma WHERE ma." + DB.gu_workarea + "='" + oAppendedList.getString(DB.gu_workarea) + "' AND (" + oQBF.composeSQL() + "))"; 783 } 784 785 else 786 787 sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "' AND " + DB.tx_email + " IN (SELECT " + DB.tx_email + " FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + sListGUID + "')"; 788 789 oDlte = oConn.createStatement(); 790 791 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 792 793 oDlte.execute(sSQL); 794 795 oDlte.close(); 796 797 if (DebugFile.trace) { 798 DebugFile.decIdent(); 799 DebugFile.writeln("End DistributionList.substract()"); 800 } 801 } 803 805 812 public String clone(JDCConnection oConn) throws SQLException { 813 String sSQL; 814 String sCloneId; 815 Statement oStmt; 816 DistributionList oClone; 817 818 if (DebugFile.trace) { 819 DebugFile.writeln("Begin DistributionList.clone()"); 820 DebugFile.incIdent(); 821 } 822 823 oClone = new DistributionList(oConn, getString(DB.gu_list)); 824 825 oClone.remove(DB.gu_list); 826 oClone.store(oConn); 827 828 sCloneId = oClone.getString(DB.gu_list); 829 830 oStmt = oConn.createStatement(); 831 oStmt.setQueryTimeout(60); 832 833 sSQL = "INSERT INTO " + DB.k_x_list_members + "(gu_list,tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format) SELECT '" + oClone.getString(DB.gu_list) + "',tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + getString(DB.gu_list) + "'"; 834 835 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 836 837 oStmt.execute(sSQL); 838 839 String sBlackList = blackList(oConn); 840 841 if (null!=sBlackList) { 842 oClone = new DistributionList(oConn, sBlackList); 843 844 oClone.remove(DB.gu_list); 845 oClone.replace(DB.gu_query, sCloneId); 846 oClone.store(oConn); 847 848 sSQL = "INSERT INTO " + DB.k_x_list_members + "(gu_list,tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format) SELECT '" + oClone.getString(DB.gu_list) + "',tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format FROM " + DB.k_x_list_members + " WHERE " + DB.gu_list + "='" + sBlackList + "'"; 849 850 if (DebugFile.trace) DebugFile.writeln("Statement.execute(" + sSQL + ")"); 851 852 oStmt.execute(sSQL); 853 } 855 oStmt.close(); 856 857 if (DebugFile.trace) { 858 DebugFile.decIdent(); 859 DebugFile.writeln("End DistributionList.clone() : " + sCloneId); 860 } 861 return sCloneId; 862 } 864 866 873 public String print(JDCConnection oConn, boolean bPrintHeader) throws SQLException { 874 String sSQL; 875 String sColumnList; 876 String sTableName; 877 String sWhere; 878 StringBuffer oBuffer; 879 Statement oStmt; 880 ResultSet oRSet; 881 Object oFld; 882 883 885 if (DebugFile.trace) { 886 DebugFile.writeln("Begin DistributionList.print([Connection])"); 887 DebugFile.incIdent(); 888 } 889 890 oBuffer = new StringBuffer (); 891 892 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 893 894 try { oStmt.setQueryTimeout(120); } catch (SQLException sqle) { } 895 896 sColumnList = "m." + DB.tx_email + ",m." + DB.tx_name + ",m." + DB.tx_surname + ",m." + DB.tx_salutation + ",m." + DB.bo_active + ",m." + DB.gu_company + ",m." + DB.gu_contact + ",m." + DB.dt_modified; 897 898 if (getShort(DB.tp_list)==TYPE_DYNAMIC) { 899 sTableName = DB.k_member_address; 900 901 QueryByForm oQBF = new QueryByForm(oConn, DB.k_member_address, "m", getString(DB.gu_query)); 902 903 sWhere = "m." + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "' AND (" + oQBF.composeSQL() + ")"; 904 905 oQBF = null; 906 } 907 else { 908 sTableName = DB.k_x_list_members; 909 sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list) + "'"; 910 } 911 912 sSQL = "SELECT " + sColumnList + " FROM " + sTableName + " m WHERE " + sWhere; 913 914 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")"); 915 916 oRSet = oStmt.executeQuery(sSQL); 917 918 try { oRSet.setFetchSize(500); } catch (SQLException sqle) { } 919 920 if (bPrintHeader) oBuffer.append(sColumnList + "\n"); 921 922 while (oRSet.next()) { 923 oBuffer.append(oRSet.getString(1)); 924 oBuffer.append(","); 925 926 oFld = oRSet.getObject(2); if (!oRSet.wasNull()) oBuffer.append(oFld); 928 oBuffer.append(","); 929 930 oFld = oRSet.getObject(3); if (!oRSet.wasNull()) oBuffer.append(oFld); 932 oBuffer.append(","); 933 934 oFld = oRSet.getObject(4); if (!oRSet.wasNull()) oBuffer.append(oFld); 936 oBuffer.append(","); 937 938 oBuffer.append(String.valueOf(oRSet.getShort(5))); 939 oBuffer.append(","); 940 941 oFld = oRSet.getObject(6); if (!oRSet.wasNull()) oBuffer.append(oFld); 943 oBuffer.append(","); 944 945 oFld = oRSet.getObject(7); if (!oRSet.wasNull()) oBuffer.append(oFld); 947 oBuffer.append(","); 948 949 oBuffer.append(oRSet.getString(8)); 950 oBuffer.append("\n"); 951 } 953 oRSet.close(); 954 oStmt.close(); 955 956 if (DebugFile.trace) { 957 DebugFile.decIdent(); 958 DebugFile.writeln("End DistributionList.print()"); 959 } 960 961 return oBuffer.toString(); 962 } 964 966 969 977 public static boolean delete(JDCConnection oConn, String sListGUID) throws SQLException { 978 boolean bRetVal; 979 980 if (DebugFile.trace) { 981 DebugFile.writeln("Begin DistributionList.delete([Connection]," + sListGUID + ")"); 982 DebugFile.incIdent(); 983 } 984 985 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 986 Statement oStmt = oConn.createStatement(); 987 oStmt.executeQuery("SELECT k_sp_del_list ('" + sListGUID + "')"); 988 oStmt.close(); 989 bRetVal = true; 990 } else { 991 CallableStatement oCall = oConn.prepareCall("{ call k_sp_del_list ('" + sListGUID + "') }"); 992 bRetVal = oCall.execute(); 993 oCall.close(); 994 } 995 996 if (DebugFile.trace) { 997 DebugFile.decIdent(); 998 DebugFile.writeln("End DistributionList.delete() : " + String.valueOf(bRetVal)); 999 } 1000 1001 return bRetVal; 1002 } 1004 1007 public static final short ClassId = 96; 1008 1009 public static final short TYPE_STATIC=(short)1; 1010 public static final short TYPE_DYNAMIC=(short)2; 1011 public static final short TYPE_DIRECT=(short)3; 1012 public static final short TYPE_BLACK=(short)4; 1013} 1014
| Popular Tags
|