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