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