001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * ContactPostalAddressFactory.java 021 */ 022 023package com.echothree.model.data.contact.server.factory; 024 025import com.echothree.model.data.contact.common.pk.ContactMechanismPK; 026import com.echothree.model.data.party.common.pk.PersonalTitlePK; 027import com.echothree.model.data.party.common.pk.NameSuffixPK; 028import com.echothree.model.data.geo.common.pk.GeoCodePK; 029 030import com.echothree.model.data.contact.server.entity.ContactMechanism; 031import com.echothree.model.data.party.server.entity.PersonalTitle; 032import com.echothree.model.data.party.server.entity.NameSuffix; 033import com.echothree.model.data.geo.server.entity.GeoCode; 034 035import com.echothree.model.data.contact.common.ContactPostalAddressConstants; 036import com.echothree.model.data.contact.common.pk.ContactPostalAddressPK; 037import com.echothree.model.data.contact.server.value.ContactPostalAddressValue; 038import com.echothree.model.data.contact.server.entity.ContactPostalAddress; 039import com.echothree.util.common.exception.PersistenceDatabaseException; 040import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 041import com.echothree.util.common.exception.PersistenceNotNullException; 042import com.echothree.util.server.persistence.BaseFactory; 043import com.echothree.util.server.persistence.EntityIdGenerator; 044import com.echothree.util.server.persistence.EntityPermission; 045import com.echothree.util.server.persistence.PersistenceDebugFlags; 046import com.echothree.util.server.persistence.Session; 047import com.echothree.util.server.persistence.ThreadSession; 048import java.sql.PreparedStatement; 049import java.sql.ResultSet; 050import java.sql.SQLException; 051import java.sql.Types; 052import java.io.ByteArrayInputStream; 053import java.io.StringReader; 054import java.util.ArrayList; 055import java.util.Collection; 056import java.util.HashSet; 057import java.util.List; 058import java.util.Map; 059import java.util.Set; 060import org.apache.commons.logging.Log; 061import org.apache.commons.logging.LogFactory; 062 063public class ContactPostalAddressFactory 064 implements BaseFactory<ContactPostalAddressPK, ContactPostalAddress> { 065 066 //final private static Log log = LogFactory.getLog(ContactPostalAddressFactory.class); 067 068 final private static String SQL_SELECT_READ_ONLY = "SELECT ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?"; 069 final private static String SQL_SELECT_READ_WRITE = "SELECT ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ? FOR UPDATE"; 070 final private static String SQL_INSERT = "INSERT INTO contactpostaladdresses (ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 071 final private static String SQL_UPDATE = "UPDATE contactpostaladdresses SET ctpa_cmch_contactmechanismid = ?, ctpa_pert_personaltitleid = ?, ctpa_firstname = ?, ctpa_firstnamesdx = ?, ctpa_middlename = ?, ctpa_middlenamesdx = ?, ctpa_lastname = ?, ctpa_lastnamesdx = ?, ctpa_nsfx_namesuffixid = ?, ctpa_companyname = ?, ctpa_attention = ?, ctpa_address1 = ?, ctpa_address2 = ?, ctpa_address3 = ?, ctpa_city = ?, ctpa_citygeocodeid = ?, ctpa_countygeocodeid = ?, ctpa_state = ?, ctpa_stategeocodeid = ?, ctpa_postalcode = ?, ctpa_postalcodegeocodeid = ?, ctpa_countrygeocodeid = ?, ctpa_iscommercial = ?, ctpa_fromtime = ?, ctpa_thrutime = ? WHERE ctpa_contactpostaladdressid = ?"; 072 final private static String SQL_DELETE = "DELETE FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?"; 073 final private static String SQL_VALID = "SELECT COUNT(*) FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?"; 074 075 final private static String PK_COLUMN = "ctpa_contactpostaladdressid"; 076 final private static String ALL_COLUMNS = "ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime"; 077 final public static String TABLE_NAME = "contactpostaladdresses"; 078 079 final public static String CTPA_CONTACTPOSTALADDRESSID = "ctpa_contactpostaladdressid"; 080 final public static String CTPA_CMCH_CONTACTMECHANISMID = "ctpa_cmch_contactmechanismid"; 081 final public static String CTPA_PERT_PERSONALTITLEID = "ctpa_pert_personaltitleid"; 082 final public static String CTPA_FIRSTNAME = "ctpa_firstname"; 083 final public static String CTPA_FIRSTNAMESDX = "ctpa_firstnamesdx"; 084 final public static String CTPA_MIDDLENAME = "ctpa_middlename"; 085 final public static String CTPA_MIDDLENAMESDX = "ctpa_middlenamesdx"; 086 final public static String CTPA_LASTNAME = "ctpa_lastname"; 087 final public static String CTPA_LASTNAMESDX = "ctpa_lastnamesdx"; 088 final public static String CTPA_NSFX_NAMESUFFIXID = "ctpa_nsfx_namesuffixid"; 089 final public static String CTPA_COMPANYNAME = "ctpa_companyname"; 090 final public static String CTPA_ATTENTION = "ctpa_attention"; 091 final public static String CTPA_ADDRESS1 = "ctpa_address1"; 092 final public static String CTPA_ADDRESS2 = "ctpa_address2"; 093 final public static String CTPA_ADDRESS3 = "ctpa_address3"; 094 final public static String CTPA_CITY = "ctpa_city"; 095 final public static String CTPA_CITYGEOCODEID = "ctpa_citygeocodeid"; 096 final public static String CTPA_COUNTYGEOCODEID = "ctpa_countygeocodeid"; 097 final public static String CTPA_STATE = "ctpa_state"; 098 final public static String CTPA_STATEGEOCODEID = "ctpa_stategeocodeid"; 099 final public static String CTPA_POSTALCODE = "ctpa_postalcode"; 100 final public static String CTPA_POSTALCODEGEOCODEID = "ctpa_postalcodegeocodeid"; 101 final public static String CTPA_COUNTRYGEOCODEID = "ctpa_countrygeocodeid"; 102 final public static String CTPA_ISCOMMERCIAL = "ctpa_iscommercial"; 103 final public static String CTPA_FROMTIME = "ctpa_fromtime"; 104 final public static String CTPA_THRUTIME = "ctpa_thrutime"; 105 106 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ContactPostalAddressConstants.COMPONENT_VENDOR_NAME, ContactPostalAddressConstants.ENTITY_TYPE_NAME); 107 108 /** Creates a new instance of ContactPostalAddressFactory */ 109 private ContactPostalAddressFactory() { 110 super(); 111 } 112 113 private static class ContactPostalAddressFactoryHolder { 114 static ContactPostalAddressFactory instance = new ContactPostalAddressFactory(); 115 } 116 117 public static ContactPostalAddressFactory getInstance() { 118 return ContactPostalAddressFactoryHolder.instance; 119 } 120 121 @Override 122 public String getPKColumn() { 123 return PK_COLUMN; 124 } 125 126 @Override 127 public String getAllColumns() { 128 return ALL_COLUMNS; 129 } 130 131 @Override 132 public String getTableName() { 133 return TABLE_NAME; 134 } 135 136 @Override 137 public String getComponentVendorName() { 138 return ContactPostalAddressConstants.COMPONENT_VENDOR_NAME; 139 } 140 141 @Override 142 public String getEntityTypeName() { 143 return ContactPostalAddressConstants.ENTITY_TYPE_NAME; 144 } 145 146 public PreparedStatement prepareStatement(String query) { 147 return ThreadSession.currentSession().prepareStatement(ContactPostalAddressFactory.class, query); 148 } 149 150 public ContactPostalAddressPK getNextPK() { 151 return new ContactPostalAddressPK(entityIdGenerator.getNextEntityId()); 152 } 153 154 public Set<ContactPostalAddressPK> getPKsFromResultSetAsSet(ResultSet rs) 155 throws PersistenceDatabaseException { 156 Set<ContactPostalAddressPK> _result = new HashSet<>(); 157 158 try { 159 while(rs.next()) { 160 _result.add(getPKFromResultSet(rs)); 161 } 162 } catch (SQLException se) { 163 throw new PersistenceDatabaseException(se); 164 } 165 166 return _result; 167 } 168 169 public java.util.List<ContactPostalAddressPK> getPKsFromResultSetAsList(ResultSet rs) 170 throws PersistenceDatabaseException { 171 java.util.List<ContactPostalAddressPK> _result = new ArrayList<>(); 172 173 try { 174 while(rs.next()) { 175 _result.add(getPKFromResultSet(rs)); 176 } 177 } catch (SQLException se) { 178 throw new PersistenceDatabaseException(se); 179 } 180 181 return _result; 182 } 183 184 public ContactPostalAddressPK getPKFromResultSet(ResultSet rs) 185 throws PersistenceDatabaseException { 186 ContactPostalAddressPK _result; 187 188 try { 189 long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID); 190 Long _entityId = rs.wasNull() ? null : ctpa_contactpostaladdressid; 191 192 _result = new ContactPostalAddressPK(_entityId); 193 } catch (SQLException se) { 194 throw new PersistenceDatabaseException(se); 195 } 196 197 return _result; 198 } 199 200 public java.util.List<ContactPostalAddressValue> getValuesFromPKs(Session session, Collection<ContactPostalAddressPK> pks) 201 throws PersistenceDatabaseException { 202 java.util.List<ContactPostalAddressValue> _values = new ArrayList<>(pks.size()); 203 204 for(ContactPostalAddressPK _pk: pks) { 205 _values.add(getValueFromPK(session, _pk)); 206 } 207 208 return _values; 209 } 210 211 public ContactPostalAddressValue getValueFromPK(Session session, ContactPostalAddressPK pk) 212 throws PersistenceDatabaseException { 213 ContactPostalAddressValue _value; 214 215 // See if we already have the entity in the session cache 216 ContactPostalAddress _entity = (ContactPostalAddress)session.getEntity(pk); 217 if(_entity == null) 218 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getContactPostalAddressValue(); 219 else 220 _value = _entity.getContactPostalAddressValue(); 221 222 return _value; 223 } 224 225 public java.util.List<ContactPostalAddressValue> getValuesFromResultSet(Session session, ResultSet rs) 226 throws PersistenceDatabaseException { 227 java.util.List<ContactPostalAddressValue> _result = new ArrayList<>(); 228 229 try { 230 while(rs.next()) { 231 _result.add(getValueFromResultSet(session, rs)); 232 } 233 } catch (SQLException se) { 234 throw new PersistenceDatabaseException(se); 235 } 236 237 return _result; 238 } 239 240 public ContactPostalAddressValue getValueFromResultSet(Session session, ResultSet rs) 241 throws PersistenceDatabaseException { 242 ContactPostalAddressValue _value; 243 244 try { 245 Long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID); 246 ContactPostalAddressPK _pk = new ContactPostalAddressPK(ctpa_contactpostaladdressid); 247 248 // See if we already have the entity in the session cache 249 ContactPostalAddress _entity = (ContactPostalAddress)session.getEntity(_pk); 250 251 if(_entity == null) { 252 Long ctpa_cmch_contactmechanismid = rs.getLong(CTPA_CMCH_CONTACTMECHANISMID); 253 if(rs.wasNull()) 254 ctpa_cmch_contactmechanismid = null; 255 256 Long ctpa_pert_personaltitleid = rs.getLong(CTPA_PERT_PERSONALTITLEID); 257 if(rs.wasNull()) 258 ctpa_pert_personaltitleid = null; 259 260 String ctpa_firstname = rs.getString(CTPA_FIRSTNAME); 261 if(rs.wasNull()) 262 ctpa_firstname = null; 263 264 String ctpa_firstnamesdx = rs.getString(CTPA_FIRSTNAMESDX); 265 if(rs.wasNull()) 266 ctpa_firstnamesdx = null; 267 268 String ctpa_middlename = rs.getString(CTPA_MIDDLENAME); 269 if(rs.wasNull()) 270 ctpa_middlename = null; 271 272 String ctpa_middlenamesdx = rs.getString(CTPA_MIDDLENAMESDX); 273 if(rs.wasNull()) 274 ctpa_middlenamesdx = null; 275 276 String ctpa_lastname = rs.getString(CTPA_LASTNAME); 277 if(rs.wasNull()) 278 ctpa_lastname = null; 279 280 String ctpa_lastnamesdx = rs.getString(CTPA_LASTNAMESDX); 281 if(rs.wasNull()) 282 ctpa_lastnamesdx = null; 283 284 Long ctpa_nsfx_namesuffixid = rs.getLong(CTPA_NSFX_NAMESUFFIXID); 285 if(rs.wasNull()) 286 ctpa_nsfx_namesuffixid = null; 287 288 String ctpa_companyname = rs.getString(CTPA_COMPANYNAME); 289 if(rs.wasNull()) 290 ctpa_companyname = null; 291 292 String ctpa_attention = rs.getString(CTPA_ATTENTION); 293 if(rs.wasNull()) 294 ctpa_attention = null; 295 296 String ctpa_address1 = rs.getString(CTPA_ADDRESS1); 297 if(rs.wasNull()) 298 ctpa_address1 = null; 299 300 String ctpa_address2 = rs.getString(CTPA_ADDRESS2); 301 if(rs.wasNull()) 302 ctpa_address2 = null; 303 304 String ctpa_address3 = rs.getString(CTPA_ADDRESS3); 305 if(rs.wasNull()) 306 ctpa_address3 = null; 307 308 String ctpa_city = rs.getString(CTPA_CITY); 309 if(rs.wasNull()) 310 ctpa_city = null; 311 312 Long ctpa_citygeocodeid = rs.getLong(CTPA_CITYGEOCODEID); 313 if(rs.wasNull()) 314 ctpa_citygeocodeid = null; 315 316 Long ctpa_countygeocodeid = rs.getLong(CTPA_COUNTYGEOCODEID); 317 if(rs.wasNull()) 318 ctpa_countygeocodeid = null; 319 320 String ctpa_state = rs.getString(CTPA_STATE); 321 if(rs.wasNull()) 322 ctpa_state = null; 323 324 Long ctpa_stategeocodeid = rs.getLong(CTPA_STATEGEOCODEID); 325 if(rs.wasNull()) 326 ctpa_stategeocodeid = null; 327 328 String ctpa_postalcode = rs.getString(CTPA_POSTALCODE); 329 if(rs.wasNull()) 330 ctpa_postalcode = null; 331 332 Long ctpa_postalcodegeocodeid = rs.getLong(CTPA_POSTALCODEGEOCODEID); 333 if(rs.wasNull()) 334 ctpa_postalcodegeocodeid = null; 335 336 Long ctpa_countrygeocodeid = rs.getLong(CTPA_COUNTRYGEOCODEID); 337 if(rs.wasNull()) 338 ctpa_countrygeocodeid = null; 339 340 Boolean ctpa_iscommercial = rs.getInt(CTPA_ISCOMMERCIAL) == 1; 341 if(rs.wasNull()) 342 ctpa_iscommercial = null; 343 344 Long ctpa_fromtime = rs.getLong(CTPA_FROMTIME); 345 if(rs.wasNull()) 346 ctpa_fromtime = null; 347 348 Long ctpa_thrutime = rs.getLong(CTPA_THRUTIME); 349 if(rs.wasNull()) 350 ctpa_thrutime = null; 351 352 _value = new ContactPostalAddressValue(_pk, new ContactMechanismPK(ctpa_cmch_contactmechanismid), new PersonalTitlePK(ctpa_pert_personaltitleid), ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, new NameSuffixPK(ctpa_nsfx_namesuffixid), ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, new GeoCodePK(ctpa_citygeocodeid), new GeoCodePK(ctpa_countygeocodeid), ctpa_state, new GeoCodePK(ctpa_stategeocodeid), ctpa_postalcode, new GeoCodePK(ctpa_postalcodegeocodeid), new GeoCodePK(ctpa_countrygeocodeid), ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime); 353 } else 354 _value = _entity.getContactPostalAddressValue(); 355 } catch (SQLException se) { 356 throw new PersistenceDatabaseException(se); 357 } 358 359 return _value; 360 } 361 362 public java.util.List<ContactPostalAddress> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ContactPostalAddressPK> pks) 363 throws PersistenceDatabaseException { 364 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 365 } 366 367 public java.util.List<ContactPostalAddress> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<ContactPostalAddressPK> pks) 368 throws PersistenceDatabaseException { 369 java.util.List<ContactPostalAddress> _entities = new ArrayList<>(pks.size()); 370 371 for(ContactPostalAddressPK _pk: pks) { 372 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 373 } 374 375 return _entities; 376 } 377 378 public ContactPostalAddress getEntityFromValue(EntityPermission entityPermission, ContactPostalAddressValue value) { 379 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 380 } 381 382 public ContactPostalAddress getEntityFromValue(Session session, EntityPermission entityPermission, ContactPostalAddressValue value) { 383 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 384 } 385 386 public ContactPostalAddress getEntityFromPK(EntityPermission entityPermission, ContactPostalAddressPK pk) 387 throws PersistenceDatabaseException { 388 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 389 } 390 391 public ContactPostalAddress getEntityFromCache(Session session, ContactPostalAddressPK pk) { 392 ContactPostalAddressValue _value = (ContactPostalAddressValue)session.getValueCache().get(pk); 393 394 return _value == null ? null : new ContactPostalAddress(_value, EntityPermission.READ_ONLY); 395 } 396 397 public ContactPostalAddress getEntityFromPK(Session session, EntityPermission entityPermission, ContactPostalAddressPK pk) 398 throws PersistenceDatabaseException { 399 ContactPostalAddress _entity; 400 401 // See if we already have the entity in the session cache 402 _entity = (ContactPostalAddress)session.getEntity(pk); 403 if(_entity != null) { 404 // If the requested permission is READ_WRITE, and the cached permission is 405 // READ_ONLY, then pretend that the cached object wasn't found, and create 406 // a new entity that is READ_WRITE. 407 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 408 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 409 _entity = null; 410 } 411 } 412 413 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 414 _entity = getEntityFromCache(session, pk); 415 } 416 417 if(_entity == null) { 418 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 419 long _entityId = pk.getEntityId(); 420 ResultSet _rs = null; 421 422 try { 423 _ps.setLong(1, _entityId); 424 _rs = _ps.executeQuery(); 425 if(_rs.next()) { 426 _entity = getEntityFromResultSet(session, entityPermission, _rs); 427 } 428 } catch (SQLException se) { 429 throw new PersistenceDatabaseException(se); 430 } finally { 431 if(_rs != null) { 432 try { 433 _rs.close(); 434 } catch (SQLException se) { 435 // do nothing 436 } 437 } 438 } 439 } 440 441 return _entity; 442 } 443 444 public Set<ContactPostalAddressPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 445 throws PersistenceDatabaseException { 446 Set<ContactPostalAddressPK> _pks; 447 ResultSet _rs = null; 448 449 try { 450 if(params.length != 0) { 451 Session.setQueryParams(ps, params); 452 } 453 454 _rs = ps.executeQuery(); 455 _pks = getPKsFromResultSetAsSet(_rs); 456 _rs.close(); 457 } catch (SQLException se) { 458 throw new PersistenceDatabaseException(se); 459 } finally { 460 if(_rs != null) { 461 try { 462 _rs.close(); 463 } catch (SQLException se) { 464 // do nothing 465 } 466 } 467 } 468 469 return _pks; 470 } 471 472 public java.util.List<ContactPostalAddressPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 473 throws PersistenceDatabaseException { 474 java.util.List<ContactPostalAddressPK> _pks; 475 ResultSet _rs = null; 476 477 try { 478 if(params.length != 0) { 479 Session.setQueryParams(ps, params); 480 } 481 482 _rs = ps.executeQuery(); 483 _pks = getPKsFromResultSetAsList(_rs); 484 _rs.close(); 485 } catch (SQLException se) { 486 throw new PersistenceDatabaseException(se); 487 } finally { 488 if(_rs != null) { 489 try { 490 _rs.close(); 491 } catch (SQLException se) { 492 // do nothing 493 } 494 } 495 } 496 497 return _pks; 498 } 499 500 public ContactPostalAddressPK getPKFromQuery(PreparedStatement ps, final Object... params) 501 throws PersistenceDatabaseException { 502 ContactPostalAddressPK _pk = null; 503 ResultSet _rs = null; 504 505 try { 506 if(params.length != 0) { 507 Session.setQueryParams(ps, params); 508 } 509 510 _rs = ps.executeQuery(); 511 if(_rs.next()) { 512 _pk = getPKFromResultSet(_rs); 513 } 514 _rs.close(); 515 } catch (SQLException se) { 516 throw new PersistenceDatabaseException(se); 517 } finally { 518 if(_rs != null) { 519 try { 520 _rs.close(); 521 } catch (SQLException se) { 522 // do nothing 523 } 524 } 525 } 526 527 return _pk; 528 } 529 530 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 531 throws PersistenceDatabaseException { 532 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 533 534 return getEntitiesFromQuery(session, entityPermission, ps, params); 535 } 536 537 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 538 throws PersistenceDatabaseException { 539 Session session = ThreadSession.currentSession(); 540 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 541 542 return getEntitiesFromQuery(session, entityPermission, ps, params); 543 } 544 545 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 546 throws PersistenceDatabaseException { 547 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 548 549 return getEntitiesFromQuery(session, entityPermission, ps); 550 } 551 552 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 553 throws PersistenceDatabaseException { 554 Session session = ThreadSession.currentSession(); 555 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 556 557 return getEntitiesFromQuery(session, entityPermission, ps); 558 } 559 560 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 561 throws PersistenceDatabaseException { 562 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 563 } 564 565 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 566 throws PersistenceDatabaseException { 567 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 568 } 569 570 public java.util.List<ContactPostalAddress> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 571 throws PersistenceDatabaseException { 572 java.util.List<ContactPostalAddress> _entities; 573 ResultSet _rs = null; 574 575 try { 576 if(params.length != 0) { 577 Session.setQueryParams(ps, params); 578 } 579 580 _rs = ps.executeQuery(); 581 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 582 _rs.close(); 583 } catch (SQLException se) { 584 throw new PersistenceDatabaseException(se); 585 } finally { 586 if(_rs != null) { 587 try { 588 _rs.close(); 589 } catch (SQLException se) { 590 // do nothing 591 } 592 } 593 } 594 595 return _entities; 596 } 597 598 public ContactPostalAddress getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 599 throws PersistenceDatabaseException { 600 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 601 602 return getEntityFromQuery(session, entityPermission, ps, params); 603 } 604 605 public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 606 throws PersistenceDatabaseException { 607 Session session = ThreadSession.currentSession(); 608 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 609 610 return getEntityFromQuery(session, entityPermission, ps, params); 611 } 612 613 public ContactPostalAddress getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 614 throws PersistenceDatabaseException { 615 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 616 617 return getEntityFromQuery(session, entityPermission, ps); 618 } 619 620 public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 621 throws PersistenceDatabaseException { 622 Session session = ThreadSession.currentSession(); 623 PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission)); 624 625 return getEntityFromQuery(session, entityPermission, ps); 626 } 627 628 public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 629 throws PersistenceDatabaseException { 630 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 631 } 632 633 public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 634 throws PersistenceDatabaseException { 635 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 636 } 637 638 public ContactPostalAddress getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 639 throws PersistenceDatabaseException { 640 ContactPostalAddress _entity = null; 641 ResultSet _rs = null; 642 643 try { 644 if(params.length != 0) { 645 Session.setQueryParams(ps, params); 646 } 647 648 _rs = ps.executeQuery(); 649 if(_rs.next()) { 650 _entity = getEntityFromResultSet(session, entityPermission, _rs); 651 } 652 _rs.close(); 653 } catch (SQLException se) { 654 throw new PersistenceDatabaseException(se); 655 } finally { 656 if(_rs != null) { 657 try { 658 _rs.close(); 659 } catch (SQLException se) { 660 // do nothing 661 } 662 } 663 } 664 665 return _entity; 666 } 667 668 public java.util.List<ContactPostalAddress> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 669 throws PersistenceDatabaseException { 670 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 671 } 672 673 public java.util.List<ContactPostalAddress> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 674 throws PersistenceDatabaseException { 675 java.util.List<ContactPostalAddress> _result = new ArrayList<>(); 676 677 try { 678 while(rs.next()) { 679 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 680 } 681 } catch (SQLException se) { 682 throw new PersistenceDatabaseException(se); 683 } 684 685 return _result; 686 } 687 688 public ContactPostalAddress getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 689 throws PersistenceDatabaseException { 690 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 691 } 692 693 public ContactPostalAddress getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 694 throws PersistenceDatabaseException { 695 ContactPostalAddress _entity; 696 697 try { 698 Long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID); 699 ContactPostalAddressPK _pk = new ContactPostalAddressPK(ctpa_contactpostaladdressid); 700 701 // See if we already have the entity in the session cache 702 _entity = (ContactPostalAddress)session.getEntity(_pk); 703 if(_entity != null) { 704 // If the requested permission is READ_WRITE, and the cached permission is 705 // READ_ONLY, then pretend that the cached object wasn't found, and create 706 // a new entity that is READ_WRITE. 707 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 708 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 709 _entity = null; 710 } 711 } 712 boolean foundInSessionCache = _entity != null; 713 714 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 715 _entity = getEntityFromCache(session, _pk); 716 } 717 718 if(_entity == null) { 719 Long ctpa_cmch_contactmechanismid = rs.getLong(CTPA_CMCH_CONTACTMECHANISMID); 720 if(rs.wasNull()) 721 ctpa_cmch_contactmechanismid = null; 722 723 Long ctpa_pert_personaltitleid = rs.getLong(CTPA_PERT_PERSONALTITLEID); 724 if(rs.wasNull()) 725 ctpa_pert_personaltitleid = null; 726 727 String ctpa_firstname = rs.getString(CTPA_FIRSTNAME); 728 if(rs.wasNull()) 729 ctpa_firstname = null; 730 731 String ctpa_firstnamesdx = rs.getString(CTPA_FIRSTNAMESDX); 732 if(rs.wasNull()) 733 ctpa_firstnamesdx = null; 734 735 String ctpa_middlename = rs.getString(CTPA_MIDDLENAME); 736 if(rs.wasNull()) 737 ctpa_middlename = null; 738 739 String ctpa_middlenamesdx = rs.getString(CTPA_MIDDLENAMESDX); 740 if(rs.wasNull()) 741 ctpa_middlenamesdx = null; 742 743 String ctpa_lastname = rs.getString(CTPA_LASTNAME); 744 if(rs.wasNull()) 745 ctpa_lastname = null; 746 747 String ctpa_lastnamesdx = rs.getString(CTPA_LASTNAMESDX); 748 if(rs.wasNull()) 749 ctpa_lastnamesdx = null; 750 751 Long ctpa_nsfx_namesuffixid = rs.getLong(CTPA_NSFX_NAMESUFFIXID); 752 if(rs.wasNull()) 753 ctpa_nsfx_namesuffixid = null; 754 755 String ctpa_companyname = rs.getString(CTPA_COMPANYNAME); 756 if(rs.wasNull()) 757 ctpa_companyname = null; 758 759 String ctpa_attention = rs.getString(CTPA_ATTENTION); 760 if(rs.wasNull()) 761 ctpa_attention = null; 762 763 String ctpa_address1 = rs.getString(CTPA_ADDRESS1); 764 if(rs.wasNull()) 765 ctpa_address1 = null; 766 767 String ctpa_address2 = rs.getString(CTPA_ADDRESS2); 768 if(rs.wasNull()) 769 ctpa_address2 = null; 770 771 String ctpa_address3 = rs.getString(CTPA_ADDRESS3); 772 if(rs.wasNull()) 773 ctpa_address3 = null; 774 775 String ctpa_city = rs.getString(CTPA_CITY); 776 if(rs.wasNull()) 777 ctpa_city = null; 778 779 Long ctpa_citygeocodeid = rs.getLong(CTPA_CITYGEOCODEID); 780 if(rs.wasNull()) 781 ctpa_citygeocodeid = null; 782 783 Long ctpa_countygeocodeid = rs.getLong(CTPA_COUNTYGEOCODEID); 784 if(rs.wasNull()) 785 ctpa_countygeocodeid = null; 786 787 String ctpa_state = rs.getString(CTPA_STATE); 788 if(rs.wasNull()) 789 ctpa_state = null; 790 791 Long ctpa_stategeocodeid = rs.getLong(CTPA_STATEGEOCODEID); 792 if(rs.wasNull()) 793 ctpa_stategeocodeid = null; 794 795 String ctpa_postalcode = rs.getString(CTPA_POSTALCODE); 796 if(rs.wasNull()) 797 ctpa_postalcode = null; 798 799 Long ctpa_postalcodegeocodeid = rs.getLong(CTPA_POSTALCODEGEOCODEID); 800 if(rs.wasNull()) 801 ctpa_postalcodegeocodeid = null; 802 803 Long ctpa_countrygeocodeid = rs.getLong(CTPA_COUNTRYGEOCODEID); 804 if(rs.wasNull()) 805 ctpa_countrygeocodeid = null; 806 807 Boolean ctpa_iscommercial = rs.getInt(CTPA_ISCOMMERCIAL) == 1; 808 if(rs.wasNull()) 809 ctpa_iscommercial = null; 810 811 Long ctpa_fromtime = rs.getLong(CTPA_FROMTIME); 812 if(rs.wasNull()) 813 ctpa_fromtime = null; 814 815 Long ctpa_thrutime = rs.getLong(CTPA_THRUTIME); 816 if(rs.wasNull()) 817 ctpa_thrutime = null; 818 819 ContactPostalAddressValue _value = new ContactPostalAddressValue(_pk, ctpa_cmch_contactmechanismid == null? null: new ContactMechanismPK(ctpa_cmch_contactmechanismid), ctpa_pert_personaltitleid == null? null: new PersonalTitlePK(ctpa_pert_personaltitleid), ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid == null? null: new NameSuffixPK(ctpa_nsfx_namesuffixid), ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid == null? null: new GeoCodePK(ctpa_citygeocodeid), ctpa_countygeocodeid == null? null: new GeoCodePK(ctpa_countygeocodeid), ctpa_state, ctpa_stategeocodeid == null? null: new GeoCodePK(ctpa_stategeocodeid), ctpa_postalcode, ctpa_postalcodegeocodeid == null? null: new GeoCodePK(ctpa_postalcodegeocodeid), ctpa_countrygeocodeid == null? null: new GeoCodePK(ctpa_countrygeocodeid), ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime); 820 _entity = new ContactPostalAddress(_value, entityPermission); 821 } 822 823 if(!foundInSessionCache) { 824 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 825 session.putReadOnlyEntity(_pk, _entity); 826 session.getValueCache().put(_entity.getContactPostalAddressValue()); 827 } else { 828 session.putReadWriteEntity(_pk, _entity); 829 } 830 } 831 } catch (SQLException se) { 832 throw new PersistenceDatabaseException(se); 833 } 834 835 return _entity; 836 } 837 838 public ContactPostalAddress create(Session session, ContactMechanism contactMechanism, PersonalTitle personalTitle, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffix nameSuffix, String companyName, String attention, String address1, String address2, String address3, String city, GeoCode cityGeoCode, GeoCode countyGeoCode, String state, GeoCode stateGeoCode, String postalCode, GeoCode postalCodeGeoCode, GeoCode countryGeoCode, Boolean isCommercial, Long fromTime, Long thruTime) 839 throws PersistenceDatabaseException, PersistenceNotNullException { 840 return create(session, contactMechanism == null ? null : contactMechanism.getPrimaryKey(), personalTitle == null ? null : personalTitle.getPrimaryKey(), firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffix == null ? null : nameSuffix.getPrimaryKey(), companyName, attention, address1, address2, address3, city, cityGeoCode == null ? null : cityGeoCode.getPrimaryKey(), countyGeoCode == null ? null : countyGeoCode.getPrimaryKey(), state, stateGeoCode == null ? null : stateGeoCode.getPrimaryKey(), postalCode, postalCodeGeoCode == null ? null : postalCodeGeoCode.getPrimaryKey(), countryGeoCode == null ? null : countryGeoCode.getPrimaryKey(), isCommercial, fromTime, thruTime); 841 } 842 843 public ContactPostalAddress create(ContactMechanism contactMechanism, PersonalTitle personalTitle, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffix nameSuffix, String companyName, String attention, String address1, String address2, String address3, String city, GeoCode cityGeoCode, GeoCode countyGeoCode, String state, GeoCode stateGeoCode, String postalCode, GeoCode postalCodeGeoCode, GeoCode countryGeoCode, Boolean isCommercial, Long fromTime, Long thruTime) 844 throws PersistenceDatabaseException, PersistenceNotNullException { 845 return create(ThreadSession.currentSession(), contactMechanism == null ? null : contactMechanism.getPrimaryKey(), personalTitle == null ? null : personalTitle.getPrimaryKey(), firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffix == null ? null : nameSuffix.getPrimaryKey(), companyName, attention, address1, address2, address3, city, cityGeoCode == null ? null : cityGeoCode.getPrimaryKey(), countyGeoCode == null ? null : countyGeoCode.getPrimaryKey(), state, stateGeoCode == null ? null : stateGeoCode.getPrimaryKey(), postalCode, postalCodeGeoCode == null ? null : postalCodeGeoCode.getPrimaryKey(), countryGeoCode == null ? null : countryGeoCode.getPrimaryKey(), isCommercial, fromTime, thruTime); 846 } 847 848 private void bindForCreate(PreparedStatement _ps, ContactPostalAddressValue _value) 849 throws SQLException { 850 _ps.setLong(1, _value.getEntityId()); 851 852 ContactMechanismPK ctpa_cmch_contactmechanismid = _value.getContactMechanismPK(); 853 if(ctpa_cmch_contactmechanismid == null) 854 _ps.setNull(2, Types.BIGINT); 855 else 856 _ps.setLong(2, ctpa_cmch_contactmechanismid.getEntityId()); 857 858 PersonalTitlePK ctpa_pert_personaltitleid = _value.getPersonalTitlePK(); 859 if(ctpa_pert_personaltitleid == null) 860 _ps.setNull(3, Types.BIGINT); 861 else 862 _ps.setLong(3, ctpa_pert_personaltitleid.getEntityId()); 863 864 String ctpa_firstname = _value.getFirstName(); 865 if(ctpa_firstname == null) 866 _ps.setNull(4, Types.VARCHAR); 867 else 868 _ps.setString(4, ctpa_firstname); 869 870 String ctpa_firstnamesdx = _value.getFirstNameSdx(); 871 if(ctpa_firstnamesdx == null) 872 _ps.setNull(5, Types.VARCHAR); 873 else 874 _ps.setString(5, ctpa_firstnamesdx); 875 876 String ctpa_middlename = _value.getMiddleName(); 877 if(ctpa_middlename == null) 878 _ps.setNull(6, Types.VARCHAR); 879 else 880 _ps.setString(6, ctpa_middlename); 881 882 String ctpa_middlenamesdx = _value.getMiddleNameSdx(); 883 if(ctpa_middlenamesdx == null) 884 _ps.setNull(7, Types.VARCHAR); 885 else 886 _ps.setString(7, ctpa_middlenamesdx); 887 888 String ctpa_lastname = _value.getLastName(); 889 if(ctpa_lastname == null) 890 _ps.setNull(8, Types.VARCHAR); 891 else 892 _ps.setString(8, ctpa_lastname); 893 894 String ctpa_lastnamesdx = _value.getLastNameSdx(); 895 if(ctpa_lastnamesdx == null) 896 _ps.setNull(9, Types.VARCHAR); 897 else 898 _ps.setString(9, ctpa_lastnamesdx); 899 900 NameSuffixPK ctpa_nsfx_namesuffixid = _value.getNameSuffixPK(); 901 if(ctpa_nsfx_namesuffixid == null) 902 _ps.setNull(10, Types.BIGINT); 903 else 904 _ps.setLong(10, ctpa_nsfx_namesuffixid.getEntityId()); 905 906 String ctpa_companyname = _value.getCompanyName(); 907 if(ctpa_companyname == null) 908 _ps.setNull(11, Types.VARCHAR); 909 else 910 _ps.setString(11, ctpa_companyname); 911 912 String ctpa_attention = _value.getAttention(); 913 if(ctpa_attention == null) 914 _ps.setNull(12, Types.VARCHAR); 915 else 916 _ps.setString(12, ctpa_attention); 917 918 String ctpa_address1 = _value.getAddress1(); 919 if(ctpa_address1 == null) 920 _ps.setNull(13, Types.VARCHAR); 921 else 922 _ps.setString(13, ctpa_address1); 923 924 String ctpa_address2 = _value.getAddress2(); 925 if(ctpa_address2 == null) 926 _ps.setNull(14, Types.VARCHAR); 927 else 928 _ps.setString(14, ctpa_address2); 929 930 String ctpa_address3 = _value.getAddress3(); 931 if(ctpa_address3 == null) 932 _ps.setNull(15, Types.VARCHAR); 933 else 934 _ps.setString(15, ctpa_address3); 935 936 String ctpa_city = _value.getCity(); 937 if(ctpa_city == null) 938 _ps.setNull(16, Types.VARCHAR); 939 else 940 _ps.setString(16, ctpa_city); 941 942 GeoCodePK ctpa_citygeocodeid = _value.getCityGeoCodePK(); 943 if(ctpa_citygeocodeid == null) 944 _ps.setNull(17, Types.BIGINT); 945 else 946 _ps.setLong(17, ctpa_citygeocodeid.getEntityId()); 947 948 GeoCodePK ctpa_countygeocodeid = _value.getCountyGeoCodePK(); 949 if(ctpa_countygeocodeid == null) 950 _ps.setNull(18, Types.BIGINT); 951 else 952 _ps.setLong(18, ctpa_countygeocodeid.getEntityId()); 953 954 String ctpa_state = _value.getState(); 955 if(ctpa_state == null) 956 _ps.setNull(19, Types.VARCHAR); 957 else 958 _ps.setString(19, ctpa_state); 959 960 GeoCodePK ctpa_stategeocodeid = _value.getStateGeoCodePK(); 961 if(ctpa_stategeocodeid == null) 962 _ps.setNull(20, Types.BIGINT); 963 else 964 _ps.setLong(20, ctpa_stategeocodeid.getEntityId()); 965 966 String ctpa_postalcode = _value.getPostalCode(); 967 if(ctpa_postalcode == null) 968 _ps.setNull(21, Types.VARCHAR); 969 else 970 _ps.setString(21, ctpa_postalcode); 971 972 GeoCodePK ctpa_postalcodegeocodeid = _value.getPostalCodeGeoCodePK(); 973 if(ctpa_postalcodegeocodeid == null) 974 _ps.setNull(22, Types.BIGINT); 975 else 976 _ps.setLong(22, ctpa_postalcodegeocodeid.getEntityId()); 977 978 GeoCodePK ctpa_countrygeocodeid = _value.getCountryGeoCodePK(); 979 if(ctpa_countrygeocodeid == null) 980 _ps.setNull(23, Types.BIGINT); 981 else 982 _ps.setLong(23, ctpa_countrygeocodeid.getEntityId()); 983 984 Boolean ctpa_iscommercial = _value.getIsCommercial(); 985 if(ctpa_iscommercial == null) 986 _ps.setNull(24, Types.BIT); 987 else 988 _ps.setInt(24, ctpa_iscommercial? 1: 0); 989 990 Long ctpa_fromtime = _value.getFromTime(); 991 if(ctpa_fromtime == null) 992 _ps.setNull(25, Types.BIGINT); 993 else 994 _ps.setLong(25, ctpa_fromtime); 995 996 Long ctpa_thrutime = _value.getThruTime(); 997 if(ctpa_thrutime == null) 998 _ps.setNull(26, Types.BIGINT); 999 else 1000 _ps.setLong(26, ctpa_thrutime); 1001 1002 } 1003 1004 public ContactPostalAddress create(Session session, ContactMechanismPK contactMechanismPK, PersonalTitlePK personalTitlePK, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffixPK nameSuffixPK, String companyName, String attention, String address1, String address2, String address3, String city, GeoCodePK cityGeoCodePK, GeoCodePK countyGeoCodePK, String state, GeoCodePK stateGeoCodePK, String postalCode, GeoCodePK postalCodeGeoCodePK, GeoCodePK countryGeoCodePK, Boolean isCommercial, Long fromTime, Long thruTime) 1005 throws PersistenceDatabaseException, PersistenceNotNullException { 1006 ContactPostalAddressPK _pk = getNextPK(); 1007 ContactPostalAddressValue _value = new ContactPostalAddressValue(_pk, contactMechanismPK, personalTitlePK, firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffixPK, companyName, attention, address1, address2, address3, city, cityGeoCodePK, countyGeoCodePK, state, stateGeoCodePK, postalCode, postalCodeGeoCodePK, countryGeoCodePK, isCommercial, fromTime, thruTime); 1008 1009 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 1010 1011 try { 1012 bindForCreate(_ps, _value); 1013 1014 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 1015 int _count = _ps.executeUpdate(); 1016 1017 if(_count != 1) { 1018 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 1019 } 1020 } else { 1021 _ps.executeUpdate(); 1022 } 1023 1024 session.getValueCache().put(_value); 1025 } catch (SQLException se) { 1026 throw new PersistenceDatabaseException(se); 1027 } 1028 1029 ContactPostalAddress _entity = new ContactPostalAddress(_value, EntityPermission.READ_ONLY); 1030 session.putReadOnlyEntity(_pk, _entity); 1031 1032 return _entity; 1033 } 1034 1035 public ContactPostalAddress create(ContactMechanismPK contactMechanismPK, PersonalTitlePK personalTitlePK, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffixPK nameSuffixPK, String companyName, String attention, String address1, String address2, String address3, String city, GeoCodePK cityGeoCodePK, GeoCodePK countyGeoCodePK, String state, GeoCodePK stateGeoCodePK, String postalCode, GeoCodePK postalCodeGeoCodePK, GeoCodePK countryGeoCodePK, Boolean isCommercial, Long fromTime, Long thruTime) 1036 throws PersistenceDatabaseException, PersistenceNotNullException { 1037 return create(ThreadSession.currentSession(), contactMechanismPK, personalTitlePK, firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffixPK, companyName, attention, address1, address2, address3, city, cityGeoCodePK, countyGeoCodePK, state, stateGeoCodePK, postalCode, postalCodeGeoCodePK, countryGeoCodePK, isCommercial, fromTime, thruTime); 1038 } 1039 1040 public void create(Session session, Collection<ContactPostalAddressValue> _values) 1041 throws PersistenceDatabaseException, PersistenceNotNullException { 1042 int _size = _values.size(); 1043 1044 if(_size > 0) { 1045 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 1046 List<ContactPostalAddressValue> _cacheValues = new ArrayList<>(_size); 1047 1048 try { 1049 for(ContactPostalAddressValue _value : _values) { 1050 _value.setEntityId(entityIdGenerator.getNextEntityId()); 1051 bindForCreate(_ps, _value); 1052 1053 _ps.addBatch(); 1054 1055 _cacheValues.add(_value); 1056 } 1057 1058 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 1059 int[] _counts = _ps.executeBatch(); 1060 1061 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 1062 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1063 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1064 } 1065 } 1066 } else { 1067 _ps.executeBatch(); 1068 } 1069 1070 _ps.clearBatch(); 1071 } catch (SQLException se) { 1072 throw new PersistenceDatabaseException(se); 1073 } 1074 1075 _cacheValues.forEach((_cacheValue) -> { 1076 ContactPostalAddress _cacheEntity = new ContactPostalAddress(_cacheValue, EntityPermission.READ_ONLY); 1077 1078 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 1079 }); 1080 } 1081 } 1082 1083 public void create(Collection<ContactPostalAddressValue> _values) 1084 throws PersistenceDatabaseException, PersistenceNotNullException { 1085 create(ThreadSession.currentSession(), _values); 1086 } 1087 1088 private boolean bindForStore(PreparedStatement _ps, ContactPostalAddressValue _value) 1089 throws SQLException { 1090 boolean _hasBeenModified = _value.hasBeenModified(); 1091 1092 if(_hasBeenModified) { 1093 ContactMechanismPK ctpa_cmch_contactmechanismid = _value.getContactMechanismPK(); 1094 if(ctpa_cmch_contactmechanismid == null) 1095 _ps.setNull(1, Types.BIGINT); 1096 else 1097 _ps.setLong(1, ctpa_cmch_contactmechanismid.getEntityId()); 1098 1099 PersonalTitlePK ctpa_pert_personaltitleid = _value.getPersonalTitlePK(); 1100 if(ctpa_pert_personaltitleid == null) 1101 _ps.setNull(2, Types.BIGINT); 1102 else 1103 _ps.setLong(2, ctpa_pert_personaltitleid.getEntityId()); 1104 1105 String ctpa_firstname = _value.getFirstName(); 1106 if(ctpa_firstname == null) 1107 _ps.setNull(3, Types.VARCHAR); 1108 else 1109 _ps.setString(3, ctpa_firstname); 1110 1111 String ctpa_firstnamesdx = _value.getFirstNameSdx(); 1112 if(ctpa_firstnamesdx == null) 1113 _ps.setNull(4, Types.VARCHAR); 1114 else 1115 _ps.setString(4, ctpa_firstnamesdx); 1116 1117 String ctpa_middlename = _value.getMiddleName(); 1118 if(ctpa_middlename == null) 1119 _ps.setNull(5, Types.VARCHAR); 1120 else 1121 _ps.setString(5, ctpa_middlename); 1122 1123 String ctpa_middlenamesdx = _value.getMiddleNameSdx(); 1124 if(ctpa_middlenamesdx == null) 1125 _ps.setNull(6, Types.VARCHAR); 1126 else 1127 _ps.setString(6, ctpa_middlenamesdx); 1128 1129 String ctpa_lastname = _value.getLastName(); 1130 if(ctpa_lastname == null) 1131 _ps.setNull(7, Types.VARCHAR); 1132 else 1133 _ps.setString(7, ctpa_lastname); 1134 1135 String ctpa_lastnamesdx = _value.getLastNameSdx(); 1136 if(ctpa_lastnamesdx == null) 1137 _ps.setNull(8, Types.VARCHAR); 1138 else 1139 _ps.setString(8, ctpa_lastnamesdx); 1140 1141 NameSuffixPK ctpa_nsfx_namesuffixid = _value.getNameSuffixPK(); 1142 if(ctpa_nsfx_namesuffixid == null) 1143 _ps.setNull(9, Types.BIGINT); 1144 else 1145 _ps.setLong(9, ctpa_nsfx_namesuffixid.getEntityId()); 1146 1147 String ctpa_companyname = _value.getCompanyName(); 1148 if(ctpa_companyname == null) 1149 _ps.setNull(10, Types.VARCHAR); 1150 else 1151 _ps.setString(10, ctpa_companyname); 1152 1153 String ctpa_attention = _value.getAttention(); 1154 if(ctpa_attention == null) 1155 _ps.setNull(11, Types.VARCHAR); 1156 else 1157 _ps.setString(11, ctpa_attention); 1158 1159 String ctpa_address1 = _value.getAddress1(); 1160 if(ctpa_address1 == null) 1161 _ps.setNull(12, Types.VARCHAR); 1162 else 1163 _ps.setString(12, ctpa_address1); 1164 1165 String ctpa_address2 = _value.getAddress2(); 1166 if(ctpa_address2 == null) 1167 _ps.setNull(13, Types.VARCHAR); 1168 else 1169 _ps.setString(13, ctpa_address2); 1170 1171 String ctpa_address3 = _value.getAddress3(); 1172 if(ctpa_address3 == null) 1173 _ps.setNull(14, Types.VARCHAR); 1174 else 1175 _ps.setString(14, ctpa_address3); 1176 1177 String ctpa_city = _value.getCity(); 1178 if(ctpa_city == null) 1179 _ps.setNull(15, Types.VARCHAR); 1180 else 1181 _ps.setString(15, ctpa_city); 1182 1183 GeoCodePK ctpa_citygeocodeid = _value.getCityGeoCodePK(); 1184 if(ctpa_citygeocodeid == null) 1185 _ps.setNull(16, Types.BIGINT); 1186 else 1187 _ps.setLong(16, ctpa_citygeocodeid.getEntityId()); 1188 1189 GeoCodePK ctpa_countygeocodeid = _value.getCountyGeoCodePK(); 1190 if(ctpa_countygeocodeid == null) 1191 _ps.setNull(17, Types.BIGINT); 1192 else 1193 _ps.setLong(17, ctpa_countygeocodeid.getEntityId()); 1194 1195 String ctpa_state = _value.getState(); 1196 if(ctpa_state == null) 1197 _ps.setNull(18, Types.VARCHAR); 1198 else 1199 _ps.setString(18, ctpa_state); 1200 1201 GeoCodePK ctpa_stategeocodeid = _value.getStateGeoCodePK(); 1202 if(ctpa_stategeocodeid == null) 1203 _ps.setNull(19, Types.BIGINT); 1204 else 1205 _ps.setLong(19, ctpa_stategeocodeid.getEntityId()); 1206 1207 String ctpa_postalcode = _value.getPostalCode(); 1208 if(ctpa_postalcode == null) 1209 _ps.setNull(20, Types.VARCHAR); 1210 else 1211 _ps.setString(20, ctpa_postalcode); 1212 1213 GeoCodePK ctpa_postalcodegeocodeid = _value.getPostalCodeGeoCodePK(); 1214 if(ctpa_postalcodegeocodeid == null) 1215 _ps.setNull(21, Types.BIGINT); 1216 else 1217 _ps.setLong(21, ctpa_postalcodegeocodeid.getEntityId()); 1218 1219 GeoCodePK ctpa_countrygeocodeid = _value.getCountryGeoCodePK(); 1220 if(ctpa_countrygeocodeid == null) 1221 _ps.setNull(22, Types.BIGINT); 1222 else 1223 _ps.setLong(22, ctpa_countrygeocodeid.getEntityId()); 1224 1225 Boolean ctpa_iscommercial = _value.getIsCommercial(); 1226 if(ctpa_iscommercial == null) 1227 _ps.setNull(23, Types.BIT); 1228 else 1229 _ps.setInt(23, ctpa_iscommercial? 1: 0); 1230 1231 Long ctpa_fromtime = _value.getFromTime(); 1232 if(ctpa_fromtime == null) 1233 _ps.setNull(24, Types.BIGINT); 1234 else 1235 _ps.setLong(24, ctpa_fromtime); 1236 1237 Long ctpa_thrutime = _value.getThruTime(); 1238 if(ctpa_thrutime == null) 1239 _ps.setNull(25, Types.BIGINT); 1240 else 1241 _ps.setLong(25, ctpa_thrutime); 1242 1243 _ps.setLong(26, _value.getPrimaryKey().getEntityId()); 1244 1245 _value.clearHasBeenModified(); 1246 } 1247 1248 return _hasBeenModified; 1249 } 1250 1251 @Override 1252 public void store(Session session, ContactPostalAddress entity) 1253 throws PersistenceDatabaseException { 1254 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1255 1256 try { 1257 ContactPostalAddressValue _value = entity.getContactPostalAddressValue(); 1258 1259 if(bindForStore(_ps, _value)) { 1260 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1261 int _count = _ps.executeUpdate(); 1262 1263 if(_count != 1) { 1264 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 1265 } 1266 } else { 1267 _ps.executeUpdate(); 1268 } 1269 1270 session.getValueCache().put(_value); 1271 } 1272 } catch (SQLException se) { 1273 throw new PersistenceDatabaseException(se); 1274 } 1275 } 1276 1277 @Override 1278 public void store(Session session, Collection<ContactPostalAddress> entities) 1279 throws PersistenceDatabaseException { 1280 if(entities.size() > 0) { 1281 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1282 int _modifiedEntities = 0; 1283 1284 try { 1285 for(ContactPostalAddress entity : entities) { 1286 if(bindForStore(_ps, entity.getContactPostalAddressValue())) { 1287 _ps.addBatch(); 1288 _modifiedEntities++; 1289 } 1290 } 1291 1292 if(_modifiedEntities != 0) { 1293 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1294 int[] _counts = _ps.executeBatch(); 1295 1296 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1297 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1298 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1299 } 1300 } 1301 } else { 1302 _ps.executeBatch(); 1303 } 1304 1305 _ps.clearBatch(); 1306 1307 entities.forEach((entity) -> { 1308 session.getValueCache().put(entity.getContactPostalAddressValue()); 1309 }); 1310 } 1311 } catch (SQLException se) { 1312 throw new PersistenceDatabaseException(se); 1313 } 1314 } 1315 } 1316 1317 @Override 1318 public void store(Collection<ContactPostalAddress> entities) 1319 throws PersistenceDatabaseException { 1320 store(ThreadSession.currentSession(), entities); 1321 } 1322 1323 @Override 1324 public void remove(Session session, ContactPostalAddress entity) 1325 throws PersistenceDatabaseException { 1326 remove(session, entity.getPrimaryKey()); 1327 } 1328 1329 @Override 1330 public void remove(Session session, ContactPostalAddressPK pk) 1331 throws PersistenceDatabaseException { 1332 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1333 long _entityId = pk.getEntityId(); 1334 1335 try { 1336 _ps.setLong(1, _entityId); 1337 1338 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1339 int _count = _ps.executeUpdate(); 1340 1341 if(_count != 1) { 1342 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1343 } 1344 } else { 1345 _ps.executeUpdate(); 1346 } 1347 1348 session.getValueCache().remove(pk); 1349 } catch (SQLException se) { 1350 throw new PersistenceDatabaseException(se); 1351 } 1352 1353 session.removed(pk, false); 1354 } 1355 1356 @Override 1357 public void remove(Session session, Collection<ContactPostalAddressPK> pks) 1358 throws PersistenceDatabaseException { 1359 if(pks.size() > 0) { 1360 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1361 int _modifiedEntities = 0; 1362 1363 try { 1364 for(ContactPostalAddressPK pk : pks) { 1365 long _entityId = pk.getEntityId(); 1366 1367 _ps.setLong(1, _entityId); 1368 1369 _ps.addBatch(); 1370 _modifiedEntities++; 1371 } 1372 1373 if(_modifiedEntities != 0) { 1374 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1375 int[] _counts = _ps.executeBatch(); 1376 1377 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1378 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1379 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1380 } 1381 } 1382 } else { 1383 _ps.executeBatch(); 1384 } 1385 1386 _ps.clearBatch(); 1387 1388 pks.forEach((pk) -> { 1389 session.getValueCache().remove(pk); 1390 }); 1391 } 1392 } catch (SQLException se) { 1393 throw new PersistenceDatabaseException(se); 1394 } 1395 1396 pks.forEach((pk) -> { 1397 session.removed(pk, true); 1398 }); 1399 } 1400 } 1401 1402 @Override 1403 public void remove(Collection<ContactPostalAddressPK> pks) 1404 throws PersistenceDatabaseException { 1405 remove(ThreadSession.currentSession(), pks); 1406 } 1407 1408 @Override 1409 public boolean validPK(Session session, ContactPostalAddressPK pk) 1410 throws PersistenceDatabaseException { 1411 boolean valid = false; 1412 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1413 ResultSet _rs = null; 1414 1415 try { 1416 _ps.setLong(1, pk.getEntityId()); 1417 1418 _rs = _ps.executeQuery(); 1419 if(_rs.next()) { 1420 long _count = _rs.getLong(1); 1421 if(_rs.wasNull()) 1422 _count = 0; 1423 1424 if(_count == 1) 1425 valid = true; 1426 } 1427 } catch (SQLException se) { 1428 throw new PersistenceDatabaseException(se); 1429 } finally { 1430 if(_rs != null) { 1431 try { 1432 _rs.close(); 1433 } catch (SQLException se) { 1434 // do nothing 1435 } 1436 } 1437 } 1438 1439 return valid; 1440 } 1441 1442}