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