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