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