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