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