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