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