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