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