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 * BillingAccountRoleFactory.java 021 */ 022 023package com.echothree.model.data.payment.server.factory; 024 025import com.echothree.model.data.payment.common.pk.BillingAccountPK; 026import com.echothree.model.data.party.common.pk.PartyPK; 027import com.echothree.model.data.contact.common.pk.PartyContactMechanismPK; 028import com.echothree.model.data.payment.common.pk.BillingAccountRoleTypePK; 029 030import com.echothree.model.data.payment.server.entity.BillingAccount; 031import com.echothree.model.data.party.server.entity.Party; 032import com.echothree.model.data.contact.server.entity.PartyContactMechanism; 033import com.echothree.model.data.payment.server.entity.BillingAccountRoleType; 034 035import com.echothree.model.data.payment.common.BillingAccountRoleConstants; 036import com.echothree.model.data.payment.common.pk.BillingAccountRolePK; 037import com.echothree.model.data.payment.server.value.BillingAccountRoleValue; 038import com.echothree.model.data.payment.server.entity.BillingAccountRole; 039import com.echothree.util.common.exception.PersistenceDatabaseException; 040import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 041import com.echothree.util.common.exception.PersistenceNotNullException; 042import com.echothree.util.server.persistence.BaseFactory; 043import com.echothree.util.server.persistence.EntityIdGenerator; 044import com.echothree.util.server.persistence.EntityPermission; 045import com.echothree.util.server.persistence.PersistenceDebugFlags; 046import com.echothree.util.server.persistence.Session; 047import java.sql.PreparedStatement; 048import java.sql.ResultSet; 049import java.sql.SQLException; 050import java.sql.Types; 051import java.io.ByteArrayInputStream; 052import java.io.StringReader; 053import java.util.ArrayList; 054import java.util.Collection; 055import java.util.HashSet; 056import java.util.List; 057import java.util.Map; 058import java.util.Set; 059import javax.enterprise.context.ApplicationScoped; 060import javax.enterprise.inject.spi.CDI; 061import javax.inject.Inject; 062import org.jooq.ResultQuery; 063import org.slf4j.Logger; 064import org.slf4j.LoggerFactory; 065 066@ApplicationScoped 067public class BillingAccountRoleFactory 068 implements BaseFactory<BillingAccountRolePK, BillingAccountRole> { 069 070 @Inject 071 Session session; 072 073 //private static final Logger log = LoggerFactory.getLogger(BillingAccountRoleFactory.class); 074 075 final private static String SQL_SELECT_READ_ONLY = "SELECT bllactr_billingaccountroleid, bllactr_bllact_billingaccountid, bllactr_par_partyid, bllactr_pcm_partycontactmechanismid, bllactr_bllactrtyp_billingaccountroletypeid, bllactr_fromtime, bllactr_thrutime FROM billingaccountroles WHERE bllactr_billingaccountroleid = ?"; 076 final private static String SQL_SELECT_READ_WRITE = "SELECT bllactr_billingaccountroleid, bllactr_bllact_billingaccountid, bllactr_par_partyid, bllactr_pcm_partycontactmechanismid, bllactr_bllactrtyp_billingaccountroletypeid, bllactr_fromtime, bllactr_thrutime FROM billingaccountroles WHERE bllactr_billingaccountroleid = ? FOR UPDATE"; 077 final private static String SQL_INSERT = "INSERT INTO billingaccountroles (bllactr_billingaccountroleid, bllactr_bllact_billingaccountid, bllactr_par_partyid, bllactr_pcm_partycontactmechanismid, bllactr_bllactrtyp_billingaccountroletypeid, bllactr_fromtime, bllactr_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?)"; 078 final private static String SQL_UPDATE = "UPDATE billingaccountroles SET bllactr_bllact_billingaccountid = ?, bllactr_par_partyid = ?, bllactr_pcm_partycontactmechanismid = ?, bllactr_bllactrtyp_billingaccountroletypeid = ?, bllactr_fromtime = ?, bllactr_thrutime = ? WHERE bllactr_billingaccountroleid = ?"; 079 final private static String SQL_DELETE = "DELETE FROM billingaccountroles WHERE bllactr_billingaccountroleid = ?"; 080 final private static String SQL_VALID = "SELECT COUNT(*) FROM billingaccountroles WHERE bllactr_billingaccountroleid = ?"; 081 082 final private static String PK_COLUMN = "bllactr_billingaccountroleid"; 083 final private static String ALL_COLUMNS = "bllactr_billingaccountroleid, bllactr_bllact_billingaccountid, bllactr_par_partyid, bllactr_pcm_partycontactmechanismid, bllactr_bllactrtyp_billingaccountroletypeid, bllactr_fromtime, bllactr_thrutime"; 084 final public static String TABLE_NAME = "billingaccountroles"; 085 086 final public static String BLLACTR_BILLINGACCOUNTROLEID = "bllactr_billingaccountroleid"; 087 final public static String BLLACTR_BLLACT_BILLINGACCOUNTID = "bllactr_bllact_billingaccountid"; 088 final public static String BLLACTR_PAR_PARTYID = "bllactr_par_partyid"; 089 final public static String BLLACTR_PCM_PARTYCONTACTMECHANISMID = "bllactr_pcm_partycontactmechanismid"; 090 final public static String BLLACTR_BLLACTRTYP_BILLINGACCOUNTROLETYPEID = "bllactr_bllactrtyp_billingaccountroletypeid"; 091 final public static String BLLACTR_FROMTIME = "bllactr_fromtime"; 092 final public static String BLLACTR_THRUTIME = "bllactr_thrutime"; 093 094 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(BillingAccountRoleConstants.COMPONENT_VENDOR_NAME, BillingAccountRoleConstants.ENTITY_TYPE_NAME); 095 096 /** Creates a new instance of BillingAccountRoleFactory */ 097 protected BillingAccountRoleFactory() { 098 super(); 099 } 100 101 public static BillingAccountRoleFactory getInstance() { 102 return CDI.current().select(BillingAccountRoleFactory.class).get(); 103 } 104 105 @Override 106 public String getPKColumn() { 107 return PK_COLUMN; 108 } 109 110 @Override 111 public String getAllColumns() { 112 return ALL_COLUMNS; 113 } 114 115 @Override 116 public String getTableName() { 117 return TABLE_NAME; 118 } 119 120 @Override 121 public String getComponentVendorName() { 122 return BillingAccountRoleConstants.COMPONENT_VENDOR_NAME; 123 } 124 125 @Override 126 public String getEntityTypeName() { 127 return BillingAccountRoleConstants.ENTITY_TYPE_NAME; 128 } 129 130 public PreparedStatement prepareStatement(String query) { 131 return session.prepareStatement(BillingAccountRoleFactory.class, query); 132 } 133 134 public BillingAccountRolePK getNextPK() { 135 return new BillingAccountRolePK(entityIdGenerator.getNextEntityId()); 136 } 137 138 public Set<BillingAccountRolePK> getPKsFromResultSetAsSet(ResultSet rs) 139 throws PersistenceDatabaseException { 140 Set<BillingAccountRolePK> _result = new HashSet<>(); 141 142 try { 143 while(rs.next()) { 144 _result.add(getPKFromResultSet(rs)); 145 } 146 } catch (SQLException se) { 147 throw new PersistenceDatabaseException(se); 148 } 149 150 return _result; 151 } 152 153 public java.util.List<BillingAccountRolePK> getPKsFromResultSetAsList(ResultSet rs) 154 throws PersistenceDatabaseException { 155 java.util.List<BillingAccountRolePK> _result = new ArrayList<>(); 156 157 try { 158 while(rs.next()) { 159 _result.add(getPKFromResultSet(rs)); 160 } 161 } catch (SQLException se) { 162 throw new PersistenceDatabaseException(se); 163 } 164 165 return _result; 166 } 167 168 public BillingAccountRolePK getPKFromResultSet(ResultSet rs) 169 throws PersistenceDatabaseException { 170 BillingAccountRolePK _result; 171 172 try { 173 long bllactr_billingaccountroleid = rs.getLong(BLLACTR_BILLINGACCOUNTROLEID); 174 Long _entityId = rs.wasNull() ? null : bllactr_billingaccountroleid; 175 176 _result = new BillingAccountRolePK(_entityId); 177 } catch (SQLException se) { 178 throw new PersistenceDatabaseException(se); 179 } 180 181 return _result; 182 } 183 184 public java.util.List<BillingAccountRoleValue> getValuesFromPKs(Collection<BillingAccountRolePK> pks) 185 throws PersistenceDatabaseException { 186 java.util.List<BillingAccountRoleValue> _values = new ArrayList<>(pks.size()); 187 188 for(BillingAccountRolePK _pk: pks) { 189 _values.add(getValueFromPK(_pk)); 190 } 191 192 return _values; 193 } 194 195 public BillingAccountRoleValue getValueFromPK(BillingAccountRolePK pk) 196 throws PersistenceDatabaseException { 197 BillingAccountRoleValue _value; 198 199 // See if we already have the entity in the session cache 200 BillingAccountRole _entity = (BillingAccountRole)session.getEntity(pk); 201 if(_entity == null) 202 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getBillingAccountRoleValue(); 203 else 204 _value = _entity.getBillingAccountRoleValue(); 205 206 return _value; 207 } 208 209 public java.util.List<BillingAccountRoleValue> getValuesFromResultSet(ResultSet rs) 210 throws PersistenceDatabaseException { 211 java.util.List<BillingAccountRoleValue> _result = new ArrayList<>(); 212 213 try { 214 while(rs.next()) { 215 _result.add(getValueFromResultSet(rs)); 216 } 217 } catch (SQLException se) { 218 throw new PersistenceDatabaseException(se); 219 } 220 221 return _result; 222 } 223 224 public BillingAccountRoleValue getValueFromResultSet(ResultSet rs) 225 throws PersistenceDatabaseException { 226 BillingAccountRoleValue _value; 227 228 try { 229 Long bllactr_billingaccountroleid = rs.getLong(BLLACTR_BILLINGACCOUNTROLEID); 230 BillingAccountRolePK _pk = new BillingAccountRolePK(bllactr_billingaccountroleid); 231 232 // See if we already have the entity in the session cache 233 BillingAccountRole _entity = (BillingAccountRole)session.getEntity(_pk); 234 235 if(_entity == null) { 236 Long bllactr_bllact_billingaccountid = rs.getLong(BLLACTR_BLLACT_BILLINGACCOUNTID); 237 if(rs.wasNull()) 238 bllactr_bllact_billingaccountid = null; 239 240 Long bllactr_par_partyid = rs.getLong(BLLACTR_PAR_PARTYID); 241 if(rs.wasNull()) 242 bllactr_par_partyid = null; 243 244 Long bllactr_pcm_partycontactmechanismid = rs.getLong(BLLACTR_PCM_PARTYCONTACTMECHANISMID); 245 if(rs.wasNull()) 246 bllactr_pcm_partycontactmechanismid = null; 247 248 Long bllactr_bllactrtyp_billingaccountroletypeid = rs.getLong(BLLACTR_BLLACTRTYP_BILLINGACCOUNTROLETYPEID); 249 if(rs.wasNull()) 250 bllactr_bllactrtyp_billingaccountroletypeid = null; 251 252 Long bllactr_fromtime = rs.getLong(BLLACTR_FROMTIME); 253 if(rs.wasNull()) 254 bllactr_fromtime = null; 255 256 Long bllactr_thrutime = rs.getLong(BLLACTR_THRUTIME); 257 if(rs.wasNull()) 258 bllactr_thrutime = null; 259 260 _value = new BillingAccountRoleValue(_pk, new BillingAccountPK(bllactr_bllact_billingaccountid), new PartyPK(bllactr_par_partyid), new PartyContactMechanismPK(bllactr_pcm_partycontactmechanismid), new BillingAccountRoleTypePK(bllactr_bllactrtyp_billingaccountroletypeid), bllactr_fromtime, bllactr_thrutime); 261 } else 262 _value = _entity.getBillingAccountRoleValue(); 263 } catch (SQLException se) { 264 throw new PersistenceDatabaseException(se); 265 } 266 267 return _value; 268 } 269 270 public java.util.List<BillingAccountRole> getEntitiesFromPKs(EntityPermission entityPermission, Collection<BillingAccountRolePK> pks) 271 throws PersistenceDatabaseException { 272 java.util.List<BillingAccountRole> _entities = new ArrayList<>(pks.size()); 273 274 for(BillingAccountRolePK _pk: pks) { 275 _entities.add(getEntityFromPK(entityPermission, _pk)); 276 } 277 278 return _entities; 279 } 280 281 public BillingAccountRole getEntityFromValue(EntityPermission entityPermission, BillingAccountRoleValue value) { 282 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 283 } 284 285 public BillingAccountRole getEntityFromCache(BillingAccountRolePK pk) { 286 BillingAccountRoleValue _value = (BillingAccountRoleValue)session.getValueCache().get(pk); 287 288 return _value == null ? null : new BillingAccountRole(_value, EntityPermission.READ_ONLY); 289 } 290 291 public BillingAccountRole getEntityFromPK(EntityPermission entityPermission, BillingAccountRolePK pk) 292 throws PersistenceDatabaseException { 293 BillingAccountRole _entity; 294 295 // See if we already have the entity in the session cache 296 _entity = (BillingAccountRole)session.getEntity(pk); 297 if(_entity != null) { 298 // If the requested permission is READ_WRITE, and the cached permission is 299 // READ_ONLY, then pretend that the cached object wasn't found, and create 300 // a new entity that is READ_WRITE. 301 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 302 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 303 _entity = null; 304 } 305 } 306 307 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 308 _entity = getEntityFromCache(pk); 309 } 310 311 if(_entity == null) { 312 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 313 long _entityId = pk.getEntityId(); 314 ResultSet _rs = null; 315 316 try { 317 _ps.setLong(1, _entityId); 318 _rs = _ps.executeQuery(); 319 if(_rs.next()) { 320 _entity = getEntityFromResultSet(entityPermission, _rs); 321 } 322 } catch (SQLException se) { 323 throw new PersistenceDatabaseException(se); 324 } finally { 325 if(_rs != null) { 326 try { 327 _rs.close(); 328 } catch (SQLException se) { 329 // do nothing 330 } 331 } 332 } 333 } 334 335 return _entity; 336 } 337 338 public Set<BillingAccountRolePK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 339 throws PersistenceDatabaseException { 340 Set<BillingAccountRolePK> _pks; 341 ResultSet _rs = null; 342 343 try { 344 if(params.length != 0) { 345 Session.setQueryParams(ps, params); 346 } 347 348 _rs = ps.executeQuery(); 349 _pks = getPKsFromResultSetAsSet(_rs); 350 _rs.close(); 351 } catch (SQLException se) { 352 throw new PersistenceDatabaseException(se); 353 } finally { 354 if(_rs != null) { 355 try { 356 _rs.close(); 357 } catch (SQLException se) { 358 // do nothing 359 } 360 } 361 } 362 363 return _pks; 364 } 365 366 public java.util.List<BillingAccountRolePK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 367 throws PersistenceDatabaseException { 368 java.util.List<BillingAccountRolePK> _pks; 369 ResultSet _rs = null; 370 371 try { 372 if(params.length != 0) { 373 Session.setQueryParams(ps, params); 374 } 375 376 _rs = ps.executeQuery(); 377 _pks = getPKsFromResultSetAsList(_rs); 378 _rs.close(); 379 } catch (SQLException se) { 380 throw new PersistenceDatabaseException(se); 381 } finally { 382 if(_rs != null) { 383 try { 384 _rs.close(); 385 } catch (SQLException se) { 386 // do nothing 387 } 388 } 389 } 390 391 return _pks; 392 } 393 394 public BillingAccountRolePK getPKFromQuery(PreparedStatement ps, final Object... params) 395 throws PersistenceDatabaseException { 396 BillingAccountRolePK _pk = null; 397 ResultSet _rs = null; 398 399 try { 400 if(params.length != 0) { 401 Session.setQueryParams(ps, params); 402 } 403 404 _rs = ps.executeQuery(); 405 if(_rs.next()) { 406 _pk = getPKFromResultSet(_rs); 407 } 408 _rs.close(); 409 } catch (SQLException se) { 410 throw new PersistenceDatabaseException(se); 411 } finally { 412 if(_rs != null) { 413 try { 414 _rs.close(); 415 } catch (SQLException se) { 416 // do nothing 417 } 418 } 419 } 420 421 return _pk; 422 } 423 424 public java.util.List<BillingAccountRole> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 425 throws PersistenceDatabaseException { 426 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, queryMap.get(entityPermission)); 427 428 return getEntitiesFromQuery(entityPermission, ps, params); 429 } 430 431 public java.util.List<BillingAccountRole> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 432 throws PersistenceDatabaseException { 433 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, queryMap.get(entityPermission)); 434 435 return getEntitiesFromQuery(entityPermission, ps); 436 } 437 438 public java.util.List<BillingAccountRole> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 439 throws PersistenceDatabaseException { 440 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, query.getSQL()); 441 442 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 443 } 444 445 public java.util.List<BillingAccountRole> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 446 throws PersistenceDatabaseException { 447 java.util.List<BillingAccountRole> _entities; 448 ResultSet _rs = null; 449 450 try { 451 if(params.length != 0) { 452 Session.setQueryParams(ps, params); 453 } 454 455 _rs = ps.executeQuery(); 456 _entities = getEntitiesFromResultSet(entityPermission, _rs); 457 _rs.close(); 458 } catch (SQLException se) { 459 throw new PersistenceDatabaseException(se); 460 } finally { 461 if(_rs != null) { 462 try { 463 _rs.close(); 464 } catch (SQLException se) { 465 // do nothing 466 } 467 } 468 } 469 470 return _entities; 471 } 472 473 public BillingAccountRole getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 474 throws PersistenceDatabaseException { 475 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, queryMap.get(entityPermission)); 476 477 return getEntityFromQuery(entityPermission, ps, params); 478 } 479 480 public BillingAccountRole getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 481 throws PersistenceDatabaseException { 482 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, queryMap.get(entityPermission)); 483 484 return getEntityFromQuery(entityPermission, ps); 485 } 486 487 public BillingAccountRole getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 488 throws PersistenceDatabaseException { 489 PreparedStatement ps = session.prepareStatement(BillingAccountRoleFactory.class, query.getSQL()); 490 491 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 492 } 493 494 public BillingAccountRole getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 495 throws PersistenceDatabaseException { 496 BillingAccountRole _entity = null; 497 ResultSet _rs = null; 498 499 try { 500 if(params.length != 0) { 501 Session.setQueryParams(ps, params); 502 } 503 504 _rs = ps.executeQuery(); 505 if(_rs.next()) { 506 _entity = getEntityFromResultSet(entityPermission, _rs); 507 } 508 _rs.close(); 509 } catch (SQLException se) { 510 throw new PersistenceDatabaseException(se); 511 } finally { 512 if(_rs != null) { 513 try { 514 _rs.close(); 515 } catch (SQLException se) { 516 // do nothing 517 } 518 } 519 } 520 521 return _entity; 522 } 523 524 public java.util.List<BillingAccountRole> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 525 throws PersistenceDatabaseException { 526 java.util.List<BillingAccountRole> _result = new ArrayList<>(); 527 528 try { 529 while(rs.next()) { 530 _result.add(getEntityFromResultSet(entityPermission, rs)); 531 } 532 } catch (SQLException se) { 533 throw new PersistenceDatabaseException(se); 534 } 535 536 return _result; 537 } 538 539 public BillingAccountRole getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 540 throws PersistenceDatabaseException { 541 BillingAccountRole _entity; 542 543 try { 544 Long bllactr_billingaccountroleid = rs.getLong(BLLACTR_BILLINGACCOUNTROLEID); 545 BillingAccountRolePK _pk = new BillingAccountRolePK(bllactr_billingaccountroleid); 546 547 // See if we already have the entity in the session cache 548 _entity = (BillingAccountRole)session.getEntity(_pk); 549 if(_entity != null) { 550 // If the requested permission is READ_WRITE, and the cached permission is 551 // READ_ONLY, then pretend that the cached object wasn't found, and create 552 // a new entity that is READ_WRITE. 553 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 554 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 555 _entity = null; 556 } 557 } 558 boolean foundInSessionCache = _entity != null; 559 560 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 561 _entity = getEntityFromCache(_pk); 562 } 563 564 if(_entity == null) { 565 Long bllactr_bllact_billingaccountid = rs.getLong(BLLACTR_BLLACT_BILLINGACCOUNTID); 566 if(rs.wasNull()) 567 bllactr_bllact_billingaccountid = null; 568 569 Long bllactr_par_partyid = rs.getLong(BLLACTR_PAR_PARTYID); 570 if(rs.wasNull()) 571 bllactr_par_partyid = null; 572 573 Long bllactr_pcm_partycontactmechanismid = rs.getLong(BLLACTR_PCM_PARTYCONTACTMECHANISMID); 574 if(rs.wasNull()) 575 bllactr_pcm_partycontactmechanismid = null; 576 577 Long bllactr_bllactrtyp_billingaccountroletypeid = rs.getLong(BLLACTR_BLLACTRTYP_BILLINGACCOUNTROLETYPEID); 578 if(rs.wasNull()) 579 bllactr_bllactrtyp_billingaccountroletypeid = null; 580 581 Long bllactr_fromtime = rs.getLong(BLLACTR_FROMTIME); 582 if(rs.wasNull()) 583 bllactr_fromtime = null; 584 585 Long bllactr_thrutime = rs.getLong(BLLACTR_THRUTIME); 586 if(rs.wasNull()) 587 bllactr_thrutime = null; 588 589 BillingAccountRoleValue _value = new BillingAccountRoleValue(_pk, bllactr_bllact_billingaccountid == null? null: new BillingAccountPK(bllactr_bllact_billingaccountid), bllactr_par_partyid == null? null: new PartyPK(bllactr_par_partyid), bllactr_pcm_partycontactmechanismid == null? null: new PartyContactMechanismPK(bllactr_pcm_partycontactmechanismid), bllactr_bllactrtyp_billingaccountroletypeid == null? null: new BillingAccountRoleTypePK(bllactr_bllactrtyp_billingaccountroletypeid), bllactr_fromtime, bllactr_thrutime); 590 _entity = new BillingAccountRole(_value, entityPermission); 591 } 592 593 if(!foundInSessionCache) { 594 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 595 session.putReadOnlyEntity(_pk, _entity); 596 session.getValueCache().put(_entity.getBillingAccountRoleValue()); 597 } else { 598 session.putReadWriteEntity(_pk, _entity); 599 } 600 } 601 } catch (SQLException se) { 602 throw new PersistenceDatabaseException(se); 603 } 604 605 return _entity; 606 } 607 608 public BillingAccountRole create(BillingAccount billingAccount, Party party, PartyContactMechanism partyContactMechanism, BillingAccountRoleType billingAccountRoleType, Long fromTime, Long thruTime) 609 throws PersistenceDatabaseException, PersistenceNotNullException { 610 return create(billingAccount == null ? null : billingAccount.getPrimaryKey(), party == null ? null : party.getPrimaryKey(), partyContactMechanism == null ? null : partyContactMechanism.getPrimaryKey(), billingAccountRoleType == null ? null : billingAccountRoleType.getPrimaryKey(), fromTime, thruTime); 611 } 612 613 private void bindForCreate(PreparedStatement _ps, BillingAccountRoleValue _value) 614 throws SQLException { 615 _ps.setLong(1, _value.getEntityId()); 616 617 BillingAccountPK bllactr_bllact_billingaccountid = _value.getBillingAccountPK(); 618 if(bllactr_bllact_billingaccountid == null) 619 _ps.setNull(2, Types.BIGINT); 620 else 621 _ps.setLong(2, bllactr_bllact_billingaccountid.getEntityId()); 622 623 PartyPK bllactr_par_partyid = _value.getPartyPK(); 624 if(bllactr_par_partyid == null) 625 _ps.setNull(3, Types.BIGINT); 626 else 627 _ps.setLong(3, bllactr_par_partyid.getEntityId()); 628 629 PartyContactMechanismPK bllactr_pcm_partycontactmechanismid = _value.getPartyContactMechanismPK(); 630 if(bllactr_pcm_partycontactmechanismid == null) 631 _ps.setNull(4, Types.BIGINT); 632 else 633 _ps.setLong(4, bllactr_pcm_partycontactmechanismid.getEntityId()); 634 635 BillingAccountRoleTypePK bllactr_bllactrtyp_billingaccountroletypeid = _value.getBillingAccountRoleTypePK(); 636 if(bllactr_bllactrtyp_billingaccountroletypeid == null) 637 _ps.setNull(5, Types.BIGINT); 638 else 639 _ps.setLong(5, bllactr_bllactrtyp_billingaccountroletypeid.getEntityId()); 640 641 Long bllactr_fromtime = _value.getFromTime(); 642 if(bllactr_fromtime == null) 643 _ps.setNull(6, Types.BIGINT); 644 else 645 _ps.setLong(6, bllactr_fromtime); 646 647 Long bllactr_thrutime = _value.getThruTime(); 648 if(bllactr_thrutime == null) 649 _ps.setNull(7, Types.BIGINT); 650 else 651 _ps.setLong(7, bllactr_thrutime); 652 653 } 654 655 public BillingAccountRole create(BillingAccountPK billingAccountPK, PartyPK partyPK, PartyContactMechanismPK partyContactMechanismPK, BillingAccountRoleTypePK billingAccountRoleTypePK, Long fromTime, Long thruTime) 656 throws PersistenceDatabaseException, PersistenceNotNullException { 657 BillingAccountRolePK _pk = getNextPK(); 658 BillingAccountRoleValue _value = new BillingAccountRoleValue(_pk, billingAccountPK, partyPK, partyContactMechanismPK, billingAccountRoleTypePK, fromTime, thruTime); 659 660 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 661 662 try { 663 bindForCreate(_ps, _value); 664 665 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 666 int _count = _ps.executeUpdate(); 667 668 if(_count != 1) { 669 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 670 } 671 } else { 672 _ps.executeUpdate(); 673 } 674 675 session.getValueCache().put(_value); 676 } catch (SQLException se) { 677 throw new PersistenceDatabaseException(se); 678 } 679 680 BillingAccountRole _entity = new BillingAccountRole(_value, EntityPermission.READ_ONLY); 681 session.putReadOnlyEntity(_pk, _entity); 682 683 return _entity; 684 } 685 686 public void create(Collection<BillingAccountRoleValue> _values) 687 throws PersistenceDatabaseException, PersistenceNotNullException { 688 int _size = _values.size(); 689 690 if(_size > 0) { 691 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 692 List<BillingAccountRoleValue> _cacheValues = new ArrayList<>(_size); 693 694 try { 695 for(BillingAccountRoleValue _value : _values) { 696 _value.setEntityId(entityIdGenerator.getNextEntityId()); 697 bindForCreate(_ps, _value); 698 699 _ps.addBatch(); 700 701 _cacheValues.add(_value); 702 } 703 704 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 705 int[] _counts = _ps.executeBatch(); 706 707 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 708 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 709 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 710 } 711 } 712 } else { 713 _ps.executeBatch(); 714 } 715 716 _ps.clearBatch(); 717 } catch (SQLException se) { 718 throw new PersistenceDatabaseException(se); 719 } 720 721 _cacheValues.forEach((_cacheValue) -> { 722 BillingAccountRole _cacheEntity = new BillingAccountRole(_cacheValue, EntityPermission.READ_ONLY); 723 724 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 725 }); 726 } 727 } 728 729 private boolean bindForStore(PreparedStatement _ps, BillingAccountRoleValue _value) 730 throws SQLException { 731 boolean _hasBeenModified = _value.hasBeenModified(); 732 733 if(_hasBeenModified) { 734 BillingAccountPK bllactr_bllact_billingaccountid = _value.getBillingAccountPK(); 735 if(bllactr_bllact_billingaccountid == null) 736 _ps.setNull(1, Types.BIGINT); 737 else 738 _ps.setLong(1, bllactr_bllact_billingaccountid.getEntityId()); 739 740 PartyPK bllactr_par_partyid = _value.getPartyPK(); 741 if(bllactr_par_partyid == null) 742 _ps.setNull(2, Types.BIGINT); 743 else 744 _ps.setLong(2, bllactr_par_partyid.getEntityId()); 745 746 PartyContactMechanismPK bllactr_pcm_partycontactmechanismid = _value.getPartyContactMechanismPK(); 747 if(bllactr_pcm_partycontactmechanismid == null) 748 _ps.setNull(3, Types.BIGINT); 749 else 750 _ps.setLong(3, bllactr_pcm_partycontactmechanismid.getEntityId()); 751 752 BillingAccountRoleTypePK bllactr_bllactrtyp_billingaccountroletypeid = _value.getBillingAccountRoleTypePK(); 753 if(bllactr_bllactrtyp_billingaccountroletypeid == null) 754 _ps.setNull(4, Types.BIGINT); 755 else 756 _ps.setLong(4, bllactr_bllactrtyp_billingaccountroletypeid.getEntityId()); 757 758 Long bllactr_fromtime = _value.getFromTime(); 759 if(bllactr_fromtime == null) 760 _ps.setNull(5, Types.BIGINT); 761 else 762 _ps.setLong(5, bllactr_fromtime); 763 764 Long bllactr_thrutime = _value.getThruTime(); 765 if(bllactr_thrutime == null) 766 _ps.setNull(6, Types.BIGINT); 767 else 768 _ps.setLong(6, bllactr_thrutime); 769 770 _ps.setLong(7, _value.getPrimaryKey().getEntityId()); 771 772 _value.clearHasBeenModified(); 773 } 774 775 return _hasBeenModified; 776 } 777 778 @Override 779 public void store(BillingAccountRole entity) 780 throws PersistenceDatabaseException { 781 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 782 783 try { 784 BillingAccountRoleValue _value = entity.getBillingAccountRoleValue(); 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<BillingAccountRole> 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(BillingAccountRole entity : entities) { 813 if(bindForStore(_ps, entity.getBillingAccountRoleValue())) { 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.getBillingAccountRoleValue()); 836 }); 837 } 838 } catch (SQLException se) { 839 throw new PersistenceDatabaseException(se); 840 } 841 } 842 } 843 844 @Override 845 public void remove(BillingAccountRole entity) 846 throws PersistenceDatabaseException { 847 remove(entity.getPrimaryKey()); 848 } 849 850 @Override 851 public void remove(BillingAccountRolePK 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<BillingAccountRolePK> 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(BillingAccountRolePK 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(BillingAccountRolePK 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}