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