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