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 * TrainingClassDetailFactory.java
021 */
022
023package com.echothree.model.data.training.server.factory;
024
025import com.echothree.model.data.training.common.pk.TrainingClassPK;
026import com.echothree.model.data.workeffort.common.pk.WorkEffortScopePK;
027
028import com.echothree.model.data.training.server.entity.TrainingClass;
029import com.echothree.model.data.workeffort.server.entity.WorkEffortScope;
030
031import com.echothree.model.data.training.common.TrainingClassDetailConstants;
032import com.echothree.model.data.training.common.pk.TrainingClassDetailPK;
033import com.echothree.model.data.training.server.value.TrainingClassDetailValue;
034import com.echothree.model.data.training.server.entity.TrainingClassDetail;
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 com.echothree.util.server.persistence.ThreadSession;
044import java.sql.PreparedStatement;
045import java.sql.ResultSet;
046import java.sql.SQLException;
047import java.sql.Types;
048import java.io.ByteArrayInputStream;
049import java.io.StringReader;
050import java.util.ArrayList;
051import java.util.Collection;
052import java.util.HashSet;
053import java.util.List;
054import java.util.Map;
055import java.util.Set;
056import org.apache.commons.logging.Log;
057import org.apache.commons.logging.LogFactory;
058
059public class TrainingClassDetailFactory
060        implements BaseFactory<TrainingClassDetailPK, TrainingClassDetail> {
061    
062    //final private static Log log = LogFactory.getLog(TrainingClassDetailFactory.class);
063    
064    final private static String SQL_SELECT_READ_ONLY = "SELECT trnclsdt_trainingclassdetailid, trnclsdt_trncls_trainingclassid, trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, trnclsdt_wes_workeffortscopeid, trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime FROM trainingclassdetails WHERE trnclsdt_trainingclassdetailid = ?";
065    final private static String SQL_SELECT_READ_WRITE = "SELECT trnclsdt_trainingclassdetailid, trnclsdt_trncls_trainingclassid, trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, trnclsdt_wes_workeffortscopeid, trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime FROM trainingclassdetails WHERE trnclsdt_trainingclassdetailid = ? FOR UPDATE";
066    final private static String SQL_INSERT = "INSERT INTO trainingclassdetails (trnclsdt_trainingclassdetailid, trnclsdt_trncls_trainingclassid, trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, trnclsdt_wes_workeffortscopeid, trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
067    final private static String SQL_UPDATE = "UPDATE trainingclassdetails SET trnclsdt_trncls_trainingclassid = ?, trnclsdt_trainingclassname = ?, trnclsdt_estimatedreadingtime = ?, trnclsdt_readingtimeallowed = ?, trnclsdt_estimatedtestingtime = ?, trnclsdt_testingtimeallowed = ?, trnclsdt_requiredcompletiontime = ?, trnclsdt_wes_workeffortscopeid = ?, trnclsdt_defaultpercentagetopass = ?, trnclsdt_overallquestioncount = ?, trnclsdt_testingvaliditytime = ?, trnclsdt_expiredretentiontime = ?, trnclsdt_alwaysreassignonexpiration = ?, trnclsdt_isdefault = ?, trnclsdt_sortorder = ?, trnclsdt_fromtime = ?, trnclsdt_thrutime = ? WHERE trnclsdt_trainingclassdetailid = ?";
068    final private static String SQL_DELETE = "DELETE FROM trainingclassdetails WHERE trnclsdt_trainingclassdetailid = ?";
069    final private static String SQL_VALID = "SELECT COUNT(*) FROM trainingclassdetails WHERE trnclsdt_trainingclassdetailid = ?";
070    
071    final private static String PK_COLUMN = "trnclsdt_trainingclassdetailid";
072    final private static String ALL_COLUMNS = "trnclsdt_trainingclassdetailid, trnclsdt_trncls_trainingclassid, trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, trnclsdt_wes_workeffortscopeid, trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime";
073    final public static String TABLE_NAME = "trainingclassdetails";
074    
075    final public static String TRNCLSDT_TRAININGCLASSDETAILID = "trnclsdt_trainingclassdetailid";
076    final public static String TRNCLSDT_TRNCLS_TRAININGCLASSID = "trnclsdt_trncls_trainingclassid";
077    final public static String TRNCLSDT_TRAININGCLASSNAME = "trnclsdt_trainingclassname";
078    final public static String TRNCLSDT_ESTIMATEDREADINGTIME = "trnclsdt_estimatedreadingtime";
079    final public static String TRNCLSDT_READINGTIMEALLOWED = "trnclsdt_readingtimeallowed";
080    final public static String TRNCLSDT_ESTIMATEDTESTINGTIME = "trnclsdt_estimatedtestingtime";
081    final public static String TRNCLSDT_TESTINGTIMEALLOWED = "trnclsdt_testingtimeallowed";
082    final public static String TRNCLSDT_REQUIREDCOMPLETIONTIME = "trnclsdt_requiredcompletiontime";
083    final public static String TRNCLSDT_WES_WORKEFFORTSCOPEID = "trnclsdt_wes_workeffortscopeid";
084    final public static String TRNCLSDT_DEFAULTPERCENTAGETOPASS = "trnclsdt_defaultpercentagetopass";
085    final public static String TRNCLSDT_OVERALLQUESTIONCOUNT = "trnclsdt_overallquestioncount";
086    final public static String TRNCLSDT_TESTINGVALIDITYTIME = "trnclsdt_testingvaliditytime";
087    final public static String TRNCLSDT_EXPIREDRETENTIONTIME = "trnclsdt_expiredretentiontime";
088    final public static String TRNCLSDT_ALWAYSREASSIGNONEXPIRATION = "trnclsdt_alwaysreassignonexpiration";
089    final public static String TRNCLSDT_ISDEFAULT = "trnclsdt_isdefault";
090    final public static String TRNCLSDT_SORTORDER = "trnclsdt_sortorder";
091    final public static String TRNCLSDT_FROMTIME = "trnclsdt_fromtime";
092    final public static String TRNCLSDT_THRUTIME = "trnclsdt_thrutime";
093    
094    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(TrainingClassDetailConstants.COMPONENT_VENDOR_NAME, TrainingClassDetailConstants.ENTITY_TYPE_NAME);
095    
096    /** Creates a new instance of TrainingClassDetailFactory */
097    private TrainingClassDetailFactory() {
098        super();
099    }
100    
101    private static class TrainingClassDetailFactoryHolder {
102        static TrainingClassDetailFactory instance = new TrainingClassDetailFactory();
103    }
104    
105    public static TrainingClassDetailFactory getInstance() {
106        return TrainingClassDetailFactoryHolder.instance;
107    }
108    
109    @Override
110    public String getPKColumn() {
111        return PK_COLUMN;
112    }
113    
114    @Override
115    public String getAllColumns() {
116        return ALL_COLUMNS;
117    }
118    
119    @Override
120    public String getTableName() {
121        return TABLE_NAME;
122    }
123    
124    @Override
125    public String getComponentVendorName() {
126        return TrainingClassDetailConstants.COMPONENT_VENDOR_NAME;
127    }
128    
129    @Override
130    public String getEntityTypeName() {
131        return TrainingClassDetailConstants.ENTITY_TYPE_NAME;
132    }
133    
134    public PreparedStatement prepareStatement(String query) {
135        return ThreadSession.currentSession().prepareStatement(TrainingClassDetailFactory.class, query);
136    }
137    
138    public TrainingClassDetailPK getNextPK() {
139        return new TrainingClassDetailPK(entityIdGenerator.getNextEntityId());
140    }
141    
142    public Set<TrainingClassDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
143            throws PersistenceDatabaseException {
144        Set<TrainingClassDetailPK> _result = new HashSet<>();
145        
146        try {
147            while(rs.next()) {
148                _result.add(getPKFromResultSet(rs));
149            }
150        } catch (SQLException se) {
151            throw new PersistenceDatabaseException(se);
152        }
153        
154        return _result;
155    }
156    
157    public java.util.List<TrainingClassDetailPK> getPKsFromResultSetAsList(ResultSet rs)
158            throws PersistenceDatabaseException {
159        java.util.List<TrainingClassDetailPK> _result = new ArrayList<>();
160        
161        try {
162            while(rs.next()) {
163                _result.add(getPKFromResultSet(rs));
164            }
165        } catch (SQLException se) {
166            throw new PersistenceDatabaseException(se);
167        }
168        
169        return _result;
170    }
171    
172    public TrainingClassDetailPK getPKFromResultSet(ResultSet rs)
173            throws PersistenceDatabaseException {
174        TrainingClassDetailPK _result;
175        
176        try {
177            long trnclsdt_trainingclassdetailid = rs.getLong(TRNCLSDT_TRAININGCLASSDETAILID);
178            Long _entityId = rs.wasNull() ? null : trnclsdt_trainingclassdetailid;
179            
180            _result = new TrainingClassDetailPK(_entityId);
181        } catch (SQLException se) {
182            throw new PersistenceDatabaseException(se);
183        }
184        
185        return _result;
186    }
187    
188    public java.util.List<TrainingClassDetailValue> getValuesFromPKs(Session session, Collection<TrainingClassDetailPK> pks)
189            throws PersistenceDatabaseException {
190        java.util.List<TrainingClassDetailValue> _values = new ArrayList<>(pks.size());
191        
192        for(TrainingClassDetailPK _pk: pks) {
193            _values.add(getValueFromPK(session, _pk));
194        }
195        
196        return _values;
197    }
198    
199    public TrainingClassDetailValue getValueFromPK(Session session, TrainingClassDetailPK pk)
200            throws PersistenceDatabaseException {
201        TrainingClassDetailValue _value;
202        
203        // See if we already have the entity in the session cache
204        TrainingClassDetail _entity = (TrainingClassDetail)session.getEntity(pk);
205        if(_entity == null)
206            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getTrainingClassDetailValue();
207        else
208            _value = _entity.getTrainingClassDetailValue();
209        
210        return _value;
211    }
212    
213    public java.util.List<TrainingClassDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
214            throws PersistenceDatabaseException {
215        java.util.List<TrainingClassDetailValue> _result = new ArrayList<>();
216        
217        try {
218            while(rs.next()) {
219                _result.add(getValueFromResultSet(session, rs));
220            }
221        } catch (SQLException se) {
222            throw new PersistenceDatabaseException(se);
223        }
224        
225        return _result;
226    }
227    
228    public TrainingClassDetailValue getValueFromResultSet(Session session, ResultSet rs)
229            throws PersistenceDatabaseException {
230        TrainingClassDetailValue _value;
231        
232        try {
233            Long trnclsdt_trainingclassdetailid = rs.getLong(TRNCLSDT_TRAININGCLASSDETAILID);
234            TrainingClassDetailPK _pk = new TrainingClassDetailPK(trnclsdt_trainingclassdetailid);
235            
236            // See if we already have the entity in the session cache
237            TrainingClassDetail _entity = (TrainingClassDetail)session.getEntity(_pk);
238            
239            if(_entity == null) {
240                Long trnclsdt_trncls_trainingclassid = rs.getLong(TRNCLSDT_TRNCLS_TRAININGCLASSID);
241                if(rs.wasNull())
242                    trnclsdt_trncls_trainingclassid = null;
243                
244                String trnclsdt_trainingclassname = rs.getString(TRNCLSDT_TRAININGCLASSNAME);
245                if(rs.wasNull())
246                    trnclsdt_trainingclassname = null;
247                
248                Long trnclsdt_estimatedreadingtime = rs.getLong(TRNCLSDT_ESTIMATEDREADINGTIME);
249                if(rs.wasNull())
250                    trnclsdt_estimatedreadingtime = null;
251                
252                Long trnclsdt_readingtimeallowed = rs.getLong(TRNCLSDT_READINGTIMEALLOWED);
253                if(rs.wasNull())
254                    trnclsdt_readingtimeallowed = null;
255                
256                Long trnclsdt_estimatedtestingtime = rs.getLong(TRNCLSDT_ESTIMATEDTESTINGTIME);
257                if(rs.wasNull())
258                    trnclsdt_estimatedtestingtime = null;
259                
260                Long trnclsdt_testingtimeallowed = rs.getLong(TRNCLSDT_TESTINGTIMEALLOWED);
261                if(rs.wasNull())
262                    trnclsdt_testingtimeallowed = null;
263                
264                Long trnclsdt_requiredcompletiontime = rs.getLong(TRNCLSDT_REQUIREDCOMPLETIONTIME);
265                if(rs.wasNull())
266                    trnclsdt_requiredcompletiontime = null;
267                
268                Long trnclsdt_wes_workeffortscopeid = rs.getLong(TRNCLSDT_WES_WORKEFFORTSCOPEID);
269                if(rs.wasNull())
270                    trnclsdt_wes_workeffortscopeid = null;
271                
272                Integer trnclsdt_defaultpercentagetopass = rs.getInt(TRNCLSDT_DEFAULTPERCENTAGETOPASS);
273                if(rs.wasNull())
274                    trnclsdt_defaultpercentagetopass = null;
275                
276                Integer trnclsdt_overallquestioncount = rs.getInt(TRNCLSDT_OVERALLQUESTIONCOUNT);
277                if(rs.wasNull())
278                    trnclsdt_overallquestioncount = null;
279                
280                Long trnclsdt_testingvaliditytime = rs.getLong(TRNCLSDT_TESTINGVALIDITYTIME);
281                if(rs.wasNull())
282                    trnclsdt_testingvaliditytime = null;
283                
284                Long trnclsdt_expiredretentiontime = rs.getLong(TRNCLSDT_EXPIREDRETENTIONTIME);
285                if(rs.wasNull())
286                    trnclsdt_expiredretentiontime = null;
287                
288                Boolean trnclsdt_alwaysreassignonexpiration = rs.getInt(TRNCLSDT_ALWAYSREASSIGNONEXPIRATION) == 1;
289                if(rs.wasNull())
290                    trnclsdt_alwaysreassignonexpiration = null;
291                
292                Boolean trnclsdt_isdefault = rs.getInt(TRNCLSDT_ISDEFAULT) == 1;
293                if(rs.wasNull())
294                    trnclsdt_isdefault = null;
295                
296                Integer trnclsdt_sortorder = rs.getInt(TRNCLSDT_SORTORDER);
297                if(rs.wasNull())
298                    trnclsdt_sortorder = null;
299                
300                Long trnclsdt_fromtime = rs.getLong(TRNCLSDT_FROMTIME);
301                if(rs.wasNull())
302                    trnclsdt_fromtime = null;
303                
304                Long trnclsdt_thrutime = rs.getLong(TRNCLSDT_THRUTIME);
305                if(rs.wasNull())
306                    trnclsdt_thrutime = null;
307                
308                _value = new TrainingClassDetailValue(_pk, new TrainingClassPK(trnclsdt_trncls_trainingclassid), trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, new WorkEffortScopePK(trnclsdt_wes_workeffortscopeid), trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime);
309            } else
310                _value = _entity.getTrainingClassDetailValue();
311        } catch (SQLException se) {
312            throw new PersistenceDatabaseException(se);
313        }
314        
315        return _value;
316    }
317    
318    public java.util.List<TrainingClassDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<TrainingClassDetailPK> pks)
319            throws PersistenceDatabaseException {
320        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
321    }
322    
323    public java.util.List<TrainingClassDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<TrainingClassDetailPK> pks)
324            throws PersistenceDatabaseException {
325        java.util.List<TrainingClassDetail> _entities = new ArrayList<>(pks.size());
326        
327        for(TrainingClassDetailPK _pk: pks) {
328            _entities.add(getEntityFromPK(session, entityPermission, _pk));
329        }
330        
331        return _entities;
332    }
333    
334    public TrainingClassDetail getEntityFromValue(EntityPermission entityPermission, TrainingClassDetailValue value) {
335        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
336    }
337    
338    public TrainingClassDetail getEntityFromValue(Session session, EntityPermission entityPermission, TrainingClassDetailValue value) {
339        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
340    }
341    
342    public TrainingClassDetail getEntityFromPK(EntityPermission entityPermission, TrainingClassDetailPK pk)
343            throws PersistenceDatabaseException {
344        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
345    }
346    
347    public TrainingClassDetail getEntityFromCache(Session session, TrainingClassDetailPK pk) {
348        TrainingClassDetailValue _value = (TrainingClassDetailValue)session.getValueCache().get(pk);
349    
350        return _value == null ? null : new TrainingClassDetail(_value, EntityPermission.READ_ONLY);
351    }
352    
353    public TrainingClassDetail getEntityFromPK(Session session, EntityPermission entityPermission, TrainingClassDetailPK pk)
354            throws PersistenceDatabaseException {
355        TrainingClassDetail _entity;
356        
357        // See if we already have the entity in the session cache
358        _entity = (TrainingClassDetail)session.getEntity(pk);
359        if(_entity != null) {
360            // If the requested permission is READ_WRITE, and the cached permission is
361            // READ_ONLY, then pretend that the cached object wasn't found, and create
362            // a new entity that is READ_WRITE.
363            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
364                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
365                    _entity = null;
366            }
367        }
368        
369        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
370            _entity = getEntityFromCache(session, pk);
371        }
372        
373        if(_entity == null) {
374            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
375            long _entityId = pk.getEntityId();
376            ResultSet _rs = null;
377            
378            try {
379                _ps.setLong(1, _entityId);
380                _rs = _ps.executeQuery();
381                if(_rs.next()) {
382                    _entity = getEntityFromResultSet(session, entityPermission, _rs);
383                }
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        
397        return _entity;
398    }
399    
400    public Set<TrainingClassDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
401            throws PersistenceDatabaseException {
402        Set<TrainingClassDetailPK> _pks;
403        ResultSet _rs = null;
404        
405        try {
406            if(params.length != 0) {
407                Session.setQueryParams(ps, params);
408            }
409            
410            _rs = ps.executeQuery();
411            _pks = getPKsFromResultSetAsSet(_rs);
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 _pks;
426    }
427    
428    public java.util.List<TrainingClassDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
429            throws PersistenceDatabaseException {
430        java.util.List<TrainingClassDetailPK> _pks;
431        ResultSet _rs = null;
432        
433        try {
434            if(params.length != 0) {
435                Session.setQueryParams(ps, params);
436            }
437            
438            _rs = ps.executeQuery();
439            _pks = getPKsFromResultSetAsList(_rs);
440            _rs.close();
441        } catch (SQLException se) {
442            throw new PersistenceDatabaseException(se);
443        } finally {
444            if(_rs != null) {
445                try {
446                    _rs.close();
447                } catch (SQLException se) {
448                    // do nothing
449                }
450            }
451        }
452        
453        return _pks;
454    }
455    
456    public TrainingClassDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
457            throws PersistenceDatabaseException {
458        TrainingClassDetailPK _pk = null;
459        ResultSet _rs = null;
460        
461        try {
462            if(params.length != 0) {
463                Session.setQueryParams(ps, params);
464            }
465            
466            _rs = ps.executeQuery();
467            if(_rs.next()) {
468                _pk = getPKFromResultSet(_rs);
469            }
470            _rs.close();
471        } catch (SQLException se) {
472            throw new PersistenceDatabaseException(se);
473        } finally {
474            if(_rs != null) {
475                try {
476                    _rs.close();
477                } catch (SQLException se) {
478                    // do nothing
479                }
480            }
481        }
482        
483        return _pk;
484    }
485    
486    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
487            throws PersistenceDatabaseException {
488        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
489        
490        return getEntitiesFromQuery(session, entityPermission, ps, params);
491    }
492    
493    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
494            throws PersistenceDatabaseException {
495        Session session = ThreadSession.currentSession();
496        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
497        
498        return getEntitiesFromQuery(session, entityPermission, ps, params);
499    }
500    
501    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
502            throws PersistenceDatabaseException {
503        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
504        
505        return getEntitiesFromQuery(session, entityPermission, ps);
506    }
507    
508    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
509            throws PersistenceDatabaseException {
510        Session session = ThreadSession.currentSession();
511        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
512        
513        return getEntitiesFromQuery(session, entityPermission, ps);
514    }
515    
516    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
517            throws PersistenceDatabaseException {
518        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
519    }
520    
521    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
522            throws PersistenceDatabaseException {
523        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
524    }
525    
526    public java.util.List<TrainingClassDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
527            throws PersistenceDatabaseException {
528        java.util.List<TrainingClassDetail> _entities;
529        ResultSet _rs = null;
530        
531        try {
532            if(params.length != 0) {
533                Session.setQueryParams(ps, params);
534            }
535            
536            _rs = ps.executeQuery();
537            _entities = getEntitiesFromResultSet(session, entityPermission, _rs);
538            _rs.close();
539        } catch (SQLException se) {
540            throw new PersistenceDatabaseException(se);
541        } finally {
542            if(_rs != null) {
543                try {
544                    _rs.close();
545                } catch (SQLException se) {
546                    // do nothing
547                }
548            }
549        }
550        
551        return _entities;
552    }
553    
554    public TrainingClassDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
555            throws PersistenceDatabaseException {
556        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
557        
558        return getEntityFromQuery(session, entityPermission, ps, params);
559    }
560    
561    public TrainingClassDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
562            throws PersistenceDatabaseException {
563        Session session = ThreadSession.currentSession();
564        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
565        
566        return getEntityFromQuery(session, entityPermission, ps, params);
567    }
568    
569    public TrainingClassDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
570            throws PersistenceDatabaseException {
571        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
572        
573        return getEntityFromQuery(session, entityPermission, ps);
574    }
575    
576    public TrainingClassDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
577            throws PersistenceDatabaseException {
578        Session session = ThreadSession.currentSession();
579        PreparedStatement ps = session.prepareStatement(TrainingClassDetailFactory.class, queryMap.get(entityPermission));
580        
581        return getEntityFromQuery(session, entityPermission, ps);
582    }
583    
584    public TrainingClassDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
585            throws PersistenceDatabaseException {
586        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
587    }
588    
589    public TrainingClassDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
590            throws PersistenceDatabaseException {
591        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
592    }
593    
594    public TrainingClassDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
595            throws PersistenceDatabaseException {
596        TrainingClassDetail _entity = null;
597        ResultSet _rs = null;
598        
599        try {
600            if(params.length != 0) {
601                Session.setQueryParams(ps, params);
602            }
603            
604            _rs = ps.executeQuery();
605            if(_rs.next()) {
606                _entity = getEntityFromResultSet(session, entityPermission, _rs);
607            }
608            _rs.close();
609        } catch (SQLException se) {
610            throw new PersistenceDatabaseException(se);
611        } finally {
612            if(_rs != null) {
613                try {
614                    _rs.close();
615                } catch (SQLException se) {
616                    // do nothing
617                }
618            }
619        }
620        
621        return _entity;
622    }
623    
624    public java.util.List<TrainingClassDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
625            throws PersistenceDatabaseException {
626        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
627    }
628    
629    public java.util.List<TrainingClassDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
630            throws PersistenceDatabaseException {
631        java.util.List<TrainingClassDetail> _result = new ArrayList<>();
632        
633        try {
634            while(rs.next()) {
635                _result.add(getEntityFromResultSet(session, entityPermission, rs));
636            }
637        } catch (SQLException se) {
638            throw new PersistenceDatabaseException(se);
639        }
640        
641        return _result;
642    }
643    
644    public TrainingClassDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
645            throws PersistenceDatabaseException {
646        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
647    }
648    
649    public TrainingClassDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
650            throws PersistenceDatabaseException {
651        TrainingClassDetail _entity;
652        
653        try {
654            Long trnclsdt_trainingclassdetailid = rs.getLong(TRNCLSDT_TRAININGCLASSDETAILID);
655            TrainingClassDetailPK _pk = new TrainingClassDetailPK(trnclsdt_trainingclassdetailid);
656            
657            // See if we already have the entity in the session cache
658            _entity = (TrainingClassDetail)session.getEntity(_pk);
659            if(_entity != null) {
660                // If the requested permission is READ_WRITE, and the cached permission is
661                // READ_ONLY, then pretend that the cached object wasn't found, and create
662                // a new entity that is READ_WRITE.
663                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
664                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
665                        _entity = null;
666                }
667            }
668            boolean foundInSessionCache = _entity != null;
669            
670            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
671                _entity = getEntityFromCache(session, _pk);
672            }
673            
674            if(_entity == null) {
675                Long trnclsdt_trncls_trainingclassid = rs.getLong(TRNCLSDT_TRNCLS_TRAININGCLASSID);
676                if(rs.wasNull())
677                    trnclsdt_trncls_trainingclassid = null;
678                
679                String trnclsdt_trainingclassname = rs.getString(TRNCLSDT_TRAININGCLASSNAME);
680                if(rs.wasNull())
681                    trnclsdt_trainingclassname = null;
682                
683                Long trnclsdt_estimatedreadingtime = rs.getLong(TRNCLSDT_ESTIMATEDREADINGTIME);
684                if(rs.wasNull())
685                    trnclsdt_estimatedreadingtime = null;
686                
687                Long trnclsdt_readingtimeallowed = rs.getLong(TRNCLSDT_READINGTIMEALLOWED);
688                if(rs.wasNull())
689                    trnclsdt_readingtimeallowed = null;
690                
691                Long trnclsdt_estimatedtestingtime = rs.getLong(TRNCLSDT_ESTIMATEDTESTINGTIME);
692                if(rs.wasNull())
693                    trnclsdt_estimatedtestingtime = null;
694                
695                Long trnclsdt_testingtimeallowed = rs.getLong(TRNCLSDT_TESTINGTIMEALLOWED);
696                if(rs.wasNull())
697                    trnclsdt_testingtimeallowed = null;
698                
699                Long trnclsdt_requiredcompletiontime = rs.getLong(TRNCLSDT_REQUIREDCOMPLETIONTIME);
700                if(rs.wasNull())
701                    trnclsdt_requiredcompletiontime = null;
702                
703                Long trnclsdt_wes_workeffortscopeid = rs.getLong(TRNCLSDT_WES_WORKEFFORTSCOPEID);
704                if(rs.wasNull())
705                    trnclsdt_wes_workeffortscopeid = null;
706                
707                Integer trnclsdt_defaultpercentagetopass = rs.getInt(TRNCLSDT_DEFAULTPERCENTAGETOPASS);
708                if(rs.wasNull())
709                    trnclsdt_defaultpercentagetopass = null;
710                
711                Integer trnclsdt_overallquestioncount = rs.getInt(TRNCLSDT_OVERALLQUESTIONCOUNT);
712                if(rs.wasNull())
713                    trnclsdt_overallquestioncount = null;
714                
715                Long trnclsdt_testingvaliditytime = rs.getLong(TRNCLSDT_TESTINGVALIDITYTIME);
716                if(rs.wasNull())
717                    trnclsdt_testingvaliditytime = null;
718                
719                Long trnclsdt_expiredretentiontime = rs.getLong(TRNCLSDT_EXPIREDRETENTIONTIME);
720                if(rs.wasNull())
721                    trnclsdt_expiredretentiontime = null;
722                
723                Boolean trnclsdt_alwaysreassignonexpiration = rs.getInt(TRNCLSDT_ALWAYSREASSIGNONEXPIRATION) == 1;
724                if(rs.wasNull())
725                    trnclsdt_alwaysreassignonexpiration = null;
726                
727                Boolean trnclsdt_isdefault = rs.getInt(TRNCLSDT_ISDEFAULT) == 1;
728                if(rs.wasNull())
729                    trnclsdt_isdefault = null;
730                
731                Integer trnclsdt_sortorder = rs.getInt(TRNCLSDT_SORTORDER);
732                if(rs.wasNull())
733                    trnclsdt_sortorder = null;
734                
735                Long trnclsdt_fromtime = rs.getLong(TRNCLSDT_FROMTIME);
736                if(rs.wasNull())
737                    trnclsdt_fromtime = null;
738                
739                Long trnclsdt_thrutime = rs.getLong(TRNCLSDT_THRUTIME);
740                if(rs.wasNull())
741                    trnclsdt_thrutime = null;
742                
743                TrainingClassDetailValue _value = new TrainingClassDetailValue(_pk, trnclsdt_trncls_trainingclassid == null? null: new TrainingClassPK(trnclsdt_trncls_trainingclassid), trnclsdt_trainingclassname, trnclsdt_estimatedreadingtime, trnclsdt_readingtimeallowed, trnclsdt_estimatedtestingtime, trnclsdt_testingtimeallowed, trnclsdt_requiredcompletiontime, trnclsdt_wes_workeffortscopeid == null? null: new WorkEffortScopePK(trnclsdt_wes_workeffortscopeid), trnclsdt_defaultpercentagetopass, trnclsdt_overallquestioncount, trnclsdt_testingvaliditytime, trnclsdt_expiredretentiontime, trnclsdt_alwaysreassignonexpiration, trnclsdt_isdefault, trnclsdt_sortorder, trnclsdt_fromtime, trnclsdt_thrutime);
744                _entity = new TrainingClassDetail(_value, entityPermission);
745            }
746            
747            if(!foundInSessionCache) {
748                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
749                    session.putReadOnlyEntity(_pk, _entity);
750                    session.getValueCache().put(_entity.getTrainingClassDetailValue());
751                } else {
752                    session.putReadWriteEntity(_pk, _entity);
753                }
754            }
755        } catch (SQLException se) {
756            throw new PersistenceDatabaseException(se);
757        }
758        
759        return _entity;
760    }
761    
762    public TrainingClassDetail create(Session session, TrainingClass trainingClass, String trainingClassName, Long estimatedReadingTime, Long readingTimeAllowed, Long estimatedTestingTime, Long testingTimeAllowed, Long requiredCompletionTime, WorkEffortScope workEffortScope, Integer defaultPercentageToPass, Integer overallQuestionCount, Long testingValidityTime, Long expiredRetentionTime, Boolean alwaysReassignOnExpiration, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
763            throws PersistenceDatabaseException, PersistenceNotNullException {
764        return create(session, trainingClass == null ? null : trainingClass.getPrimaryKey(), trainingClassName, estimatedReadingTime, readingTimeAllowed, estimatedTestingTime, testingTimeAllowed, requiredCompletionTime, workEffortScope == null ? null : workEffortScope.getPrimaryKey(), defaultPercentageToPass, overallQuestionCount, testingValidityTime, expiredRetentionTime, alwaysReassignOnExpiration, isDefault, sortOrder, fromTime, thruTime);
765    }
766    
767    public TrainingClassDetail create(TrainingClass trainingClass, String trainingClassName, Long estimatedReadingTime, Long readingTimeAllowed, Long estimatedTestingTime, Long testingTimeAllowed, Long requiredCompletionTime, WorkEffortScope workEffortScope, Integer defaultPercentageToPass, Integer overallQuestionCount, Long testingValidityTime, Long expiredRetentionTime, Boolean alwaysReassignOnExpiration, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
768            throws PersistenceDatabaseException, PersistenceNotNullException {
769        return create(ThreadSession.currentSession(), trainingClass == null ? null : trainingClass.getPrimaryKey(), trainingClassName, estimatedReadingTime, readingTimeAllowed, estimatedTestingTime, testingTimeAllowed, requiredCompletionTime, workEffortScope == null ? null : workEffortScope.getPrimaryKey(), defaultPercentageToPass, overallQuestionCount, testingValidityTime, expiredRetentionTime, alwaysReassignOnExpiration, isDefault, sortOrder, fromTime, thruTime);
770    }
771    
772    private void bindForCreate(PreparedStatement _ps, TrainingClassDetailValue _value)
773            throws SQLException {
774        _ps.setLong(1, _value.getEntityId());
775        
776        TrainingClassPK trnclsdt_trncls_trainingclassid = _value.getTrainingClassPK();
777        if(trnclsdt_trncls_trainingclassid == null)
778            _ps.setNull(2, Types.BIGINT);
779        else
780            _ps.setLong(2, trnclsdt_trncls_trainingclassid.getEntityId());
781            
782        String trnclsdt_trainingclassname = _value.getTrainingClassName();
783        if(trnclsdt_trainingclassname == null)
784            _ps.setNull(3, Types.VARCHAR);
785        else
786            _ps.setString(3, trnclsdt_trainingclassname);
787            
788        Long trnclsdt_estimatedreadingtime = _value.getEstimatedReadingTime();
789        if(trnclsdt_estimatedreadingtime == null)
790            _ps.setNull(4, Types.BIGINT);
791        else
792            _ps.setLong(4, trnclsdt_estimatedreadingtime);
793            
794        Long trnclsdt_readingtimeallowed = _value.getReadingTimeAllowed();
795        if(trnclsdt_readingtimeallowed == null)
796            _ps.setNull(5, Types.BIGINT);
797        else
798            _ps.setLong(5, trnclsdt_readingtimeallowed);
799            
800        Long trnclsdt_estimatedtestingtime = _value.getEstimatedTestingTime();
801        if(trnclsdt_estimatedtestingtime == null)
802            _ps.setNull(6, Types.BIGINT);
803        else
804            _ps.setLong(6, trnclsdt_estimatedtestingtime);
805            
806        Long trnclsdt_testingtimeallowed = _value.getTestingTimeAllowed();
807        if(trnclsdt_testingtimeallowed == null)
808            _ps.setNull(7, Types.BIGINT);
809        else
810            _ps.setLong(7, trnclsdt_testingtimeallowed);
811            
812        Long trnclsdt_requiredcompletiontime = _value.getRequiredCompletionTime();
813        if(trnclsdt_requiredcompletiontime == null)
814            _ps.setNull(8, Types.BIGINT);
815        else
816            _ps.setLong(8, trnclsdt_requiredcompletiontime);
817            
818        WorkEffortScopePK trnclsdt_wes_workeffortscopeid = _value.getWorkEffortScopePK();
819        if(trnclsdt_wes_workeffortscopeid == null)
820            _ps.setNull(9, Types.BIGINT);
821        else
822            _ps.setLong(9, trnclsdt_wes_workeffortscopeid.getEntityId());
823            
824        Integer trnclsdt_defaultpercentagetopass = _value.getDefaultPercentageToPass();
825        if(trnclsdt_defaultpercentagetopass == null)
826            _ps.setNull(10, Types.INTEGER);
827        else
828            _ps.setInt(10, trnclsdt_defaultpercentagetopass);
829            
830        Integer trnclsdt_overallquestioncount = _value.getOverallQuestionCount();
831        if(trnclsdt_overallquestioncount == null)
832            _ps.setNull(11, Types.INTEGER);
833        else
834            _ps.setInt(11, trnclsdt_overallquestioncount);
835            
836        Long trnclsdt_testingvaliditytime = _value.getTestingValidityTime();
837        if(trnclsdt_testingvaliditytime == null)
838            _ps.setNull(12, Types.BIGINT);
839        else
840            _ps.setLong(12, trnclsdt_testingvaliditytime);
841            
842        Long trnclsdt_expiredretentiontime = _value.getExpiredRetentionTime();
843        if(trnclsdt_expiredretentiontime == null)
844            _ps.setNull(13, Types.BIGINT);
845        else
846            _ps.setLong(13, trnclsdt_expiredretentiontime);
847            
848        Boolean trnclsdt_alwaysreassignonexpiration = _value.getAlwaysReassignOnExpiration();
849        if(trnclsdt_alwaysreassignonexpiration == null)
850            _ps.setNull(14, Types.BIT);
851        else
852            _ps.setInt(14, trnclsdt_alwaysreassignonexpiration? 1: 0);
853            
854        Boolean trnclsdt_isdefault = _value.getIsDefault();
855        if(trnclsdt_isdefault == null)
856            _ps.setNull(15, Types.BIT);
857        else
858            _ps.setInt(15, trnclsdt_isdefault? 1: 0);
859            
860        Integer trnclsdt_sortorder = _value.getSortOrder();
861        if(trnclsdt_sortorder == null)
862            _ps.setNull(16, Types.INTEGER);
863        else
864            _ps.setInt(16, trnclsdt_sortorder);
865            
866        Long trnclsdt_fromtime = _value.getFromTime();
867        if(trnclsdt_fromtime == null)
868            _ps.setNull(17, Types.BIGINT);
869        else
870            _ps.setLong(17, trnclsdt_fromtime);
871            
872        Long trnclsdt_thrutime = _value.getThruTime();
873        if(trnclsdt_thrutime == null)
874            _ps.setNull(18, Types.BIGINT);
875        else
876            _ps.setLong(18, trnclsdt_thrutime);
877            
878    }
879    
880    public TrainingClassDetail create(Session session, TrainingClassPK trainingClassPK, String trainingClassName, Long estimatedReadingTime, Long readingTimeAllowed, Long estimatedTestingTime, Long testingTimeAllowed, Long requiredCompletionTime, WorkEffortScopePK workEffortScopePK, Integer defaultPercentageToPass, Integer overallQuestionCount, Long testingValidityTime, Long expiredRetentionTime, Boolean alwaysReassignOnExpiration, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
881            throws PersistenceDatabaseException, PersistenceNotNullException {
882        TrainingClassDetailPK _pk = getNextPK();
883        TrainingClassDetailValue _value = new TrainingClassDetailValue(_pk, trainingClassPK, trainingClassName, estimatedReadingTime, readingTimeAllowed, estimatedTestingTime, testingTimeAllowed, requiredCompletionTime, workEffortScopePK, defaultPercentageToPass, overallQuestionCount, testingValidityTime, expiredRetentionTime, alwaysReassignOnExpiration, isDefault, sortOrder, fromTime, thruTime);
884        
885        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
886        
887        try {
888            bindForCreate(_ps, _value);
889            
890            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
891                int _count = _ps.executeUpdate();
892                
893                if(_count != 1) {
894                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
895                }
896            } else {
897                 _ps.executeUpdate();
898            }
899            
900            session.getValueCache().put(_value);
901        } catch (SQLException se) {
902            throw new PersistenceDatabaseException(se);
903        }
904        
905        TrainingClassDetail _entity = new TrainingClassDetail(_value, EntityPermission.READ_ONLY);
906        session.putReadOnlyEntity(_pk, _entity);
907        
908        return _entity;
909    }
910    
911    public TrainingClassDetail create(TrainingClassPK trainingClassPK, String trainingClassName, Long estimatedReadingTime, Long readingTimeAllowed, Long estimatedTestingTime, Long testingTimeAllowed, Long requiredCompletionTime, WorkEffortScopePK workEffortScopePK, Integer defaultPercentageToPass, Integer overallQuestionCount, Long testingValidityTime, Long expiredRetentionTime, Boolean alwaysReassignOnExpiration, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
912            throws PersistenceDatabaseException, PersistenceNotNullException {
913        return create(ThreadSession.currentSession(), trainingClassPK, trainingClassName, estimatedReadingTime, readingTimeAllowed, estimatedTestingTime, testingTimeAllowed, requiredCompletionTime, workEffortScopePK, defaultPercentageToPass, overallQuestionCount, testingValidityTime, expiredRetentionTime, alwaysReassignOnExpiration, isDefault, sortOrder, fromTime, thruTime);
914    }
915    
916    public void create(Session session, Collection<TrainingClassDetailValue> _values)
917            throws PersistenceDatabaseException, PersistenceNotNullException {
918        int _size = _values.size();
919        
920        if(_size > 0) {
921            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
922            List<TrainingClassDetailValue> _cacheValues = new ArrayList<>(_size);
923            
924            try {
925                for(TrainingClassDetailValue _value : _values) {
926                    _value.setEntityId(entityIdGenerator.getNextEntityId());
927                    bindForCreate(_ps, _value);
928                    
929                    _ps.addBatch();
930                    
931                    _cacheValues.add(_value);
932                }
933                
934                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
935                    int[] _counts = _ps.executeBatch();
936                    
937                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
938                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
939                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
940                        }
941                    }
942                } else {
943                     _ps.executeBatch();
944                }
945                
946                _ps.clearBatch();
947            } catch (SQLException se) {
948                throw new PersistenceDatabaseException(se);
949            }
950            
951            _cacheValues.forEach((_cacheValue) -> {
952                TrainingClassDetail _cacheEntity = new TrainingClassDetail(_cacheValue, EntityPermission.READ_ONLY);
953                
954                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
955            });
956        }
957    }
958    
959    public void create(Collection<TrainingClassDetailValue> _values)
960            throws PersistenceDatabaseException, PersistenceNotNullException {
961        create(ThreadSession.currentSession(), _values);
962    }
963    
964    private boolean bindForStore(PreparedStatement _ps, TrainingClassDetailValue _value)
965            throws SQLException {
966        boolean _hasBeenModified = _value.hasBeenModified();
967        
968        if(_hasBeenModified) {
969            TrainingClassPK trnclsdt_trncls_trainingclassid = _value.getTrainingClassPK();
970            if(trnclsdt_trncls_trainingclassid == null)
971                _ps.setNull(1, Types.BIGINT);
972            else
973                _ps.setLong(1, trnclsdt_trncls_trainingclassid.getEntityId());
974            
975            String trnclsdt_trainingclassname = _value.getTrainingClassName();
976            if(trnclsdt_trainingclassname == null)
977                _ps.setNull(2, Types.VARCHAR);
978            else
979                _ps.setString(2, trnclsdt_trainingclassname);
980            
981            Long trnclsdt_estimatedreadingtime = _value.getEstimatedReadingTime();
982            if(trnclsdt_estimatedreadingtime == null)
983                _ps.setNull(3, Types.BIGINT);
984            else
985                _ps.setLong(3, trnclsdt_estimatedreadingtime);
986            
987            Long trnclsdt_readingtimeallowed = _value.getReadingTimeAllowed();
988            if(trnclsdt_readingtimeallowed == null)
989                _ps.setNull(4, Types.BIGINT);
990            else
991                _ps.setLong(4, trnclsdt_readingtimeallowed);
992            
993            Long trnclsdt_estimatedtestingtime = _value.getEstimatedTestingTime();
994            if(trnclsdt_estimatedtestingtime == null)
995                _ps.setNull(5, Types.BIGINT);
996            else
997                _ps.setLong(5, trnclsdt_estimatedtestingtime);
998            
999            Long trnclsdt_testingtimeallowed = _value.getTestingTimeAllowed();
1000            if(trnclsdt_testingtimeallowed == null)
1001                _ps.setNull(6, Types.BIGINT);
1002            else
1003                _ps.setLong(6, trnclsdt_testingtimeallowed);
1004            
1005            Long trnclsdt_requiredcompletiontime = _value.getRequiredCompletionTime();
1006            if(trnclsdt_requiredcompletiontime == null)
1007                _ps.setNull(7, Types.BIGINT);
1008            else
1009                _ps.setLong(7, trnclsdt_requiredcompletiontime);
1010            
1011            WorkEffortScopePK trnclsdt_wes_workeffortscopeid = _value.getWorkEffortScopePK();
1012            if(trnclsdt_wes_workeffortscopeid == null)
1013                _ps.setNull(8, Types.BIGINT);
1014            else
1015                _ps.setLong(8, trnclsdt_wes_workeffortscopeid.getEntityId());
1016            
1017            Integer trnclsdt_defaultpercentagetopass = _value.getDefaultPercentageToPass();
1018            if(trnclsdt_defaultpercentagetopass == null)
1019                _ps.setNull(9, Types.INTEGER);
1020            else
1021                _ps.setInt(9, trnclsdt_defaultpercentagetopass);
1022            
1023            Integer trnclsdt_overallquestioncount = _value.getOverallQuestionCount();
1024            if(trnclsdt_overallquestioncount == null)
1025                _ps.setNull(10, Types.INTEGER);
1026            else
1027                _ps.setInt(10, trnclsdt_overallquestioncount);
1028            
1029            Long trnclsdt_testingvaliditytime = _value.getTestingValidityTime();
1030            if(trnclsdt_testingvaliditytime == null)
1031                _ps.setNull(11, Types.BIGINT);
1032            else
1033                _ps.setLong(11, trnclsdt_testingvaliditytime);
1034            
1035            Long trnclsdt_expiredretentiontime = _value.getExpiredRetentionTime();
1036            if(trnclsdt_expiredretentiontime == null)
1037                _ps.setNull(12, Types.BIGINT);
1038            else
1039                _ps.setLong(12, trnclsdt_expiredretentiontime);
1040            
1041            Boolean trnclsdt_alwaysreassignonexpiration = _value.getAlwaysReassignOnExpiration();
1042            if(trnclsdt_alwaysreassignonexpiration == null)
1043                _ps.setNull(13, Types.BIT);
1044            else
1045                _ps.setInt(13, trnclsdt_alwaysreassignonexpiration? 1: 0);
1046            
1047            Boolean trnclsdt_isdefault = _value.getIsDefault();
1048            if(trnclsdt_isdefault == null)
1049                _ps.setNull(14, Types.BIT);
1050            else
1051                _ps.setInt(14, trnclsdt_isdefault? 1: 0);
1052            
1053            Integer trnclsdt_sortorder = _value.getSortOrder();
1054            if(trnclsdt_sortorder == null)
1055                _ps.setNull(15, Types.INTEGER);
1056            else
1057                _ps.setInt(15, trnclsdt_sortorder);
1058            
1059            Long trnclsdt_fromtime = _value.getFromTime();
1060            if(trnclsdt_fromtime == null)
1061                _ps.setNull(16, Types.BIGINT);
1062            else
1063                _ps.setLong(16, trnclsdt_fromtime);
1064            
1065            Long trnclsdt_thrutime = _value.getThruTime();
1066            if(trnclsdt_thrutime == null)
1067                _ps.setNull(17, Types.BIGINT);
1068            else
1069                _ps.setLong(17, trnclsdt_thrutime);
1070            
1071            _ps.setLong(18, _value.getPrimaryKey().getEntityId());
1072            
1073            _value.clearHasBeenModified();
1074        }
1075        
1076        return _hasBeenModified;
1077    }
1078    
1079    @Override
1080    public void store(Session session, TrainingClassDetail entity)
1081            throws PersistenceDatabaseException {
1082        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1083        
1084        try {
1085            TrainingClassDetailValue _value = entity.getTrainingClassDetailValue();
1086            
1087            if(bindForStore(_ps, _value)) {
1088                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1089                    int _count = _ps.executeUpdate();
1090                    
1091                    if(_count != 1) {
1092                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1093                    }
1094                } else {
1095                     _ps.executeUpdate();
1096                }
1097                
1098                session.getValueCache().put(_value);
1099            }
1100        } catch (SQLException se) {
1101            throw new PersistenceDatabaseException(se);
1102        }
1103    }
1104    
1105    @Override
1106    public void store(Session session, Collection<TrainingClassDetail> entities)
1107            throws PersistenceDatabaseException {
1108        if(entities.size() > 0) {
1109            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1110            int _modifiedEntities = 0;
1111            
1112            try {
1113                for(TrainingClassDetail entity : entities) {
1114                    if(bindForStore(_ps, entity.getTrainingClassDetailValue())) {
1115                        _ps.addBatch();
1116                        _modifiedEntities++;
1117                    }
1118                }
1119                
1120                if(_modifiedEntities != 0) {
1121                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1122                        int[] _counts = _ps.executeBatch();
1123                        
1124                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1125                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1126                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1127                            }
1128                        }
1129                    } else {
1130                         _ps.executeBatch();
1131                    }
1132                    
1133                    _ps.clearBatch();
1134                    
1135                    entities.forEach((entity) -> {
1136                        session.getValueCache().put(entity.getTrainingClassDetailValue());
1137                    });
1138                }
1139            } catch (SQLException se) {
1140                throw new PersistenceDatabaseException(se);
1141            }
1142        }
1143    }
1144    
1145    @Override
1146    public void store(Collection<TrainingClassDetail> entities)
1147            throws PersistenceDatabaseException {
1148        store(ThreadSession.currentSession(), entities);
1149    }
1150    
1151    @Override
1152    public void remove(Session session, TrainingClassDetail entity)
1153            throws PersistenceDatabaseException {
1154        remove(session, entity.getPrimaryKey());
1155    }
1156    
1157    @Override
1158    public void remove(Session session, TrainingClassDetailPK pk)
1159            throws PersistenceDatabaseException {
1160        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1161        long _entityId = pk.getEntityId();
1162        
1163        try {
1164            _ps.setLong(1, _entityId);
1165            
1166            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1167                int _count = _ps.executeUpdate();
1168                
1169                if(_count != 1) {
1170                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1171                }
1172            } else {
1173                 _ps.executeUpdate();
1174            }
1175            
1176            session.getValueCache().remove(pk);
1177        } catch (SQLException se) {
1178            throw new PersistenceDatabaseException(se);
1179        }
1180        
1181        session.removed(pk, false);
1182    }
1183    
1184    @Override
1185    public void remove(Session session, Collection<TrainingClassDetailPK> pks)
1186            throws PersistenceDatabaseException {
1187        if(pks.size() > 0) {
1188            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1189            int _modifiedEntities = 0;
1190            
1191            try {
1192                for(TrainingClassDetailPK pk : pks) {
1193                    long _entityId = pk.getEntityId();
1194                    
1195                    _ps.setLong(1, _entityId);
1196                    
1197                    _ps.addBatch();
1198                    _modifiedEntities++;
1199                }
1200                
1201                if(_modifiedEntities != 0) {
1202                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1203                        int[] _counts = _ps.executeBatch();
1204                        
1205                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1206                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1207                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1208                            }
1209                        }
1210                    } else {
1211                        _ps.executeBatch();
1212                    }
1213                    
1214                    _ps.clearBatch();
1215                    
1216                    pks.forEach((pk) -> {
1217                        session.getValueCache().remove(pk);
1218                    });
1219                }
1220            } catch (SQLException se) {
1221                throw new PersistenceDatabaseException(se);
1222            }
1223            
1224            pks.forEach((pk) -> {
1225                session.removed(pk, true);
1226            });
1227        }
1228    }
1229    
1230    @Override
1231    public void remove(Collection<TrainingClassDetailPK> pks)
1232            throws PersistenceDatabaseException {
1233        remove(ThreadSession.currentSession(), pks);
1234    }
1235    
1236    @Override
1237    public boolean validPK(Session session, TrainingClassDetailPK pk)
1238            throws PersistenceDatabaseException {
1239        boolean valid = false;
1240        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1241        ResultSet _rs = null;
1242        
1243        try {
1244            _ps.setLong(1, pk.getEntityId());
1245            
1246            _rs = _ps.executeQuery();
1247            if(_rs.next()) {
1248                long _count = _rs.getLong(1);
1249                if(_rs.wasNull())
1250                    _count = 0;
1251                
1252                if(_count == 1)
1253                    valid = true;
1254            }
1255        } catch (SQLException se) {
1256            throw new PersistenceDatabaseException(se);
1257        } finally {
1258            if(_rs != null) {
1259                try {
1260                    _rs.close();
1261                } catch (SQLException se) {
1262                    // do nothing
1263                }
1264            }
1265        }
1266        
1267        return valid;
1268    }
1269    
1270}