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