1 32 33 package com.knowgate.forums; 34 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 import java.sql.ResultSet ; 38 39 import com.knowgate.debug.DebugFile; 40 import com.knowgate.jdc.JDCConnection; 41 import com.knowgate.dataobjs.DB; 42 import com.knowgate.dataobjs.DBPersist; 43 44 50 51 public class Subscription extends DBPersist { 52 53 56 public Subscription() { 57 super(DB.k_newsgroup_subscriptions, "Subscription"); 58 } 59 60 public Subscription(JDCConnection oConn, String sNewsGroupId, String sUserId) 61 throws SQLException { 62 63 super(DB.k_newsgroup_subscriptions, "Subscription"); 64 65 load (oConn, new Object []{sNewsGroupId, sUserId}); 66 } 67 68 70 81 public static boolean subscribe (JDCConnection oConn, String sNewsGroupId, String sUserId, String sMessageFormat, short iMessagesGrouping) 82 throws SQLException { 83 84 if (DebugFile.trace) { 85 DebugFile.writeln("Begin Subscription.subscribe ([Connection], " + sNewsGroupId + "," + sUserId + ")"); 86 DebugFile.incIdent(); 87 } 88 89 String sTxEmail; 90 91 Statement oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 92 93 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery (SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "='" + sUserId + "')"); 94 95 ResultSet oRSet = oStmt.executeQuery("SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "='" + sUserId + "'"); 96 97 if (oRSet.next()) 98 sTxEmail = oRSet.getString(1); 99 else 100 sTxEmail = null; 101 102 oRSet.close(); 103 oStmt.close(); 104 105 if (null!=sTxEmail) { 106 Subscription oUsrSubs = new Subscription(); 107 108 oUsrSubs.put(DB.gu_newsgrp, sNewsGroupId); 109 oUsrSubs.put(DB.gu_user, sUserId); 110 oUsrSubs.put(DB.id_msg_type, sMessageFormat); 111 oUsrSubs.put(DB.tp_subscrip, iMessagesGrouping); 112 oUsrSubs.put(DB.tx_email, sTxEmail); 113 114 oUsrSubs.store(oConn); 115 } 117 if (DebugFile.trace) { 118 DebugFile.decIdent(); 119 DebugFile.writeln("End Subscription.subscribe() : " + (null!=sTxEmail ? sTxEmail : "false")); 120 } 121 122 return (null!=sTxEmail); 123 } 125 127 136 public static boolean subscribe (JDCConnection oConn, String sNewsGroupId, String sUserId) 137 throws SQLException { 138 139 return subscribe (oConn, sNewsGroupId, sUserId, "TXT", Subscription.GROUP_NONE); 140 } 141 142 144 154 public static boolean unsubscribe (JDCConnection oConn, String sNewsGroupId, String sUserId) 155 throws SQLException { 156 157 if (DebugFile.trace) { 158 DebugFile.writeln("Begin Subscription.unsubscribe ([Connection], " + sNewsGroupId + "," + sUserId + ")"); 159 DebugFile.incIdent(); 160 } 161 162 Statement oStmt = oConn.createStatement(); 163 164 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate (DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "')"); 165 166 int iAffected = oStmt.executeUpdate("DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "'"); 167 168 oStmt.close(); 169 170 if (DebugFile.trace) { 171 DebugFile.decIdent(); 172 DebugFile.writeln("End Subscription.unsubscribe() : " + (iAffected!=0 ? "true" : "false")); 173 } 174 175 return (iAffected!=0); 176 } 178 180 189 public static boolean activate (JDCConnection oConn, String sNewsGroupId, String sUserId) 190 throws SQLException { 191 192 if (DebugFile.trace) { 193 DebugFile.writeln("Begin Subscription.activate ([Connection], " + sNewsGroupId + "," + sUserId + ")"); 194 DebugFile.incIdent(); 195 } 196 197 Statement oStmt = oConn.createStatement(); 198 199 if (DebugFile.trace) 200 DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_newsgroup_subscriptions + " SET " + DB.id_status + "=" + String.valueOf(ACTIVE) + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "')"); 201 202 int iAffected = oStmt.executeUpdate("UPDATE " + DB.k_newsgroup_subscriptions + " SET " + DB.id_status + "=" + String.valueOf(ACTIVE) + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "'"); 203 204 oStmt.close(); 205 206 if (DebugFile.trace) { 207 DebugFile.decIdent(); 208 DebugFile.writeln("End Subscription.activate() : " + (iAffected!=0 ? "true" : "false")); 209 } 210 211 return (iAffected!=0); 212 } 214 216 225 public static boolean deactivate (JDCConnection oConn, String sNewsGroupId, String sUserId) 226 throws SQLException { 227 228 if (DebugFile.trace) { 229 DebugFile.writeln("Begin Subscription.deactivate ([Connection], " + sNewsGroupId + "," + sUserId + ")"); 230 DebugFile.incIdent(); 231 } 232 233 Statement oStmt = oConn.createStatement(); 234 235 if (DebugFile.trace) 236 DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_newsgroup_subscriptions + " SET " + DB.id_status + "=" + String.valueOf(UNACTIVE) + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "')"); 237 238 int iAffected = oStmt.executeUpdate("UPDATE " + DB.k_newsgroup_subscriptions + " SET " + DB.id_status + "=" + String.valueOf(UNACTIVE) + " WHERE " + DB.gu_newsgrp + "='" + sNewsGroupId + "' AND " + DB.gu_user + "='" + sUserId + "'"); 239 240 oStmt.close(); 241 242 if (DebugFile.trace) { 243 DebugFile.decIdent(); 244 DebugFile.writeln("End Subscription.deactivate() : " + (iAffected!=0 ? "true" : "false")); 245 } 246 247 return (iAffected!=0); 248 } 250 252 public static final short ACTIVE = 1; 253 public static final short UNACTIVE = 0; 254 255 public static final short GROUP_NONE = 1; 256 public static final short GROUP_DIGEST = 2; 257 } | Popular Tags |