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