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