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