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