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