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