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 * ItemKitMemberFactory.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; 028 029import com.echothree.model.data.item.server.entity.Item; 030import com.echothree.model.data.inventory.server.entity.InventoryCondition; 031import com.echothree.model.data.uom.server.entity.UnitOfMeasureType; 032 033import com.echothree.model.data.item.common.ItemKitMemberConstants; 034import com.echothree.model.data.item.common.pk.ItemKitMemberPK; 035import com.echothree.model.data.item.server.value.ItemKitMemberValue; 036import com.echothree.model.data.item.server.entity.ItemKitMember; 037import com.echothree.util.common.exception.PersistenceDatabaseException; 038import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 039import com.echothree.util.common.exception.PersistenceNotNullException; 040import com.echothree.util.server.persistence.BaseFactory; 041import com.echothree.util.server.persistence.EntityIdGenerator; 042import com.echothree.util.server.persistence.EntityPermission; 043import com.echothree.util.server.persistence.PersistenceDebugFlags; 044import com.echothree.util.server.persistence.Session; 045import java.sql.PreparedStatement; 046import java.sql.ResultSet; 047import java.sql.SQLException; 048import java.sql.Types; 049import java.io.ByteArrayInputStream; 050import java.io.StringReader; 051import java.util.ArrayList; 052import java.util.Collection; 053import java.util.HashSet; 054import java.util.List; 055import java.util.Map; 056import java.util.Set; 057import javax.enterprise.context.ApplicationScoped; 058import javax.enterprise.inject.spi.CDI; 059import javax.inject.Inject; 060import org.jooq.ResultQuery; 061import org.slf4j.Logger; 062import org.slf4j.LoggerFactory; 063 064@ApplicationScoped 065public class ItemKitMemberFactory 066 implements BaseFactory<ItemKitMemberPK, ItemKitMember> { 067 068 @Inject 069 Session session; 070 071 //private static final Logger log = LoggerFactory.getLogger(ItemKitMemberFactory.class); 072 073 final private static String SQL_SELECT_READ_ONLY = "SELECT ikm_itemkitmemberid, ikm_itm_itemid, ikm_invcon_inventoryconditionid, ikm_uomt_unitofmeasuretypeid, ikm_memberitemid, ikm_memberinventoryconditionid, ikm_memberunitofmeasuretypeid, ikm_quantity, ikm_fromtime, ikm_thrutime FROM itemkitmembers WHERE ikm_itemkitmemberid = ?"; 074 final private static String SQL_SELECT_READ_WRITE = "SELECT ikm_itemkitmemberid, ikm_itm_itemid, ikm_invcon_inventoryconditionid, ikm_uomt_unitofmeasuretypeid, ikm_memberitemid, ikm_memberinventoryconditionid, ikm_memberunitofmeasuretypeid, ikm_quantity, ikm_fromtime, ikm_thrutime FROM itemkitmembers WHERE ikm_itemkitmemberid = ? FOR UPDATE"; 075 final private static String SQL_INSERT = "INSERT INTO itemkitmembers (ikm_itemkitmemberid, ikm_itm_itemid, ikm_invcon_inventoryconditionid, ikm_uomt_unitofmeasuretypeid, ikm_memberitemid, ikm_memberinventoryconditionid, ikm_memberunitofmeasuretypeid, ikm_quantity, ikm_fromtime, ikm_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 076 final private static String SQL_UPDATE = "UPDATE itemkitmembers SET ikm_itm_itemid = ?, ikm_invcon_inventoryconditionid = ?, ikm_uomt_unitofmeasuretypeid = ?, ikm_memberitemid = ?, ikm_memberinventoryconditionid = ?, ikm_memberunitofmeasuretypeid = ?, ikm_quantity = ?, ikm_fromtime = ?, ikm_thrutime = ? WHERE ikm_itemkitmemberid = ?"; 077 final private static String SQL_DELETE = "DELETE FROM itemkitmembers WHERE ikm_itemkitmemberid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM itemkitmembers WHERE ikm_itemkitmemberid = ?"; 079 080 final public static String IKM_ITEMKITMEMBERID = "ikm_itemkitmemberid"; 081 final public static String IKM_ITM_ITEMID = "ikm_itm_itemid"; 082 final public static String IKM_INVCON_INVENTORYCONDITIONID = "ikm_invcon_inventoryconditionid"; 083 final public static String IKM_UOMT_UNITOFMEASURETYPEID = "ikm_uomt_unitofmeasuretypeid"; 084 final public static String IKM_MEMBERITEMID = "ikm_memberitemid"; 085 final public static String IKM_MEMBERINVENTORYCONDITIONID = "ikm_memberinventoryconditionid"; 086 final public static String IKM_MEMBERUNITOFMEASURETYPEID = "ikm_memberunitofmeasuretypeid"; 087 final public static String IKM_QUANTITY = "ikm_quantity"; 088 final public static String IKM_FROMTIME = "ikm_fromtime"; 089 final public static String IKM_THRUTIME = "ikm_thrutime"; 090 091 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ItemKitMemberConstants.COMPONENT_VENDOR_NAME, ItemKitMemberConstants.ENTITY_TYPE_NAME); 092 093 /** Creates a new instance of ItemKitMemberFactory */ 094 protected ItemKitMemberFactory() { 095 super(); 096 } 097 098 public static ItemKitMemberFactory getInstance() { 099 return CDI.current().select(ItemKitMemberFactory.class).get(); 100 } 101 102 @Override 103 public String getComponentVendorName() { 104 return ItemKitMemberConstants.COMPONENT_VENDOR_NAME; 105 } 106 107 @Override 108 public String getEntityTypeName() { 109 return ItemKitMemberConstants.ENTITY_TYPE_NAME; 110 } 111 112 public PreparedStatement prepareStatement(String query) { 113 return session.prepareStatement(query); 114 } 115 116 public ItemKitMemberPK getNextPK() { 117 return new ItemKitMemberPK(entityIdGenerator.getNextEntityId()); 118 } 119 120 public Set<ItemKitMemberPK> getPKsFromResultSetAsSet(ResultSet rs) 121 throws PersistenceDatabaseException { 122 Set<ItemKitMemberPK> _result = new HashSet<>(); 123 124 try { 125 while(rs.next()) { 126 _result.add(getPKFromResultSet(rs)); 127 } 128 } catch (SQLException se) { 129 throw new PersistenceDatabaseException(se); 130 } 131 132 return _result; 133 } 134 135 public java.util.List<ItemKitMemberPK> getPKsFromResultSetAsList(ResultSet rs) 136 throws PersistenceDatabaseException { 137 java.util.List<ItemKitMemberPK> _result = new ArrayList<>(); 138 139 try { 140 while(rs.next()) { 141 _result.add(getPKFromResultSet(rs)); 142 } 143 } catch (SQLException se) { 144 throw new PersistenceDatabaseException(se); 145 } 146 147 return _result; 148 } 149 150 public ItemKitMemberPK getPKFromResultSet(ResultSet rs) 151 throws PersistenceDatabaseException { 152 ItemKitMemberPK _result; 153 154 try { 155 long ikm_itemkitmemberid = rs.getLong(IKM_ITEMKITMEMBERID); 156 Long _entityId = rs.wasNull() ? null : ikm_itemkitmemberid; 157 158 _result = new ItemKitMemberPK(_entityId); 159 } catch (SQLException se) { 160 throw new PersistenceDatabaseException(se); 161 } 162 163 return _result; 164 } 165 166 public java.util.List<ItemKitMemberValue> getValuesFromPKs(Collection<ItemKitMemberPK> pks) 167 throws PersistenceDatabaseException { 168 java.util.List<ItemKitMemberValue> _values = new ArrayList<>(pks.size()); 169 170 for(ItemKitMemberPK _pk: pks) { 171 _values.add(getValueFromPK(_pk)); 172 } 173 174 return _values; 175 } 176 177 public ItemKitMemberValue getValueFromPK(ItemKitMemberPK pk) 178 throws PersistenceDatabaseException { 179 ItemKitMemberValue _value; 180 181 // See if we already have the entity in the session cache 182 ItemKitMember _entity = (ItemKitMember)session.getEntity(pk); 183 if(_entity == null) 184 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getItemKitMemberValue(); 185 else 186 _value = _entity.getItemKitMemberValue(); 187 188 return _value; 189 } 190 191 public java.util.List<ItemKitMemberValue> getValuesFromResultSet(ResultSet rs) 192 throws PersistenceDatabaseException { 193 java.util.List<ItemKitMemberValue> _result = new ArrayList<>(); 194 195 try { 196 while(rs.next()) { 197 _result.add(getValueFromResultSet(rs)); 198 } 199 } catch (SQLException se) { 200 throw new PersistenceDatabaseException(se); 201 } 202 203 return _result; 204 } 205 206 public ItemKitMemberValue getValueFromResultSet(ResultSet rs) 207 throws PersistenceDatabaseException { 208 ItemKitMemberValue _value; 209 210 try { 211 Long ikm_itemkitmemberid = rs.getLong(IKM_ITEMKITMEMBERID); 212 ItemKitMemberPK _pk = new ItemKitMemberPK(ikm_itemkitmemberid); 213 214 // See if we already have the entity in the session cache 215 ItemKitMember _entity = (ItemKitMember)session.getEntity(_pk); 216 217 if(_entity == null) { 218 Long ikm_itm_itemid = rs.getLong(IKM_ITM_ITEMID); 219 if(rs.wasNull()) 220 ikm_itm_itemid = null; 221 222 Long ikm_invcon_inventoryconditionid = rs.getLong(IKM_INVCON_INVENTORYCONDITIONID); 223 if(rs.wasNull()) 224 ikm_invcon_inventoryconditionid = null; 225 226 Long ikm_uomt_unitofmeasuretypeid = rs.getLong(IKM_UOMT_UNITOFMEASURETYPEID); 227 if(rs.wasNull()) 228 ikm_uomt_unitofmeasuretypeid = null; 229 230 Long ikm_memberitemid = rs.getLong(IKM_MEMBERITEMID); 231 if(rs.wasNull()) 232 ikm_memberitemid = null; 233 234 Long ikm_memberinventoryconditionid = rs.getLong(IKM_MEMBERINVENTORYCONDITIONID); 235 if(rs.wasNull()) 236 ikm_memberinventoryconditionid = null; 237 238 Long ikm_memberunitofmeasuretypeid = rs.getLong(IKM_MEMBERUNITOFMEASURETYPEID); 239 if(rs.wasNull()) 240 ikm_memberunitofmeasuretypeid = null; 241 242 Long ikm_quantity = rs.getLong(IKM_QUANTITY); 243 if(rs.wasNull()) 244 ikm_quantity = null; 245 246 Long ikm_fromtime = rs.getLong(IKM_FROMTIME); 247 if(rs.wasNull()) 248 ikm_fromtime = null; 249 250 Long ikm_thrutime = rs.getLong(IKM_THRUTIME); 251 if(rs.wasNull()) 252 ikm_thrutime = null; 253 254 _value = new ItemKitMemberValue(_pk, new ItemPK(ikm_itm_itemid), new InventoryConditionPK(ikm_invcon_inventoryconditionid), new UnitOfMeasureTypePK(ikm_uomt_unitofmeasuretypeid), new ItemPK(ikm_memberitemid), new InventoryConditionPK(ikm_memberinventoryconditionid), new UnitOfMeasureTypePK(ikm_memberunitofmeasuretypeid), ikm_quantity, ikm_fromtime, ikm_thrutime); 255 } else 256 _value = _entity.getItemKitMemberValue(); 257 } catch (SQLException se) { 258 throw new PersistenceDatabaseException(se); 259 } 260 261 return _value; 262 } 263 264 public java.util.List<ItemKitMember> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ItemKitMemberPK> pks) 265 throws PersistenceDatabaseException { 266 java.util.List<ItemKitMember> _entities = new ArrayList<>(pks.size()); 267 268 for(ItemKitMemberPK _pk: pks) { 269 _entities.add(getEntityFromPK(entityPermission, _pk)); 270 } 271 272 return _entities; 273 } 274 275 public ItemKitMember getEntityFromValue(EntityPermission entityPermission, ItemKitMemberValue value) { 276 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 277 } 278 279 public ItemKitMember getEntityFromCache(ItemKitMemberPK pk) { 280 ItemKitMemberValue _value = (ItemKitMemberValue)session.getValueCache().get(pk); 281 282 return _value == null ? null : new ItemKitMember(_value, EntityPermission.READ_ONLY); 283 } 284 285 public ItemKitMember getEntityFromPK(EntityPermission entityPermission, ItemKitMemberPK pk) 286 throws PersistenceDatabaseException { 287 ItemKitMember _entity; 288 289 // See if we already have the entity in the session cache 290 _entity = (ItemKitMember)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<ItemKitMemberPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 333 throws PersistenceDatabaseException { 334 Set<ItemKitMemberPK> _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<ItemKitMemberPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 361 throws PersistenceDatabaseException { 362 java.util.List<ItemKitMemberPK> _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 ItemKitMemberPK getPKFromQuery(PreparedStatement ps, final Object... params) 389 throws PersistenceDatabaseException { 390 ItemKitMemberPK _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<ItemKitMember> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 419 throws PersistenceDatabaseException { 420 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 421 422 return getEntitiesFromQuery(entityPermission, ps, params); 423 } 424 425 public java.util.List<ItemKitMember> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 426 throws PersistenceDatabaseException { 427 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 428 429 return getEntitiesFromQuery(entityPermission, ps); 430 } 431 432 public java.util.List<ItemKitMember> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 433 throws PersistenceDatabaseException { 434 PreparedStatement ps = session.prepareStatement(query.getSQL()); 435 436 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 437 } 438 439 public java.util.List<ItemKitMember> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 440 throws PersistenceDatabaseException { 441 java.util.List<ItemKitMember> _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 ItemKitMember getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 468 throws PersistenceDatabaseException { 469 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 470 471 return getEntityFromQuery(entityPermission, ps, params); 472 } 473 474 public ItemKitMember getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 475 throws PersistenceDatabaseException { 476 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 477 478 return getEntityFromQuery(entityPermission, ps); 479 } 480 481 public ItemKitMember getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 482 throws PersistenceDatabaseException { 483 PreparedStatement ps = session.prepareStatement(query.getSQL()); 484 485 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 486 } 487 488 public ItemKitMember getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 489 throws PersistenceDatabaseException { 490 ItemKitMember _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<ItemKitMember> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 519 throws PersistenceDatabaseException { 520 java.util.List<ItemKitMember> _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 ItemKitMember getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 534 throws PersistenceDatabaseException { 535 ItemKitMember _entity; 536 537 try { 538 Long ikm_itemkitmemberid = rs.getLong(IKM_ITEMKITMEMBERID); 539 ItemKitMemberPK _pk = new ItemKitMemberPK(ikm_itemkitmemberid); 540 541 // See if we already have the entity in the session cache 542 _entity = (ItemKitMember)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 ikm_itm_itemid = rs.getLong(IKM_ITM_ITEMID); 560 if(rs.wasNull()) 561 ikm_itm_itemid = null; 562 563 Long ikm_invcon_inventoryconditionid = rs.getLong(IKM_INVCON_INVENTORYCONDITIONID); 564 if(rs.wasNull()) 565 ikm_invcon_inventoryconditionid = null; 566 567 Long ikm_uomt_unitofmeasuretypeid = rs.getLong(IKM_UOMT_UNITOFMEASURETYPEID); 568 if(rs.wasNull()) 569 ikm_uomt_unitofmeasuretypeid = null; 570 571 Long ikm_memberitemid = rs.getLong(IKM_MEMBERITEMID); 572 if(rs.wasNull()) 573 ikm_memberitemid = null; 574 575 Long ikm_memberinventoryconditionid = rs.getLong(IKM_MEMBERINVENTORYCONDITIONID); 576 if(rs.wasNull()) 577 ikm_memberinventoryconditionid = null; 578 579 Long ikm_memberunitofmeasuretypeid = rs.getLong(IKM_MEMBERUNITOFMEASURETYPEID); 580 if(rs.wasNull()) 581 ikm_memberunitofmeasuretypeid = null; 582 583 Long ikm_quantity = rs.getLong(IKM_QUANTITY); 584 if(rs.wasNull()) 585 ikm_quantity = null; 586 587 Long ikm_fromtime = rs.getLong(IKM_FROMTIME); 588 if(rs.wasNull()) 589 ikm_fromtime = null; 590 591 Long ikm_thrutime = rs.getLong(IKM_THRUTIME); 592 if(rs.wasNull()) 593 ikm_thrutime = null; 594 595 ItemKitMemberValue _value = new ItemKitMemberValue(_pk, ikm_itm_itemid == null? null: new ItemPK(ikm_itm_itemid), ikm_invcon_inventoryconditionid == null? null: new InventoryConditionPK(ikm_invcon_inventoryconditionid), ikm_uomt_unitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(ikm_uomt_unitofmeasuretypeid), ikm_memberitemid == null? null: new ItemPK(ikm_memberitemid), ikm_memberinventoryconditionid == null? null: new InventoryConditionPK(ikm_memberinventoryconditionid), ikm_memberunitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(ikm_memberunitofmeasuretypeid), ikm_quantity, ikm_fromtime, ikm_thrutime); 596 _entity = new ItemKitMember(_value, entityPermission); 597 } 598 599 if(!foundInSessionCache) { 600 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 601 session.putReadOnlyEntity(_pk, _entity); 602 session.getValueCache().put(_entity.getItemKitMemberValue()); 603 } else { 604 session.putReadWriteEntity(_pk, _entity); 605 } 606 } 607 } catch (SQLException se) { 608 throw new PersistenceDatabaseException(se); 609 } 610 611 return _entity; 612 } 613 614 public ItemKitMember create(Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Item memberItem, InventoryCondition memberInventoryCondition, UnitOfMeasureType memberUnitOfMeasureType, Long quantity, Long fromTime, Long thruTime) 615 throws PersistenceDatabaseException, PersistenceNotNullException { 616 return create(item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), memberItem == null ? null : memberItem.getPrimaryKey(), memberInventoryCondition == null ? null : memberInventoryCondition.getPrimaryKey(), memberUnitOfMeasureType == null ? null : memberUnitOfMeasureType.getPrimaryKey(), quantity, fromTime, thruTime); 617 } 618 619 private void bindForCreate(PreparedStatement _ps, ItemKitMemberValue _value) 620 throws SQLException { 621 _ps.setLong(1, _value.getEntityId()); 622 623 ItemPK ikm_itm_itemid = _value.getItemPK(); 624 if(ikm_itm_itemid == null) 625 _ps.setNull(2, Types.BIGINT); 626 else 627 _ps.setLong(2, ikm_itm_itemid.getEntityId()); 628 629 InventoryConditionPK ikm_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 630 if(ikm_invcon_inventoryconditionid == null) 631 _ps.setNull(3, Types.BIGINT); 632 else 633 _ps.setLong(3, ikm_invcon_inventoryconditionid.getEntityId()); 634 635 UnitOfMeasureTypePK ikm_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 636 if(ikm_uomt_unitofmeasuretypeid == null) 637 _ps.setNull(4, Types.BIGINT); 638 else 639 _ps.setLong(4, ikm_uomt_unitofmeasuretypeid.getEntityId()); 640 641 ItemPK ikm_memberitemid = _value.getMemberItemPK(); 642 if(ikm_memberitemid == null) 643 _ps.setNull(5, Types.BIGINT); 644 else 645 _ps.setLong(5, ikm_memberitemid.getEntityId()); 646 647 InventoryConditionPK ikm_memberinventoryconditionid = _value.getMemberInventoryConditionPK(); 648 if(ikm_memberinventoryconditionid == null) 649 _ps.setNull(6, Types.BIGINT); 650 else 651 _ps.setLong(6, ikm_memberinventoryconditionid.getEntityId()); 652 653 UnitOfMeasureTypePK ikm_memberunitofmeasuretypeid = _value.getMemberUnitOfMeasureTypePK(); 654 if(ikm_memberunitofmeasuretypeid == null) 655 _ps.setNull(7, Types.BIGINT); 656 else 657 _ps.setLong(7, ikm_memberunitofmeasuretypeid.getEntityId()); 658 659 Long ikm_quantity = _value.getQuantity(); 660 if(ikm_quantity == null) 661 _ps.setNull(8, Types.BIGINT); 662 else 663 _ps.setLong(8, ikm_quantity); 664 665 Long ikm_fromtime = _value.getFromTime(); 666 if(ikm_fromtime == null) 667 _ps.setNull(9, Types.BIGINT); 668 else 669 _ps.setLong(9, ikm_fromtime); 670 671 Long ikm_thrutime = _value.getThruTime(); 672 if(ikm_thrutime == null) 673 _ps.setNull(10, Types.BIGINT); 674 else 675 _ps.setLong(10, ikm_thrutime); 676 677 } 678 679 public ItemKitMember create(ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, ItemPK memberItemPK, InventoryConditionPK memberInventoryConditionPK, UnitOfMeasureTypePK memberUnitOfMeasureTypePK, Long quantity, Long fromTime, Long thruTime) 680 throws PersistenceDatabaseException, PersistenceNotNullException { 681 ItemKitMemberPK _pk = getNextPK(); 682 ItemKitMemberValue _value = new ItemKitMemberValue(_pk, itemPK, inventoryConditionPK, unitOfMeasureTypePK, memberItemPK, memberInventoryConditionPK, memberUnitOfMeasureTypePK, quantity, fromTime, thruTime); 683 684 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 685 686 try { 687 bindForCreate(_ps, _value); 688 689 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 690 int _count = _ps.executeUpdate(); 691 692 if(_count != 1) { 693 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 694 } 695 } else { 696 _ps.executeUpdate(); 697 } 698 699 session.getValueCache().put(_value); 700 } catch (SQLException se) { 701 throw new PersistenceDatabaseException(se); 702 } 703 704 ItemKitMember _entity = new ItemKitMember(_value, EntityPermission.READ_ONLY); 705 session.putReadOnlyEntity(_pk, _entity); 706 707 return _entity; 708 } 709 710 public void create(Collection<ItemKitMemberValue> _values) 711 throws PersistenceDatabaseException, PersistenceNotNullException { 712 int _size = _values.size(); 713 714 if(_size > 0) { 715 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 716 List<ItemKitMemberValue> _cacheValues = new ArrayList<>(_size); 717 718 try { 719 for(ItemKitMemberValue _value : _values) { 720 _value.setEntityId(entityIdGenerator.getNextEntityId()); 721 bindForCreate(_ps, _value); 722 723 _ps.addBatch(); 724 725 _cacheValues.add(_value); 726 } 727 728 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 729 int[] _counts = _ps.executeBatch(); 730 731 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 732 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 733 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 734 } 735 } 736 } else { 737 _ps.executeBatch(); 738 } 739 740 _ps.clearBatch(); 741 } catch (SQLException se) { 742 throw new PersistenceDatabaseException(se); 743 } 744 745 _cacheValues.forEach((_cacheValue) -> { 746 ItemKitMember _cacheEntity = new ItemKitMember(_cacheValue, EntityPermission.READ_ONLY); 747 748 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 749 }); 750 } 751 } 752 753 private boolean bindForStore(PreparedStatement _ps, ItemKitMemberValue _value) 754 throws SQLException { 755 boolean _hasBeenModified = _value.hasBeenModified(); 756 757 if(_hasBeenModified) { 758 ItemPK ikm_itm_itemid = _value.getItemPK(); 759 if(ikm_itm_itemid == null) 760 _ps.setNull(1, Types.BIGINT); 761 else 762 _ps.setLong(1, ikm_itm_itemid.getEntityId()); 763 764 InventoryConditionPK ikm_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 765 if(ikm_invcon_inventoryconditionid == null) 766 _ps.setNull(2, Types.BIGINT); 767 else 768 _ps.setLong(2, ikm_invcon_inventoryconditionid.getEntityId()); 769 770 UnitOfMeasureTypePK ikm_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 771 if(ikm_uomt_unitofmeasuretypeid == null) 772 _ps.setNull(3, Types.BIGINT); 773 else 774 _ps.setLong(3, ikm_uomt_unitofmeasuretypeid.getEntityId()); 775 776 ItemPK ikm_memberitemid = _value.getMemberItemPK(); 777 if(ikm_memberitemid == null) 778 _ps.setNull(4, Types.BIGINT); 779 else 780 _ps.setLong(4, ikm_memberitemid.getEntityId()); 781 782 InventoryConditionPK ikm_memberinventoryconditionid = _value.getMemberInventoryConditionPK(); 783 if(ikm_memberinventoryconditionid == null) 784 _ps.setNull(5, Types.BIGINT); 785 else 786 _ps.setLong(5, ikm_memberinventoryconditionid.getEntityId()); 787 788 UnitOfMeasureTypePK ikm_memberunitofmeasuretypeid = _value.getMemberUnitOfMeasureTypePK(); 789 if(ikm_memberunitofmeasuretypeid == null) 790 _ps.setNull(6, Types.BIGINT); 791 else 792 _ps.setLong(6, ikm_memberunitofmeasuretypeid.getEntityId()); 793 794 Long ikm_quantity = _value.getQuantity(); 795 if(ikm_quantity == null) 796 _ps.setNull(7, Types.BIGINT); 797 else 798 _ps.setLong(7, ikm_quantity); 799 800 Long ikm_fromtime = _value.getFromTime(); 801 if(ikm_fromtime == null) 802 _ps.setNull(8, Types.BIGINT); 803 else 804 _ps.setLong(8, ikm_fromtime); 805 806 Long ikm_thrutime = _value.getThruTime(); 807 if(ikm_thrutime == null) 808 _ps.setNull(9, Types.BIGINT); 809 else 810 _ps.setLong(9, ikm_thrutime); 811 812 _ps.setLong(10, _value.getPrimaryKey().getEntityId()); 813 814 _value.clearHasBeenModified(); 815 } 816 817 return _hasBeenModified; 818 } 819 820 @Override 821 public void store(ItemKitMember entity) 822 throws PersistenceDatabaseException { 823 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 824 825 try { 826 ItemKitMemberValue _value = entity.getItemKitMemberValue(); 827 828 if(bindForStore(_ps, _value)) { 829 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 830 int _count = _ps.executeUpdate(); 831 832 if(_count != 1) { 833 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 834 } 835 } else { 836 _ps.executeUpdate(); 837 } 838 839 session.getValueCache().put(_value); 840 } 841 } catch (SQLException se) { 842 throw new PersistenceDatabaseException(se); 843 } 844 } 845 846 @Override 847 public void store(Collection<ItemKitMember> entities) 848 throws PersistenceDatabaseException { 849 if(entities.size() > 0) { 850 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 851 int _modifiedEntities = 0; 852 853 try { 854 for(ItemKitMember entity : entities) { 855 if(bindForStore(_ps, entity.getItemKitMemberValue())) { 856 _ps.addBatch(); 857 _modifiedEntities++; 858 } 859 } 860 861 if(_modifiedEntities != 0) { 862 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 863 int[] _counts = _ps.executeBatch(); 864 865 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 866 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 867 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 868 } 869 } 870 } else { 871 _ps.executeBatch(); 872 } 873 874 _ps.clearBatch(); 875 876 entities.forEach((entity) -> { 877 session.getValueCache().put(entity.getItemKitMemberValue()); 878 }); 879 } 880 } catch (SQLException se) { 881 throw new PersistenceDatabaseException(se); 882 } 883 } 884 } 885 886 @Override 887 public void remove(ItemKitMember entity) 888 throws PersistenceDatabaseException { 889 remove(entity.getPrimaryKey()); 890 } 891 892 @Override 893 public void remove(ItemKitMemberPK pk) 894 throws PersistenceDatabaseException { 895 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 896 long _entityId = pk.getEntityId(); 897 898 try { 899 _ps.setLong(1, _entityId); 900 901 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 902 int _count = _ps.executeUpdate(); 903 904 if(_count != 1) { 905 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 906 } 907 } else { 908 _ps.executeUpdate(); 909 } 910 911 session.getValueCache().remove(pk); 912 } catch (SQLException se) { 913 throw new PersistenceDatabaseException(se); 914 } 915 916 session.removed(pk, false); 917 } 918 919 @Override 920 public void remove(Collection<ItemKitMemberPK> pks) 921 throws PersistenceDatabaseException { 922 if(pks.size() > 0) { 923 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 924 int _modifiedEntities = 0; 925 926 try { 927 for(ItemKitMemberPK pk : pks) { 928 long _entityId = pk.getEntityId(); 929 930 _ps.setLong(1, _entityId); 931 932 _ps.addBatch(); 933 _modifiedEntities++; 934 } 935 936 if(_modifiedEntities != 0) { 937 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 938 int[] _counts = _ps.executeBatch(); 939 940 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 941 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 942 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 943 } 944 } 945 } else { 946 _ps.executeBatch(); 947 } 948 949 _ps.clearBatch(); 950 951 pks.forEach((pk) -> { 952 session.getValueCache().remove(pk); 953 }); 954 } 955 } catch (SQLException se) { 956 throw new PersistenceDatabaseException(se); 957 } 958 959 pks.forEach((pk) -> { 960 session.removed(pk, true); 961 }); 962 } 963 } 964 965 @Override 966 public boolean validPK(ItemKitMemberPK pk) 967 throws PersistenceDatabaseException { 968 boolean valid = false; 969 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 970 ResultSet _rs = null; 971 972 try { 973 _ps.setLong(1, pk.getEntityId()); 974 975 _rs = _ps.executeQuery(); 976 if(_rs.next()) { 977 long _count = _rs.getLong(1); 978 if(_rs.wasNull()) 979 _count = 0; 980 981 if(_count == 1) 982 valid = true; 983 } 984 } catch (SQLException se) { 985 throw new PersistenceDatabaseException(se); 986 } finally { 987 if(_rs != null) { 988 try { 989 _rs.close(); 990 } catch (SQLException se) { 991 // do nothing 992 } 993 } 994 } 995 996 return valid; 997 } 998 999}