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