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