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