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