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