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