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