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