0001: /*
0002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
0003: C/Oña, 107 1º2 28050 Madrid (Spain)
0004:
0005: Redistribution and use in source and binary forms, with or without
0006: modification, are permitted provided that the following conditions
0007: are met:
0008:
0009: 1. Redistributions of source code must retain the above copyright
0010: notice, this list of conditions and the following disclaimer.
0011:
0012: 2. The end-user documentation included with the redistribution,
0013: if any, must include the following acknowledgment:
0014: "This product includes software parts from hipergate
0015: (http://www.hipergate.org/)."
0016: Alternately, this acknowledgment may appear in the software itself,
0017: if and wherever such third-party acknowledgments normally appear.
0018:
0019: 3. The name hipergate must not be used to endorse or promote products
0020: derived from this software without prior written permission.
0021: Products derived from this software may not be called hipergate,
0022: nor may hipergate appear in their name, without prior written
0023: permission.
0024:
0025: This library is distributed in the hope that it will be useful,
0026: but WITHOUT ANY WARRANTY; without even the implied warranty of
0027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0028:
0029: You should have received a copy of hipergate License with this code;
0030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
0031: */
0032:
0033: package com.knowgate.crm;
0034:
0035: import java.sql.SQLException;
0036: import java.sql.CallableStatement;
0037: import java.sql.PreparedStatement;
0038: import java.sql.Statement;
0039: import java.sql.ResultSet;
0040: import java.sql.Types;
0041:
0042: import com.knowgate.debug.DebugFile;
0043: import com.knowgate.jdc.JDCConnection;
0044: import com.knowgate.misc.Gadgets;
0045: import com.knowgate.dataobjs.DB;
0046: import com.knowgate.dataobjs.DBCommand;
0047: import com.knowgate.dataobjs.DBPersist;
0048:
0049: import com.knowgate.hipergate.QueryByForm;
0050:
0051: /**
0052: * <p>Distribution List</p>
0053: * @author Sergio Montoro Ten
0054: * @version 3.0
0055: */
0056: public class DistributionList extends DBPersist {
0057:
0058: public DistributionList() {
0059: super (DB.k_lists, "DistributionList");
0060: }
0061:
0062: /**
0063: * Create and load distribution list
0064: * @param oConn JDCConnection HDBC Connection
0065: * @param sListGUID String List GUID
0066: * @throws SQLException
0067: */
0068: public DistributionList(JDCConnection oConn, String sListGUID)
0069: throws SQLException {
0070: super (DB.k_lists, "DistributionList");
0071: load(oConn, new Object[] { sListGUID });
0072: }
0073:
0074: // ----------------------------------------------------------
0075:
0076: /**
0077: * Create a distribution list and load its by name
0078: * @param oConn JDCConnection JDBC Connection
0079: * @param sListDesc String List Description
0080: * @param sWorkAreaGUID String GUID of WorkArea to which list belongs
0081: * @throws SQLException
0082: */
0083: public DistributionList(JDCConnection oConn, String sListDesc,
0084: String sWorkAreaGUID) throws SQLException {
0085: super (DB.k_lists, "DistributionList");
0086:
0087: String sListGUID;
0088: PreparedStatement oStmt = oConn
0089: .prepareStatement("SELECT " + DB.gu_list + " FROM "
0090: + DB.k_lists + " WHERE " + DB.gu_workarea
0091: + "=? AND " + DB.de_list + "=?",
0092: ResultSet.TYPE_FORWARD_ONLY,
0093: ResultSet.CONCUR_READ_ONLY);
0094: oStmt.setString(1, sWorkAreaGUID);
0095: oStmt.setString(2, sListDesc);
0096: ResultSet oRSet = oStmt.executeQuery();
0097: if (oRSet.next())
0098: sListGUID = oRSet.getString(1);
0099: else
0100: sListGUID = null;
0101: oRSet.close();
0102: oStmt.close();
0103:
0104: if (null != sListGUID)
0105: load(oConn, new Object[] { sListGUID });
0106: }
0107:
0108: // ----------------------------------------------------------
0109:
0110: /**
0111: * Count active members of this list
0112: * @param oConn JDBC Database Connection
0113: * @return Count of members of this list which bo_active field is not zero.
0114: * @throws SQLException
0115: */
0116: public int memberCount(JDCConnection oConn) throws SQLException {
0117:
0118: if (DebugFile.trace) {
0119: DebugFile
0120: .writeln("Begin DistributionList.memberCount([Connection])");
0121: DebugFile.incIdent();
0122: }
0123:
0124: String sSQL;
0125: String sTableName;
0126: String sWhere;
0127: Statement oStmt;
0128: ResultSet oRSet;
0129: int iCount;
0130:
0131: String sBlackList = blackList(oConn);
0132:
0133: if (getShort(DB.tp_list) == TYPE_DYNAMIC) {
0134: sTableName = DB.k_member_address;
0135:
0136: QueryByForm oQBF = new QueryByForm(oConn,
0137: DB.k_member_address, "m", getString(DB.gu_query));
0138:
0139: sWhere = "m." + DB.gu_workarea + "='"
0140: + getString(DB.gu_workarea) + "' AND ";
0141: sWhere += "(" + oQBF.composeSQL() + ") AND ";
0142: sWhere += " NOT EXISTS (SELECT " + DB.tx_email + " FROM "
0143: + DB.k_x_list_members + " b WHERE b." + DB.gu_list
0144: + "='" + sBlackList + "' AND b." + DB.tx_email
0145: + "=m." + DB.tx_email + ")";
0146:
0147: oQBF = null;
0148: } else {
0149: sTableName = DB.k_x_list_members;
0150: sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list)
0151: + "' AND ";
0152: sWhere += "m." + DB.bo_active + "<>0 ";
0153:
0154: if (getShort(DB.tp_list) != TYPE_BLACK)
0155: sWhere += " AND NOT EXISTS (SELECT " + DB.tx_email
0156: + " FROM " + DB.k_x_list_members
0157: + " b WHERE b." + DB.gu_list + "='"
0158: + sBlackList + "' AND b." + DB.tx_email + "=m."
0159: + DB.tx_email + ")";
0160: }
0161:
0162: sSQL = "SELECT COUNT(*) FROM " + sTableName + " m WHERE "
0163: + sWhere;
0164:
0165: oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
0166: ResultSet.CONCUR_READ_ONLY);
0167:
0168: try {
0169: oStmt.setQueryTimeout(120);
0170: } catch (SQLException sqle) { /* ignore */
0171: }
0172:
0173: if (DebugFile.trace)
0174: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
0175:
0176: oRSet = oStmt.executeQuery(sSQL);
0177:
0178: oRSet.next();
0179:
0180: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_ORACLE)
0181: iCount = oRSet.getBigDecimal(1).intValue();
0182: else
0183: iCount = oRSet.getInt(1);
0184:
0185: oRSet.close();
0186: oStmt.close();
0187:
0188: if (DebugFile.trace) {
0189: DebugFile.decIdent();
0190: DebugFile.writeln("End DistributionList.memberCount()");
0191: }
0192:
0193: return iCount;
0194: } // memberCount
0195:
0196: // ----------------------------------------------------------
0197:
0198: /**
0199: * Get e-mail address for all active members
0200: * @param oConn JDBC Database Connection
0201: * @return String with e-mail addresses delimited by commas
0202: * @throws SQLException
0203: * @throws IllegalStateException
0204: */
0205: public String activeMembers(JDCConnection oConn)
0206: throws SQLException, IllegalStateException {
0207:
0208: if (DebugFile.trace) {
0209: DebugFile
0210: .writeln("Begin DistributionList.activeMembers([Connection])");
0211: if (isNull(DB.tp_list))
0212: throw new IllegalStateException(
0213: "DistributionList.activeMembers() list type not set");
0214: DebugFile.incIdent();
0215: }
0216:
0217: String sSQL;
0218: String sTableName;
0219: String sWhere;
0220: StringBuffer oBuffer;
0221: Statement oStmt;
0222: ResultSet oRSet;
0223:
0224: String sBlackList = blackList(oConn);
0225:
0226: if (getShort(DB.tp_list) == TYPE_DYNAMIC) {
0227: sTableName = DB.k_member_address;
0228:
0229: QueryByForm oQBF = new QueryByForm(oConn,
0230: DB.k_member_address, "m", getString(DB.gu_query));
0231:
0232: sWhere = "m." + DB.gu_workarea + "='"
0233: + getString(DB.gu_workarea) + "' AND ";
0234: sWhere += "(" + oQBF.composeSQL() + ") AND ";
0235: sWhere += " NOT EXISTS (SELECT " + DB.tx_email + " FROM "
0236: + DB.k_x_list_members + " b WHERE b." + DB.gu_list
0237: + "='" + sBlackList + "' AND b." + DB.tx_email
0238: + "=m." + DB.tx_email + ")";
0239:
0240: oQBF = null;
0241: } else {
0242: sTableName = DB.k_x_list_members;
0243: sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list)
0244: + "' AND ";
0245: sWhere += "m." + DB.bo_active + "<>0 ";
0246:
0247: if (getShort(DB.tp_list) != TYPE_BLACK)
0248: sWhere += " AND NOT EXISTS (SELECT " + DB.tx_email
0249: + " FROM " + DB.k_x_list_members
0250: + " b WHERE b." + DB.gu_list + "='"
0251: + sBlackList + "' AND b." + DB.tx_email + "=m."
0252: + DB.tx_email + ")";
0253: }
0254:
0255: sSQL = "SELECT " + DB.tx_email + " FROM " + sTableName
0256: + " m WHERE " + sWhere;
0257:
0258: oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
0259: ResultSet.CONCUR_READ_ONLY);
0260:
0261: try {
0262: oStmt.setQueryTimeout(120);
0263: } catch (SQLException sqle) { /* ignore */
0264: }
0265:
0266: if (DebugFile.trace)
0267: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
0268:
0269: oRSet = oStmt.executeQuery(sSQL);
0270:
0271: try {
0272: oRSet.setFetchSize(500);
0273: } catch (SQLException sqle) { /* ignore */
0274: }
0275:
0276: oBuffer = new StringBuffer(4096);
0277:
0278: if (oRSet.next())
0279: oBuffer.append(oRSet.getString(1));
0280:
0281: while (oRSet.next()) {
0282: oBuffer.append(",");
0283: oBuffer.append(oRSet.getString(1));
0284: } // wend
0285:
0286: oRSet.close();
0287: oStmt.close();
0288:
0289: if (DebugFile.trace) {
0290: DebugFile.decIdent();
0291: DebugFile.writeln("End DistributionList.activeMembers()");
0292: }
0293:
0294: return oBuffer.toString();
0295: } // activeMembers
0296:
0297: // ----------------------------------------------------------
0298:
0299: /**
0300: * Get GUIDs for all active contacts
0301: * @param oConn JDBC Database Connection
0302: * @return String with GUIDs delimited by commas
0303: * @throws SQLException
0304: */
0305:
0306: public String activeContacts(JDCConnection oConn)
0307: throws SQLException {
0308:
0309: if (getShort(DB.tp_list) == TYPE_DIRECT)
0310: throw new SQLException(
0311: "Contacts cannot be directly retrived for DIRECT lists");
0312:
0313: if (DebugFile.trace) {
0314: DebugFile
0315: .writeln("Begin DistributionList.activeContacts([Connection])");
0316: DebugFile.incIdent();
0317: }
0318:
0319: String sSQL;
0320: String sTableName = null;
0321: String sWhere = null;
0322: StringBuffer oBuffer;
0323: Statement oStmt;
0324: ResultSet oRSet;
0325:
0326: String sBlackList = blackList(oConn);
0327:
0328: if (getShort(DB.tp_list) == TYPE_DYNAMIC) {
0329: sTableName = DB.k_member_address;
0330:
0331: QueryByForm oQBF = new QueryByForm(oConn,
0332: DB.k_member_address, "m", getString(DB.gu_query));
0333:
0334: sWhere = "m." + DB.gu_workarea + "='"
0335: + getString(DB.gu_workarea) + "' AND ";
0336: sWhere += "(" + oQBF.composeSQL() + ") AND "
0337: + DB.gu_contact + " IS NOT NULL AND ";
0338: sWhere += " NOT EXISTS (SELECT " + DB.tx_email + " FROM "
0339: + DB.k_x_list_members + " b WHERE b." + DB.gu_list
0340: + "='" + sBlackList + "' AND b." + DB.tx_email
0341: + "=m." + DB.tx_email + ")";
0342:
0343: oQBF = null;
0344: } else if (getShort(DB.tp_list) != TYPE_DIRECT) {
0345: sTableName = DB.k_x_list_members;
0346: sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list)
0347: + "' AND ";
0348: sWhere += "m." + DB.bo_active + "<>0 AND " + DB.gu_contact
0349: + " IS NOT NULL ";
0350:
0351: if (getShort(DB.tp_list) != TYPE_BLACK)
0352: sWhere += " AND NOT EXISTS (SELECT " + DB.tx_email
0353: + " FROM " + DB.k_x_list_members
0354: + " b WHERE b." + DB.gu_list + "='"
0355: + sBlackList + "' AND b." + DB.tx_email + "=m."
0356: + DB.tx_email + ")";
0357: }
0358:
0359: sSQL = "SELECT " + DB.gu_contact + " FROM " + sTableName
0360: + " m WHERE " + sWhere;
0361:
0362: oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
0363: ResultSet.CONCUR_READ_ONLY);
0364:
0365: try {
0366: oStmt.setQueryTimeout(120);
0367: } catch (SQLException sqle) { /* ignore */
0368: }
0369:
0370: if (DebugFile.trace)
0371: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
0372:
0373: oRSet = oStmt.executeQuery(sSQL);
0374:
0375: try {
0376: oRSet.setFetchSize(500);
0377: } catch (SQLException sqle) { /* ignore */
0378: }
0379:
0380: oBuffer = new StringBuffer(4096);
0381:
0382: if (oRSet.next())
0383: oBuffer.append(oRSet.getString(1));
0384:
0385: while (oRSet.next()) {
0386: oBuffer.append(",");
0387: oBuffer.append(oRSet.getString(1));
0388: } // wend
0389:
0390: oRSet.close();
0391: oStmt.close();
0392:
0393: if (DebugFile.trace) {
0394: DebugFile.decIdent();
0395: DebugFile.writeln("End DistributionList.activeContacts()");
0396: }
0397:
0398: return oBuffer.toString();
0399: }
0400:
0401: // ----------------------------------------------------------
0402:
0403: /**
0404: * Get GUIDs for all active companies
0405: * @param oConn JDBC Database Connection
0406: * @return String with GUIDs delimited by commas
0407: * @throws SQLException
0408: */
0409:
0410: public String activeCompanies(JDCConnection oConn)
0411: throws SQLException {
0412:
0413: if (getShort(DB.tp_list) == TYPE_DIRECT)
0414: throw new SQLException(
0415: "Companies cannot be directly retrived for DIRECT lists");
0416:
0417: if (DebugFile.trace) {
0418: DebugFile
0419: .writeln("Begin DistributionList.activeCompanies([Connection])");
0420: DebugFile.incIdent();
0421: }
0422:
0423: String sBlackList = blackList(oConn);
0424:
0425: String sSQL;
0426: String sTableName;
0427: String sWhere;
0428: StringBuffer oBuffer;
0429: Statement oStmt;
0430: ResultSet oRSet;
0431:
0432: if (getShort(DB.tp_list) == TYPE_DYNAMIC) {
0433: sTableName = DB.k_member_address;
0434:
0435: QueryByForm oQBF = new QueryByForm(oConn,
0436: DB.k_member_address, "m", getString(DB.gu_query));
0437:
0438: sWhere = "m." + DB.gu_workarea + "='"
0439: + getString(DB.gu_workarea) + "' AND ";
0440: sWhere += "(" + oQBF.composeSQL() + ") AND "
0441: + DB.gu_company + " IS NOT NULL AND ";
0442: sWhere += " NOT EXISTS (SELECT " + DB.tx_email + " FROM "
0443: + DB.k_x_list_members + " b WHERE b." + DB.gu_list
0444: + "='" + sBlackList + "' AND b." + DB.tx_email
0445: + "=m." + DB.tx_email + ")";
0446:
0447: oQBF = null;
0448: } else {
0449: sTableName = DB.k_x_list_members;
0450: sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list)
0451: + "' AND ";
0452: sWhere += "m." + DB.bo_active + "<>0 AND " + DB.gu_company
0453: + " IS NOT NULL ";
0454:
0455: if (getShort(DB.tp_list) != TYPE_BLACK)
0456: sWhere += " AND NOT EXISTS (SELECT " + DB.tx_email
0457: + " FROM " + DB.k_x_list_members
0458: + " b WHERE b." + DB.gu_list + "='"
0459: + sBlackList + "' AND b." + DB.tx_email + "=m."
0460: + DB.tx_email + ")";
0461: }
0462:
0463: sSQL = "SELECT " + DB.gu_company + " FROM " + sTableName
0464: + " m WHERE " + sWhere;
0465:
0466: oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
0467: ResultSet.CONCUR_READ_ONLY);
0468:
0469: try {
0470: oStmt.setQueryTimeout(120);
0471: } catch (SQLException sqle) { /* ignore */
0472: }
0473:
0474: if (DebugFile.trace)
0475: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
0476:
0477: oRSet = oStmt.executeQuery(sSQL);
0478:
0479: try {
0480: oRSet.setFetchSize(500);
0481: } catch (SQLException sqle) { /* ignore */
0482: }
0483:
0484: oBuffer = new StringBuffer(4096);
0485:
0486: if (oRSet.next())
0487: oBuffer.append(oRSet.getString(1));
0488:
0489: while (oRSet.next()) {
0490: oBuffer.append(",");
0491: oBuffer.append(oRSet.getString(1));
0492: } // wend
0493:
0494: oRSet.close();
0495: oStmt.close();
0496:
0497: if (DebugFile.trace) {
0498: DebugFile.decIdent();
0499: DebugFile.writeln("End DistributionList.activeCompanies()");
0500: }
0501:
0502: return oBuffer.toString();
0503: } // activeCompanies
0504:
0505: // ----------------------------------------------------------
0506:
0507: /**
0508: * <p>Find out if list contains a particular member</p>
0509: * Member is searched at k_x_list_members table either at gu_company and
0510: * gu_contact or tx_email. If list is Dynamic or Static, member is searched at
0511: * gu_company and gu_contact. If list is Direct or Black, member is searched at tx_email
0512: * @param oConn Database Connection
0513: * @param sMember If this is a Static or Dynamic list then sMember must be the GUID of Contact or Company searched.<br>
0514: * If this is a Direct or Black list then sMember must be an e-mail address.
0515: * @return <b>true</b> if sMember is contained in list.<br>
0516: * Take into account that the member may be unactive or blocked and still be contained at the list.<br>
0517: * Unactive (k_x_list_members.bo_active=0) and blocked (present at black list) members should not receive any e-mails.
0518: * @throws SQLException
0519: */
0520: public boolean contains(JDCConnection oConn, String sMember)
0521: throws SQLException {
0522: boolean bRetVal;
0523: PreparedStatement oStmt;
0524: ResultSet oRSet;
0525: QueryByForm oQBF;
0526:
0527: if (DebugFile.trace) {
0528: DebugFile
0529: .writeln("Begin DistributionList.contains([Connection], "
0530: + sMember + ")");
0531: DebugFile.incIdent();
0532: }
0533:
0534: switch (getShort(DB.tp_list)) {
0535:
0536: case TYPE_DYNAMIC:
0537: oQBF = new QueryByForm(oConn, DB.k_member_address, "ma",
0538: getString(DB.gu_query));
0539:
0540: if (DebugFile.trace)
0541: DebugFile
0542: .writeln("Connection.prepareStatement(SELECT NULL FROM "
0543: + DB.k_member_address
0544: + " ma WHERE ma."
0545: + DB.gu_workarea
0546: + "=? AND (ma."
0547: + DB.gu_contact
0548: + "='"
0549: + sMember
0550: + "' OR ma."
0551: + DB.gu_company
0552: + "='"
0553: + sMember
0554: + "') AND ("
0555: + oQBF.composeSQL() + "))");
0556:
0557: oStmt = oConn.prepareStatement("SELECT NULL FROM "
0558: + DB.k_member_address + " ma WHERE ma."
0559: + DB.gu_workarea + "=? AND (ma." + DB.gu_contact
0560: + "=? OR ma." + DB.gu_company + "=?) AND ("
0561: + oQBF.composeSQL() + ")",
0562: ResultSet.TYPE_FORWARD_ONLY,
0563: ResultSet.CONCUR_READ_ONLY);
0564:
0565: oStmt.setString(1, getString(DB.gu_workarea));
0566: oStmt.setString(2, sMember);
0567: oStmt.setString(3, sMember);
0568: oRSet = oStmt.executeQuery();
0569: bRetVal = oRSet.next();
0570: oRSet.close();
0571: oStmt.close();
0572:
0573: oQBF = null;
0574: break;
0575:
0576: case TYPE_STATIC:
0577:
0578: if (DebugFile.trace)
0579: DebugFile
0580: .writeln("Connection.prepareStatement(SELECT NULL FROM "
0581: + DB.k_x_list_members
0582: + " WHERE "
0583: + DB.gu_list
0584: + "='"
0585: + getString(DB.gu_list)
0586: + "' AND ("
0587: + DB.gu_contact
0588: + "='"
0589: + sMember
0590: + "' OR "
0591: + DB.gu_company
0592: + "='"
0593: + sMember + "'))");
0594:
0595: oStmt = oConn.prepareStatement("SELECT NULL FROM "
0596: + DB.k_x_list_members + " WHERE " + DB.gu_list
0597: + "=? AND (" + DB.gu_contact + "=? OR "
0598: + DB.gu_company + "=?)",
0599: ResultSet.TYPE_FORWARD_ONLY,
0600: ResultSet.CONCUR_READ_ONLY);
0601: oStmt.setString(1, getString(DB.gu_list));
0602: oStmt.setString(2, sMember);
0603: oStmt.setString(3, sMember);
0604: oRSet = oStmt.executeQuery();
0605: bRetVal = oRSet.next();
0606: oRSet.close();
0607: oStmt.close();
0608: break;
0609:
0610: case TYPE_DIRECT:
0611: case TYPE_BLACK:
0612:
0613: if (DebugFile.trace)
0614: DebugFile
0615: .writeln("Connection.prepareStatement(SELECT NULL FROM "
0616: + DB.k_x_list_members
0617: + " WHERE "
0618: + DB.gu_list
0619: + "=? AND "
0620: + DB.tx_email
0621: + "='" + sMember + "')");
0622:
0623: oStmt = oConn.prepareStatement("SELECT NULL FROM "
0624: + DB.k_x_list_members + " WHERE " + DB.gu_list
0625: + "=? AND " + DB.tx_email + "=?",
0626: ResultSet.TYPE_FORWARD_ONLY,
0627: ResultSet.CONCUR_READ_ONLY);
0628: oStmt.setString(1, getString(DB.gu_list));
0629: oStmt.setString(2, sMember);
0630: oRSet = oStmt.executeQuery();
0631: bRetVal = oRSet.next();
0632: oRSet.close();
0633: oStmt.close();
0634: break;
0635:
0636: default:
0637: throw new java.lang.IllegalArgumentException(
0638: "DistributionList.contains() invalid value of tp_list property");
0639: }
0640:
0641: if (DebugFile.trace) {
0642: DebugFile.decIdent();
0643: DebugFile.writeln("End DistributionList.contains() : "
0644: + String.valueOf(bRetVal));
0645: }
0646: return bRetVal;
0647: }
0648:
0649: // ----------------------------------------------------------
0650:
0651: /**
0652: * Store DistributionList
0653: * Automatically generates gu_list GUID if not explicitly set.
0654: * @param oConn Database Connection
0655: * @throws SQLException
0656: */
0657: public boolean store(JDCConnection oConn) throws SQLException {
0658:
0659: if (!AllVals.containsKey(DB.gu_list))
0660: put(DB.gu_list, Gadgets.generateUUID());
0661:
0662: return super .store(oConn);
0663: } // store()
0664:
0665: // ----------------------------------------------------------
0666:
0667: public boolean delete(JDCConnection oConn) throws SQLException {
0668: return DistributionList.delete(oConn, getString(DB.gu_list));
0669: } // delete()
0670:
0671: // ----------------------------------------------------------
0672:
0673: /**
0674: * <p>Get associated Black List GUID</p>
0675: * The Black List is that witch tp_list=BLACK_LIST AND gu_query=this.gu_list
0676: * @param oConn Database Connection
0677: * @return Black List GUID or <b>null</b> if there is no associated Black List.
0678: * @throws SQLException
0679: * @throws IllegalStateException if this DistributionList has not been previously loaded
0680: */
0681: public String blackList(JDCConnection oConn) throws SQLException,
0682: IllegalStateException {
0683: PreparedStatement oStmt;
0684: ResultSet oRSet;
0685: String sBlackListId;
0686:
0687: if (DebugFile.trace) {
0688: DebugFile
0689: .writeln("Begin DistributionList.blackList([Connection])");
0690: if (isNull(DB.gu_workarea))
0691: throw new IllegalStateException(
0692: "DistributionList.blackList() workarea is not set");
0693: if (isNull(DB.gu_list))
0694: throw new IllegalStateException(
0695: "DistributionList.blackList() list GUID is not set");
0696: DebugFile.incIdent();
0697: }
0698:
0699: oStmt = oConn.prepareStatement("SELECT " + DB.gu_list
0700: + " FROM " + DB.k_lists + " WHERE " + DB.gu_workarea
0701: + "=? AND " + DB.tp_list + "="
0702: + String.valueOf(TYPE_BLACK) + " AND " + DB.gu_query
0703: + "=?", ResultSet.TYPE_FORWARD_ONLY,
0704: ResultSet.CONCUR_READ_ONLY);
0705:
0706: try {
0707: oStmt.setQueryTimeout(10);
0708: } catch (SQLException e) {
0709: }
0710:
0711: oStmt.setString(1, getString(DB.gu_workarea));
0712: oStmt.setString(2, getString(DB.gu_list));
0713:
0714: try {
0715: oStmt.setQueryTimeout(20);
0716: } catch (SQLException sqle) {
0717: }
0718:
0719: oRSet = oStmt.executeQuery();
0720:
0721: if (oRSet.next())
0722: sBlackListId = oRSet.getString(1);
0723: else
0724: sBlackListId = null;
0725:
0726: oRSet.close();
0727: oStmt.close();
0728:
0729: if (DebugFile.trace) {
0730: DebugFile.decIdent();
0731: DebugFile.writeln("End DistributionList.blackList() : "
0732: + (sBlackListId != null ? sBlackListId : "null"));
0733: }
0734:
0735: return sBlackListId;
0736: } // blackList()
0737:
0738: // ----------------------------------------------------------
0739:
0740: /**
0741: * <p>Append members of a list to this DistributionList.<p>
0742: * Members that where already present are not touched.
0743: * Results are placed at this DistributionList.
0744: * @param oConn Database Connection
0745: * @param sListGUID GUID of DistributionList to be appended
0746: * @throws SQLException
0747: * @throws IllegalArgumentException If sListGUID==null
0748: * @throws IllegalStateException If this.gu_list is not set
0749: * @throws ClassCastException If this DistributionList type is DYNAMIC
0750: */
0751: public void append(JDCConnection oConn, String sListGUID)
0752: throws SQLException, IllegalArgumentException,
0753: IllegalStateException, ClassCastException {
0754: Statement oInsrt;
0755: String sSQL;
0756: String sColumnList;
0757: DistributionList oAppendedList;
0758:
0759: if (DebugFile.trace) {
0760: DebugFile
0761: .writeln("Begin DistributionList.append([Connection], "
0762: + (sListGUID != null ? sListGUID : "null")
0763: + ")");
0764: DebugFile.incIdent();
0765: }
0766:
0767: if (null == sListGUID)
0768: throw new IllegalArgumentException("list id cannot be null");
0769:
0770: if (null == get(DB.gu_list))
0771: throw new IllegalStateException("list id not set");
0772:
0773: if (getShort(DB.tp_list) == DistributionList.TYPE_DYNAMIC)
0774: throw new ClassCastException(
0775: "append operation not supported for Dynamic lists");
0776:
0777: if (sListGUID.equals(getString(DB.gu_list)))
0778: return;
0779:
0780: oAppendedList = new DistributionList(oConn, sListGUID);
0781:
0782: // *******************************************************************
0783: // Añadir los miembros que no estuviesen ya presentes en la lista base
0784:
0785: oInsrt = oConn.createStatement();
0786:
0787: try {
0788: oInsrt.setQueryTimeout(120);
0789: } catch (SQLException sqle) { /* ignore */
0790: }
0791:
0792: if (oAppendedList.getShort(DB.tp_list) == TYPE_DYNAMIC) {
0793:
0794: // Componer la sentencia SQL de filtrado de datos a partir de la definición de la consulta almacenada en la tabla k_queries
0795: QueryByForm oQBF = new QueryByForm(oConn,
0796: DB.k_member_address, "ma", oAppendedList
0797: .getString(DB.gu_query));
0798: sColumnList = DB.tx_email + "," + DB.tx_name + ","
0799: + DB.tx_surname + "," + DB.tx_salutation + ","
0800: + DB.gu_company + "," + DB.gu_contact;
0801:
0802: sSQL = "INSERT INTO " + DB.k_x_list_members + " ("
0803: + DB.gu_list + "," + sColumnList + ") "
0804: + "SELECT '" + getString(DB.gu_list) + "',"
0805: + sColumnList + " FROM " + DB.k_member_address
0806: + " ma WHERE ma.gu_workarea='"
0807: + oAppendedList.getString(DB.gu_workarea)
0808: + "' AND (" + oQBF.composeSQL() + ") AND " + "ma."
0809: + DB.tx_email + " NOT IN (SELECT " + DB.tx_email
0810: + " FROM " + DB.k_x_list_members + " WHERE "
0811: + DB.gu_list + "='" + getString(DB.gu_list) + "')";
0812: }
0813:
0814: else {
0815:
0816: sColumnList = DB.tx_email + "," + DB.tx_name + ","
0817: + DB.tx_surname + "," + DB.tx_salutation + ","
0818: + DB.bo_active + "," + DB.gu_company + ","
0819: + DB.gu_contact + "," + DB.id_format;
0820:
0821: sSQL = "INSERT INTO " + DB.k_x_list_members + " ("
0822: + DB.gu_list + "," + sColumnList + ") "
0823: + "SELECT '" + getString(DB.gu_list) + "',"
0824: + sColumnList + " FROM " + DB.k_x_list_members
0825: + " WHERE " + DB.gu_list + "='" + sListGUID
0826: + "' AND " + DB.tx_email + " NOT IN (SELECT "
0827: + DB.tx_email + " FROM " + DB.k_x_list_members
0828: + " WHERE " + DB.gu_list + "='"
0829: + getString(DB.gu_list) + "')";
0830:
0831: }
0832:
0833: if (DebugFile.trace)
0834: DebugFile.writeln("Statement.execute(" + sSQL + ")");
0835:
0836: oInsrt.execute(sSQL);
0837: oInsrt.close();
0838:
0839: if (DebugFile.trace) {
0840: DebugFile.decIdent();
0841: DebugFile.writeln("End DistributionList.append()");
0842: }
0843: } // append
0844:
0845: // ----------------------------------------------------------
0846:
0847: /**
0848: * Overwrite members of this DistributionList with members of given DistributionList.
0849: * Members of sListGUID not present at this list are NOT appended.
0850: * @param oConn Database Connection
0851: * @throws SQLException
0852: * @throws IllegalArgumentException If sListGUID==null
0853: * @throws IllegalStateException If this.gu_list is not set
0854: * @throws ClassCastException If this DistributionList type is DYNAMIC
0855: */
0856: public void overwrite(JDCConnection oConn, String sListGUID)
0857: throws SQLException, IllegalArgumentException,
0858: ClassCastException, IllegalStateException {
0859: Statement oInsrt;
0860: PreparedStatement oUpdt;
0861: ResultSet oRSet;
0862: String sSQL;
0863: String sColumnList;
0864: DistributionList oAppendedList;
0865:
0866: if (DebugFile.trace) {
0867: DebugFile
0868: .writeln("Begin DistributionList.overwrite([Connection], "
0869: + (sListGUID != null ? sListGUID : "null")
0870: + ")");
0871: DebugFile.incIdent();
0872: }
0873:
0874: if (null == sListGUID)
0875: throw new IllegalArgumentException("list id cannot be null");
0876:
0877: if (null == get(DB.gu_list))
0878: throw new IllegalStateException("list id not set");
0879:
0880: if (getShort(DB.tp_list) == DistributionList.TYPE_DYNAMIC)
0881: throw new ClassCastException(
0882: "overwrite operation not supported for Dynamic lists");
0883:
0884: if (sListGUID.equals(getString(DB.gu_list)))
0885: return;
0886:
0887: oAppendedList = new DistributionList(oConn, sListGUID);
0888:
0889: sColumnList = DB.tx_email + "," + DB.tx_name + ","
0890: + DB.tx_surname + "," + DB.tx_salutation + ","
0891: + DB.bo_active + "," + DB.gu_company + ","
0892: + DB.gu_contact + "," + DB.id_format;
0893:
0894: // ************************************************************************************
0895: // Actualizar los miembros de la lista a añadir que ya estén presentes en la lista base
0896:
0897: // Preparar la sentencia de actualización de registros en la lista base
0898: sSQL = "UPDATE " + DB.k_x_list_members + " SET " + DB.tx_name
0899: + "=?," + DB.tx_surname + "=?," + DB.tx_salutation
0900: + "=?," + DB.bo_active + "=?," + DB.gu_company + "=?,"
0901: + DB.gu_contact + "=?," + DB.id_format + "=? WHERE "
0902: + DB.gu_list + "='" + getString(DB.gu_list) + "' AND "
0903: + DB.tx_email + "=?";
0904:
0905: if (DebugFile.trace)
0906: DebugFile.writeln("Connection.prepareStatement(" + sSQL
0907: + ")");
0908:
0909: oUpdt = oConn.prepareStatement(sSQL);
0910:
0911: // Preparar la sentencia para leer registros comunes en la lista añadida
0912: oInsrt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
0913: ResultSet.CONCUR_READ_ONLY);
0914:
0915: try {
0916: oInsrt.setQueryTimeout(60);
0917: } catch (SQLException sqle) { /* ignore */
0918: }
0919:
0920: if (oAppendedList.getShort(DB.tp_list) == TYPE_DYNAMIC) {
0921: QueryByForm oQBF = new QueryByForm(oConn,
0922: DB.k_member_address, "b", oAppendedList
0923: .getString(DB.gu_query));
0924:
0925: sSQL = "SELECT b." + DB.tx_name + ",b." + DB.tx_surname
0926: + ",b." + DB.tx_salutation + ",1,b."
0927: + DB.gu_company + ",b." + DB.gu_contact
0928: + ",'TXT', a." + DB.tx_email + " FROM "
0929: + DB.k_x_list_members + " a, "
0930: + DB.k_member_address + " b WHERE a." + DB.gu_list
0931: + "='" + getString(DB.gu_list) + "' AND b."
0932: + DB.gu_workarea + "='"
0933: + oAppendedList.getString(DB.gu_workarea)
0934: + "' AND (" + oQBF.composeSQL() + ") AND a."
0935: + DB.tx_email + "=b." + DB.tx_email;
0936: } else
0937: sSQL = "SELECT b." + DB.tx_name + ",b." + DB.tx_surname
0938: + ",b." + DB.tx_salutation + ",b." + DB.bo_active
0939: + ",b." + DB.gu_company + ",b." + DB.gu_contact
0940: + ",b." + DB.id_format + ", a." + DB.tx_email
0941: + " FROM " + DB.k_x_list_members + " a, "
0942: + DB.k_x_list_members + " b WHERE a." + DB.gu_list
0943: + "='" + getString(DB.gu_list) + "' AND b."
0944: + DB.gu_list + "='" + sListGUID + "' AND a."
0945: + DB.tx_email + "=b." + DB.tx_email;
0946:
0947: if (DebugFile.trace)
0948: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
0949:
0950: oRSet = oInsrt.executeQuery(sSQL);
0951:
0952: // Recorrer los registros de la lista añadida que ya estén en la lista base
0953: // y actualizar sus campos con los valores de la lista añadida.
0954: while (oRSet.next()) {
0955: oUpdt.setObject(1, oRSet.getObject(1), Types.VARCHAR); // tx_name
0956: oUpdt.setObject(2, oRSet.getObject(2), Types.VARCHAR); // tx_surname
0957: oUpdt.setObject(3, oRSet.getObject(3), Types.VARCHAR); // tx_salutation
0958: oUpdt.setObject(4, oRSet.getObject(4), Types.SMALLINT); // bo_active
0959: oUpdt.setObject(5, oRSet.getObject(5), Types.VARCHAR); // gu_company
0960: oUpdt.setObject(6, oRSet.getObject(6), Types.VARCHAR); // gu_contact
0961: oUpdt.setObject(7, oRSet.getObject(7), Types.VARCHAR); // id_format
0962: oUpdt.setObject(8, oRSet.getObject(8), Types.VARCHAR); // tx_email
0963: oUpdt.executeUpdate();
0964: } // wend
0965:
0966: oInsrt.close();
0967: oUpdt.close();
0968:
0969: if (DebugFile.trace) {
0970: DebugFile.decIdent();
0971: DebugFile.writeln("End DistributionList.overwrite()");
0972: }
0973: } // overwrite
0974:
0975: // ----------------------------------------------------------
0976:
0977: /**
0978: * Remove from this DistributionList those members present at given DistributionList.
0979: * @param oConn Database Connection
0980: * @throws SQLException
0981: * @throws IllegalArgumentException If sListGUID==null
0982: * @throws IllegalStateException If this.gu_list is not set
0983: * @throws ClassCastException If this DistributionList type is DYNAMIC
0984: */
0985: public void substract(JDCConnection oConn, String sListGUID)
0986: throws SQLException, IllegalArgumentException,
0987: IllegalStateException, ClassCastException {
0988: String sSQL;
0989: Statement oDlte;
0990: DistributionList oAppendedList;
0991:
0992: if (DebugFile.trace) {
0993: DebugFile
0994: .writeln("Begin DistributionList.substract([Connection], "
0995: + (sListGUID != null ? sListGUID : "null")
0996: + ")");
0997: DebugFile.incIdent();
0998: }
0999:
1000: if (null == sListGUID)
1001: throw new IllegalArgumentException("list id cannot be null");
1002:
1003: if (null == get(DB.gu_list))
1004: throw new IllegalStateException("list id not set");
1005:
1006: if (getShort(DB.tp_list) == DistributionList.TYPE_DYNAMIC)
1007: throw new ClassCastException(
1008: "substract operation not supported for Dynamic lists");
1009:
1010: oAppendedList = new DistributionList(oConn, sListGUID);
1011:
1012: if (sListGUID.equals(getString(DB.gu_list)))
1013:
1014: sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE "
1015: + DB.gu_list + "='" + getString(DB.gu_list) + "'";
1016:
1017: else if (oAppendedList.getShort(DB.tp_list) == TYPE_DYNAMIC) {
1018:
1019: QueryByForm oQBF = new QueryByForm(oConn,
1020: DB.k_member_address, "ma", oAppendedList
1021: .getString(DB.gu_query));
1022:
1023: sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE "
1024: + DB.gu_list + "='" + getString(DB.gu_list)
1025: + "' AND " + DB.tx_email + " IN (SELECT "
1026: + DB.tx_email + " FROM " + DB.k_member_address
1027: + " ma WHERE ma." + DB.gu_workarea + "='"
1028: + oAppendedList.getString(DB.gu_workarea)
1029: + "' AND (" + oQBF.composeSQL() + "))";
1030: }
1031:
1032: else
1033:
1034: sSQL = "DELETE FROM " + DB.k_x_list_members + " WHERE "
1035: + DB.gu_list + "='" + getString(DB.gu_list)
1036: + "' AND " + DB.tx_email + " IN (SELECT "
1037: + DB.tx_email + " FROM " + DB.k_x_list_members
1038: + " WHERE " + DB.gu_list + "='" + sListGUID + "')";
1039:
1040: oDlte = oConn.createStatement();
1041:
1042: if (DebugFile.trace)
1043: DebugFile.writeln("Statement.execute(" + sSQL + ")");
1044:
1045: oDlte.execute(sSQL);
1046:
1047: oDlte.close();
1048:
1049: if (DebugFile.trace) {
1050: DebugFile.decIdent();
1051: DebugFile.writeln("End DistributionList.substract()");
1052: }
1053: } // substract
1054:
1055: // ----------------------------------------------------------
1056:
1057: /**
1058: * Clone this DistributionList.
1059: * The associated Black List, if it exists, is also cloned and associated to the new clone.
1060: * @param oConn Database Connection
1061: * @return New DistributionList GUID
1062: * @throws SQLException
1063: */
1064: public String clone(JDCConnection oConn) throws SQLException {
1065: String sSQL;
1066: String sCloneId;
1067: Statement oStmt;
1068: DistributionList oClone;
1069:
1070: if (DebugFile.trace) {
1071: DebugFile.writeln("Begin DistributionList.clone()");
1072: DebugFile.incIdent();
1073: }
1074:
1075: oClone = new DistributionList(oConn, getString(DB.gu_list));
1076:
1077: oClone.remove(DB.gu_list);
1078: oClone.store(oConn);
1079:
1080: sCloneId = oClone.getString(DB.gu_list);
1081:
1082: oStmt = oConn.createStatement();
1083: oStmt.setQueryTimeout(60);
1084:
1085: sSQL = "INSERT INTO "
1086: + DB.k_x_list_members
1087: + "(gu_list,tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format) SELECT '"
1088: + oClone.getString(DB.gu_list)
1089: + "',tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format FROM "
1090: + DB.k_x_list_members + " WHERE " + DB.gu_list + "='"
1091: + getString(DB.gu_list) + "'";
1092:
1093: if (DebugFile.trace)
1094: DebugFile.writeln("Statement.execute(" + sSQL + ")");
1095:
1096: oStmt.execute(sSQL);
1097:
1098: String sBlackList = blackList(oConn);
1099:
1100: if (null != sBlackList) {
1101: oClone = new DistributionList(oConn, sBlackList);
1102:
1103: oClone.remove(DB.gu_list);
1104: oClone.replace(DB.gu_query, sCloneId);
1105: oClone.store(oConn);
1106:
1107: sSQL = "INSERT INTO "
1108: + DB.k_x_list_members
1109: + "(gu_list,tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format) SELECT '"
1110: + oClone.getString(DB.gu_list)
1111: + "',tx_email,tx_name,tx_surname,tx_salutation,bo_active,tp_member,gu_company,gu_contact,id_format FROM "
1112: + DB.k_x_list_members + " WHERE " + DB.gu_list
1113: + "='" + sBlackList + "'";
1114:
1115: if (DebugFile.trace)
1116: DebugFile.writeln("Statement.execute(" + sSQL + ")");
1117:
1118: oStmt.execute(sSQL);
1119: } // fi(sBlackList)
1120:
1121: oStmt.close();
1122:
1123: if (DebugFile.trace) {
1124: DebugFile.decIdent();
1125: DebugFile.writeln("End DistributionList.clone() : "
1126: + sCloneId);
1127: }
1128: return sCloneId;
1129: } // clone
1130:
1131: // ----------------------------------------------------------
1132:
1133: /**
1134: * Print List Members to a comma delimited String.
1135: * @param oConn Database Connection
1136: * @param bPrintHeader <b>true</b> if column names are to be printed at first row.
1137: * @return Comma delimited String with one Member per line.
1138: * @throws SQLException
1139: */
1140: public String print(JDCConnection oConn, boolean bPrintHeader)
1141: throws SQLException {
1142: String sSQL;
1143: String sColumnList;
1144: String sTableName;
1145: String sWhere;
1146: StringBuffer oBuffer;
1147: Statement oStmt;
1148: ResultSet oRSet;
1149: Object oFld;
1150:
1151: // Imprime los miembros de una lista en formato de texto delimitado por comas
1152:
1153: if (DebugFile.trace) {
1154: DebugFile
1155: .writeln("Begin DistributionList.print([Connection])");
1156: DebugFile.incIdent();
1157: }
1158:
1159: oBuffer = new StringBuffer();
1160:
1161: oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
1162: ResultSet.CONCUR_READ_ONLY);
1163:
1164: try {
1165: oStmt.setQueryTimeout(120);
1166: } catch (SQLException sqle) { /* ignore */
1167: }
1168:
1169: sColumnList = "m." + DB.tx_email + ",m." + DB.tx_name + ",m."
1170: + DB.tx_surname + ",m." + DB.tx_salutation + ",m."
1171: + DB.bo_active + ",m." + DB.gu_company + ",m."
1172: + DB.gu_contact + ",m." + DB.dt_modified;
1173:
1174: if (getShort(DB.tp_list) == TYPE_DYNAMIC) {
1175: sTableName = DB.k_member_address;
1176:
1177: QueryByForm oQBF = new QueryByForm(oConn,
1178: DB.k_member_address, "m", getString(DB.gu_query));
1179:
1180: sWhere = "m." + DB.gu_workarea + "='"
1181: + getString(DB.gu_workarea) + "' AND ("
1182: + oQBF.composeSQL() + ")";
1183:
1184: oQBF = null;
1185: } else {
1186: sTableName = DB.k_x_list_members;
1187: sWhere = "m." + DB.gu_list + "='" + getString(DB.gu_list)
1188: + "'";
1189: }
1190:
1191: sSQL = "SELECT " + sColumnList + " FROM " + sTableName
1192: + " m WHERE " + sWhere;
1193:
1194: if (DebugFile.trace)
1195: DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
1196:
1197: oRSet = oStmt.executeQuery(sSQL);
1198:
1199: try {
1200: oRSet.setFetchSize(500);
1201: } catch (SQLException sqle) { /* ignore */
1202: }
1203:
1204: if (bPrintHeader)
1205: oBuffer.append(sColumnList + "\n");
1206:
1207: while (oRSet.next()) {
1208: oBuffer.append(oRSet.getString(1));
1209: oBuffer.append(",");
1210:
1211: oFld = oRSet.getObject(2); // tx_name
1212: if (!oRSet.wasNull())
1213: oBuffer.append(oFld);
1214: oBuffer.append(",");
1215:
1216: oFld = oRSet.getObject(3); // tx_surname
1217: if (!oRSet.wasNull())
1218: oBuffer.append(oFld);
1219: oBuffer.append(",");
1220:
1221: oFld = oRSet.getObject(4); // tx_salutation
1222: if (!oRSet.wasNull())
1223: oBuffer.append(oFld);
1224: oBuffer.append(",");
1225:
1226: oBuffer.append(String.valueOf(oRSet.getShort(5)));
1227: oBuffer.append(",");
1228:
1229: oFld = oRSet.getObject(6); // gu_company
1230: if (!oRSet.wasNull())
1231: oBuffer.append(oFld);
1232: oBuffer.append(",");
1233:
1234: oFld = oRSet.getObject(7); // gu_contact
1235: if (!oRSet.wasNull())
1236: oBuffer.append(oFld);
1237: oBuffer.append(",");
1238:
1239: oBuffer.append(oRSet.getString(8));
1240: oBuffer.append("\n");
1241: } // wend
1242:
1243: oRSet.close();
1244: oStmt.close();
1245:
1246: if (DebugFile.trace) {
1247: DebugFile.decIdent();
1248: DebugFile.writeln("End DistributionList.print()");
1249: }
1250:
1251: return oBuffer.toString();
1252: } // print()
1253:
1254: // ----------------------------------------------------------
1255:
1256: // **********************************************************
1257: // Static Methods
1258:
1259: /**
1260: * Delete Distribution List
1261: * Call k_sp_del_list stored procedure.<br>
1262: * Associated Black List (if present) is also deleted.
1263: * @param oConn Database Connection
1264: * @param sListGUID GUID of DistributionList to be deleted
1265: * @throws SQLException
1266: */
1267: public static boolean delete(JDCConnection oConn, String sListGUID)
1268: throws SQLException {
1269: boolean bRetVal;
1270:
1271: if (DebugFile.trace) {
1272: DebugFile
1273: .writeln("Begin DistributionList.delete([Connection],"
1274: + sListGUID + ")");
1275: DebugFile.incIdent();
1276: }
1277:
1278: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
1279: Statement oStmt = oConn.createStatement();
1280: oStmt.executeQuery("SELECT k_sp_del_list ('" + sListGUID
1281: + "')");
1282: oStmt.close();
1283: bRetVal = true;
1284: } else {
1285: CallableStatement oCall = oConn
1286: .prepareCall("{ call k_sp_del_list ('" + sListGUID
1287: + "') }");
1288: bRetVal = oCall.execute();
1289: oCall.close();
1290: }
1291:
1292: if (DebugFile.trace) {
1293: DebugFile.decIdent();
1294: DebugFile.writeln("End DistributionList.delete() : "
1295: + String.valueOf(bRetVal));
1296: }
1297:
1298: return bRetVal;
1299: } // delete()
1300:
1301: // **********************************************************
1302: // Public Constants
1303:
1304: public static final short ClassId = 96;
1305:
1306: public static final short TYPE_STATIC = (short) 1;
1307: public static final short TYPE_DYNAMIC = (short) 2;
1308: public static final short TYPE_DIRECT = (short) 3;
1309: public static final short TYPE_BLACK = (short) 4;
1310: }
|