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