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