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