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