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