1 32 33 package com.knowgate.acl; 34 35 import java.util.StringTokenizer ; 36 37 import java.sql.Connection ; 38 import java.sql.SQLException ; 39 import java.sql.Statement ; 40 import java.sql.PreparedStatement ; 41 import java.sql.CallableStatement ; 42 import java.sql.ResultSet ; 43 44 import com.knowgate.debug.DebugFile; 45 import com.knowgate.jdc.JDCConnection; 46 import com.knowgate.dataobjs.DB; 47 import com.knowgate.dataobjs.DBPersist; 48 49 import com.knowgate.misc.Gadgets; 50 import com.knowgate.dataobjs.DBSubset; 51 52 57 public final class ACLGroup extends DBPersist { 58 59 62 public ACLGroup() { 63 super(DB.k_acl_groups, "ACLGroup"); 64 } 65 66 71 public ACLGroup(String sGroupUId) { 72 super(DB.k_acl_groups, "ACLGroup"); 73 put(DB.gu_acl_group, sGroupUId); 74 } 75 76 78 public boolean store(JDCConnection oConn) throws SQLException { 79 80 if (!AllVals.containsKey(DB.gu_acl_group)) { 81 put(DB.gu_acl_group, Gadgets.generateUUID()); 82 } 83 84 return super.store(oConn); 85 } 87 89 96 public int addACLUser(JDCConnection oConn, String sIdUser) throws SQLException { 97 Statement oStmt; 98 int iRetVal; 99 100 if (DebugFile.trace) { 101 DebugFile.writeln("Begin ACLGroup.addACLUser(Connection], " + sIdUser + ")"); 102 DebugFile.incIdent(); 103 } 104 105 oStmt = oConn.createStatement(); 106 107 if (DebugFile.trace) 108 DebugFile.writeln("Statement.executeUpdate(INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_acl_group + "," + DB.gu_user + ") VALUES('" + getStringNull(DB.gu_acl_group, "null") + "','" + sIdUser + "')"); 109 110 iRetVal = oStmt.executeUpdate("INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_acl_group + "," + DB.gu_user + ") VALUES('" + getString(DB.gu_acl_group) + "','" + sIdUser + "')"); 111 oStmt.close(); 112 113 if (DebugFile.trace) { 114 DebugFile.decIdent(); 115 DebugFile.writeln("End ACLGroup.addACLUser() : " + String.valueOf(iRetVal)); 116 } 117 118 return iRetVal; 119 } 121 123 130 public int addACLUsers(JDCConnection oConn, String sUserList) throws SQLException { 131 132 if (DebugFile.trace) { 133 DebugFile.writeln("Begin ACLGroup.addACLUsers(Connection], " + sUserList + ")"); 134 DebugFile.incIdent(); 135 } 136 137 Statement oStmt; 138 int iRetVal = 0; 139 StringTokenizer oStrTok = new StringTokenizer (sUserList, ","); 140 String sIdUser; 141 142 oStmt = oConn.createStatement(); 143 144 while (oStrTok.hasMoreElements()) { 145 sIdUser = oStrTok.nextToken(); 146 147 if (DebugFile.trace) 148 DebugFile.writeln("Statement.executeUpdate(INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_acl_group + "," + DB.gu_user + ") VALUES('" + getStringNull(DB.gu_acl_group, "null") + "','" + sIdUser + "')"); 149 150 iRetVal += oStmt.executeUpdate("INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_acl_group + "," + DB.gu_user + ") VALUES('" + getString(DB.gu_acl_group) + "','" + sIdUser + "')"); 151 oStmt.close(); 152 } 154 if (DebugFile.trace) { 155 DebugFile.decIdent(); 156 DebugFile.writeln("End ACLGroup.addACLUsers() : " + String.valueOf(iRetVal)); 157 } 158 159 return iRetVal; 160 } 162 164 171 172 public int removeACLUser(JDCConnection oConn, String sIdUser) throws SQLException { 173 174 if (DebugFile.trace) { 175 DebugFile.writeln("Begin ACLGroup.removeACLUser(Connection], " + sIdUser + ")"); 176 DebugFile.incIdent(); 177 } 178 179 int iRetVal; 180 Statement oStmt = oConn.createStatement(); 181 182 if (DebugFile.trace) 183 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + sIdUser + "' AND " + DB.gu_acl_group + "='" + getStringNull(DB.gu_acl_group, "null") + "'"); 184 185 iRetVal = oStmt.executeUpdate("DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + sIdUser + "' AND " + DB.gu_acl_group + "='" + getString(DB.gu_acl_group) + "'"); 186 oStmt.close(); 187 188 if (DebugFile.trace) { 189 DebugFile.decIdent(); 190 DebugFile.writeln("End ACLGroup.removeACLUser() : " + String.valueOf(iRetVal)); 191 } 192 193 return iRetVal; 194 } 196 198 204 public int clearACLUsers(JDCConnection oConn) throws SQLException { 205 206 if (DebugFile.trace) { 207 DebugFile.writeln("Begin ACLGroup.clearACLUsers([Connection])"); 208 DebugFile.incIdent(); 209 } 210 211 int iRetVal; 212 213 Statement oStmt = oConn.createStatement(); 214 215 if (DebugFile.trace) DebugFile.writeln("DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_acl_group + "='" + getStringNull(DB.gu_acl_group, "null") + "'"); 216 217 iRetVal = oStmt.executeUpdate("DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_acl_group + "='" + getString(DB.gu_acl_group) + "'"); 218 219 oStmt.close(); 220 221 if (DebugFile.trace) { 222 DebugFile.decIdent(); 223 DebugFile.writeln("End ACLGroup.clearACLUsers() : " + String.valueOf(iRetVal)); 224 } 225 226 return iRetVal; 227 } 229 236 public DBSubset getACLUsers(JDCConnection oConn) throws SQLException { 237 Object aGroup[] = { get(DB.gu_acl_group) }; 238 DBSubset oUsers = new DBSubset(DB.k_x_group_user+" x,"+DB.k_users+" u", 239 "u."+DB.gu_user+",u."+DB.dt_created+",u."+DB.id_domain+",u."+ 240 DB.tx_nickname+",u."+DB.tx_pwd+",u."+DB.tx_pwd_sign+",u."+ 241 DB.bo_change_pwd+",u."+DB.bo_searchable+",u."+ 242 DB.bo_active+",u."+DB.len_quota+",u."+DB.max_quota+",u."+ 243 DB.tp_account+",u."+DB.id_account+",u."+ 244 DB.dt_last_update+",u."+DB.dt_last_visit+",u."+ 245 DB.dt_cancel+",u."+DB.tx_main_email+",u."+ 246 DB.tx_alt_email+",u."+DB.nm_user+",u."+ 247 DB.tx_surname1+",u."+DB.tx_surname2+",u."+ 248 DB.tx_challenge+",u."+DB.tx_reply+",u."+ 249 DB.dt_pwd_expires+",u."+DB.gu_category+",u."+ 250 DB.gu_workarea+",u."+DB.nm_company+",u."+ 251 DB.de_title+",u."+DB.id_gender+",u."+DB.dt_birth+",u."+ 252 DB.ny_age+",u."+DB.marital_status+",u."+ 253 DB.tx_education+",u."+DB.icq_id+",u."+ 254 DB.sn_passport+",u."+DB.tp_passport+",u."+ 255 DB.tx_comments, 256 "x."+DB.gu_acl_group + "=? AND "+ 257 "x."+DB.gu_user+"=u."+DB.k_users,10); 258 259 oUsers.load (oConn, aGroup); 260 return oUsers; 261 } 263 266 276 277 public static String getIdFromName(Connection oConn, int iDomainId, String sGroupNm) throws SQLException { 278 String sRetVal; 279 PreparedStatement oStmt; 280 ResultSet oRSet; 281 oStmt = oConn.prepareStatement("SELECT " + DB.gu_acl_group + " FROM " + DB.k_acl_groups + " WHERE " + DB.id_domain + "=? AND " + DB.nm_acl_group + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 282 oStmt.setInt (1, iDomainId); 283 oStmt.setString(2, sGroupNm); 284 oRSet = oStmt.executeQuery(); 285 if (oRSet.next()) 286 sRetVal = oRSet.getString(1); 287 else 288 sRetVal = null; 289 oRSet.close(); 290 oStmt.close(); 291 return sRetVal; 292 } 293 294 303 304 public static String getIdFromName(JDCConnection oConn, int iDomainId, String sGroupNm) throws SQLException { 305 String sRetVal; 306 307 switch (oConn.getDataBaseProduct()) { 308 309 case JDCConnection.DBMS_MYSQL: 310 case JDCConnection.DBMS_MSSQL: 311 case JDCConnection.DBMS_ORACLE: 312 sRetVal = DBPersist.getUIdFromName(oConn, new Integer (iDomainId), sGroupNm, "k_sp_get_group_id"); 313 break; 314 default: 315 sRetVal = getIdFromName((Connection ) oConn, iDomainId, sGroupNm); 316 } 318 return sRetVal; 319 } 321 323 330 public static boolean delete(JDCConnection oConn, String sGroupGUID) throws SQLException { 331 boolean bRetVal; 332 333 if (DebugFile.trace) { 334 DebugFile.writeln("Begin ACLGroup.delete([Connection], " + sGroupGUID + ")"); 335 DebugFile.incIdent(); 336 } 337 338 switch (oConn.getDataBaseProduct()) { 339 case JDCConnection.DBMS_POSTGRESQL: 340 Statement oStmt = oConn.createStatement(); 341 if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT k_sp_del_group ('" + sGroupGUID + "'))"); 342 ResultSet oRSet = oStmt.executeQuery("SELECT k_sp_del_group ('" + sGroupGUID + "')"); 343 oRSet.close(); 344 oStmt.close(); 345 bRetVal = true; 346 break; 347 default: 348 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_group ('" + sGroupGUID + "') })"); 349 CallableStatement oCall = oConn.prepareCall("{ call k_sp_del_group ('" + sGroupGUID + "') }"); 350 bRetVal = oCall.execute(); 351 oCall.close(); 352 } 353 354 if (DebugFile.trace) { 355 DebugFile.decIdent(); 356 DebugFile.writeln("End ACLGroup.delete() : " + String.valueOf(bRetVal)); 357 } 358 359 return bRetVal; 360 } 361 362 365 public static final short ClassId = 3; 366 367 } | Popular Tags |