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