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