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