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