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