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