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