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