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