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