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