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