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