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 * AssociatePartyContactMechanismDetailFactory.java 021 */ 022 023package com.echothree.model.data.associate.server.factory; 024 025import com.echothree.model.data.associate.common.pk.AssociatePartyContactMechanismPK; 026import com.echothree.model.data.associate.common.pk.AssociatePK; 027import com.echothree.model.data.contact.common.pk.PartyContactMechanismPK; 028 029import com.echothree.model.data.associate.server.entity.AssociatePartyContactMechanism; 030import com.echothree.model.data.associate.server.entity.Associate; 031import com.echothree.model.data.contact.server.entity.PartyContactMechanism; 032 033import com.echothree.model.data.associate.common.AssociatePartyContactMechanismDetailConstants; 034import com.echothree.model.data.associate.common.pk.AssociatePartyContactMechanismDetailPK; 035import com.echothree.model.data.associate.server.value.AssociatePartyContactMechanismDetailValue; 036import com.echothree.model.data.associate.server.entity.AssociatePartyContactMechanismDetail; 037import com.echothree.util.common.exception.PersistenceDatabaseException; 038import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 039import com.echothree.util.common.exception.PersistenceNotNullException; 040import com.echothree.util.server.persistence.BaseFactory; 041import com.echothree.util.server.persistence.EntityIdGenerator; 042import com.echothree.util.server.persistence.EntityPermission; 043import com.echothree.util.server.persistence.PersistenceDebugFlags; 044import com.echothree.util.server.persistence.Session; 045import java.sql.PreparedStatement; 046import java.sql.ResultSet; 047import java.sql.SQLException; 048import java.sql.Types; 049import java.io.ByteArrayInputStream; 050import java.io.StringReader; 051import java.util.ArrayList; 052import java.util.Collection; 053import java.util.HashSet; 054import java.util.List; 055import java.util.Map; 056import java.util.Set; 057import javax.enterprise.context.ApplicationScoped; 058import javax.enterprise.inject.spi.CDI; 059import javax.inject.Inject; 060import org.jooq.ResultQuery; 061import org.slf4j.Logger; 062import org.slf4j.LoggerFactory; 063 064@ApplicationScoped 065public class AssociatePartyContactMechanismDetailFactory 066 implements BaseFactory<AssociatePartyContactMechanismDetailPK, AssociatePartyContactMechanismDetail> { 067 068 @Inject 069 Session session; 070 071 //private static final Logger log = LoggerFactory.getLogger(AssociatePartyContactMechanismDetailFactory.class); 072 073 final private static String SQL_SELECT_READ_ONLY = "SELECT ascpcmdt_associatepartycontactmechanismdetailid, ascpcmdt_ascpcm_associatepartycontactmechanismid, ascpcmdt_asc_associateid, ascpcmdt_associatepartycontactmechanismname, ascpcmdt_pcm_partycontactmechanismid, ascpcmdt_isdefault, ascpcmdt_sortorder, ascpcmdt_fromtime, ascpcmdt_thrutime FROM associatepartycontactmechanismdetails WHERE ascpcmdt_associatepartycontactmechanismdetailid = ?"; 074 final private static String SQL_SELECT_READ_WRITE = "SELECT ascpcmdt_associatepartycontactmechanismdetailid, ascpcmdt_ascpcm_associatepartycontactmechanismid, ascpcmdt_asc_associateid, ascpcmdt_associatepartycontactmechanismname, ascpcmdt_pcm_partycontactmechanismid, ascpcmdt_isdefault, ascpcmdt_sortorder, ascpcmdt_fromtime, ascpcmdt_thrutime FROM associatepartycontactmechanismdetails WHERE ascpcmdt_associatepartycontactmechanismdetailid = ? FOR UPDATE"; 075 final private static String SQL_INSERT = "INSERT INTO associatepartycontactmechanismdetails (ascpcmdt_associatepartycontactmechanismdetailid, ascpcmdt_ascpcm_associatepartycontactmechanismid, ascpcmdt_asc_associateid, ascpcmdt_associatepartycontactmechanismname, ascpcmdt_pcm_partycontactmechanismid, ascpcmdt_isdefault, ascpcmdt_sortorder, ascpcmdt_fromtime, ascpcmdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 076 final private static String SQL_UPDATE = "UPDATE associatepartycontactmechanismdetails SET ascpcmdt_ascpcm_associatepartycontactmechanismid = ?, ascpcmdt_asc_associateid = ?, ascpcmdt_associatepartycontactmechanismname = ?, ascpcmdt_pcm_partycontactmechanismid = ?, ascpcmdt_isdefault = ?, ascpcmdt_sortorder = ?, ascpcmdt_fromtime = ?, ascpcmdt_thrutime = ? WHERE ascpcmdt_associatepartycontactmechanismdetailid = ?"; 077 final private static String SQL_DELETE = "DELETE FROM associatepartycontactmechanismdetails WHERE ascpcmdt_associatepartycontactmechanismdetailid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM associatepartycontactmechanismdetails WHERE ascpcmdt_associatepartycontactmechanismdetailid = ?"; 079 080 final public static String ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMDETAILID = "ascpcmdt_associatepartycontactmechanismdetailid"; 081 final public static String ASCPCMDT_ASCPCM_ASSOCIATEPARTYCONTACTMECHANISMID = "ascpcmdt_ascpcm_associatepartycontactmechanismid"; 082 final public static String ASCPCMDT_ASC_ASSOCIATEID = "ascpcmdt_asc_associateid"; 083 final public static String ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMNAME = "ascpcmdt_associatepartycontactmechanismname"; 084 final public static String ASCPCMDT_PCM_PARTYCONTACTMECHANISMID = "ascpcmdt_pcm_partycontactmechanismid"; 085 final public static String ASCPCMDT_ISDEFAULT = "ascpcmdt_isdefault"; 086 final public static String ASCPCMDT_SORTORDER = "ascpcmdt_sortorder"; 087 final public static String ASCPCMDT_FROMTIME = "ascpcmdt_fromtime"; 088 final public static String ASCPCMDT_THRUTIME = "ascpcmdt_thrutime"; 089 090 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(AssociatePartyContactMechanismDetailConstants.COMPONENT_VENDOR_NAME, AssociatePartyContactMechanismDetailConstants.ENTITY_TYPE_NAME); 091 092 /** Creates a new instance of AssociatePartyContactMechanismDetailFactory */ 093 protected AssociatePartyContactMechanismDetailFactory() { 094 super(); 095 } 096 097 public static AssociatePartyContactMechanismDetailFactory getInstance() { 098 return CDI.current().select(AssociatePartyContactMechanismDetailFactory.class).get(); 099 } 100 101 @Override 102 public String getComponentVendorName() { 103 return AssociatePartyContactMechanismDetailConstants.COMPONENT_VENDOR_NAME; 104 } 105 106 @Override 107 public String getEntityTypeName() { 108 return AssociatePartyContactMechanismDetailConstants.ENTITY_TYPE_NAME; 109 } 110 111 public PreparedStatement prepareStatement(String query) { 112 return session.prepareStatement(query); 113 } 114 115 public AssociatePartyContactMechanismDetailPK getNextPK() { 116 return new AssociatePartyContactMechanismDetailPK(entityIdGenerator.getNextEntityId()); 117 } 118 119 public Set<AssociatePartyContactMechanismDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 120 throws PersistenceDatabaseException { 121 Set<AssociatePartyContactMechanismDetailPK> _result = new HashSet<>(); 122 123 try { 124 while(rs.next()) { 125 _result.add(getPKFromResultSet(rs)); 126 } 127 } catch (SQLException se) { 128 throw new PersistenceDatabaseException(se); 129 } 130 131 return _result; 132 } 133 134 public java.util.List<AssociatePartyContactMechanismDetailPK> getPKsFromResultSetAsList(ResultSet rs) 135 throws PersistenceDatabaseException { 136 java.util.List<AssociatePartyContactMechanismDetailPK> _result = new ArrayList<>(); 137 138 try { 139 while(rs.next()) { 140 _result.add(getPKFromResultSet(rs)); 141 } 142 } catch (SQLException se) { 143 throw new PersistenceDatabaseException(se); 144 } 145 146 return _result; 147 } 148 149 public AssociatePartyContactMechanismDetailPK getPKFromResultSet(ResultSet rs) 150 throws PersistenceDatabaseException { 151 AssociatePartyContactMechanismDetailPK _result; 152 153 try { 154 long ascpcmdt_associatepartycontactmechanismdetailid = rs.getLong(ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMDETAILID); 155 Long _entityId = rs.wasNull() ? null : ascpcmdt_associatepartycontactmechanismdetailid; 156 157 _result = new AssociatePartyContactMechanismDetailPK(_entityId); 158 } catch (SQLException se) { 159 throw new PersistenceDatabaseException(se); 160 } 161 162 return _result; 163 } 164 165 public java.util.List<AssociatePartyContactMechanismDetailValue> getValuesFromPKs(Collection<AssociatePartyContactMechanismDetailPK> pks) 166 throws PersistenceDatabaseException { 167 java.util.List<AssociatePartyContactMechanismDetailValue> _values = new ArrayList<>(pks.size()); 168 169 for(AssociatePartyContactMechanismDetailPK _pk: pks) { 170 _values.add(getValueFromPK(_pk)); 171 } 172 173 return _values; 174 } 175 176 public AssociatePartyContactMechanismDetailValue getValueFromPK(AssociatePartyContactMechanismDetailPK pk) 177 throws PersistenceDatabaseException { 178 AssociatePartyContactMechanismDetailValue _value; 179 180 // See if we already have the entity in the session cache 181 AssociatePartyContactMechanismDetail _entity = (AssociatePartyContactMechanismDetail)session.getEntity(pk); 182 if(_entity == null) 183 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getAssociatePartyContactMechanismDetailValue(); 184 else 185 _value = _entity.getAssociatePartyContactMechanismDetailValue(); 186 187 return _value; 188 } 189 190 public java.util.List<AssociatePartyContactMechanismDetailValue> getValuesFromResultSet(ResultSet rs) 191 throws PersistenceDatabaseException { 192 java.util.List<AssociatePartyContactMechanismDetailValue> _result = new ArrayList<>(); 193 194 try { 195 while(rs.next()) { 196 _result.add(getValueFromResultSet(rs)); 197 } 198 } catch (SQLException se) { 199 throw new PersistenceDatabaseException(se); 200 } 201 202 return _result; 203 } 204 205 public AssociatePartyContactMechanismDetailValue getValueFromResultSet(ResultSet rs) 206 throws PersistenceDatabaseException { 207 AssociatePartyContactMechanismDetailValue _value; 208 209 try { 210 Long ascpcmdt_associatepartycontactmechanismdetailid = rs.getLong(ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMDETAILID); 211 AssociatePartyContactMechanismDetailPK _pk = new AssociatePartyContactMechanismDetailPK(ascpcmdt_associatepartycontactmechanismdetailid); 212 213 // See if we already have the entity in the session cache 214 AssociatePartyContactMechanismDetail _entity = (AssociatePartyContactMechanismDetail)session.getEntity(_pk); 215 216 if(_entity == null) { 217 Long ascpcmdt_ascpcm_associatepartycontactmechanismid = rs.getLong(ASCPCMDT_ASCPCM_ASSOCIATEPARTYCONTACTMECHANISMID); 218 if(rs.wasNull()) 219 ascpcmdt_ascpcm_associatepartycontactmechanismid = null; 220 221 Long ascpcmdt_asc_associateid = rs.getLong(ASCPCMDT_ASC_ASSOCIATEID); 222 if(rs.wasNull()) 223 ascpcmdt_asc_associateid = null; 224 225 String ascpcmdt_associatepartycontactmechanismname = rs.getString(ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMNAME); 226 if(rs.wasNull()) 227 ascpcmdt_associatepartycontactmechanismname = null; 228 229 Long ascpcmdt_pcm_partycontactmechanismid = rs.getLong(ASCPCMDT_PCM_PARTYCONTACTMECHANISMID); 230 if(rs.wasNull()) 231 ascpcmdt_pcm_partycontactmechanismid = null; 232 233 Boolean ascpcmdt_isdefault = rs.getInt(ASCPCMDT_ISDEFAULT) == 1; 234 if(rs.wasNull()) 235 ascpcmdt_isdefault = null; 236 237 Integer ascpcmdt_sortorder = rs.getInt(ASCPCMDT_SORTORDER); 238 if(rs.wasNull()) 239 ascpcmdt_sortorder = null; 240 241 Long ascpcmdt_fromtime = rs.getLong(ASCPCMDT_FROMTIME); 242 if(rs.wasNull()) 243 ascpcmdt_fromtime = null; 244 245 Long ascpcmdt_thrutime = rs.getLong(ASCPCMDT_THRUTIME); 246 if(rs.wasNull()) 247 ascpcmdt_thrutime = null; 248 249 _value = new AssociatePartyContactMechanismDetailValue(_pk, new AssociatePartyContactMechanismPK(ascpcmdt_ascpcm_associatepartycontactmechanismid), new AssociatePK(ascpcmdt_asc_associateid), ascpcmdt_associatepartycontactmechanismname, new PartyContactMechanismPK(ascpcmdt_pcm_partycontactmechanismid), ascpcmdt_isdefault, ascpcmdt_sortorder, ascpcmdt_fromtime, ascpcmdt_thrutime); 250 } else 251 _value = _entity.getAssociatePartyContactMechanismDetailValue(); 252 } catch (SQLException se) { 253 throw new PersistenceDatabaseException(se); 254 } 255 256 return _value; 257 } 258 259 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<AssociatePartyContactMechanismDetailPK> pks) 260 throws PersistenceDatabaseException { 261 java.util.List<AssociatePartyContactMechanismDetail> _entities = new ArrayList<>(pks.size()); 262 263 for(AssociatePartyContactMechanismDetailPK _pk: pks) { 264 _entities.add(getEntityFromPK(entityPermission, _pk)); 265 } 266 267 return _entities; 268 } 269 270 public AssociatePartyContactMechanismDetail getEntityFromValue(EntityPermission entityPermission, AssociatePartyContactMechanismDetailValue value) { 271 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 272 } 273 274 public AssociatePartyContactMechanismDetail getEntityFromCache(AssociatePartyContactMechanismDetailPK pk) { 275 AssociatePartyContactMechanismDetailValue _value = (AssociatePartyContactMechanismDetailValue)session.getValueCache().get(pk); 276 277 return _value == null ? null : new AssociatePartyContactMechanismDetail(_value, EntityPermission.READ_ONLY); 278 } 279 280 public AssociatePartyContactMechanismDetail getEntityFromPK(EntityPermission entityPermission, AssociatePartyContactMechanismDetailPK pk) 281 throws PersistenceDatabaseException { 282 AssociatePartyContactMechanismDetail _entity; 283 284 // See if we already have the entity in the session cache 285 _entity = (AssociatePartyContactMechanismDetail)session.getEntity(pk); 286 if(_entity != null) { 287 // If the requested permission is READ_WRITE, and the cached permission is 288 // READ_ONLY, then pretend that the cached object wasn't found, and create 289 // a new entity that is READ_WRITE. 290 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 291 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 292 _entity = null; 293 } 294 } 295 296 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 297 _entity = getEntityFromCache(pk); 298 } 299 300 if(_entity == null) { 301 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 302 long _entityId = pk.getEntityId(); 303 ResultSet _rs = null; 304 305 try { 306 _ps.setLong(1, _entityId); 307 _rs = _ps.executeQuery(); 308 if(_rs.next()) { 309 _entity = getEntityFromResultSet(entityPermission, _rs); 310 } 311 } catch (SQLException se) { 312 throw new PersistenceDatabaseException(se); 313 } finally { 314 if(_rs != null) { 315 try { 316 _rs.close(); 317 } catch (SQLException se) { 318 // do nothing 319 } 320 } 321 } 322 } 323 324 return _entity; 325 } 326 327 public Set<AssociatePartyContactMechanismDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 328 throws PersistenceDatabaseException { 329 Set<AssociatePartyContactMechanismDetailPK> _pks; 330 ResultSet _rs = null; 331 332 try { 333 if(params.length != 0) { 334 Session.setQueryParams(ps, params); 335 } 336 337 _rs = ps.executeQuery(); 338 _pks = getPKsFromResultSetAsSet(_rs); 339 _rs.close(); 340 } catch (SQLException se) { 341 throw new PersistenceDatabaseException(se); 342 } finally { 343 if(_rs != null) { 344 try { 345 _rs.close(); 346 } catch (SQLException se) { 347 // do nothing 348 } 349 } 350 } 351 352 return _pks; 353 } 354 355 public java.util.List<AssociatePartyContactMechanismDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 356 throws PersistenceDatabaseException { 357 java.util.List<AssociatePartyContactMechanismDetailPK> _pks; 358 ResultSet _rs = null; 359 360 try { 361 if(params.length != 0) { 362 Session.setQueryParams(ps, params); 363 } 364 365 _rs = ps.executeQuery(); 366 _pks = getPKsFromResultSetAsList(_rs); 367 _rs.close(); 368 } catch (SQLException se) { 369 throw new PersistenceDatabaseException(se); 370 } finally { 371 if(_rs != null) { 372 try { 373 _rs.close(); 374 } catch (SQLException se) { 375 // do nothing 376 } 377 } 378 } 379 380 return _pks; 381 } 382 383 public AssociatePartyContactMechanismDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 384 throws PersistenceDatabaseException { 385 AssociatePartyContactMechanismDetailPK _pk = null; 386 ResultSet _rs = null; 387 388 try { 389 if(params.length != 0) { 390 Session.setQueryParams(ps, params); 391 } 392 393 _rs = ps.executeQuery(); 394 if(_rs.next()) { 395 _pk = getPKFromResultSet(_rs); 396 } 397 _rs.close(); 398 } catch (SQLException se) { 399 throw new PersistenceDatabaseException(se); 400 } finally { 401 if(_rs != null) { 402 try { 403 _rs.close(); 404 } catch (SQLException se) { 405 // do nothing 406 } 407 } 408 } 409 410 return _pk; 411 } 412 413 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 414 throws PersistenceDatabaseException { 415 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 416 417 return getEntitiesFromQuery(entityPermission, ps, params); 418 } 419 420 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 421 throws PersistenceDatabaseException { 422 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 423 424 return getEntitiesFromQuery(entityPermission, ps); 425 } 426 427 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 428 throws PersistenceDatabaseException { 429 PreparedStatement ps = session.prepareStatement(query.getSQL()); 430 431 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 432 } 433 434 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 435 throws PersistenceDatabaseException { 436 java.util.List<AssociatePartyContactMechanismDetail> _entities; 437 ResultSet _rs = null; 438 439 try { 440 if(params.length != 0) { 441 Session.setQueryParams(ps, params); 442 } 443 444 _rs = ps.executeQuery(); 445 _entities = getEntitiesFromResultSet(entityPermission, _rs); 446 _rs.close(); 447 } catch (SQLException se) { 448 throw new PersistenceDatabaseException(se); 449 } finally { 450 if(_rs != null) { 451 try { 452 _rs.close(); 453 } catch (SQLException se) { 454 // do nothing 455 } 456 } 457 } 458 459 return _entities; 460 } 461 462 public AssociatePartyContactMechanismDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 463 throws PersistenceDatabaseException { 464 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 465 466 return getEntityFromQuery(entityPermission, ps, params); 467 } 468 469 public AssociatePartyContactMechanismDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 470 throws PersistenceDatabaseException { 471 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 472 473 return getEntityFromQuery(entityPermission, ps); 474 } 475 476 public AssociatePartyContactMechanismDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 477 throws PersistenceDatabaseException { 478 PreparedStatement ps = session.prepareStatement(query.getSQL()); 479 480 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 481 } 482 483 public AssociatePartyContactMechanismDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 484 throws PersistenceDatabaseException { 485 AssociatePartyContactMechanismDetail _entity = null; 486 ResultSet _rs = null; 487 488 try { 489 if(params.length != 0) { 490 Session.setQueryParams(ps, params); 491 } 492 493 _rs = ps.executeQuery(); 494 if(_rs.next()) { 495 _entity = getEntityFromResultSet(entityPermission, _rs); 496 } 497 _rs.close(); 498 } catch (SQLException se) { 499 throw new PersistenceDatabaseException(se); 500 } finally { 501 if(_rs != null) { 502 try { 503 _rs.close(); 504 } catch (SQLException se) { 505 // do nothing 506 } 507 } 508 } 509 510 return _entity; 511 } 512 513 public java.util.List<AssociatePartyContactMechanismDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 514 throws PersistenceDatabaseException { 515 java.util.List<AssociatePartyContactMechanismDetail> _result = new ArrayList<>(); 516 517 try { 518 while(rs.next()) { 519 _result.add(getEntityFromResultSet(entityPermission, rs)); 520 } 521 } catch (SQLException se) { 522 throw new PersistenceDatabaseException(se); 523 } 524 525 return _result; 526 } 527 528 public AssociatePartyContactMechanismDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 529 throws PersistenceDatabaseException { 530 AssociatePartyContactMechanismDetail _entity; 531 532 try { 533 Long ascpcmdt_associatepartycontactmechanismdetailid = rs.getLong(ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMDETAILID); 534 AssociatePartyContactMechanismDetailPK _pk = new AssociatePartyContactMechanismDetailPK(ascpcmdt_associatepartycontactmechanismdetailid); 535 536 // See if we already have the entity in the session cache 537 _entity = (AssociatePartyContactMechanismDetail)session.getEntity(_pk); 538 if(_entity != null) { 539 // If the requested permission is READ_WRITE, and the cached permission is 540 // READ_ONLY, then pretend that the cached object wasn't found, and create 541 // a new entity that is READ_WRITE. 542 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 543 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 544 _entity = null; 545 } 546 } 547 boolean foundInSessionCache = _entity != null; 548 549 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 550 _entity = getEntityFromCache(_pk); 551 } 552 553 if(_entity == null) { 554 Long ascpcmdt_ascpcm_associatepartycontactmechanismid = rs.getLong(ASCPCMDT_ASCPCM_ASSOCIATEPARTYCONTACTMECHANISMID); 555 if(rs.wasNull()) 556 ascpcmdt_ascpcm_associatepartycontactmechanismid = null; 557 558 Long ascpcmdt_asc_associateid = rs.getLong(ASCPCMDT_ASC_ASSOCIATEID); 559 if(rs.wasNull()) 560 ascpcmdt_asc_associateid = null; 561 562 String ascpcmdt_associatepartycontactmechanismname = rs.getString(ASCPCMDT_ASSOCIATEPARTYCONTACTMECHANISMNAME); 563 if(rs.wasNull()) 564 ascpcmdt_associatepartycontactmechanismname = null; 565 566 Long ascpcmdt_pcm_partycontactmechanismid = rs.getLong(ASCPCMDT_PCM_PARTYCONTACTMECHANISMID); 567 if(rs.wasNull()) 568 ascpcmdt_pcm_partycontactmechanismid = null; 569 570 Boolean ascpcmdt_isdefault = rs.getInt(ASCPCMDT_ISDEFAULT) == 1; 571 if(rs.wasNull()) 572 ascpcmdt_isdefault = null; 573 574 Integer ascpcmdt_sortorder = rs.getInt(ASCPCMDT_SORTORDER); 575 if(rs.wasNull()) 576 ascpcmdt_sortorder = null; 577 578 Long ascpcmdt_fromtime = rs.getLong(ASCPCMDT_FROMTIME); 579 if(rs.wasNull()) 580 ascpcmdt_fromtime = null; 581 582 Long ascpcmdt_thrutime = rs.getLong(ASCPCMDT_THRUTIME); 583 if(rs.wasNull()) 584 ascpcmdt_thrutime = null; 585 586 AssociatePartyContactMechanismDetailValue _value = new AssociatePartyContactMechanismDetailValue(_pk, ascpcmdt_ascpcm_associatepartycontactmechanismid == null? null: new AssociatePartyContactMechanismPK(ascpcmdt_ascpcm_associatepartycontactmechanismid), ascpcmdt_asc_associateid == null? null: new AssociatePK(ascpcmdt_asc_associateid), ascpcmdt_associatepartycontactmechanismname, ascpcmdt_pcm_partycontactmechanismid == null? null: new PartyContactMechanismPK(ascpcmdt_pcm_partycontactmechanismid), ascpcmdt_isdefault, ascpcmdt_sortorder, ascpcmdt_fromtime, ascpcmdt_thrutime); 587 _entity = new AssociatePartyContactMechanismDetail(_value, entityPermission); 588 } 589 590 if(!foundInSessionCache) { 591 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 592 session.putReadOnlyEntity(_pk, _entity); 593 session.getValueCache().put(_entity.getAssociatePartyContactMechanismDetailValue()); 594 } else { 595 session.putReadWriteEntity(_pk, _entity); 596 } 597 } 598 } catch (SQLException se) { 599 throw new PersistenceDatabaseException(se); 600 } 601 602 return _entity; 603 } 604 605 public AssociatePartyContactMechanismDetail create(AssociatePartyContactMechanism associatePartyContactMechanism, Associate associate, String associatePartyContactMechanismName, PartyContactMechanism partyContactMechanism, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 606 throws PersistenceDatabaseException, PersistenceNotNullException { 607 return create(associatePartyContactMechanism == null ? null : associatePartyContactMechanism.getPrimaryKey(), associate == null ? null : associate.getPrimaryKey(), associatePartyContactMechanismName, partyContactMechanism == null ? null : partyContactMechanism.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 608 } 609 610 private void bindForCreate(PreparedStatement _ps, AssociatePartyContactMechanismDetailValue _value) 611 throws SQLException { 612 _ps.setLong(1, _value.getEntityId()); 613 614 AssociatePartyContactMechanismPK ascpcmdt_ascpcm_associatepartycontactmechanismid = _value.getAssociatePartyContactMechanismPK(); 615 if(ascpcmdt_ascpcm_associatepartycontactmechanismid == null) 616 _ps.setNull(2, Types.BIGINT); 617 else 618 _ps.setLong(2, ascpcmdt_ascpcm_associatepartycontactmechanismid.getEntityId()); 619 620 AssociatePK ascpcmdt_asc_associateid = _value.getAssociatePK(); 621 if(ascpcmdt_asc_associateid == null) 622 _ps.setNull(3, Types.BIGINT); 623 else 624 _ps.setLong(3, ascpcmdt_asc_associateid.getEntityId()); 625 626 String ascpcmdt_associatepartycontactmechanismname = _value.getAssociatePartyContactMechanismName(); 627 if(ascpcmdt_associatepartycontactmechanismname == null) 628 _ps.setNull(4, Types.VARCHAR); 629 else 630 _ps.setString(4, ascpcmdt_associatepartycontactmechanismname); 631 632 PartyContactMechanismPK ascpcmdt_pcm_partycontactmechanismid = _value.getPartyContactMechanismPK(); 633 if(ascpcmdt_pcm_partycontactmechanismid == null) 634 _ps.setNull(5, Types.BIGINT); 635 else 636 _ps.setLong(5, ascpcmdt_pcm_partycontactmechanismid.getEntityId()); 637 638 Boolean ascpcmdt_isdefault = _value.getIsDefault(); 639 if(ascpcmdt_isdefault == null) 640 _ps.setNull(6, Types.BIT); 641 else 642 _ps.setInt(6, ascpcmdt_isdefault? 1: 0); 643 644 Integer ascpcmdt_sortorder = _value.getSortOrder(); 645 if(ascpcmdt_sortorder == null) 646 _ps.setNull(7, Types.INTEGER); 647 else 648 _ps.setInt(7, ascpcmdt_sortorder); 649 650 Long ascpcmdt_fromtime = _value.getFromTime(); 651 if(ascpcmdt_fromtime == null) 652 _ps.setNull(8, Types.BIGINT); 653 else 654 _ps.setLong(8, ascpcmdt_fromtime); 655 656 Long ascpcmdt_thrutime = _value.getThruTime(); 657 if(ascpcmdt_thrutime == null) 658 _ps.setNull(9, Types.BIGINT); 659 else 660 _ps.setLong(9, ascpcmdt_thrutime); 661 662 } 663 664 public AssociatePartyContactMechanismDetail create(AssociatePartyContactMechanismPK associatePartyContactMechanismPK, AssociatePK associatePK, String associatePartyContactMechanismName, PartyContactMechanismPK partyContactMechanismPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 665 throws PersistenceDatabaseException, PersistenceNotNullException { 666 AssociatePartyContactMechanismDetailPK _pk = getNextPK(); 667 AssociatePartyContactMechanismDetailValue _value = new AssociatePartyContactMechanismDetailValue(_pk, associatePartyContactMechanismPK, associatePK, associatePartyContactMechanismName, partyContactMechanismPK, isDefault, sortOrder, fromTime, thruTime); 668 669 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 670 671 try { 672 bindForCreate(_ps, _value); 673 674 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 675 int _count = _ps.executeUpdate(); 676 677 if(_count != 1) { 678 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 679 } 680 } else { 681 _ps.executeUpdate(); 682 } 683 684 session.getValueCache().put(_value); 685 } catch (SQLException se) { 686 throw new PersistenceDatabaseException(se); 687 } 688 689 AssociatePartyContactMechanismDetail _entity = new AssociatePartyContactMechanismDetail(_value, EntityPermission.READ_ONLY); 690 session.putReadOnlyEntity(_pk, _entity); 691 692 return _entity; 693 } 694 695 public void create(Collection<AssociatePartyContactMechanismDetailValue> _values) 696 throws PersistenceDatabaseException, PersistenceNotNullException { 697 int _size = _values.size(); 698 699 if(_size > 0) { 700 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 701 List<AssociatePartyContactMechanismDetailValue> _cacheValues = new ArrayList<>(_size); 702 703 try { 704 for(AssociatePartyContactMechanismDetailValue _value : _values) { 705 _value.setEntityId(entityIdGenerator.getNextEntityId()); 706 bindForCreate(_ps, _value); 707 708 _ps.addBatch(); 709 710 _cacheValues.add(_value); 711 } 712 713 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 714 int[] _counts = _ps.executeBatch(); 715 716 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 717 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 718 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 719 } 720 } 721 } else { 722 _ps.executeBatch(); 723 } 724 725 _ps.clearBatch(); 726 } catch (SQLException se) { 727 throw new PersistenceDatabaseException(se); 728 } 729 730 _cacheValues.forEach((_cacheValue) -> { 731 AssociatePartyContactMechanismDetail _cacheEntity = new AssociatePartyContactMechanismDetail(_cacheValue, EntityPermission.READ_ONLY); 732 733 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 734 }); 735 } 736 } 737 738 private boolean bindForStore(PreparedStatement _ps, AssociatePartyContactMechanismDetailValue _value) 739 throws SQLException { 740 boolean _hasBeenModified = _value.hasBeenModified(); 741 742 if(_hasBeenModified) { 743 AssociatePartyContactMechanismPK ascpcmdt_ascpcm_associatepartycontactmechanismid = _value.getAssociatePartyContactMechanismPK(); 744 if(ascpcmdt_ascpcm_associatepartycontactmechanismid == null) 745 _ps.setNull(1, Types.BIGINT); 746 else 747 _ps.setLong(1, ascpcmdt_ascpcm_associatepartycontactmechanismid.getEntityId()); 748 749 AssociatePK ascpcmdt_asc_associateid = _value.getAssociatePK(); 750 if(ascpcmdt_asc_associateid == null) 751 _ps.setNull(2, Types.BIGINT); 752 else 753 _ps.setLong(2, ascpcmdt_asc_associateid.getEntityId()); 754 755 String ascpcmdt_associatepartycontactmechanismname = _value.getAssociatePartyContactMechanismName(); 756 if(ascpcmdt_associatepartycontactmechanismname == null) 757 _ps.setNull(3, Types.VARCHAR); 758 else 759 _ps.setString(3, ascpcmdt_associatepartycontactmechanismname); 760 761 PartyContactMechanismPK ascpcmdt_pcm_partycontactmechanismid = _value.getPartyContactMechanismPK(); 762 if(ascpcmdt_pcm_partycontactmechanismid == null) 763 _ps.setNull(4, Types.BIGINT); 764 else 765 _ps.setLong(4, ascpcmdt_pcm_partycontactmechanismid.getEntityId()); 766 767 Boolean ascpcmdt_isdefault = _value.getIsDefault(); 768 if(ascpcmdt_isdefault == null) 769 _ps.setNull(5, Types.BIT); 770 else 771 _ps.setInt(5, ascpcmdt_isdefault? 1: 0); 772 773 Integer ascpcmdt_sortorder = _value.getSortOrder(); 774 if(ascpcmdt_sortorder == null) 775 _ps.setNull(6, Types.INTEGER); 776 else 777 _ps.setInt(6, ascpcmdt_sortorder); 778 779 Long ascpcmdt_fromtime = _value.getFromTime(); 780 if(ascpcmdt_fromtime == null) 781 _ps.setNull(7, Types.BIGINT); 782 else 783 _ps.setLong(7, ascpcmdt_fromtime); 784 785 Long ascpcmdt_thrutime = _value.getThruTime(); 786 if(ascpcmdt_thrutime == null) 787 _ps.setNull(8, Types.BIGINT); 788 else 789 _ps.setLong(8, ascpcmdt_thrutime); 790 791 _ps.setLong(9, _value.getPrimaryKey().getEntityId()); 792 793 _value.clearHasBeenModified(); 794 } 795 796 return _hasBeenModified; 797 } 798 799 @Override 800 public void store(AssociatePartyContactMechanismDetail entity) 801 throws PersistenceDatabaseException { 802 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 803 804 try { 805 AssociatePartyContactMechanismDetailValue _value = entity.getAssociatePartyContactMechanismDetailValue(); 806 807 if(bindForStore(_ps, _value)) { 808 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 809 int _count = _ps.executeUpdate(); 810 811 if(_count != 1) { 812 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 813 } 814 } else { 815 _ps.executeUpdate(); 816 } 817 818 session.getValueCache().put(_value); 819 } 820 } catch (SQLException se) { 821 throw new PersistenceDatabaseException(se); 822 } 823 } 824 825 @Override 826 public void store(Collection<AssociatePartyContactMechanismDetail> entities) 827 throws PersistenceDatabaseException { 828 if(entities.size() > 0) { 829 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 830 int _modifiedEntities = 0; 831 832 try { 833 for(AssociatePartyContactMechanismDetail entity : entities) { 834 if(bindForStore(_ps, entity.getAssociatePartyContactMechanismDetailValue())) { 835 _ps.addBatch(); 836 _modifiedEntities++; 837 } 838 } 839 840 if(_modifiedEntities != 0) { 841 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 842 int[] _counts = _ps.executeBatch(); 843 844 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 845 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 846 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 847 } 848 } 849 } else { 850 _ps.executeBatch(); 851 } 852 853 _ps.clearBatch(); 854 855 entities.forEach((entity) -> { 856 session.getValueCache().put(entity.getAssociatePartyContactMechanismDetailValue()); 857 }); 858 } 859 } catch (SQLException se) { 860 throw new PersistenceDatabaseException(se); 861 } 862 } 863 } 864 865 @Override 866 public void remove(AssociatePartyContactMechanismDetail entity) 867 throws PersistenceDatabaseException { 868 remove(entity.getPrimaryKey()); 869 } 870 871 @Override 872 public void remove(AssociatePartyContactMechanismDetailPK pk) 873 throws PersistenceDatabaseException { 874 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 875 long _entityId = pk.getEntityId(); 876 877 try { 878 _ps.setLong(1, _entityId); 879 880 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 881 int _count = _ps.executeUpdate(); 882 883 if(_count != 1) { 884 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 885 } 886 } else { 887 _ps.executeUpdate(); 888 } 889 890 session.getValueCache().remove(pk); 891 } catch (SQLException se) { 892 throw new PersistenceDatabaseException(se); 893 } 894 895 session.removed(pk, false); 896 } 897 898 @Override 899 public void remove(Collection<AssociatePartyContactMechanismDetailPK> pks) 900 throws PersistenceDatabaseException { 901 if(pks.size() > 0) { 902 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 903 int _modifiedEntities = 0; 904 905 try { 906 for(AssociatePartyContactMechanismDetailPK pk : pks) { 907 long _entityId = pk.getEntityId(); 908 909 _ps.setLong(1, _entityId); 910 911 _ps.addBatch(); 912 _modifiedEntities++; 913 } 914 915 if(_modifiedEntities != 0) { 916 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 917 int[] _counts = _ps.executeBatch(); 918 919 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 920 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 921 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 922 } 923 } 924 } else { 925 _ps.executeBatch(); 926 } 927 928 _ps.clearBatch(); 929 930 pks.forEach((pk) -> { 931 session.getValueCache().remove(pk); 932 }); 933 } 934 } catch (SQLException se) { 935 throw new PersistenceDatabaseException(se); 936 } 937 938 pks.forEach((pk) -> { 939 session.removed(pk, true); 940 }); 941 } 942 } 943 944 @Override 945 public boolean validPK(AssociatePartyContactMechanismDetailPK pk) 946 throws PersistenceDatabaseException { 947 boolean valid = false; 948 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 949 ResultSet _rs = null; 950 951 try { 952 _ps.setLong(1, pk.getEntityId()); 953 954 _rs = _ps.executeQuery(); 955 if(_rs.next()) { 956 long _count = _rs.getLong(1); 957 if(_rs.wasNull()) 958 _count = 0; 959 960 if(_count == 1) 961 valid = true; 962 } 963 } catch (SQLException se) { 964 throw new PersistenceDatabaseException(se); 965 } finally { 966 if(_rs != null) { 967 try { 968 _rs.close(); 969 } catch (SQLException se) { 970 // do nothing 971 } 972 } 973 } 974 975 return valid; 976 } 977 978}