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