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