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 * TrainingClassQuestionDetailFactory.java 021 */ 022 023package com.echothree.model.data.training.server.factory; 024 025import com.echothree.model.data.training.common.pk.TrainingClassQuestionPK; 026import com.echothree.model.data.training.common.pk.TrainingClassSectionPK; 027 028import com.echothree.model.data.training.server.entity.TrainingClassQuestion; 029import com.echothree.model.data.training.server.entity.TrainingClassSection; 030 031import com.echothree.model.data.training.common.TrainingClassQuestionDetailConstants; 032import com.echothree.model.data.training.common.pk.TrainingClassQuestionDetailPK; 033import com.echothree.model.data.training.server.value.TrainingClassQuestionDetailValue; 034import com.echothree.model.data.training.server.entity.TrainingClassQuestionDetail; 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 TrainingClassQuestionDetailFactory 064 implements BaseFactory<TrainingClassQuestionDetailPK, TrainingClassQuestionDetail> { 065 066 @Inject 067 Session session; 068 069 //private static final Logger log = LoggerFactory.getLogger(TrainingClassQuestionDetailFactory.class); 070 071 final private static String SQL_SELECT_READ_ONLY = "SELECT trnclsqusdt_trainingclassquestiondetailid, trnclsqusdt_trnclsqus_trainingclassquestionid, trnclsqusdt_trnclss_trainingclasssectionid, trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime FROM trainingclassquestiondetails WHERE trnclsqusdt_trainingclassquestiondetailid = ?"; 072 final private static String SQL_SELECT_READ_WRITE = "SELECT trnclsqusdt_trainingclassquestiondetailid, trnclsqusdt_trnclsqus_trainingclassquestionid, trnclsqusdt_trnclss_trainingclasssectionid, trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime FROM trainingclassquestiondetails WHERE trnclsqusdt_trainingclassquestiondetailid = ? FOR UPDATE"; 073 final private static String SQL_INSERT = "INSERT INTO trainingclassquestiondetails (trnclsqusdt_trainingclassquestiondetailid, trnclsqusdt_trnclsqus_trainingclassquestionid, trnclsqusdt_trnclss_trainingclasssectionid, trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 074 final private static String SQL_UPDATE = "UPDATE trainingclassquestiondetails SET trnclsqusdt_trnclsqus_trainingclassquestionid = ?, trnclsqusdt_trnclss_trainingclasssectionid = ?, trnclsqusdt_trainingclassquestionname = ?, trnclsqusdt_askingrequired = ?, trnclsqusdt_passingrequired = ?, trnclsqusdt_sortorder = ?, trnclsqusdt_fromtime = ?, trnclsqusdt_thrutime = ? WHERE trnclsqusdt_trainingclassquestiondetailid = ?"; 075 final private static String SQL_DELETE = "DELETE FROM trainingclassquestiondetails WHERE trnclsqusdt_trainingclassquestiondetailid = ?"; 076 final private static String SQL_VALID = "SELECT COUNT(*) FROM trainingclassquestiondetails WHERE trnclsqusdt_trainingclassquestiondetailid = ?"; 077 078 final private static String PK_COLUMN = "trnclsqusdt_trainingclassquestiondetailid"; 079 final private static String ALL_COLUMNS = "trnclsqusdt_trainingclassquestiondetailid, trnclsqusdt_trnclsqus_trainingclassquestionid, trnclsqusdt_trnclss_trainingclasssectionid, trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime"; 080 final public static String TABLE_NAME = "trainingclassquestiondetails"; 081 082 final public static String TRNCLSQUSDT_TRAININGCLASSQUESTIONDETAILID = "trnclsqusdt_trainingclassquestiondetailid"; 083 final public static String TRNCLSQUSDT_TRNCLSQUS_TRAININGCLASSQUESTIONID = "trnclsqusdt_trnclsqus_trainingclassquestionid"; 084 final public static String TRNCLSQUSDT_TRNCLSS_TRAININGCLASSSECTIONID = "trnclsqusdt_trnclss_trainingclasssectionid"; 085 final public static String TRNCLSQUSDT_TRAININGCLASSQUESTIONNAME = "trnclsqusdt_trainingclassquestionname"; 086 final public static String TRNCLSQUSDT_ASKINGREQUIRED = "trnclsqusdt_askingrequired"; 087 final public static String TRNCLSQUSDT_PASSINGREQUIRED = "trnclsqusdt_passingrequired"; 088 final public static String TRNCLSQUSDT_SORTORDER = "trnclsqusdt_sortorder"; 089 final public static String TRNCLSQUSDT_FROMTIME = "trnclsqusdt_fromtime"; 090 final public static String TRNCLSQUSDT_THRUTIME = "trnclsqusdt_thrutime"; 091 092 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(TrainingClassQuestionDetailConstants.COMPONENT_VENDOR_NAME, TrainingClassQuestionDetailConstants.ENTITY_TYPE_NAME); 093 094 /** Creates a new instance of TrainingClassQuestionDetailFactory */ 095 protected TrainingClassQuestionDetailFactory() { 096 super(); 097 } 098 099 public static TrainingClassQuestionDetailFactory getInstance() { 100 return CDI.current().select(TrainingClassQuestionDetailFactory.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 TrainingClassQuestionDetailConstants.COMPONENT_VENDOR_NAME; 121 } 122 123 @Override 124 public String getEntityTypeName() { 125 return TrainingClassQuestionDetailConstants.ENTITY_TYPE_NAME; 126 } 127 128 public PreparedStatement prepareStatement(String query) { 129 return session.prepareStatement(TrainingClassQuestionDetailFactory.class, query); 130 } 131 132 public TrainingClassQuestionDetailPK getNextPK() { 133 return new TrainingClassQuestionDetailPK(entityIdGenerator.getNextEntityId()); 134 } 135 136 public Set<TrainingClassQuestionDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 137 throws PersistenceDatabaseException { 138 Set<TrainingClassQuestionDetailPK> _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<TrainingClassQuestionDetailPK> getPKsFromResultSetAsList(ResultSet rs) 152 throws PersistenceDatabaseException { 153 java.util.List<TrainingClassQuestionDetailPK> _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 TrainingClassQuestionDetailPK getPKFromResultSet(ResultSet rs) 167 throws PersistenceDatabaseException { 168 TrainingClassQuestionDetailPK _result; 169 170 try { 171 long trnclsqusdt_trainingclassquestiondetailid = rs.getLong(TRNCLSQUSDT_TRAININGCLASSQUESTIONDETAILID); 172 Long _entityId = rs.wasNull() ? null : trnclsqusdt_trainingclassquestiondetailid; 173 174 _result = new TrainingClassQuestionDetailPK(_entityId); 175 } catch (SQLException se) { 176 throw new PersistenceDatabaseException(se); 177 } 178 179 return _result; 180 } 181 182 public java.util.List<TrainingClassQuestionDetailValue> getValuesFromPKs(Collection<TrainingClassQuestionDetailPK> pks) 183 throws PersistenceDatabaseException { 184 java.util.List<TrainingClassQuestionDetailValue> _values = new ArrayList<>(pks.size()); 185 186 for(TrainingClassQuestionDetailPK _pk: pks) { 187 _values.add(getValueFromPK(_pk)); 188 } 189 190 return _values; 191 } 192 193 public TrainingClassQuestionDetailValue getValueFromPK(TrainingClassQuestionDetailPK pk) 194 throws PersistenceDatabaseException { 195 TrainingClassQuestionDetailValue _value; 196 197 // See if we already have the entity in the session cache 198 TrainingClassQuestionDetail _entity = (TrainingClassQuestionDetail)session.getEntity(pk); 199 if(_entity == null) 200 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getTrainingClassQuestionDetailValue(); 201 else 202 _value = _entity.getTrainingClassQuestionDetailValue(); 203 204 return _value; 205 } 206 207 public java.util.List<TrainingClassQuestionDetailValue> getValuesFromResultSet(ResultSet rs) 208 throws PersistenceDatabaseException { 209 java.util.List<TrainingClassQuestionDetailValue> _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 TrainingClassQuestionDetailValue getValueFromResultSet(ResultSet rs) 223 throws PersistenceDatabaseException { 224 TrainingClassQuestionDetailValue _value; 225 226 try { 227 Long trnclsqusdt_trainingclassquestiondetailid = rs.getLong(TRNCLSQUSDT_TRAININGCLASSQUESTIONDETAILID); 228 TrainingClassQuestionDetailPK _pk = new TrainingClassQuestionDetailPK(trnclsqusdt_trainingclassquestiondetailid); 229 230 // See if we already have the entity in the session cache 231 TrainingClassQuestionDetail _entity = (TrainingClassQuestionDetail)session.getEntity(_pk); 232 233 if(_entity == null) { 234 Long trnclsqusdt_trnclsqus_trainingclassquestionid = rs.getLong(TRNCLSQUSDT_TRNCLSQUS_TRAININGCLASSQUESTIONID); 235 if(rs.wasNull()) 236 trnclsqusdt_trnclsqus_trainingclassquestionid = null; 237 238 Long trnclsqusdt_trnclss_trainingclasssectionid = rs.getLong(TRNCLSQUSDT_TRNCLSS_TRAININGCLASSSECTIONID); 239 if(rs.wasNull()) 240 trnclsqusdt_trnclss_trainingclasssectionid = null; 241 242 String trnclsqusdt_trainingclassquestionname = rs.getString(TRNCLSQUSDT_TRAININGCLASSQUESTIONNAME); 243 if(rs.wasNull()) 244 trnclsqusdt_trainingclassquestionname = null; 245 246 Boolean trnclsqusdt_askingrequired = rs.getInt(TRNCLSQUSDT_ASKINGREQUIRED) == 1; 247 if(rs.wasNull()) 248 trnclsqusdt_askingrequired = null; 249 250 Boolean trnclsqusdt_passingrequired = rs.getInt(TRNCLSQUSDT_PASSINGREQUIRED) == 1; 251 if(rs.wasNull()) 252 trnclsqusdt_passingrequired = null; 253 254 Integer trnclsqusdt_sortorder = rs.getInt(TRNCLSQUSDT_SORTORDER); 255 if(rs.wasNull()) 256 trnclsqusdt_sortorder = null; 257 258 Long trnclsqusdt_fromtime = rs.getLong(TRNCLSQUSDT_FROMTIME); 259 if(rs.wasNull()) 260 trnclsqusdt_fromtime = null; 261 262 Long trnclsqusdt_thrutime = rs.getLong(TRNCLSQUSDT_THRUTIME); 263 if(rs.wasNull()) 264 trnclsqusdt_thrutime = null; 265 266 _value = new TrainingClassQuestionDetailValue(_pk, new TrainingClassQuestionPK(trnclsqusdt_trnclsqus_trainingclassquestionid), new TrainingClassSectionPK(trnclsqusdt_trnclss_trainingclasssectionid), trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime); 267 } else 268 _value = _entity.getTrainingClassQuestionDetailValue(); 269 } catch (SQLException se) { 270 throw new PersistenceDatabaseException(se); 271 } 272 273 return _value; 274 } 275 276 public java.util.List<TrainingClassQuestionDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<TrainingClassQuestionDetailPK> pks) 277 throws PersistenceDatabaseException { 278 java.util.List<TrainingClassQuestionDetail> _entities = new ArrayList<>(pks.size()); 279 280 for(TrainingClassQuestionDetailPK _pk: pks) { 281 _entities.add(getEntityFromPK(entityPermission, _pk)); 282 } 283 284 return _entities; 285 } 286 287 public TrainingClassQuestionDetail getEntityFromValue(EntityPermission entityPermission, TrainingClassQuestionDetailValue value) { 288 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 289 } 290 291 public TrainingClassQuestionDetail getEntityFromCache(TrainingClassQuestionDetailPK pk) { 292 TrainingClassQuestionDetailValue _value = (TrainingClassQuestionDetailValue)session.getValueCache().get(pk); 293 294 return _value == null ? null : new TrainingClassQuestionDetail(_value, EntityPermission.READ_ONLY); 295 } 296 297 public TrainingClassQuestionDetail getEntityFromPK(EntityPermission entityPermission, TrainingClassQuestionDetailPK pk) 298 throws PersistenceDatabaseException { 299 TrainingClassQuestionDetail _entity; 300 301 // See if we already have the entity in the session cache 302 _entity = (TrainingClassQuestionDetail)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<TrainingClassQuestionDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 345 throws PersistenceDatabaseException { 346 Set<TrainingClassQuestionDetailPK> _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<TrainingClassQuestionDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 373 throws PersistenceDatabaseException { 374 java.util.List<TrainingClassQuestionDetailPK> _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 TrainingClassQuestionDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 401 throws PersistenceDatabaseException { 402 TrainingClassQuestionDetailPK _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<TrainingClassQuestionDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 431 throws PersistenceDatabaseException { 432 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, queryMap.get(entityPermission)); 433 434 return getEntitiesFromQuery(entityPermission, ps, params); 435 } 436 437 public java.util.List<TrainingClassQuestionDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 438 throws PersistenceDatabaseException { 439 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, queryMap.get(entityPermission)); 440 441 return getEntitiesFromQuery(entityPermission, ps); 442 } 443 444 public java.util.List<TrainingClassQuestionDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 445 throws PersistenceDatabaseException { 446 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, query.getSQL()); 447 448 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 449 } 450 451 public java.util.List<TrainingClassQuestionDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 452 throws PersistenceDatabaseException { 453 java.util.List<TrainingClassQuestionDetail> _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 TrainingClassQuestionDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 480 throws PersistenceDatabaseException { 481 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, queryMap.get(entityPermission)); 482 483 return getEntityFromQuery(entityPermission, ps, params); 484 } 485 486 public TrainingClassQuestionDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 487 throws PersistenceDatabaseException { 488 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, queryMap.get(entityPermission)); 489 490 return getEntityFromQuery(entityPermission, ps); 491 } 492 493 public TrainingClassQuestionDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 494 throws PersistenceDatabaseException { 495 PreparedStatement ps = session.prepareStatement(TrainingClassQuestionDetailFactory.class, query.getSQL()); 496 497 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 498 } 499 500 public TrainingClassQuestionDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 501 throws PersistenceDatabaseException { 502 TrainingClassQuestionDetail _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<TrainingClassQuestionDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 531 throws PersistenceDatabaseException { 532 java.util.List<TrainingClassQuestionDetail> _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 TrainingClassQuestionDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 546 throws PersistenceDatabaseException { 547 TrainingClassQuestionDetail _entity; 548 549 try { 550 Long trnclsqusdt_trainingclassquestiondetailid = rs.getLong(TRNCLSQUSDT_TRAININGCLASSQUESTIONDETAILID); 551 TrainingClassQuestionDetailPK _pk = new TrainingClassQuestionDetailPK(trnclsqusdt_trainingclassquestiondetailid); 552 553 // See if we already have the entity in the session cache 554 _entity = (TrainingClassQuestionDetail)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 trnclsqusdt_trnclsqus_trainingclassquestionid = rs.getLong(TRNCLSQUSDT_TRNCLSQUS_TRAININGCLASSQUESTIONID); 572 if(rs.wasNull()) 573 trnclsqusdt_trnclsqus_trainingclassquestionid = null; 574 575 Long trnclsqusdt_trnclss_trainingclasssectionid = rs.getLong(TRNCLSQUSDT_TRNCLSS_TRAININGCLASSSECTIONID); 576 if(rs.wasNull()) 577 trnclsqusdt_trnclss_trainingclasssectionid = null; 578 579 String trnclsqusdt_trainingclassquestionname = rs.getString(TRNCLSQUSDT_TRAININGCLASSQUESTIONNAME); 580 if(rs.wasNull()) 581 trnclsqusdt_trainingclassquestionname = null; 582 583 Boolean trnclsqusdt_askingrequired = rs.getInt(TRNCLSQUSDT_ASKINGREQUIRED) == 1; 584 if(rs.wasNull()) 585 trnclsqusdt_askingrequired = null; 586 587 Boolean trnclsqusdt_passingrequired = rs.getInt(TRNCLSQUSDT_PASSINGREQUIRED) == 1; 588 if(rs.wasNull()) 589 trnclsqusdt_passingrequired = null; 590 591 Integer trnclsqusdt_sortorder = rs.getInt(TRNCLSQUSDT_SORTORDER); 592 if(rs.wasNull()) 593 trnclsqusdt_sortorder = null; 594 595 Long trnclsqusdt_fromtime = rs.getLong(TRNCLSQUSDT_FROMTIME); 596 if(rs.wasNull()) 597 trnclsqusdt_fromtime = null; 598 599 Long trnclsqusdt_thrutime = rs.getLong(TRNCLSQUSDT_THRUTIME); 600 if(rs.wasNull()) 601 trnclsqusdt_thrutime = null; 602 603 TrainingClassQuestionDetailValue _value = new TrainingClassQuestionDetailValue(_pk, trnclsqusdt_trnclsqus_trainingclassquestionid == null? null: new TrainingClassQuestionPK(trnclsqusdt_trnclsqus_trainingclassquestionid), trnclsqusdt_trnclss_trainingclasssectionid == null? null: new TrainingClassSectionPK(trnclsqusdt_trnclss_trainingclasssectionid), trnclsqusdt_trainingclassquestionname, trnclsqusdt_askingrequired, trnclsqusdt_passingrequired, trnclsqusdt_sortorder, trnclsqusdt_fromtime, trnclsqusdt_thrutime); 604 _entity = new TrainingClassQuestionDetail(_value, entityPermission); 605 } 606 607 if(!foundInSessionCache) { 608 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 609 session.putReadOnlyEntity(_pk, _entity); 610 session.getValueCache().put(_entity.getTrainingClassQuestionDetailValue()); 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 TrainingClassQuestionDetail create(TrainingClassQuestion trainingClassQuestion, TrainingClassSection trainingClassSection, String trainingClassQuestionName, Boolean askingRequired, Boolean passingRequired, Integer sortOrder, Long fromTime, Long thruTime) 623 throws PersistenceDatabaseException, PersistenceNotNullException { 624 return create(trainingClassQuestion == null ? null : trainingClassQuestion.getPrimaryKey(), trainingClassSection == null ? null : trainingClassSection.getPrimaryKey(), trainingClassQuestionName, askingRequired, passingRequired, sortOrder, fromTime, thruTime); 625 } 626 627 private void bindForCreate(PreparedStatement _ps, TrainingClassQuestionDetailValue _value) 628 throws SQLException { 629 _ps.setLong(1, _value.getEntityId()); 630 631 TrainingClassQuestionPK trnclsqusdt_trnclsqus_trainingclassquestionid = _value.getTrainingClassQuestionPK(); 632 if(trnclsqusdt_trnclsqus_trainingclassquestionid == null) 633 _ps.setNull(2, Types.BIGINT); 634 else 635 _ps.setLong(2, trnclsqusdt_trnclsqus_trainingclassquestionid.getEntityId()); 636 637 TrainingClassSectionPK trnclsqusdt_trnclss_trainingclasssectionid = _value.getTrainingClassSectionPK(); 638 if(trnclsqusdt_trnclss_trainingclasssectionid == null) 639 _ps.setNull(3, Types.BIGINT); 640 else 641 _ps.setLong(3, trnclsqusdt_trnclss_trainingclasssectionid.getEntityId()); 642 643 String trnclsqusdt_trainingclassquestionname = _value.getTrainingClassQuestionName(); 644 if(trnclsqusdt_trainingclassquestionname == null) 645 _ps.setNull(4, Types.VARCHAR); 646 else 647 _ps.setString(4, trnclsqusdt_trainingclassquestionname); 648 649 Boolean trnclsqusdt_askingrequired = _value.getAskingRequired(); 650 if(trnclsqusdt_askingrequired == null) 651 _ps.setNull(5, Types.BIT); 652 else 653 _ps.setInt(5, trnclsqusdt_askingrequired? 1: 0); 654 655 Boolean trnclsqusdt_passingrequired = _value.getPassingRequired(); 656 if(trnclsqusdt_passingrequired == null) 657 _ps.setNull(6, Types.BIT); 658 else 659 _ps.setInt(6, trnclsqusdt_passingrequired? 1: 0); 660 661 Integer trnclsqusdt_sortorder = _value.getSortOrder(); 662 if(trnclsqusdt_sortorder == null) 663 _ps.setNull(7, Types.INTEGER); 664 else 665 _ps.setInt(7, trnclsqusdt_sortorder); 666 667 Long trnclsqusdt_fromtime = _value.getFromTime(); 668 if(trnclsqusdt_fromtime == null) 669 _ps.setNull(8, Types.BIGINT); 670 else 671 _ps.setLong(8, trnclsqusdt_fromtime); 672 673 Long trnclsqusdt_thrutime = _value.getThruTime(); 674 if(trnclsqusdt_thrutime == null) 675 _ps.setNull(9, Types.BIGINT); 676 else 677 _ps.setLong(9, trnclsqusdt_thrutime); 678 679 } 680 681 public TrainingClassQuestionDetail create(TrainingClassQuestionPK trainingClassQuestionPK, TrainingClassSectionPK trainingClassSectionPK, String trainingClassQuestionName, Boolean askingRequired, Boolean passingRequired, Integer sortOrder, Long fromTime, Long thruTime) 682 throws PersistenceDatabaseException, PersistenceNotNullException { 683 TrainingClassQuestionDetailPK _pk = getNextPK(); 684 TrainingClassQuestionDetailValue _value = new TrainingClassQuestionDetailValue(_pk, trainingClassQuestionPK, trainingClassSectionPK, trainingClassQuestionName, askingRequired, passingRequired, 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 TrainingClassQuestionDetail _entity = new TrainingClassQuestionDetail(_value, EntityPermission.READ_ONLY); 707 session.putReadOnlyEntity(_pk, _entity); 708 709 return _entity; 710 } 711 712 public void create(Collection<TrainingClassQuestionDetailValue> _values) 713 throws PersistenceDatabaseException, PersistenceNotNullException { 714 int _size = _values.size(); 715 716 if(_size > 0) { 717 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 718 List<TrainingClassQuestionDetailValue> _cacheValues = new ArrayList<>(_size); 719 720 try { 721 for(TrainingClassQuestionDetailValue _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 TrainingClassQuestionDetail _cacheEntity = new TrainingClassQuestionDetail(_cacheValue, EntityPermission.READ_ONLY); 749 750 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 751 }); 752 } 753 } 754 755 private boolean bindForStore(PreparedStatement _ps, TrainingClassQuestionDetailValue _value) 756 throws SQLException { 757 boolean _hasBeenModified = _value.hasBeenModified(); 758 759 if(_hasBeenModified) { 760 TrainingClassQuestionPK trnclsqusdt_trnclsqus_trainingclassquestionid = _value.getTrainingClassQuestionPK(); 761 if(trnclsqusdt_trnclsqus_trainingclassquestionid == null) 762 _ps.setNull(1, Types.BIGINT); 763 else 764 _ps.setLong(1, trnclsqusdt_trnclsqus_trainingclassquestionid.getEntityId()); 765 766 TrainingClassSectionPK trnclsqusdt_trnclss_trainingclasssectionid = _value.getTrainingClassSectionPK(); 767 if(trnclsqusdt_trnclss_trainingclasssectionid == null) 768 _ps.setNull(2, Types.BIGINT); 769 else 770 _ps.setLong(2, trnclsqusdt_trnclss_trainingclasssectionid.getEntityId()); 771 772 String trnclsqusdt_trainingclassquestionname = _value.getTrainingClassQuestionName(); 773 if(trnclsqusdt_trainingclassquestionname == null) 774 _ps.setNull(3, Types.VARCHAR); 775 else 776 _ps.setString(3, trnclsqusdt_trainingclassquestionname); 777 778 Boolean trnclsqusdt_askingrequired = _value.getAskingRequired(); 779 if(trnclsqusdt_askingrequired == null) 780 _ps.setNull(4, Types.BIT); 781 else 782 _ps.setInt(4, trnclsqusdt_askingrequired? 1: 0); 783 784 Boolean trnclsqusdt_passingrequired = _value.getPassingRequired(); 785 if(trnclsqusdt_passingrequired == null) 786 _ps.setNull(5, Types.BIT); 787 else 788 _ps.setInt(5, trnclsqusdt_passingrequired? 1: 0); 789 790 Integer trnclsqusdt_sortorder = _value.getSortOrder(); 791 if(trnclsqusdt_sortorder == null) 792 _ps.setNull(6, Types.INTEGER); 793 else 794 _ps.setInt(6, trnclsqusdt_sortorder); 795 796 Long trnclsqusdt_fromtime = _value.getFromTime(); 797 if(trnclsqusdt_fromtime == null) 798 _ps.setNull(7, Types.BIGINT); 799 else 800 _ps.setLong(7, trnclsqusdt_fromtime); 801 802 Long trnclsqusdt_thrutime = _value.getThruTime(); 803 if(trnclsqusdt_thrutime == null) 804 _ps.setNull(8, Types.BIGINT); 805 else 806 _ps.setLong(8, trnclsqusdt_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(TrainingClassQuestionDetail entity) 818 throws PersistenceDatabaseException { 819 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 820 821 try { 822 TrainingClassQuestionDetailValue _value = entity.getTrainingClassQuestionDetailValue(); 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<TrainingClassQuestionDetail> 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(TrainingClassQuestionDetail entity : entities) { 851 if(bindForStore(_ps, entity.getTrainingClassQuestionDetailValue())) { 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.getTrainingClassQuestionDetailValue()); 874 }); 875 } 876 } catch (SQLException se) { 877 throw new PersistenceDatabaseException(se); 878 } 879 } 880 } 881 882 @Override 883 public void remove(TrainingClassQuestionDetail entity) 884 throws PersistenceDatabaseException { 885 remove(entity.getPrimaryKey()); 886 } 887 888 @Override 889 public void remove(TrainingClassQuestionDetailPK 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<TrainingClassQuestionDetailPK> 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(TrainingClassQuestionDetailPK 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(TrainingClassQuestionDetailPK 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}