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