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