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