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