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