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