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