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