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