1 32 33 package com.knowgate.hipergate; 34 35 import java.util.HashMap ; 36 import java.util.Iterator ; 37 38 import java.sql.Connection ; 39 import java.sql.SQLException ; 40 import java.sql.Statement ; 41 import java.sql.ResultSet ; 42 import java.sql.PreparedStatement ; 43 import java.sql.Types ; 44 45 import com.knowgate.debug.DebugFile; 46 import com.knowgate.jdc.JDCConnection; 47 import com.knowgate.dataobjs.DB; 48 import com.knowgate.dataobjs.DBBind; 49 import com.knowgate.dataobjs.DBPersist; 50 import com.knowgate.misc.Gadgets; 51 52 59 public class Address extends DBPersist { 60 61 64 public Address() { 65 super(DB.k_addresses, "Address"); 66 } 67 68 73 74 public Address(JDCConnection oConn, String guAddr) throws SQLException { 75 super(DB.k_addresses, "Address"); 76 77 Object aAddr[] = { guAddr }; 78 79 load(oConn, aAddr); 80 } 81 82 84 93 94 public boolean load(JDCConnection oConn, Object [] PKVals) throws SQLException { 95 boolean bRetVal = super.load(oConn, PKVals); 96 if (bRetVal) { 97 if (!isNull(DB.id_country)) { 98 AllVals.remove(DB.id_country); 99 AllVals.put(DB.id_country, getString(DB.id_country).trim()); 100 } 101 } 102 return bRetVal; 103 } 104 105 107 116 public boolean load(JDCConnection oConn, String sGuAddress) throws SQLException { 117 return this.load(oConn, new Object []{sGuAddress}); 118 } 119 120 122 129 public boolean delete(JDCConnection oConn) throws SQLException { 130 Statement oDlte = oConn.createStatement(); 131 int iAffected; 132 133 if (DebugFile.trace) { 134 DebugFile.writeln("Begin Address.delete(" + getStringNull(DB.gu_address, "null") + ")"); 135 DebugFile.incIdent(); 136 } 137 138 if (DBBind.exists(oConn, DB.k_welcome_packs, "U")) { 139 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_welcome_packs_changelog + " WHERE " + DB.gu_pack + " IN (SELECT " + DB.gu_pack + " FROM " + DB.k_welcome_packs + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "'))"); 140 141 oDlte.executeUpdate("DELETE FROM " + DB.k_welcome_packs_changelog + " WHERE " + DB.gu_pack + " IN (SELECT " + DB.gu_pack + " FROM " + DB.k_welcome_packs + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "')"); 142 143 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_welcome_packs + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "')"); 144 145 oDlte.executeUpdate("DELETE FROM " + DB.k_welcome_packs + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "'"); 146 } 147 148 if (DBBind.exists(oConn, DB.k_x_company_addr, "U")) { 149 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_company_addr + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "')"); 150 151 oDlte.executeUpdate("DELETE FROM " + DB.k_x_company_addr + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "'"); 152 } 153 154 if (DBBind.exists(oConn, DB.k_x_contact_addr, "U")) { 155 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_contact_addr + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "')"); 156 157 oDlte.executeUpdate("DELETE FROM " + DB.k_x_contact_addr + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "'"); 158 } 159 160 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_addresses + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "')"); 161 162 iAffected = oDlte.executeUpdate("DELETE FROM " + DB.k_addresses + " WHERE " + DB.gu_address + "='" + getString(DB.gu_address) + "'"); 163 164 if (DebugFile.trace) { 165 DebugFile.decIdent(); 166 DebugFile.writeln("End Address.delete() : " + String.valueOf((iAffected>0 ? true : false))); 167 } 168 169 return (iAffected>0 ? true : false); 170 } 172 174 186 public boolean store(JDCConnection oConn) throws SQLException { 187 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 188 189 if (null==get(DB.gu_address)) put(DB.gu_address, Gadgets.generateUUID()); 190 191 replace(DB.dt_modified, dtNow); 192 193 return super.store (oConn); 194 } 196 199 210 public static int nextLocalIndex(Connection oConn, String sLinkTable, String sLinkField, String sLinkValue) throws SQLException { 211 if (DebugFile.trace) { 214 DebugFile.writeln("Begin Address.nextLocalIndex([Connection],"+sLinkTable+","+sLinkField+","+sLinkValue+")"); 215 DebugFile.incIdent(); 216 } 217 Statement oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 218 ResultSet oRSet = oStmt.executeQuery("SELECT COUNT(*) FROM " + sLinkTable + " WHERE " + sLinkField + "='" + sLinkValue + "'"); 219 oRSet.next(); 220 Object oCount = oRSet.getObject(1); 221 oRSet.close(); 222 oStmt.close(); 223 int iRetVal = Integer.parseInt(oCount.toString())+1; 224 if (DebugFile.trace) { 225 DebugFile.decIdent(); 226 DebugFile.writeln("End Address.nextLocalIndex() : "+String.valueOf(iRetVal)); 227 } 228 return iRetVal; 229 } 231 240 public static String getIdFromEmail(JDCConnection oConn, String sEMail, String sWorkArea) throws SQLException { 241 String sRetVal; 242 PreparedStatement oStmt; 243 ResultSet oRSet; 244 245 if (DebugFile.trace) { 246 if (null==sWorkArea) 247 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.tx_email + "='" + sEMail + "')"); 248 else 249 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.tx_email + "='" + sEMail + "' AND " + DB.gu_workarea+ "='" + sWorkArea + "')"); 250 } 251 252 if (null==sWorkArea) { 253 oStmt = oConn.prepareStatement("SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.tx_email + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 254 oStmt.setString(1, sEMail); 255 } else { 256 oStmt = oConn.prepareStatement("SELECT " + DB.gu_address + " FROM " + DB.k_addresses + " WHERE " + DB.tx_email + "=? AND " + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 257 oStmt.setString(1, sEMail); 258 oStmt.setString(2, sWorkArea); 259 } 260 261 oRSet = oStmt.executeQuery(); 262 if (oRSet.next()) 263 sRetVal = oRSet.getString(1); 264 else 265 sRetVal = null; 266 oRSet.close(); 267 oStmt.close(); 268 269 return sRetVal; 270 } 272 293 public static boolean addLookupState (Connection oConn, String sGuWorkArea, String sIdCountry, String sNmState, HashMap oTranslations) 294 throws SQLException { 295 return DBLanguages.addLookup(oConn,DB.k_addresses_lookup, sGuWorkArea, sIdCountry, sNmState, oTranslations); 296 } 297 298 308 public static boolean addLookupStreetType (Connection oConn, String sGuWorkArea, String sTpStreet, HashMap oTranslations) 309 throws SQLException { 310 return DBLanguages.addLookup(oConn,DB.k_addresses_lookup, sGuWorkArea, DB.tp_street, sTpStreet, oTranslations); 311 } 312 313 316 public static final short ClassId = 7; 317 } 318 | Popular Tags |