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