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