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 * PartyTrainingClassStatusFactory.java
021 */
022
023package com.echothree.model.data.training.server.factory;
024
025import com.echothree.model.data.training.common.pk.PartyTrainingClassPK;
026import com.echothree.model.data.training.common.pk.PartyTrainingClassSessionPK;
027
028import com.echothree.model.data.training.server.entity.PartyTrainingClass;
029import com.echothree.model.data.training.server.entity.PartyTrainingClassSession;
030
031import com.echothree.model.data.training.common.PartyTrainingClassStatusConstants;
032import com.echothree.model.data.training.common.pk.PartyTrainingClassStatusPK;
033import com.echothree.model.data.training.server.value.PartyTrainingClassStatusValue;
034import com.echothree.model.data.training.server.entity.PartyTrainingClassStatus;
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 PartyTrainingClassStatusFactory
063        implements BaseFactory<PartyTrainingClassStatusPK, PartyTrainingClassStatus> {
064    
065    @Inject
066    Session session;
067    
068    //private static final Logger log = LoggerFactory.getLogger(PartyTrainingClassStatusFactory.class);
069    
070    final private static String SQL_SELECT_READ_ONLY = "SELECT ptrnclsst_partytrainingclassstatusid, ptrnclsst_ptrncls_partytrainingclassid, ptrnclsst_partytrainingclasssessionsequence, ptrnclsst_lastpartytrainingclasssessionid FROM partytrainingclassstatuses WHERE ptrnclsst_partytrainingclassstatusid = ?";
071    final private static String SQL_SELECT_READ_WRITE = "SELECT ptrnclsst_partytrainingclassstatusid, ptrnclsst_ptrncls_partytrainingclassid, ptrnclsst_partytrainingclasssessionsequence, ptrnclsst_lastpartytrainingclasssessionid FROM partytrainingclassstatuses WHERE ptrnclsst_partytrainingclassstatusid = ? FOR UPDATE";
072    final private static String SQL_INSERT = "INSERT INTO partytrainingclassstatuses (ptrnclsst_partytrainingclassstatusid, ptrnclsst_ptrncls_partytrainingclassid, ptrnclsst_partytrainingclasssessionsequence, ptrnclsst_lastpartytrainingclasssessionid) VALUES (?, ?, ?, ?)";
073    final private static String SQL_UPDATE = "UPDATE partytrainingclassstatuses SET ptrnclsst_ptrncls_partytrainingclassid = ?, ptrnclsst_partytrainingclasssessionsequence = ?, ptrnclsst_lastpartytrainingclasssessionid = ? WHERE ptrnclsst_partytrainingclassstatusid = ?";
074    final private static String SQL_DELETE = "DELETE FROM partytrainingclassstatuses WHERE ptrnclsst_partytrainingclassstatusid = ?";
075    final private static String SQL_VALID = "SELECT COUNT(*) FROM partytrainingclassstatuses WHERE ptrnclsst_partytrainingclassstatusid = ?";
076    
077    final private static String PK_COLUMN = "ptrnclsst_partytrainingclassstatusid";
078    final private static String ALL_COLUMNS = "ptrnclsst_partytrainingclassstatusid, ptrnclsst_ptrncls_partytrainingclassid, ptrnclsst_partytrainingclasssessionsequence, ptrnclsst_lastpartytrainingclasssessionid";
079    final public static String TABLE_NAME = "partytrainingclassstatuses";
080    
081    final public static String PTRNCLSST_PARTYTRAININGCLASSSTATUSID = "ptrnclsst_partytrainingclassstatusid";
082    final public static String PTRNCLSST_PTRNCLS_PARTYTRAININGCLASSID = "ptrnclsst_ptrncls_partytrainingclassid";
083    final public static String PTRNCLSST_PARTYTRAININGCLASSSESSIONSEQUENCE = "ptrnclsst_partytrainingclasssessionsequence";
084    final public static String PTRNCLSST_LASTPARTYTRAININGCLASSSESSIONID = "ptrnclsst_lastpartytrainingclasssessionid";
085    
086    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(PartyTrainingClassStatusConstants.COMPONENT_VENDOR_NAME, PartyTrainingClassStatusConstants.ENTITY_TYPE_NAME);
087    
088    /** Creates a new instance of PartyTrainingClassStatusFactory */
089    protected PartyTrainingClassStatusFactory() {
090        super();
091    }
092    
093    public static PartyTrainingClassStatusFactory getInstance() {
094        return CDI.current().select(PartyTrainingClassStatusFactory.class).get();
095    }
096    
097    @Override
098    public String getPKColumn() {
099        return PK_COLUMN;
100    }
101    
102    @Override
103    public String getAllColumns() {
104        return ALL_COLUMNS;
105    }
106    
107    @Override
108    public String getTableName() {
109        return TABLE_NAME;
110    }
111    
112    @Override
113    public String getComponentVendorName() {
114        return PartyTrainingClassStatusConstants.COMPONENT_VENDOR_NAME;
115    }
116    
117    @Override
118    public String getEntityTypeName() {
119        return PartyTrainingClassStatusConstants.ENTITY_TYPE_NAME;
120    }
121    
122    public PreparedStatement prepareStatement(String query) {
123        return session.prepareStatement(PartyTrainingClassStatusFactory.class, query);
124    }
125    
126    public PartyTrainingClassStatusPK getNextPK() {
127        return new PartyTrainingClassStatusPK(entityIdGenerator.getNextEntityId());
128    }
129    
130    public Set<PartyTrainingClassStatusPK> getPKsFromResultSetAsSet(ResultSet rs)
131            throws PersistenceDatabaseException {
132        Set<PartyTrainingClassStatusPK> _result = new HashSet<>();
133        
134        try {
135            while(rs.next()) {
136                _result.add(getPKFromResultSet(rs));
137            }
138        } catch (SQLException se) {
139            throw new PersistenceDatabaseException(se);
140        }
141        
142        return _result;
143    }
144    
145    public java.util.List<PartyTrainingClassStatusPK> getPKsFromResultSetAsList(ResultSet rs)
146            throws PersistenceDatabaseException {
147        java.util.List<PartyTrainingClassStatusPK> _result = new ArrayList<>();
148        
149        try {
150            while(rs.next()) {
151                _result.add(getPKFromResultSet(rs));
152            }
153        } catch (SQLException se) {
154            throw new PersistenceDatabaseException(se);
155        }
156        
157        return _result;
158    }
159    
160    public PartyTrainingClassStatusPK getPKFromResultSet(ResultSet rs)
161            throws PersistenceDatabaseException {
162        PartyTrainingClassStatusPK _result;
163        
164        try {
165            long ptrnclsst_partytrainingclassstatusid = rs.getLong(PTRNCLSST_PARTYTRAININGCLASSSTATUSID);
166            Long _entityId = rs.wasNull() ? null : ptrnclsst_partytrainingclassstatusid;
167            
168            _result = new PartyTrainingClassStatusPK(_entityId);
169        } catch (SQLException se) {
170            throw new PersistenceDatabaseException(se);
171        }
172        
173        return _result;
174    }
175    
176    public java.util.List<PartyTrainingClassStatusValue> getValuesFromPKs(Collection<PartyTrainingClassStatusPK> pks)
177            throws PersistenceDatabaseException {
178        java.util.List<PartyTrainingClassStatusValue> _values = new ArrayList<>(pks.size());
179        
180        for(PartyTrainingClassStatusPK _pk: pks) {
181            _values.add(getValueFromPK(_pk));
182        }
183        
184        return _values;
185    }
186    
187    public PartyTrainingClassStatusValue getValueFromPK(PartyTrainingClassStatusPK pk)
188            throws PersistenceDatabaseException {
189        PartyTrainingClassStatusValue _value;
190        
191        // See if we already have the entity in the session cache
192        PartyTrainingClassStatus _entity = (PartyTrainingClassStatus)session.getEntity(pk);
193        if(_entity == null)
194            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getPartyTrainingClassStatusValue();
195        else
196            _value = _entity.getPartyTrainingClassStatusValue();
197        
198        return _value;
199    }
200    
201    public java.util.List<PartyTrainingClassStatusValue> getValuesFromResultSet(ResultSet rs)
202            throws PersistenceDatabaseException {
203        java.util.List<PartyTrainingClassStatusValue> _result = new ArrayList<>();
204        
205        try {
206            while(rs.next()) {
207                _result.add(getValueFromResultSet(rs));
208            }
209        } catch (SQLException se) {
210            throw new PersistenceDatabaseException(se);
211        }
212        
213        return _result;
214    }
215    
216    public PartyTrainingClassStatusValue getValueFromResultSet(ResultSet rs)
217            throws PersistenceDatabaseException {
218        PartyTrainingClassStatusValue _value;
219        
220        try {
221            Long ptrnclsst_partytrainingclassstatusid = rs.getLong(PTRNCLSST_PARTYTRAININGCLASSSTATUSID);
222            PartyTrainingClassStatusPK _pk = new PartyTrainingClassStatusPK(ptrnclsst_partytrainingclassstatusid);
223            
224            // See if we already have the entity in the session cache
225            PartyTrainingClassStatus _entity = (PartyTrainingClassStatus)session.getEntity(_pk);
226            
227            if(_entity == null) {
228                Long ptrnclsst_ptrncls_partytrainingclassid = rs.getLong(PTRNCLSST_PTRNCLS_PARTYTRAININGCLASSID);
229                if(rs.wasNull())
230                    ptrnclsst_ptrncls_partytrainingclassid = null;
231                
232                Integer ptrnclsst_partytrainingclasssessionsequence = rs.getInt(PTRNCLSST_PARTYTRAININGCLASSSESSIONSEQUENCE);
233                if(rs.wasNull())
234                    ptrnclsst_partytrainingclasssessionsequence = null;
235                
236                Long ptrnclsst_lastpartytrainingclasssessionid = rs.getLong(PTRNCLSST_LASTPARTYTRAININGCLASSSESSIONID);
237                if(rs.wasNull())
238                    ptrnclsst_lastpartytrainingclasssessionid = null;
239                
240                _value = new PartyTrainingClassStatusValue(_pk, new PartyTrainingClassPK(ptrnclsst_ptrncls_partytrainingclassid), ptrnclsst_partytrainingclasssessionsequence, new PartyTrainingClassSessionPK(ptrnclsst_lastpartytrainingclasssessionid));
241            } else
242                _value = _entity.getPartyTrainingClassStatusValue();
243        } catch (SQLException se) {
244            throw new PersistenceDatabaseException(se);
245        }
246        
247        return _value;
248    }
249    
250    public java.util.List<PartyTrainingClassStatus> getEntitiesFromPKs(EntityPermission entityPermission, Collection<PartyTrainingClassStatusPK> pks)
251            throws PersistenceDatabaseException {
252        java.util.List<PartyTrainingClassStatus> _entities = new ArrayList<>(pks.size());
253        
254        for(PartyTrainingClassStatusPK _pk: pks) {
255            _entities.add(getEntityFromPK(entityPermission, _pk));
256        }
257        
258        return _entities;
259    }
260    
261    public PartyTrainingClassStatus getEntityFromValue(EntityPermission entityPermission, PartyTrainingClassStatusValue value) {
262        return getEntityFromPK(entityPermission, value.getPrimaryKey());
263    }
264    
265    public PartyTrainingClassStatus getEntityFromCache(PartyTrainingClassStatusPK pk) {
266        PartyTrainingClassStatusValue _value = (PartyTrainingClassStatusValue)session.getValueCache().get(pk);
267    
268        return _value == null ? null : new PartyTrainingClassStatus(_value, EntityPermission.READ_ONLY);
269    }
270    
271    public PartyTrainingClassStatus getEntityFromPK(EntityPermission entityPermission, PartyTrainingClassStatusPK pk)
272            throws PersistenceDatabaseException {
273        PartyTrainingClassStatus _entity;
274        
275        // See if we already have the entity in the session cache
276        _entity = (PartyTrainingClassStatus)session.getEntity(pk);
277        if(_entity != null) {
278            // If the requested permission is READ_WRITE, and the cached permission is
279            // READ_ONLY, then pretend that the cached object wasn't found, and create
280            // a new entity that is READ_WRITE.
281            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
282                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
283                    _entity = null;
284            }
285        }
286        
287        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
288            _entity = getEntityFromCache(pk);
289        }
290        
291        if(_entity == null) {
292            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
293            long _entityId = pk.getEntityId();
294            ResultSet _rs = null;
295            
296            try {
297                _ps.setLong(1, _entityId);
298                _rs = _ps.executeQuery();
299                if(_rs.next()) {
300                    _entity = getEntityFromResultSet(entityPermission, _rs);
301                }
302            } catch (SQLException se) {
303                throw new PersistenceDatabaseException(se);
304            } finally {
305                if(_rs != null) {
306                    try {
307                        _rs.close();
308                    } catch (SQLException se) {
309                        // do nothing
310                    }
311                }
312            }
313        }
314        
315        return _entity;
316    }
317    
318    public Set<PartyTrainingClassStatusPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
319            throws PersistenceDatabaseException {
320        Set<PartyTrainingClassStatusPK> _pks;
321        ResultSet _rs = null;
322        
323        try {
324            if(params.length != 0) {
325                Session.setQueryParams(ps, params);
326            }
327            
328            _rs = ps.executeQuery();
329            _pks = getPKsFromResultSetAsSet(_rs);
330            _rs.close();
331        } catch (SQLException se) {
332            throw new PersistenceDatabaseException(se);
333        } finally {
334            if(_rs != null) {
335                try {
336                    _rs.close();
337                } catch (SQLException se) {
338                    // do nothing
339                }
340            }
341        }
342        
343        return _pks;
344    }
345    
346    public java.util.List<PartyTrainingClassStatusPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
347            throws PersistenceDatabaseException {
348        java.util.List<PartyTrainingClassStatusPK> _pks;
349        ResultSet _rs = null;
350        
351        try {
352            if(params.length != 0) {
353                Session.setQueryParams(ps, params);
354            }
355            
356            _rs = ps.executeQuery();
357            _pks = getPKsFromResultSetAsList(_rs);
358            _rs.close();
359        } catch (SQLException se) {
360            throw new PersistenceDatabaseException(se);
361        } finally {
362            if(_rs != null) {
363                try {
364                    _rs.close();
365                } catch (SQLException se) {
366                    // do nothing
367                }
368            }
369        }
370        
371        return _pks;
372    }
373    
374    public PartyTrainingClassStatusPK getPKFromQuery(PreparedStatement ps, final Object... params)
375            throws PersistenceDatabaseException {
376        PartyTrainingClassStatusPK _pk = null;
377        ResultSet _rs = null;
378        
379        try {
380            if(params.length != 0) {
381                Session.setQueryParams(ps, params);
382            }
383            
384            _rs = ps.executeQuery();
385            if(_rs.next()) {
386                _pk = getPKFromResultSet(_rs);
387            }
388            _rs.close();
389        } catch (SQLException se) {
390            throw new PersistenceDatabaseException(se);
391        } finally {
392            if(_rs != null) {
393                try {
394                    _rs.close();
395                } catch (SQLException se) {
396                    // do nothing
397                }
398            }
399        }
400        
401        return _pk;
402    }
403    
404    public java.util.List<PartyTrainingClassStatus> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
405            throws PersistenceDatabaseException {
406        PreparedStatement ps = session.prepareStatement(PartyTrainingClassStatusFactory.class, queryMap.get(entityPermission));
407        
408        return getEntitiesFromQuery(entityPermission, ps, params);
409    }
410    
411    public java.util.List<PartyTrainingClassStatus> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
412            throws PersistenceDatabaseException {
413        PreparedStatement ps = session.prepareStatement(PartyTrainingClassStatusFactory.class, queryMap.get(entityPermission));
414        
415        return getEntitiesFromQuery(entityPermission, ps);
416    }
417    
418    public java.util.List<PartyTrainingClassStatus> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
419            throws PersistenceDatabaseException {
420        java.util.List<PartyTrainingClassStatus> _entities;
421        ResultSet _rs = null;
422        
423        try {
424            if(params.length != 0) {
425                Session.setQueryParams(ps, params);
426            }
427            
428            _rs = ps.executeQuery();
429            _entities = getEntitiesFromResultSet(entityPermission, _rs);
430            _rs.close();
431        } catch (SQLException se) {
432            throw new PersistenceDatabaseException(se);
433        } finally {
434            if(_rs != null) {
435                try {
436                    _rs.close();
437                } catch (SQLException se) {
438                    // do nothing
439                }
440            }
441        }
442        
443        return _entities;
444    }
445    
446    public PartyTrainingClassStatus getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
447            throws PersistenceDatabaseException {
448        PreparedStatement ps = session.prepareStatement(PartyTrainingClassStatusFactory.class, queryMap.get(entityPermission));
449        
450        return getEntityFromQuery(entityPermission, ps, params);
451    }
452    
453    public PartyTrainingClassStatus getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
454            throws PersistenceDatabaseException {
455        PreparedStatement ps = session.prepareStatement(PartyTrainingClassStatusFactory.class, queryMap.get(entityPermission));
456        
457        return getEntityFromQuery(entityPermission, ps);
458    }
459    
460    public PartyTrainingClassStatus getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
461            throws PersistenceDatabaseException {
462        PartyTrainingClassStatus _entity = null;
463        ResultSet _rs = null;
464        
465        try {
466            if(params.length != 0) {
467                Session.setQueryParams(ps, params);
468            }
469            
470            _rs = ps.executeQuery();
471            if(_rs.next()) {
472                _entity = getEntityFromResultSet(entityPermission, _rs);
473            }
474            _rs.close();
475        } catch (SQLException se) {
476            throw new PersistenceDatabaseException(se);
477        } finally {
478            if(_rs != null) {
479                try {
480                    _rs.close();
481                } catch (SQLException se) {
482                    // do nothing
483                }
484            }
485        }
486        
487        return _entity;
488    }
489    
490    public java.util.List<PartyTrainingClassStatus> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
491            throws PersistenceDatabaseException {
492        java.util.List<PartyTrainingClassStatus> _result = new ArrayList<>();
493        
494        try {
495            while(rs.next()) {
496                _result.add(getEntityFromResultSet(entityPermission, rs));
497            }
498        } catch (SQLException se) {
499            throw new PersistenceDatabaseException(se);
500        }
501        
502        return _result;
503    }
504    
505    public PartyTrainingClassStatus getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
506            throws PersistenceDatabaseException {
507        PartyTrainingClassStatus _entity;
508        
509        try {
510            Long ptrnclsst_partytrainingclassstatusid = rs.getLong(PTRNCLSST_PARTYTRAININGCLASSSTATUSID);
511            PartyTrainingClassStatusPK _pk = new PartyTrainingClassStatusPK(ptrnclsst_partytrainingclassstatusid);
512            
513            // See if we already have the entity in the session cache
514            _entity = (PartyTrainingClassStatus)session.getEntity(_pk);
515            if(_entity != null) {
516                // If the requested permission is READ_WRITE, and the cached permission is
517                // READ_ONLY, then pretend that the cached object wasn't found, and create
518                // a new entity that is READ_WRITE.
519                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
520                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
521                        _entity = null;
522                }
523            }
524            boolean foundInSessionCache = _entity != null;
525            
526            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
527                _entity = getEntityFromCache(_pk);
528            }
529            
530            if(_entity == null) {
531                Long ptrnclsst_ptrncls_partytrainingclassid = rs.getLong(PTRNCLSST_PTRNCLS_PARTYTRAININGCLASSID);
532                if(rs.wasNull())
533                    ptrnclsst_ptrncls_partytrainingclassid = null;
534                
535                Integer ptrnclsst_partytrainingclasssessionsequence = rs.getInt(PTRNCLSST_PARTYTRAININGCLASSSESSIONSEQUENCE);
536                if(rs.wasNull())
537                    ptrnclsst_partytrainingclasssessionsequence = null;
538                
539                Long ptrnclsst_lastpartytrainingclasssessionid = rs.getLong(PTRNCLSST_LASTPARTYTRAININGCLASSSESSIONID);
540                if(rs.wasNull())
541                    ptrnclsst_lastpartytrainingclasssessionid = null;
542                
543                PartyTrainingClassStatusValue _value = new PartyTrainingClassStatusValue(_pk, ptrnclsst_ptrncls_partytrainingclassid == null? null: new PartyTrainingClassPK(ptrnclsst_ptrncls_partytrainingclassid), ptrnclsst_partytrainingclasssessionsequence, ptrnclsst_lastpartytrainingclasssessionid == null? null: new PartyTrainingClassSessionPK(ptrnclsst_lastpartytrainingclasssessionid));
544                _entity = new PartyTrainingClassStatus(_value, entityPermission);
545            }
546            
547            if(!foundInSessionCache) {
548                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
549                    session.putReadOnlyEntity(_pk, _entity);
550                    session.getValueCache().put(_entity.getPartyTrainingClassStatusValue());
551                } else {
552                    session.putReadWriteEntity(_pk, _entity);
553                }
554            }
555        } catch (SQLException se) {
556            throw new PersistenceDatabaseException(se);
557        }
558        
559        return _entity;
560    }
561    
562    public PartyTrainingClassStatus create(PartyTrainingClass partyTrainingClass, Integer partyTrainingClassSessionSequence, PartyTrainingClassSession lastPartyTrainingClassSession)
563            throws PersistenceDatabaseException, PersistenceNotNullException {
564        return create(partyTrainingClass == null ? null : partyTrainingClass.getPrimaryKey(), partyTrainingClassSessionSequence, lastPartyTrainingClassSession == null ? null : lastPartyTrainingClassSession.getPrimaryKey());
565    }
566    
567    private void bindForCreate(PreparedStatement _ps, PartyTrainingClassStatusValue _value)
568            throws SQLException {
569        _ps.setLong(1, _value.getEntityId());
570        
571        PartyTrainingClassPK ptrnclsst_ptrncls_partytrainingclassid = _value.getPartyTrainingClassPK();
572        if(ptrnclsst_ptrncls_partytrainingclassid == null)
573            _ps.setNull(2, Types.BIGINT);
574        else
575            _ps.setLong(2, ptrnclsst_ptrncls_partytrainingclassid.getEntityId());
576            
577        Integer ptrnclsst_partytrainingclasssessionsequence = _value.getPartyTrainingClassSessionSequence();
578        if(ptrnclsst_partytrainingclasssessionsequence == null)
579            _ps.setNull(3, Types.INTEGER);
580        else
581            _ps.setInt(3, ptrnclsst_partytrainingclasssessionsequence);
582            
583        PartyTrainingClassSessionPK ptrnclsst_lastpartytrainingclasssessionid = _value.getLastPartyTrainingClassSessionPK();
584        if(ptrnclsst_lastpartytrainingclasssessionid == null)
585            _ps.setNull(4, Types.BIGINT);
586        else
587            _ps.setLong(4, ptrnclsst_lastpartytrainingclasssessionid.getEntityId());
588            
589    }
590    
591    public PartyTrainingClassStatus create(PartyTrainingClassPK partyTrainingClassPK, Integer partyTrainingClassSessionSequence, PartyTrainingClassSessionPK lastPartyTrainingClassSessionPK)
592            throws PersistenceDatabaseException, PersistenceNotNullException {
593        PartyTrainingClassStatusPK _pk = getNextPK();
594        PartyTrainingClassStatusValue _value = new PartyTrainingClassStatusValue(_pk, partyTrainingClassPK, partyTrainingClassSessionSequence, lastPartyTrainingClassSessionPK);
595        
596        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
597        
598        try {
599            bindForCreate(_ps, _value);
600            
601            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
602                int _count = _ps.executeUpdate();
603                
604                if(_count != 1) {
605                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
606                }
607            } else {
608                 _ps.executeUpdate();
609            }
610            
611            session.getValueCache().put(_value);
612        } catch (SQLException se) {
613            throw new PersistenceDatabaseException(se);
614        }
615        
616        PartyTrainingClassStatus _entity = new PartyTrainingClassStatus(_value, EntityPermission.READ_ONLY);
617        session.putReadOnlyEntity(_pk, _entity);
618        
619        return _entity;
620    }
621    
622    public void create(Collection<PartyTrainingClassStatusValue> _values)
623            throws PersistenceDatabaseException, PersistenceNotNullException {
624        int _size = _values.size();
625        
626        if(_size > 0) {
627            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
628            List<PartyTrainingClassStatusValue> _cacheValues = new ArrayList<>(_size);
629            
630            try {
631                for(PartyTrainingClassStatusValue _value : _values) {
632                    _value.setEntityId(entityIdGenerator.getNextEntityId());
633                    bindForCreate(_ps, _value);
634                    
635                    _ps.addBatch();
636                    
637                    _cacheValues.add(_value);
638                }
639                
640                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
641                    int[] _counts = _ps.executeBatch();
642                    
643                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
644                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
645                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
646                        }
647                    }
648                } else {
649                     _ps.executeBatch();
650                }
651                
652                _ps.clearBatch();
653            } catch (SQLException se) {
654                throw new PersistenceDatabaseException(se);
655            }
656            
657            _cacheValues.forEach((_cacheValue) -> {
658                PartyTrainingClassStatus _cacheEntity = new PartyTrainingClassStatus(_cacheValue, EntityPermission.READ_ONLY);
659                
660                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
661            });
662        }
663    }
664    
665    private boolean bindForStore(PreparedStatement _ps, PartyTrainingClassStatusValue _value)
666            throws SQLException {
667        boolean _hasBeenModified = _value.hasBeenModified();
668        
669        if(_hasBeenModified) {
670            PartyTrainingClassPK ptrnclsst_ptrncls_partytrainingclassid = _value.getPartyTrainingClassPK();
671            if(ptrnclsst_ptrncls_partytrainingclassid == null)
672                _ps.setNull(1, Types.BIGINT);
673            else
674                _ps.setLong(1, ptrnclsst_ptrncls_partytrainingclassid.getEntityId());
675            
676            Integer ptrnclsst_partytrainingclasssessionsequence = _value.getPartyTrainingClassSessionSequence();
677            if(ptrnclsst_partytrainingclasssessionsequence == null)
678                _ps.setNull(2, Types.INTEGER);
679            else
680                _ps.setInt(2, ptrnclsst_partytrainingclasssessionsequence);
681            
682            PartyTrainingClassSessionPK ptrnclsst_lastpartytrainingclasssessionid = _value.getLastPartyTrainingClassSessionPK();
683            if(ptrnclsst_lastpartytrainingclasssessionid == null)
684                _ps.setNull(3, Types.BIGINT);
685            else
686                _ps.setLong(3, ptrnclsst_lastpartytrainingclasssessionid.getEntityId());
687            
688            _ps.setLong(4, _value.getPrimaryKey().getEntityId());
689            
690            _value.clearHasBeenModified();
691        }
692        
693        return _hasBeenModified;
694    }
695    
696    @Override
697    public void store(PartyTrainingClassStatus entity)
698            throws PersistenceDatabaseException {
699        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
700        
701        try {
702            PartyTrainingClassStatusValue _value = entity.getPartyTrainingClassStatusValue();
703            
704            if(bindForStore(_ps, _value)) {
705                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
706                    int _count = _ps.executeUpdate();
707                    
708                    if(_count != 1) {
709                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
710                    }
711                } else {
712                     _ps.executeUpdate();
713                }
714                
715                session.getValueCache().put(_value);
716            }
717        } catch (SQLException se) {
718            throw new PersistenceDatabaseException(se);
719        }
720    }
721    
722    @Override
723    public void store(Collection<PartyTrainingClassStatus> entities)
724            throws PersistenceDatabaseException {
725        if(entities.size() > 0) {
726            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
727            int _modifiedEntities = 0;
728            
729            try {
730                for(PartyTrainingClassStatus entity : entities) {
731                    if(bindForStore(_ps, entity.getPartyTrainingClassStatusValue())) {
732                        _ps.addBatch();
733                        _modifiedEntities++;
734                    }
735                }
736                
737                if(_modifiedEntities != 0) {
738                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
739                        int[] _counts = _ps.executeBatch();
740                        
741                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
742                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
743                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
744                            }
745                        }
746                    } else {
747                         _ps.executeBatch();
748                    }
749                    
750                    _ps.clearBatch();
751                    
752                    entities.forEach((entity) -> {
753                        session.getValueCache().put(entity.getPartyTrainingClassStatusValue());
754                    });
755                }
756            } catch (SQLException se) {
757                throw new PersistenceDatabaseException(se);
758            }
759        }
760    }
761    
762    @Override
763    public void remove(PartyTrainingClassStatus entity)
764            throws PersistenceDatabaseException {
765        remove(entity.getPrimaryKey());
766    }
767    
768    @Override
769    public void remove(PartyTrainingClassStatusPK pk)
770            throws PersistenceDatabaseException {
771        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
772        long _entityId = pk.getEntityId();
773        
774        try {
775            _ps.setLong(1, _entityId);
776            
777            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
778                int _count = _ps.executeUpdate();
779                
780                if(_count != 1) {
781                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
782                }
783            } else {
784                 _ps.executeUpdate();
785            }
786            
787            session.getValueCache().remove(pk);
788        } catch (SQLException se) {
789            throw new PersistenceDatabaseException(se);
790        }
791        
792        session.removed(pk, false);
793    }
794    
795    @Override
796    public void remove(Collection<PartyTrainingClassStatusPK> pks)
797            throws PersistenceDatabaseException {
798        if(pks.size() > 0) {
799            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
800            int _modifiedEntities = 0;
801            
802            try {
803                for(PartyTrainingClassStatusPK pk : pks) {
804                    long _entityId = pk.getEntityId();
805                    
806                    _ps.setLong(1, _entityId);
807                    
808                    _ps.addBatch();
809                    _modifiedEntities++;
810                }
811                
812                if(_modifiedEntities != 0) {
813                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
814                        int[] _counts = _ps.executeBatch();
815                        
816                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
817                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
818                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
819                            }
820                        }
821                    } else {
822                        _ps.executeBatch();
823                    }
824                    
825                    _ps.clearBatch();
826                    
827                    pks.forEach((pk) -> {
828                        session.getValueCache().remove(pk);
829                    });
830                }
831            } catch (SQLException se) {
832                throw new PersistenceDatabaseException(se);
833            }
834            
835            pks.forEach((pk) -> {
836                session.removed(pk, true);
837            });
838        }
839    }
840    
841    @Override
842    public boolean validPK(PartyTrainingClassStatusPK pk)
843            throws PersistenceDatabaseException {
844        boolean valid = false;
845        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
846        ResultSet _rs = null;
847        
848        try {
849            _ps.setLong(1, pk.getEntityId());
850            
851            _rs = _ps.executeQuery();
852            if(_rs.next()) {
853                long _count = _rs.getLong(1);
854                if(_rs.wasNull())
855                    _count = 0;
856                
857                if(_count == 1)
858                    valid = true;
859            }
860        } catch (SQLException se) {
861            throw new PersistenceDatabaseException(se);
862        } finally {
863            if(_rs != null) {
864                try {
865                    _rs.close();
866                } catch (SQLException se) {
867                    // do nothing
868                }
869            }
870        }
871        
872        return valid;
873    }
874    
875}