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