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