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