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