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