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