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