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