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