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 * ShipmentDetailFactory.java 021 */ 022 023package com.echothree.model.data.shipment.server.factory; 024 025import com.echothree.model.data.shipment.common.pk.ShipmentPK; 026import com.echothree.model.data.shipment.common.pk.ShipmentTypePK; 027import com.echothree.model.data.party.common.pk.PartyPK; 028import com.echothree.model.data.contact.common.pk.PartyContactMechanismPK; 029import com.echothree.model.data.shipping.common.pk.ShippingMethodPK; 030 031import com.echothree.model.data.shipment.server.entity.Shipment; 032import com.echothree.model.data.shipment.server.entity.ShipmentType; 033import com.echothree.model.data.party.server.entity.Party; 034import com.echothree.model.data.contact.server.entity.PartyContactMechanism; 035import com.echothree.model.data.shipping.server.entity.ShippingMethod; 036 037import com.echothree.model.data.shipment.common.ShipmentDetailConstants; 038import com.echothree.model.data.shipment.common.pk.ShipmentDetailPK; 039import com.echothree.model.data.shipment.server.value.ShipmentDetailValue; 040import com.echothree.model.data.shipment.server.entity.ShipmentDetail; 041import com.echothree.util.common.exception.PersistenceDatabaseException; 042import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 043import com.echothree.util.common.exception.PersistenceNotNullException; 044import com.echothree.util.server.persistence.BaseFactory; 045import com.echothree.util.server.persistence.EntityIdGenerator; 046import com.echothree.util.server.persistence.EntityPermission; 047import com.echothree.util.server.persistence.PersistenceDebugFlags; 048import com.echothree.util.server.persistence.Session; 049import java.sql.PreparedStatement; 050import java.sql.ResultSet; 051import java.sql.SQLException; 052import java.sql.Types; 053import java.io.ByteArrayInputStream; 054import java.io.StringReader; 055import java.util.ArrayList; 056import java.util.Collection; 057import java.util.HashSet; 058import java.util.List; 059import java.util.Map; 060import java.util.Set; 061import javax.enterprise.context.ApplicationScoped; 062import javax.enterprise.inject.spi.CDI; 063import javax.inject.Inject; 064import org.jooq.ResultQuery; 065import org.slf4j.Logger; 066import org.slf4j.LoggerFactory; 067 068@ApplicationScoped 069public class ShipmentDetailFactory 070 implements BaseFactory<ShipmentDetailPK, ShipmentDetail> { 071 072 @Inject 073 Session session; 074 075 //private static final Logger log = LoggerFactory.getLogger(ShipmentDetailFactory.class); 076 077 final private static String SQL_SELECT_READ_ONLY = "SELECT shpdt_shipmentdetailid, shpdt_shp_shipmentid, shpdt_shptyp_shipmenttypeid, shpdt_shipmentname, shpdt_originpartyid, shpdt_originwarehousepartyid, shpdt_originpartycontactmechanismid, shpdt_destinationpartyid, shpdt_destinationwarehousepartyid, shpdt_destinationpartycontactmechanismid, shpdt_shm_shippingmethodid, shpdt_fromtime, shpdt_thrutime FROM shipmentdetails WHERE shpdt_shipmentdetailid = ?"; 078 final private static String SQL_SELECT_READ_WRITE = "SELECT shpdt_shipmentdetailid, shpdt_shp_shipmentid, shpdt_shptyp_shipmenttypeid, shpdt_shipmentname, shpdt_originpartyid, shpdt_originwarehousepartyid, shpdt_originpartycontactmechanismid, shpdt_destinationpartyid, shpdt_destinationwarehousepartyid, shpdt_destinationpartycontactmechanismid, shpdt_shm_shippingmethodid, shpdt_fromtime, shpdt_thrutime FROM shipmentdetails WHERE shpdt_shipmentdetailid = ? FOR UPDATE"; 079 final private static String SQL_INSERT = "INSERT INTO shipmentdetails (shpdt_shipmentdetailid, shpdt_shp_shipmentid, shpdt_shptyp_shipmenttypeid, shpdt_shipmentname, shpdt_originpartyid, shpdt_originwarehousepartyid, shpdt_originpartycontactmechanismid, shpdt_destinationpartyid, shpdt_destinationwarehousepartyid, shpdt_destinationpartycontactmechanismid, shpdt_shm_shippingmethodid, shpdt_fromtime, shpdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 080 final private static String SQL_UPDATE = "UPDATE shipmentdetails SET shpdt_shp_shipmentid = ?, shpdt_shptyp_shipmenttypeid = ?, shpdt_shipmentname = ?, shpdt_originpartyid = ?, shpdt_originwarehousepartyid = ?, shpdt_originpartycontactmechanismid = ?, shpdt_destinationpartyid = ?, shpdt_destinationwarehousepartyid = ?, shpdt_destinationpartycontactmechanismid = ?, shpdt_shm_shippingmethodid = ?, shpdt_fromtime = ?, shpdt_thrutime = ? WHERE shpdt_shipmentdetailid = ?"; 081 final private static String SQL_DELETE = "DELETE FROM shipmentdetails WHERE shpdt_shipmentdetailid = ?"; 082 final private static String SQL_VALID = "SELECT COUNT(*) FROM shipmentdetails WHERE shpdt_shipmentdetailid = ?"; 083 084 final private static String PK_COLUMN = "shpdt_shipmentdetailid"; 085 final private static String ALL_COLUMNS = "shpdt_shipmentdetailid, shpdt_shp_shipmentid, shpdt_shptyp_shipmenttypeid, shpdt_shipmentname, shpdt_originpartyid, shpdt_originwarehousepartyid, shpdt_originpartycontactmechanismid, shpdt_destinationpartyid, shpdt_destinationwarehousepartyid, shpdt_destinationpartycontactmechanismid, shpdt_shm_shippingmethodid, shpdt_fromtime, shpdt_thrutime"; 086 final public static String TABLE_NAME = "shipmentdetails"; 087 088 final public static String SHPDT_SHIPMENTDETAILID = "shpdt_shipmentdetailid"; 089 final public static String SHPDT_SHP_SHIPMENTID = "shpdt_shp_shipmentid"; 090 final public static String SHPDT_SHPTYP_SHIPMENTTYPEID = "shpdt_shptyp_shipmenttypeid"; 091 final public static String SHPDT_SHIPMENTNAME = "shpdt_shipmentname"; 092 final public static String SHPDT_ORIGINPARTYID = "shpdt_originpartyid"; 093 final public static String SHPDT_ORIGINWAREHOUSEPARTYID = "shpdt_originwarehousepartyid"; 094 final public static String SHPDT_ORIGINPARTYCONTACTMECHANISMID = "shpdt_originpartycontactmechanismid"; 095 final public static String SHPDT_DESTINATIONPARTYID = "shpdt_destinationpartyid"; 096 final public static String SHPDT_DESTINATIONWAREHOUSEPARTYID = "shpdt_destinationwarehousepartyid"; 097 final public static String SHPDT_DESTINATIONPARTYCONTACTMECHANISMID = "shpdt_destinationpartycontactmechanismid"; 098 final public static String SHPDT_SHM_SHIPPINGMETHODID = "shpdt_shm_shippingmethodid"; 099 final public static String SHPDT_FROMTIME = "shpdt_fromtime"; 100 final public static String SHPDT_THRUTIME = "shpdt_thrutime"; 101 102 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ShipmentDetailConstants.COMPONENT_VENDOR_NAME, ShipmentDetailConstants.ENTITY_TYPE_NAME); 103 104 /** Creates a new instance of ShipmentDetailFactory */ 105 protected ShipmentDetailFactory() { 106 super(); 107 } 108 109 public static ShipmentDetailFactory getInstance() { 110 return CDI.current().select(ShipmentDetailFactory.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 ShipmentDetailConstants.COMPONENT_VENDOR_NAME; 131 } 132 133 @Override 134 public String getEntityTypeName() { 135 return ShipmentDetailConstants.ENTITY_TYPE_NAME; 136 } 137 138 public PreparedStatement prepareStatement(String query) { 139 return session.prepareStatement(ShipmentDetailFactory.class, query); 140 } 141 142 public ShipmentDetailPK getNextPK() { 143 return new ShipmentDetailPK(entityIdGenerator.getNextEntityId()); 144 } 145 146 public Set<ShipmentDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 147 throws PersistenceDatabaseException { 148 Set<ShipmentDetailPK> _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<ShipmentDetailPK> getPKsFromResultSetAsList(ResultSet rs) 162 throws PersistenceDatabaseException { 163 java.util.List<ShipmentDetailPK> _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 ShipmentDetailPK getPKFromResultSet(ResultSet rs) 177 throws PersistenceDatabaseException { 178 ShipmentDetailPK _result; 179 180 try { 181 long shpdt_shipmentdetailid = rs.getLong(SHPDT_SHIPMENTDETAILID); 182 Long _entityId = rs.wasNull() ? null : shpdt_shipmentdetailid; 183 184 _result = new ShipmentDetailPK(_entityId); 185 } catch (SQLException se) { 186 throw new PersistenceDatabaseException(se); 187 } 188 189 return _result; 190 } 191 192 public java.util.List<ShipmentDetailValue> getValuesFromPKs(Collection<ShipmentDetailPK> pks) 193 throws PersistenceDatabaseException { 194 java.util.List<ShipmentDetailValue> _values = new ArrayList<>(pks.size()); 195 196 for(ShipmentDetailPK _pk: pks) { 197 _values.add(getValueFromPK(_pk)); 198 } 199 200 return _values; 201 } 202 203 public ShipmentDetailValue getValueFromPK(ShipmentDetailPK pk) 204 throws PersistenceDatabaseException { 205 ShipmentDetailValue _value; 206 207 // See if we already have the entity in the session cache 208 ShipmentDetail _entity = (ShipmentDetail)session.getEntity(pk); 209 if(_entity == null) 210 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getShipmentDetailValue(); 211 else 212 _value = _entity.getShipmentDetailValue(); 213 214 return _value; 215 } 216 217 public java.util.List<ShipmentDetailValue> getValuesFromResultSet(ResultSet rs) 218 throws PersistenceDatabaseException { 219 java.util.List<ShipmentDetailValue> _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 ShipmentDetailValue getValueFromResultSet(ResultSet rs) 233 throws PersistenceDatabaseException { 234 ShipmentDetailValue _value; 235 236 try { 237 Long shpdt_shipmentdetailid = rs.getLong(SHPDT_SHIPMENTDETAILID); 238 ShipmentDetailPK _pk = new ShipmentDetailPK(shpdt_shipmentdetailid); 239 240 // See if we already have the entity in the session cache 241 ShipmentDetail _entity = (ShipmentDetail)session.getEntity(_pk); 242 243 if(_entity == null) { 244 Long shpdt_shp_shipmentid = rs.getLong(SHPDT_SHP_SHIPMENTID); 245 if(rs.wasNull()) 246 shpdt_shp_shipmentid = null; 247 248 Long shpdt_shptyp_shipmenttypeid = rs.getLong(SHPDT_SHPTYP_SHIPMENTTYPEID); 249 if(rs.wasNull()) 250 shpdt_shptyp_shipmenttypeid = null; 251 252 String shpdt_shipmentname = rs.getString(SHPDT_SHIPMENTNAME); 253 if(rs.wasNull()) 254 shpdt_shipmentname = null; 255 256 Long shpdt_originpartyid = rs.getLong(SHPDT_ORIGINPARTYID); 257 if(rs.wasNull()) 258 shpdt_originpartyid = null; 259 260 Long shpdt_originwarehousepartyid = rs.getLong(SHPDT_ORIGINWAREHOUSEPARTYID); 261 if(rs.wasNull()) 262 shpdt_originwarehousepartyid = null; 263 264 Long shpdt_originpartycontactmechanismid = rs.getLong(SHPDT_ORIGINPARTYCONTACTMECHANISMID); 265 if(rs.wasNull()) 266 shpdt_originpartycontactmechanismid = null; 267 268 Long shpdt_destinationpartyid = rs.getLong(SHPDT_DESTINATIONPARTYID); 269 if(rs.wasNull()) 270 shpdt_destinationpartyid = null; 271 272 Long shpdt_destinationwarehousepartyid = rs.getLong(SHPDT_DESTINATIONWAREHOUSEPARTYID); 273 if(rs.wasNull()) 274 shpdt_destinationwarehousepartyid = null; 275 276 Long shpdt_destinationpartycontactmechanismid = rs.getLong(SHPDT_DESTINATIONPARTYCONTACTMECHANISMID); 277 if(rs.wasNull()) 278 shpdt_destinationpartycontactmechanismid = null; 279 280 Long shpdt_shm_shippingmethodid = rs.getLong(SHPDT_SHM_SHIPPINGMETHODID); 281 if(rs.wasNull()) 282 shpdt_shm_shippingmethodid = null; 283 284 Long shpdt_fromtime = rs.getLong(SHPDT_FROMTIME); 285 if(rs.wasNull()) 286 shpdt_fromtime = null; 287 288 Long shpdt_thrutime = rs.getLong(SHPDT_THRUTIME); 289 if(rs.wasNull()) 290 shpdt_thrutime = null; 291 292 _value = new ShipmentDetailValue(_pk, new ShipmentPK(shpdt_shp_shipmentid), new ShipmentTypePK(shpdt_shptyp_shipmenttypeid), shpdt_shipmentname, new PartyPK(shpdt_originpartyid), new PartyPK(shpdt_originwarehousepartyid), new PartyContactMechanismPK(shpdt_originpartycontactmechanismid), new PartyPK(shpdt_destinationpartyid), new PartyPK(shpdt_destinationwarehousepartyid), new PartyContactMechanismPK(shpdt_destinationpartycontactmechanismid), new ShippingMethodPK(shpdt_shm_shippingmethodid), shpdt_fromtime, shpdt_thrutime); 293 } else 294 _value = _entity.getShipmentDetailValue(); 295 } catch (SQLException se) { 296 throw new PersistenceDatabaseException(se); 297 } 298 299 return _value; 300 } 301 302 public java.util.List<ShipmentDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ShipmentDetailPK> pks) 303 throws PersistenceDatabaseException { 304 java.util.List<ShipmentDetail> _entities = new ArrayList<>(pks.size()); 305 306 for(ShipmentDetailPK _pk: pks) { 307 _entities.add(getEntityFromPK(entityPermission, _pk)); 308 } 309 310 return _entities; 311 } 312 313 public ShipmentDetail getEntityFromValue(EntityPermission entityPermission, ShipmentDetailValue value) { 314 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 315 } 316 317 public ShipmentDetail getEntityFromCache(ShipmentDetailPK pk) { 318 ShipmentDetailValue _value = (ShipmentDetailValue)session.getValueCache().get(pk); 319 320 return _value == null ? null : new ShipmentDetail(_value, EntityPermission.READ_ONLY); 321 } 322 323 public ShipmentDetail getEntityFromPK(EntityPermission entityPermission, ShipmentDetailPK pk) 324 throws PersistenceDatabaseException { 325 ShipmentDetail _entity; 326 327 // See if we already have the entity in the session cache 328 _entity = (ShipmentDetail)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(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(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<ShipmentDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 371 throws PersistenceDatabaseException { 372 Set<ShipmentDetailPK> _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<ShipmentDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 399 throws PersistenceDatabaseException { 400 java.util.List<ShipmentDetailPK> _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 ShipmentDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 427 throws PersistenceDatabaseException { 428 ShipmentDetailPK _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<ShipmentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 457 throws PersistenceDatabaseException { 458 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, queryMap.get(entityPermission)); 459 460 return getEntitiesFromQuery(entityPermission, ps, params); 461 } 462 463 public java.util.List<ShipmentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 464 throws PersistenceDatabaseException { 465 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, queryMap.get(entityPermission)); 466 467 return getEntitiesFromQuery(entityPermission, ps); 468 } 469 470 public java.util.List<ShipmentDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 471 throws PersistenceDatabaseException { 472 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, query.getSQL()); 473 474 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 475 } 476 477 public java.util.List<ShipmentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 478 throws PersistenceDatabaseException { 479 java.util.List<ShipmentDetail> _entities; 480 ResultSet _rs = null; 481 482 try { 483 if(params.length != 0) { 484 Session.setQueryParams(ps, params); 485 } 486 487 _rs = ps.executeQuery(); 488 _entities = getEntitiesFromResultSet(entityPermission, _rs); 489 _rs.close(); 490 } catch (SQLException se) { 491 throw new PersistenceDatabaseException(se); 492 } finally { 493 if(_rs != null) { 494 try { 495 _rs.close(); 496 } catch (SQLException se) { 497 // do nothing 498 } 499 } 500 } 501 502 return _entities; 503 } 504 505 public ShipmentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 506 throws PersistenceDatabaseException { 507 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, queryMap.get(entityPermission)); 508 509 return getEntityFromQuery(entityPermission, ps, params); 510 } 511 512 public ShipmentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 513 throws PersistenceDatabaseException { 514 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, queryMap.get(entityPermission)); 515 516 return getEntityFromQuery(entityPermission, ps); 517 } 518 519 public ShipmentDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 520 throws PersistenceDatabaseException { 521 PreparedStatement ps = session.prepareStatement(ShipmentDetailFactory.class, query.getSQL()); 522 523 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 524 } 525 526 public ShipmentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 527 throws PersistenceDatabaseException { 528 ShipmentDetail _entity = null; 529 ResultSet _rs = null; 530 531 try { 532 if(params.length != 0) { 533 Session.setQueryParams(ps, params); 534 } 535 536 _rs = ps.executeQuery(); 537 if(_rs.next()) { 538 _entity = getEntityFromResultSet(entityPermission, _rs); 539 } 540 _rs.close(); 541 } catch (SQLException se) { 542 throw new PersistenceDatabaseException(se); 543 } finally { 544 if(_rs != null) { 545 try { 546 _rs.close(); 547 } catch (SQLException se) { 548 // do nothing 549 } 550 } 551 } 552 553 return _entity; 554 } 555 556 public java.util.List<ShipmentDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 557 throws PersistenceDatabaseException { 558 java.util.List<ShipmentDetail> _result = new ArrayList<>(); 559 560 try { 561 while(rs.next()) { 562 _result.add(getEntityFromResultSet(entityPermission, rs)); 563 } 564 } catch (SQLException se) { 565 throw new PersistenceDatabaseException(se); 566 } 567 568 return _result; 569 } 570 571 public ShipmentDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 572 throws PersistenceDatabaseException { 573 ShipmentDetail _entity; 574 575 try { 576 Long shpdt_shipmentdetailid = rs.getLong(SHPDT_SHIPMENTDETAILID); 577 ShipmentDetailPK _pk = new ShipmentDetailPK(shpdt_shipmentdetailid); 578 579 // See if we already have the entity in the session cache 580 _entity = (ShipmentDetail)session.getEntity(_pk); 581 if(_entity != null) { 582 // If the requested permission is READ_WRITE, and the cached permission is 583 // READ_ONLY, then pretend that the cached object wasn't found, and create 584 // a new entity that is READ_WRITE. 585 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 586 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 587 _entity = null; 588 } 589 } 590 boolean foundInSessionCache = _entity != null; 591 592 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 593 _entity = getEntityFromCache(_pk); 594 } 595 596 if(_entity == null) { 597 Long shpdt_shp_shipmentid = rs.getLong(SHPDT_SHP_SHIPMENTID); 598 if(rs.wasNull()) 599 shpdt_shp_shipmentid = null; 600 601 Long shpdt_shptyp_shipmenttypeid = rs.getLong(SHPDT_SHPTYP_SHIPMENTTYPEID); 602 if(rs.wasNull()) 603 shpdt_shptyp_shipmenttypeid = null; 604 605 String shpdt_shipmentname = rs.getString(SHPDT_SHIPMENTNAME); 606 if(rs.wasNull()) 607 shpdt_shipmentname = null; 608 609 Long shpdt_originpartyid = rs.getLong(SHPDT_ORIGINPARTYID); 610 if(rs.wasNull()) 611 shpdt_originpartyid = null; 612 613 Long shpdt_originwarehousepartyid = rs.getLong(SHPDT_ORIGINWAREHOUSEPARTYID); 614 if(rs.wasNull()) 615 shpdt_originwarehousepartyid = null; 616 617 Long shpdt_originpartycontactmechanismid = rs.getLong(SHPDT_ORIGINPARTYCONTACTMECHANISMID); 618 if(rs.wasNull()) 619 shpdt_originpartycontactmechanismid = null; 620 621 Long shpdt_destinationpartyid = rs.getLong(SHPDT_DESTINATIONPARTYID); 622 if(rs.wasNull()) 623 shpdt_destinationpartyid = null; 624 625 Long shpdt_destinationwarehousepartyid = rs.getLong(SHPDT_DESTINATIONWAREHOUSEPARTYID); 626 if(rs.wasNull()) 627 shpdt_destinationwarehousepartyid = null; 628 629 Long shpdt_destinationpartycontactmechanismid = rs.getLong(SHPDT_DESTINATIONPARTYCONTACTMECHANISMID); 630 if(rs.wasNull()) 631 shpdt_destinationpartycontactmechanismid = null; 632 633 Long shpdt_shm_shippingmethodid = rs.getLong(SHPDT_SHM_SHIPPINGMETHODID); 634 if(rs.wasNull()) 635 shpdt_shm_shippingmethodid = null; 636 637 Long shpdt_fromtime = rs.getLong(SHPDT_FROMTIME); 638 if(rs.wasNull()) 639 shpdt_fromtime = null; 640 641 Long shpdt_thrutime = rs.getLong(SHPDT_THRUTIME); 642 if(rs.wasNull()) 643 shpdt_thrutime = null; 644 645 ShipmentDetailValue _value = new ShipmentDetailValue(_pk, shpdt_shp_shipmentid == null? null: new ShipmentPK(shpdt_shp_shipmentid), shpdt_shptyp_shipmenttypeid == null? null: new ShipmentTypePK(shpdt_shptyp_shipmenttypeid), shpdt_shipmentname, shpdt_originpartyid == null? null: new PartyPK(shpdt_originpartyid), shpdt_originwarehousepartyid == null? null: new PartyPK(shpdt_originwarehousepartyid), shpdt_originpartycontactmechanismid == null? null: new PartyContactMechanismPK(shpdt_originpartycontactmechanismid), shpdt_destinationpartyid == null? null: new PartyPK(shpdt_destinationpartyid), shpdt_destinationwarehousepartyid == null? null: new PartyPK(shpdt_destinationwarehousepartyid), shpdt_destinationpartycontactmechanismid == null? null: new PartyContactMechanismPK(shpdt_destinationpartycontactmechanismid), shpdt_shm_shippingmethodid == null? null: new ShippingMethodPK(shpdt_shm_shippingmethodid), shpdt_fromtime, shpdt_thrutime); 646 _entity = new ShipmentDetail(_value, entityPermission); 647 } 648 649 if(!foundInSessionCache) { 650 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 651 session.putReadOnlyEntity(_pk, _entity); 652 session.getValueCache().put(_entity.getShipmentDetailValue()); 653 } else { 654 session.putReadWriteEntity(_pk, _entity); 655 } 656 } 657 } catch (SQLException se) { 658 throw new PersistenceDatabaseException(se); 659 } 660 661 return _entity; 662 } 663 664 public ShipmentDetail create(Shipment shipment, ShipmentType shipmentType, String shipmentName, Party originParty, Party originWarehouseParty, PartyContactMechanism originPartyContactMechanism, Party destinationParty, Party destinationWarehouseParty, PartyContactMechanism destinationPartyContactMechanism, ShippingMethod shippingMethod, Long fromTime, Long thruTime) 665 throws PersistenceDatabaseException, PersistenceNotNullException { 666 return create(shipment == null ? null : shipment.getPrimaryKey(), shipmentType == null ? null : shipmentType.getPrimaryKey(), shipmentName, originParty == null ? null : originParty.getPrimaryKey(), originWarehouseParty == null ? null : originWarehouseParty.getPrimaryKey(), originPartyContactMechanism == null ? null : originPartyContactMechanism.getPrimaryKey(), destinationParty == null ? null : destinationParty.getPrimaryKey(), destinationWarehouseParty == null ? null : destinationWarehouseParty.getPrimaryKey(), destinationPartyContactMechanism == null ? null : destinationPartyContactMechanism.getPrimaryKey(), shippingMethod == null ? null : shippingMethod.getPrimaryKey(), fromTime, thruTime); 667 } 668 669 private void bindForCreate(PreparedStatement _ps, ShipmentDetailValue _value) 670 throws SQLException { 671 _ps.setLong(1, _value.getEntityId()); 672 673 ShipmentPK shpdt_shp_shipmentid = _value.getShipmentPK(); 674 if(shpdt_shp_shipmentid == null) 675 _ps.setNull(2, Types.BIGINT); 676 else 677 _ps.setLong(2, shpdt_shp_shipmentid.getEntityId()); 678 679 ShipmentTypePK shpdt_shptyp_shipmenttypeid = _value.getShipmentTypePK(); 680 if(shpdt_shptyp_shipmenttypeid == null) 681 _ps.setNull(3, Types.BIGINT); 682 else 683 _ps.setLong(3, shpdt_shptyp_shipmenttypeid.getEntityId()); 684 685 String shpdt_shipmentname = _value.getShipmentName(); 686 if(shpdt_shipmentname == null) 687 _ps.setNull(4, Types.VARCHAR); 688 else 689 _ps.setString(4, shpdt_shipmentname); 690 691 PartyPK shpdt_originpartyid = _value.getOriginPartyPK(); 692 if(shpdt_originpartyid == null) 693 _ps.setNull(5, Types.BIGINT); 694 else 695 _ps.setLong(5, shpdt_originpartyid.getEntityId()); 696 697 PartyPK shpdt_originwarehousepartyid = _value.getOriginWarehousePartyPK(); 698 if(shpdt_originwarehousepartyid == null) 699 _ps.setNull(6, Types.BIGINT); 700 else 701 _ps.setLong(6, shpdt_originwarehousepartyid.getEntityId()); 702 703 PartyContactMechanismPK shpdt_originpartycontactmechanismid = _value.getOriginPartyContactMechanismPK(); 704 if(shpdt_originpartycontactmechanismid == null) 705 _ps.setNull(7, Types.BIGINT); 706 else 707 _ps.setLong(7, shpdt_originpartycontactmechanismid.getEntityId()); 708 709 PartyPK shpdt_destinationpartyid = _value.getDestinationPartyPK(); 710 if(shpdt_destinationpartyid == null) 711 _ps.setNull(8, Types.BIGINT); 712 else 713 _ps.setLong(8, shpdt_destinationpartyid.getEntityId()); 714 715 PartyPK shpdt_destinationwarehousepartyid = _value.getDestinationWarehousePartyPK(); 716 if(shpdt_destinationwarehousepartyid == null) 717 _ps.setNull(9, Types.BIGINT); 718 else 719 _ps.setLong(9, shpdt_destinationwarehousepartyid.getEntityId()); 720 721 PartyContactMechanismPK shpdt_destinationpartycontactmechanismid = _value.getDestinationPartyContactMechanismPK(); 722 if(shpdt_destinationpartycontactmechanismid == null) 723 _ps.setNull(10, Types.BIGINT); 724 else 725 _ps.setLong(10, shpdt_destinationpartycontactmechanismid.getEntityId()); 726 727 ShippingMethodPK shpdt_shm_shippingmethodid = _value.getShippingMethodPK(); 728 if(shpdt_shm_shippingmethodid == null) 729 _ps.setNull(11, Types.BIGINT); 730 else 731 _ps.setLong(11, shpdt_shm_shippingmethodid.getEntityId()); 732 733 Long shpdt_fromtime = _value.getFromTime(); 734 if(shpdt_fromtime == null) 735 _ps.setNull(12, Types.BIGINT); 736 else 737 _ps.setLong(12, shpdt_fromtime); 738 739 Long shpdt_thrutime = _value.getThruTime(); 740 if(shpdt_thrutime == null) 741 _ps.setNull(13, Types.BIGINT); 742 else 743 _ps.setLong(13, shpdt_thrutime); 744 745 } 746 747 public ShipmentDetail create(ShipmentPK shipmentPK, ShipmentTypePK shipmentTypePK, String shipmentName, PartyPK originPartyPK, PartyPK originWarehousePartyPK, PartyContactMechanismPK originPartyContactMechanismPK, PartyPK destinationPartyPK, PartyPK destinationWarehousePartyPK, PartyContactMechanismPK destinationPartyContactMechanismPK, ShippingMethodPK shippingMethodPK, Long fromTime, Long thruTime) 748 throws PersistenceDatabaseException, PersistenceNotNullException { 749 ShipmentDetailPK _pk = getNextPK(); 750 ShipmentDetailValue _value = new ShipmentDetailValue(_pk, shipmentPK, shipmentTypePK, shipmentName, originPartyPK, originWarehousePartyPK, originPartyContactMechanismPK, destinationPartyPK, destinationWarehousePartyPK, destinationPartyContactMechanismPK, shippingMethodPK, fromTime, thruTime); 751 752 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 753 754 try { 755 bindForCreate(_ps, _value); 756 757 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 758 int _count = _ps.executeUpdate(); 759 760 if(_count != 1) { 761 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 762 } 763 } else { 764 _ps.executeUpdate(); 765 } 766 767 session.getValueCache().put(_value); 768 } catch (SQLException se) { 769 throw new PersistenceDatabaseException(se); 770 } 771 772 ShipmentDetail _entity = new ShipmentDetail(_value, EntityPermission.READ_ONLY); 773 session.putReadOnlyEntity(_pk, _entity); 774 775 return _entity; 776 } 777 778 public void create(Collection<ShipmentDetailValue> _values) 779 throws PersistenceDatabaseException, PersistenceNotNullException { 780 int _size = _values.size(); 781 782 if(_size > 0) { 783 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 784 List<ShipmentDetailValue> _cacheValues = new ArrayList<>(_size); 785 786 try { 787 for(ShipmentDetailValue _value : _values) { 788 _value.setEntityId(entityIdGenerator.getNextEntityId()); 789 bindForCreate(_ps, _value); 790 791 _ps.addBatch(); 792 793 _cacheValues.add(_value); 794 } 795 796 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 797 int[] _counts = _ps.executeBatch(); 798 799 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 800 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 801 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 802 } 803 } 804 } else { 805 _ps.executeBatch(); 806 } 807 808 _ps.clearBatch(); 809 } catch (SQLException se) { 810 throw new PersistenceDatabaseException(se); 811 } 812 813 _cacheValues.forEach((_cacheValue) -> { 814 ShipmentDetail _cacheEntity = new ShipmentDetail(_cacheValue, EntityPermission.READ_ONLY); 815 816 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 817 }); 818 } 819 } 820 821 private boolean bindForStore(PreparedStatement _ps, ShipmentDetailValue _value) 822 throws SQLException { 823 boolean _hasBeenModified = _value.hasBeenModified(); 824 825 if(_hasBeenModified) { 826 ShipmentPK shpdt_shp_shipmentid = _value.getShipmentPK(); 827 if(shpdt_shp_shipmentid == null) 828 _ps.setNull(1, Types.BIGINT); 829 else 830 _ps.setLong(1, shpdt_shp_shipmentid.getEntityId()); 831 832 ShipmentTypePK shpdt_shptyp_shipmenttypeid = _value.getShipmentTypePK(); 833 if(shpdt_shptyp_shipmenttypeid == null) 834 _ps.setNull(2, Types.BIGINT); 835 else 836 _ps.setLong(2, shpdt_shptyp_shipmenttypeid.getEntityId()); 837 838 String shpdt_shipmentname = _value.getShipmentName(); 839 if(shpdt_shipmentname == null) 840 _ps.setNull(3, Types.VARCHAR); 841 else 842 _ps.setString(3, shpdt_shipmentname); 843 844 PartyPK shpdt_originpartyid = _value.getOriginPartyPK(); 845 if(shpdt_originpartyid == null) 846 _ps.setNull(4, Types.BIGINT); 847 else 848 _ps.setLong(4, shpdt_originpartyid.getEntityId()); 849 850 PartyPK shpdt_originwarehousepartyid = _value.getOriginWarehousePartyPK(); 851 if(shpdt_originwarehousepartyid == null) 852 _ps.setNull(5, Types.BIGINT); 853 else 854 _ps.setLong(5, shpdt_originwarehousepartyid.getEntityId()); 855 856 PartyContactMechanismPK shpdt_originpartycontactmechanismid = _value.getOriginPartyContactMechanismPK(); 857 if(shpdt_originpartycontactmechanismid == null) 858 _ps.setNull(6, Types.BIGINT); 859 else 860 _ps.setLong(6, shpdt_originpartycontactmechanismid.getEntityId()); 861 862 PartyPK shpdt_destinationpartyid = _value.getDestinationPartyPK(); 863 if(shpdt_destinationpartyid == null) 864 _ps.setNull(7, Types.BIGINT); 865 else 866 _ps.setLong(7, shpdt_destinationpartyid.getEntityId()); 867 868 PartyPK shpdt_destinationwarehousepartyid = _value.getDestinationWarehousePartyPK(); 869 if(shpdt_destinationwarehousepartyid == null) 870 _ps.setNull(8, Types.BIGINT); 871 else 872 _ps.setLong(8, shpdt_destinationwarehousepartyid.getEntityId()); 873 874 PartyContactMechanismPK shpdt_destinationpartycontactmechanismid = _value.getDestinationPartyContactMechanismPK(); 875 if(shpdt_destinationpartycontactmechanismid == null) 876 _ps.setNull(9, Types.BIGINT); 877 else 878 _ps.setLong(9, shpdt_destinationpartycontactmechanismid.getEntityId()); 879 880 ShippingMethodPK shpdt_shm_shippingmethodid = _value.getShippingMethodPK(); 881 if(shpdt_shm_shippingmethodid == null) 882 _ps.setNull(10, Types.BIGINT); 883 else 884 _ps.setLong(10, shpdt_shm_shippingmethodid.getEntityId()); 885 886 Long shpdt_fromtime = _value.getFromTime(); 887 if(shpdt_fromtime == null) 888 _ps.setNull(11, Types.BIGINT); 889 else 890 _ps.setLong(11, shpdt_fromtime); 891 892 Long shpdt_thrutime = _value.getThruTime(); 893 if(shpdt_thrutime == null) 894 _ps.setNull(12, Types.BIGINT); 895 else 896 _ps.setLong(12, shpdt_thrutime); 897 898 _ps.setLong(13, _value.getPrimaryKey().getEntityId()); 899 900 _value.clearHasBeenModified(); 901 } 902 903 return _hasBeenModified; 904 } 905 906 @Override 907 public void store(ShipmentDetail entity) 908 throws PersistenceDatabaseException { 909 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 910 911 try { 912 ShipmentDetailValue _value = entity.getShipmentDetailValue(); 913 914 if(bindForStore(_ps, _value)) { 915 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 916 int _count = _ps.executeUpdate(); 917 918 if(_count != 1) { 919 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 920 } 921 } else { 922 _ps.executeUpdate(); 923 } 924 925 session.getValueCache().put(_value); 926 } 927 } catch (SQLException se) { 928 throw new PersistenceDatabaseException(se); 929 } 930 } 931 932 @Override 933 public void store(Collection<ShipmentDetail> entities) 934 throws PersistenceDatabaseException { 935 if(entities.size() > 0) { 936 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 937 int _modifiedEntities = 0; 938 939 try { 940 for(ShipmentDetail entity : entities) { 941 if(bindForStore(_ps, entity.getShipmentDetailValue())) { 942 _ps.addBatch(); 943 _modifiedEntities++; 944 } 945 } 946 947 if(_modifiedEntities != 0) { 948 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 949 int[] _counts = _ps.executeBatch(); 950 951 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 952 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 953 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 954 } 955 } 956 } else { 957 _ps.executeBatch(); 958 } 959 960 _ps.clearBatch(); 961 962 entities.forEach((entity) -> { 963 session.getValueCache().put(entity.getShipmentDetailValue()); 964 }); 965 } 966 } catch (SQLException se) { 967 throw new PersistenceDatabaseException(se); 968 } 969 } 970 } 971 972 @Override 973 public void remove(ShipmentDetail entity) 974 throws PersistenceDatabaseException { 975 remove(entity.getPrimaryKey()); 976 } 977 978 @Override 979 public void remove(ShipmentDetailPK pk) 980 throws PersistenceDatabaseException { 981 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 982 long _entityId = pk.getEntityId(); 983 984 try { 985 _ps.setLong(1, _entityId); 986 987 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 988 int _count = _ps.executeUpdate(); 989 990 if(_count != 1) { 991 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 992 } 993 } else { 994 _ps.executeUpdate(); 995 } 996 997 session.getValueCache().remove(pk); 998 } catch (SQLException se) { 999 throw new PersistenceDatabaseException(se); 1000 } 1001 1002 session.removed(pk, false); 1003 } 1004 1005 @Override 1006 public void remove(Collection<ShipmentDetailPK> pks) 1007 throws PersistenceDatabaseException { 1008 if(pks.size() > 0) { 1009 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1010 int _modifiedEntities = 0; 1011 1012 try { 1013 for(ShipmentDetailPK pk : pks) { 1014 long _entityId = pk.getEntityId(); 1015 1016 _ps.setLong(1, _entityId); 1017 1018 _ps.addBatch(); 1019 _modifiedEntities++; 1020 } 1021 1022 if(_modifiedEntities != 0) { 1023 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1024 int[] _counts = _ps.executeBatch(); 1025 1026 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1027 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1028 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1029 } 1030 } 1031 } else { 1032 _ps.executeBatch(); 1033 } 1034 1035 _ps.clearBatch(); 1036 1037 pks.forEach((pk) -> { 1038 session.getValueCache().remove(pk); 1039 }); 1040 } 1041 } catch (SQLException se) { 1042 throw new PersistenceDatabaseException(se); 1043 } 1044 1045 pks.forEach((pk) -> { 1046 session.removed(pk, true); 1047 }); 1048 } 1049 } 1050 1051 @Override 1052 public boolean validPK(ShipmentDetailPK pk) 1053 throws PersistenceDatabaseException { 1054 boolean valid = false; 1055 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1056 ResultSet _rs = null; 1057 1058 try { 1059 _ps.setLong(1, pk.getEntityId()); 1060 1061 _rs = _ps.executeQuery(); 1062 if(_rs.next()) { 1063 long _count = _rs.getLong(1); 1064 if(_rs.wasNull()) 1065 _count = 0; 1066 1067 if(_count == 1) 1068 valid = true; 1069 } 1070 } catch (SQLException se) { 1071 throw new PersistenceDatabaseException(se); 1072 } finally { 1073 if(_rs != null) { 1074 try { 1075 _rs.close(); 1076 } catch (SQLException se) { 1077 // do nothing 1078 } 1079 } 1080 } 1081 1082 return valid; 1083 } 1084 1085}