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