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