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