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