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