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