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