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