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 * CarrierServiceDetailFactory.java
021 */
022
023package com.echothree.model.data.carrier.server.factory;
024
025import com.echothree.model.data.carrier.common.pk.CarrierServicePK;
026import com.echothree.model.data.party.common.pk.PartyPK;
027import com.echothree.model.data.selector.common.pk.SelectorPK;
028
029import com.echothree.model.data.carrier.server.entity.CarrierService;
030import com.echothree.model.data.party.server.entity.Party;
031import com.echothree.model.data.selector.server.entity.Selector;
032
033import com.echothree.model.data.carrier.common.CarrierServiceDetailConstants;
034import com.echothree.model.data.carrier.common.pk.CarrierServiceDetailPK;
035import com.echothree.model.data.carrier.server.value.CarrierServiceDetailValue;
036import com.echothree.model.data.carrier.server.entity.CarrierServiceDetail;
037import com.echothree.util.common.exception.PersistenceDatabaseException;
038import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
039import com.echothree.util.common.exception.PersistenceNotNullException;
040import com.echothree.util.server.persistence.BaseFactory;
041import com.echothree.util.server.persistence.EntityIdGenerator;
042import com.echothree.util.server.persistence.EntityPermission;
043import com.echothree.util.server.persistence.PersistenceDebugFlags;
044import com.echothree.util.server.persistence.Session;
045import java.sql.PreparedStatement;
046import java.sql.ResultSet;
047import java.sql.SQLException;
048import java.sql.Types;
049import java.io.ByteArrayInputStream;
050import java.io.StringReader;
051import java.util.ArrayList;
052import java.util.Collection;
053import java.util.HashSet;
054import java.util.List;
055import java.util.Map;
056import java.util.Set;
057import javax.enterprise.context.ApplicationScoped;
058import javax.enterprise.inject.spi.CDI;
059import javax.inject.Inject;
060import org.jooq.ResultQuery;
061import org.slf4j.Logger;
062import org.slf4j.LoggerFactory;
063
064@ApplicationScoped
065public class CarrierServiceDetailFactory
066        implements BaseFactory<CarrierServiceDetailPK, CarrierServiceDetail> {
067    
068    @Inject
069    Session session;
070    
071    //private static final Logger log = LoggerFactory.getLogger(CarrierServiceDetailFactory.class);
072    
073    final private static String SQL_SELECT_READ_ONLY = "SELECT crrsrvdt_carrierservicedetailid, crrsrvdt_crrsrv_carrierserviceid, crrsrvdt_carrierpartyid, crrsrvdt_carrierservicename, crrsrvdt_geocodeselectorid, crrsrvdt_itemselectorid, crrsrvdt_isdefault, crrsrvdt_sortorder, crrsrvdt_fromtime, crrsrvdt_thrutime FROM carrierservicedetails WHERE crrsrvdt_carrierservicedetailid = ?";
074    final private static String SQL_SELECT_READ_WRITE = "SELECT crrsrvdt_carrierservicedetailid, crrsrvdt_crrsrv_carrierserviceid, crrsrvdt_carrierpartyid, crrsrvdt_carrierservicename, crrsrvdt_geocodeselectorid, crrsrvdt_itemselectorid, crrsrvdt_isdefault, crrsrvdt_sortorder, crrsrvdt_fromtime, crrsrvdt_thrutime FROM carrierservicedetails WHERE crrsrvdt_carrierservicedetailid = ? FOR UPDATE";
075    final private static String SQL_INSERT = "INSERT INTO carrierservicedetails (crrsrvdt_carrierservicedetailid, crrsrvdt_crrsrv_carrierserviceid, crrsrvdt_carrierpartyid, crrsrvdt_carrierservicename, crrsrvdt_geocodeselectorid, crrsrvdt_itemselectorid, crrsrvdt_isdefault, crrsrvdt_sortorder, crrsrvdt_fromtime, crrsrvdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
076    final private static String SQL_UPDATE = "UPDATE carrierservicedetails SET crrsrvdt_crrsrv_carrierserviceid = ?, crrsrvdt_carrierpartyid = ?, crrsrvdt_carrierservicename = ?, crrsrvdt_geocodeselectorid = ?, crrsrvdt_itemselectorid = ?, crrsrvdt_isdefault = ?, crrsrvdt_sortorder = ?, crrsrvdt_fromtime = ?, crrsrvdt_thrutime = ? WHERE crrsrvdt_carrierservicedetailid = ?";
077    final private static String SQL_DELETE = "DELETE FROM carrierservicedetails WHERE crrsrvdt_carrierservicedetailid = ?";
078    final private static String SQL_VALID = "SELECT COUNT(*) FROM carrierservicedetails WHERE crrsrvdt_carrierservicedetailid = ?";
079    
080    final public static String CRRSRVDT_CARRIERSERVICEDETAILID = "crrsrvdt_carrierservicedetailid";
081    final public static String CRRSRVDT_CRRSRV_CARRIERSERVICEID = "crrsrvdt_crrsrv_carrierserviceid";
082    final public static String CRRSRVDT_CARRIERPARTYID = "crrsrvdt_carrierpartyid";
083    final public static String CRRSRVDT_CARRIERSERVICENAME = "crrsrvdt_carrierservicename";
084    final public static String CRRSRVDT_GEOCODESELECTORID = "crrsrvdt_geocodeselectorid";
085    final public static String CRRSRVDT_ITEMSELECTORID = "crrsrvdt_itemselectorid";
086    final public static String CRRSRVDT_ISDEFAULT = "crrsrvdt_isdefault";
087    final public static String CRRSRVDT_SORTORDER = "crrsrvdt_sortorder";
088    final public static String CRRSRVDT_FROMTIME = "crrsrvdt_fromtime";
089    final public static String CRRSRVDT_THRUTIME = "crrsrvdt_thrutime";
090    
091    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CarrierServiceDetailConstants.COMPONENT_VENDOR_NAME, CarrierServiceDetailConstants.ENTITY_TYPE_NAME);
092    
093    /** Creates a new instance of CarrierServiceDetailFactory */
094    protected CarrierServiceDetailFactory() {
095        super();
096    }
097    
098    public static CarrierServiceDetailFactory getInstance() {
099        return CDI.current().select(CarrierServiceDetailFactory.class).get();
100    }
101    
102    @Override
103    public String getComponentVendorName() {
104        return CarrierServiceDetailConstants.COMPONENT_VENDOR_NAME;
105    }
106    
107    @Override
108    public String getEntityTypeName() {
109        return CarrierServiceDetailConstants.ENTITY_TYPE_NAME;
110    }
111    
112    public PreparedStatement prepareStatement(String query) {
113        return session.prepareStatement(query);
114    }
115    
116    public CarrierServiceDetailPK getNextPK() {
117        return new CarrierServiceDetailPK(entityIdGenerator.getNextEntityId());
118    }
119    
120    public Set<CarrierServiceDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
121            throws PersistenceDatabaseException {
122        Set<CarrierServiceDetailPK> _result = new HashSet<>();
123        
124        try {
125            while(rs.next()) {
126                _result.add(getPKFromResultSet(rs));
127            }
128        } catch (SQLException se) {
129            throw new PersistenceDatabaseException(se);
130        }
131        
132        return _result;
133    }
134    
135    public java.util.List<CarrierServiceDetailPK> getPKsFromResultSetAsList(ResultSet rs)
136            throws PersistenceDatabaseException {
137        java.util.List<CarrierServiceDetailPK> _result = new ArrayList<>();
138        
139        try {
140            while(rs.next()) {
141                _result.add(getPKFromResultSet(rs));
142            }
143        } catch (SQLException se) {
144            throw new PersistenceDatabaseException(se);
145        }
146        
147        return _result;
148    }
149    
150    public CarrierServiceDetailPK getPKFromResultSet(ResultSet rs)
151            throws PersistenceDatabaseException {
152        CarrierServiceDetailPK _result;
153        
154        try {
155            long crrsrvdt_carrierservicedetailid = rs.getLong(CRRSRVDT_CARRIERSERVICEDETAILID);
156            Long _entityId = rs.wasNull() ? null : crrsrvdt_carrierservicedetailid;
157            
158            _result = new CarrierServiceDetailPK(_entityId);
159        } catch (SQLException se) {
160            throw new PersistenceDatabaseException(se);
161        }
162        
163        return _result;
164    }
165    
166    public java.util.List<CarrierServiceDetailValue> getValuesFromPKs(Collection<CarrierServiceDetailPK> pks)
167            throws PersistenceDatabaseException {
168        java.util.List<CarrierServiceDetailValue> _values = new ArrayList<>(pks.size());
169        
170        for(CarrierServiceDetailPK _pk: pks) {
171            _values.add(getValueFromPK(_pk));
172        }
173        
174        return _values;
175    }
176    
177    public CarrierServiceDetailValue getValueFromPK(CarrierServiceDetailPK pk)
178            throws PersistenceDatabaseException {
179        CarrierServiceDetailValue _value;
180        
181        // See if we already have the entity in the session cache
182        CarrierServiceDetail _entity = (CarrierServiceDetail)session.getEntity(pk);
183        if(_entity == null)
184            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getCarrierServiceDetailValue();
185        else
186            _value = _entity.getCarrierServiceDetailValue();
187        
188        return _value;
189    }
190    
191    public java.util.List<CarrierServiceDetailValue> getValuesFromResultSet(ResultSet rs)
192            throws PersistenceDatabaseException {
193        java.util.List<CarrierServiceDetailValue> _result = new ArrayList<>();
194        
195        try {
196            while(rs.next()) {
197                _result.add(getValueFromResultSet(rs));
198            }
199        } catch (SQLException se) {
200            throw new PersistenceDatabaseException(se);
201        }
202        
203        return _result;
204    }
205    
206    public CarrierServiceDetailValue getValueFromResultSet(ResultSet rs)
207            throws PersistenceDatabaseException {
208        CarrierServiceDetailValue _value;
209        
210        try {
211            Long crrsrvdt_carrierservicedetailid = rs.getLong(CRRSRVDT_CARRIERSERVICEDETAILID);
212            CarrierServiceDetailPK _pk = new CarrierServiceDetailPK(crrsrvdt_carrierservicedetailid);
213            
214            // See if we already have the entity in the session cache
215            CarrierServiceDetail _entity = (CarrierServiceDetail)session.getEntity(_pk);
216            
217            if(_entity == null) {
218                Long crrsrvdt_crrsrv_carrierserviceid = rs.getLong(CRRSRVDT_CRRSRV_CARRIERSERVICEID);
219                if(rs.wasNull())
220                    crrsrvdt_crrsrv_carrierserviceid = null;
221                
222                Long crrsrvdt_carrierpartyid = rs.getLong(CRRSRVDT_CARRIERPARTYID);
223                if(rs.wasNull())
224                    crrsrvdt_carrierpartyid = null;
225                
226                String crrsrvdt_carrierservicename = rs.getString(CRRSRVDT_CARRIERSERVICENAME);
227                if(rs.wasNull())
228                    crrsrvdt_carrierservicename = null;
229                
230                Long crrsrvdt_geocodeselectorid = rs.getLong(CRRSRVDT_GEOCODESELECTORID);
231                if(rs.wasNull())
232                    crrsrvdt_geocodeselectorid = null;
233                
234                Long crrsrvdt_itemselectorid = rs.getLong(CRRSRVDT_ITEMSELECTORID);
235                if(rs.wasNull())
236                    crrsrvdt_itemselectorid = null;
237                
238                Boolean crrsrvdt_isdefault = rs.getInt(CRRSRVDT_ISDEFAULT) == 1;
239                if(rs.wasNull())
240                    crrsrvdt_isdefault = null;
241                
242                Integer crrsrvdt_sortorder = rs.getInt(CRRSRVDT_SORTORDER);
243                if(rs.wasNull())
244                    crrsrvdt_sortorder = null;
245                
246                Long crrsrvdt_fromtime = rs.getLong(CRRSRVDT_FROMTIME);
247                if(rs.wasNull())
248                    crrsrvdt_fromtime = null;
249                
250                Long crrsrvdt_thrutime = rs.getLong(CRRSRVDT_THRUTIME);
251                if(rs.wasNull())
252                    crrsrvdt_thrutime = null;
253                
254                _value = new CarrierServiceDetailValue(_pk, new CarrierServicePK(crrsrvdt_crrsrv_carrierserviceid), new PartyPK(crrsrvdt_carrierpartyid), crrsrvdt_carrierservicename, new SelectorPK(crrsrvdt_geocodeselectorid), new SelectorPK(crrsrvdt_itemselectorid), crrsrvdt_isdefault, crrsrvdt_sortorder, crrsrvdt_fromtime, crrsrvdt_thrutime);
255            } else
256                _value = _entity.getCarrierServiceDetailValue();
257        } catch (SQLException se) {
258            throw new PersistenceDatabaseException(se);
259        }
260        
261        return _value;
262    }
263    
264    public java.util.List<CarrierServiceDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CarrierServiceDetailPK> pks)
265            throws PersistenceDatabaseException {
266        java.util.List<CarrierServiceDetail> _entities = new ArrayList<>(pks.size());
267        
268        for(CarrierServiceDetailPK _pk: pks) {
269            _entities.add(getEntityFromPK(entityPermission, _pk));
270        }
271        
272        return _entities;
273    }
274    
275    public CarrierServiceDetail getEntityFromValue(EntityPermission entityPermission, CarrierServiceDetailValue value) {
276        return getEntityFromPK(entityPermission, value.getPrimaryKey());
277    }
278    
279    public CarrierServiceDetail getEntityFromCache(CarrierServiceDetailPK pk) {
280        CarrierServiceDetailValue _value = (CarrierServiceDetailValue)session.getValueCache().get(pk);
281    
282        return _value == null ? null : new CarrierServiceDetail(_value, EntityPermission.READ_ONLY);
283    }
284    
285    public CarrierServiceDetail getEntityFromPK(EntityPermission entityPermission, CarrierServiceDetailPK pk)
286            throws PersistenceDatabaseException {
287        CarrierServiceDetail _entity;
288        
289        // See if we already have the entity in the session cache
290        _entity = (CarrierServiceDetail)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<CarrierServiceDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
333            throws PersistenceDatabaseException {
334        Set<CarrierServiceDetailPK> _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<CarrierServiceDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
361            throws PersistenceDatabaseException {
362        java.util.List<CarrierServiceDetailPK> _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 CarrierServiceDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
389            throws PersistenceDatabaseException {
390        CarrierServiceDetailPK _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<CarrierServiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
419            throws PersistenceDatabaseException {
420        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
421        
422        return getEntitiesFromQuery(entityPermission, ps, params);
423    }
424    
425    public java.util.List<CarrierServiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
426            throws PersistenceDatabaseException {
427        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
428        
429        return getEntitiesFromQuery(entityPermission, ps);
430    }
431    
432    public java.util.List<CarrierServiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
433            throws PersistenceDatabaseException {
434        PreparedStatement ps = session.prepareStatement(query.getSQL());
435        
436        return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray());
437    }
438    
439    public java.util.List<CarrierServiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
440            throws PersistenceDatabaseException {
441        java.util.List<CarrierServiceDetail> _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 CarrierServiceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
468            throws PersistenceDatabaseException {
469        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
470        
471        return getEntityFromQuery(entityPermission, ps, params);
472    }
473    
474    public CarrierServiceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
475            throws PersistenceDatabaseException {
476        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
477        
478        return getEntityFromQuery(entityPermission, ps);
479    }
480    
481    public CarrierServiceDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
482            throws PersistenceDatabaseException {
483        PreparedStatement ps = session.prepareStatement(query.getSQL());
484        
485        return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray());
486    }
487    
488    public CarrierServiceDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
489            throws PersistenceDatabaseException {
490        CarrierServiceDetail _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<CarrierServiceDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
519            throws PersistenceDatabaseException {
520        java.util.List<CarrierServiceDetail> _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 CarrierServiceDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
534            throws PersistenceDatabaseException {
535        CarrierServiceDetail _entity;
536        
537        try {
538            Long crrsrvdt_carrierservicedetailid = rs.getLong(CRRSRVDT_CARRIERSERVICEDETAILID);
539            CarrierServiceDetailPK _pk = new CarrierServiceDetailPK(crrsrvdt_carrierservicedetailid);
540            
541            // See if we already have the entity in the session cache
542            _entity = (CarrierServiceDetail)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 crrsrvdt_crrsrv_carrierserviceid = rs.getLong(CRRSRVDT_CRRSRV_CARRIERSERVICEID);
560                if(rs.wasNull())
561                    crrsrvdt_crrsrv_carrierserviceid = null;
562                
563                Long crrsrvdt_carrierpartyid = rs.getLong(CRRSRVDT_CARRIERPARTYID);
564                if(rs.wasNull())
565                    crrsrvdt_carrierpartyid = null;
566                
567                String crrsrvdt_carrierservicename = rs.getString(CRRSRVDT_CARRIERSERVICENAME);
568                if(rs.wasNull())
569                    crrsrvdt_carrierservicename = null;
570                
571                Long crrsrvdt_geocodeselectorid = rs.getLong(CRRSRVDT_GEOCODESELECTORID);
572                if(rs.wasNull())
573                    crrsrvdt_geocodeselectorid = null;
574                
575                Long crrsrvdt_itemselectorid = rs.getLong(CRRSRVDT_ITEMSELECTORID);
576                if(rs.wasNull())
577                    crrsrvdt_itemselectorid = null;
578                
579                Boolean crrsrvdt_isdefault = rs.getInt(CRRSRVDT_ISDEFAULT) == 1;
580                if(rs.wasNull())
581                    crrsrvdt_isdefault = null;
582                
583                Integer crrsrvdt_sortorder = rs.getInt(CRRSRVDT_SORTORDER);
584                if(rs.wasNull())
585                    crrsrvdt_sortorder = null;
586                
587                Long crrsrvdt_fromtime = rs.getLong(CRRSRVDT_FROMTIME);
588                if(rs.wasNull())
589                    crrsrvdt_fromtime = null;
590                
591                Long crrsrvdt_thrutime = rs.getLong(CRRSRVDT_THRUTIME);
592                if(rs.wasNull())
593                    crrsrvdt_thrutime = null;
594                
595                CarrierServiceDetailValue _value = new CarrierServiceDetailValue(_pk, crrsrvdt_crrsrv_carrierserviceid == null? null: new CarrierServicePK(crrsrvdt_crrsrv_carrierserviceid), crrsrvdt_carrierpartyid == null? null: new PartyPK(crrsrvdt_carrierpartyid), crrsrvdt_carrierservicename, crrsrvdt_geocodeselectorid == null? null: new SelectorPK(crrsrvdt_geocodeselectorid), crrsrvdt_itemselectorid == null? null: new SelectorPK(crrsrvdt_itemselectorid), crrsrvdt_isdefault, crrsrvdt_sortorder, crrsrvdt_fromtime, crrsrvdt_thrutime);
596                _entity = new CarrierServiceDetail(_value, entityPermission);
597            }
598            
599            if(!foundInSessionCache) {
600                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
601                    session.putReadOnlyEntity(_pk, _entity);
602                    session.getValueCache().put(_entity.getCarrierServiceDetailValue());
603                } else {
604                    session.putReadWriteEntity(_pk, _entity);
605                }
606            }
607        } catch (SQLException se) {
608            throw new PersistenceDatabaseException(se);
609        }
610        
611        return _entity;
612    }
613    
614    public CarrierServiceDetail create(CarrierService carrierService, Party carrierParty, String carrierServiceName, Selector geoCodeSelector, Selector itemSelector, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
615            throws PersistenceDatabaseException, PersistenceNotNullException {
616        return create(carrierService == null ? null : carrierService.getPrimaryKey(), carrierParty == null ? null : carrierParty.getPrimaryKey(), carrierServiceName, geoCodeSelector == null ? null : geoCodeSelector.getPrimaryKey(), itemSelector == null ? null : itemSelector.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime);
617    }
618    
619    private void bindForCreate(PreparedStatement _ps, CarrierServiceDetailValue _value)
620            throws SQLException {
621        _ps.setLong(1, _value.getEntityId());
622        
623        CarrierServicePK crrsrvdt_crrsrv_carrierserviceid = _value.getCarrierServicePK();
624        if(crrsrvdt_crrsrv_carrierserviceid == null)
625            _ps.setNull(2, Types.BIGINT);
626        else
627            _ps.setLong(2, crrsrvdt_crrsrv_carrierserviceid.getEntityId());
628            
629        PartyPK crrsrvdt_carrierpartyid = _value.getCarrierPartyPK();
630        if(crrsrvdt_carrierpartyid == null)
631            _ps.setNull(3, Types.BIGINT);
632        else
633            _ps.setLong(3, crrsrvdt_carrierpartyid.getEntityId());
634            
635        String crrsrvdt_carrierservicename = _value.getCarrierServiceName();
636        if(crrsrvdt_carrierservicename == null)
637            _ps.setNull(4, Types.VARCHAR);
638        else
639            _ps.setString(4, crrsrvdt_carrierservicename);
640            
641        SelectorPK crrsrvdt_geocodeselectorid = _value.getGeoCodeSelectorPK();
642        if(crrsrvdt_geocodeselectorid == null)
643            _ps.setNull(5, Types.BIGINT);
644        else
645            _ps.setLong(5, crrsrvdt_geocodeselectorid.getEntityId());
646            
647        SelectorPK crrsrvdt_itemselectorid = _value.getItemSelectorPK();
648        if(crrsrvdt_itemselectorid == null)
649            _ps.setNull(6, Types.BIGINT);
650        else
651            _ps.setLong(6, crrsrvdt_itemselectorid.getEntityId());
652            
653        Boolean crrsrvdt_isdefault = _value.getIsDefault();
654        if(crrsrvdt_isdefault == null)
655            _ps.setNull(7, Types.BIT);
656        else
657            _ps.setInt(7, crrsrvdt_isdefault? 1: 0);
658            
659        Integer crrsrvdt_sortorder = _value.getSortOrder();
660        if(crrsrvdt_sortorder == null)
661            _ps.setNull(8, Types.INTEGER);
662        else
663            _ps.setInt(8, crrsrvdt_sortorder);
664            
665        Long crrsrvdt_fromtime = _value.getFromTime();
666        if(crrsrvdt_fromtime == null)
667            _ps.setNull(9, Types.BIGINT);
668        else
669            _ps.setLong(9, crrsrvdt_fromtime);
670            
671        Long crrsrvdt_thrutime = _value.getThruTime();
672        if(crrsrvdt_thrutime == null)
673            _ps.setNull(10, Types.BIGINT);
674        else
675            _ps.setLong(10, crrsrvdt_thrutime);
676            
677    }
678    
679    public CarrierServiceDetail create(CarrierServicePK carrierServicePK, PartyPK carrierPartyPK, String carrierServiceName, SelectorPK geoCodeSelectorPK, SelectorPK itemSelectorPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
680            throws PersistenceDatabaseException, PersistenceNotNullException {
681        CarrierServiceDetailPK _pk = getNextPK();
682        CarrierServiceDetailValue _value = new CarrierServiceDetailValue(_pk, carrierServicePK, carrierPartyPK, carrierServiceName, geoCodeSelectorPK, itemSelectorPK, isDefault, sortOrder, fromTime, thruTime);
683        
684        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
685        
686        try {
687            bindForCreate(_ps, _value);
688            
689            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
690                int _count = _ps.executeUpdate();
691                
692                if(_count != 1) {
693                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
694                }
695            } else {
696                 _ps.executeUpdate();
697            }
698            
699            session.getValueCache().put(_value);
700        } catch (SQLException se) {
701            throw new PersistenceDatabaseException(se);
702        }
703        
704        CarrierServiceDetail _entity = new CarrierServiceDetail(_value, EntityPermission.READ_ONLY);
705        session.putReadOnlyEntity(_pk, _entity);
706        
707        return _entity;
708    }
709    
710    public void create(Collection<CarrierServiceDetailValue> _values)
711            throws PersistenceDatabaseException, PersistenceNotNullException {
712        int _size = _values.size();
713        
714        if(_size > 0) {
715            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
716            List<CarrierServiceDetailValue> _cacheValues = new ArrayList<>(_size);
717            
718            try {
719                for(CarrierServiceDetailValue _value : _values) {
720                    _value.setEntityId(entityIdGenerator.getNextEntityId());
721                    bindForCreate(_ps, _value);
722                    
723                    _ps.addBatch();
724                    
725                    _cacheValues.add(_value);
726                }
727                
728                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
729                    int[] _counts = _ps.executeBatch();
730                    
731                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
732                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
733                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
734                        }
735                    }
736                } else {
737                     _ps.executeBatch();
738                }
739                
740                _ps.clearBatch();
741            } catch (SQLException se) {
742                throw new PersistenceDatabaseException(se);
743            }
744            
745            _cacheValues.forEach((_cacheValue) -> {
746                CarrierServiceDetail _cacheEntity = new CarrierServiceDetail(_cacheValue, EntityPermission.READ_ONLY);
747                
748                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
749            });
750        }
751    }
752    
753    private boolean bindForStore(PreparedStatement _ps, CarrierServiceDetailValue _value)
754            throws SQLException {
755        boolean _hasBeenModified = _value.hasBeenModified();
756        
757        if(_hasBeenModified) {
758            CarrierServicePK crrsrvdt_crrsrv_carrierserviceid = _value.getCarrierServicePK();
759            if(crrsrvdt_crrsrv_carrierserviceid == null)
760                _ps.setNull(1, Types.BIGINT);
761            else
762                _ps.setLong(1, crrsrvdt_crrsrv_carrierserviceid.getEntityId());
763            
764            PartyPK crrsrvdt_carrierpartyid = _value.getCarrierPartyPK();
765            if(crrsrvdt_carrierpartyid == null)
766                _ps.setNull(2, Types.BIGINT);
767            else
768                _ps.setLong(2, crrsrvdt_carrierpartyid.getEntityId());
769            
770            String crrsrvdt_carrierservicename = _value.getCarrierServiceName();
771            if(crrsrvdt_carrierservicename == null)
772                _ps.setNull(3, Types.VARCHAR);
773            else
774                _ps.setString(3, crrsrvdt_carrierservicename);
775            
776            SelectorPK crrsrvdt_geocodeselectorid = _value.getGeoCodeSelectorPK();
777            if(crrsrvdt_geocodeselectorid == null)
778                _ps.setNull(4, Types.BIGINT);
779            else
780                _ps.setLong(4, crrsrvdt_geocodeselectorid.getEntityId());
781            
782            SelectorPK crrsrvdt_itemselectorid = _value.getItemSelectorPK();
783            if(crrsrvdt_itemselectorid == null)
784                _ps.setNull(5, Types.BIGINT);
785            else
786                _ps.setLong(5, crrsrvdt_itemselectorid.getEntityId());
787            
788            Boolean crrsrvdt_isdefault = _value.getIsDefault();
789            if(crrsrvdt_isdefault == null)
790                _ps.setNull(6, Types.BIT);
791            else
792                _ps.setInt(6, crrsrvdt_isdefault? 1: 0);
793            
794            Integer crrsrvdt_sortorder = _value.getSortOrder();
795            if(crrsrvdt_sortorder == null)
796                _ps.setNull(7, Types.INTEGER);
797            else
798                _ps.setInt(7, crrsrvdt_sortorder);
799            
800            Long crrsrvdt_fromtime = _value.getFromTime();
801            if(crrsrvdt_fromtime == null)
802                _ps.setNull(8, Types.BIGINT);
803            else
804                _ps.setLong(8, crrsrvdt_fromtime);
805            
806            Long crrsrvdt_thrutime = _value.getThruTime();
807            if(crrsrvdt_thrutime == null)
808                _ps.setNull(9, Types.BIGINT);
809            else
810                _ps.setLong(9, crrsrvdt_thrutime);
811            
812            _ps.setLong(10, _value.getPrimaryKey().getEntityId());
813            
814            _value.clearHasBeenModified();
815        }
816        
817        return _hasBeenModified;
818    }
819    
820    @Override
821    public void store(CarrierServiceDetail entity)
822            throws PersistenceDatabaseException {
823        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
824        
825        try {
826            CarrierServiceDetailValue _value = entity.getCarrierServiceDetailValue();
827            
828            if(bindForStore(_ps, _value)) {
829                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
830                    int _count = _ps.executeUpdate();
831                    
832                    if(_count != 1) {
833                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
834                    }
835                } else {
836                     _ps.executeUpdate();
837                }
838                
839                session.getValueCache().put(_value);
840            }
841        } catch (SQLException se) {
842            throw new PersistenceDatabaseException(se);
843        }
844    }
845    
846    @Override
847    public void store(Collection<CarrierServiceDetail> entities)
848            throws PersistenceDatabaseException {
849        if(entities.size() > 0) {
850            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
851            int _modifiedEntities = 0;
852            
853            try {
854                for(CarrierServiceDetail entity : entities) {
855                    if(bindForStore(_ps, entity.getCarrierServiceDetailValue())) {
856                        _ps.addBatch();
857                        _modifiedEntities++;
858                    }
859                }
860                
861                if(_modifiedEntities != 0) {
862                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
863                        int[] _counts = _ps.executeBatch();
864                        
865                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
866                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
867                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
868                            }
869                        }
870                    } else {
871                         _ps.executeBatch();
872                    }
873                    
874                    _ps.clearBatch();
875                    
876                    entities.forEach((entity) -> {
877                        session.getValueCache().put(entity.getCarrierServiceDetailValue());
878                    });
879                }
880            } catch (SQLException se) {
881                throw new PersistenceDatabaseException(se);
882            }
883        }
884    }
885    
886    @Override
887    public void remove(CarrierServiceDetail entity)
888            throws PersistenceDatabaseException {
889        remove(entity.getPrimaryKey());
890    }
891    
892    @Override
893    public void remove(CarrierServiceDetailPK pk)
894            throws PersistenceDatabaseException {
895        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
896        long _entityId = pk.getEntityId();
897        
898        try {
899            _ps.setLong(1, _entityId);
900            
901            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
902                int _count = _ps.executeUpdate();
903                
904                if(_count != 1) {
905                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
906                }
907            } else {
908                 _ps.executeUpdate();
909            }
910            
911            session.getValueCache().remove(pk);
912        } catch (SQLException se) {
913            throw new PersistenceDatabaseException(se);
914        }
915        
916        session.removed(pk, false);
917    }
918    
919    @Override
920    public void remove(Collection<CarrierServiceDetailPK> pks)
921            throws PersistenceDatabaseException {
922        if(pks.size() > 0) {
923            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
924            int _modifiedEntities = 0;
925            
926            try {
927                for(CarrierServiceDetailPK pk : pks) {
928                    long _entityId = pk.getEntityId();
929                    
930                    _ps.setLong(1, _entityId);
931                    
932                    _ps.addBatch();
933                    _modifiedEntities++;
934                }
935                
936                if(_modifiedEntities != 0) {
937                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
938                        int[] _counts = _ps.executeBatch();
939                        
940                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
941                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
942                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
943                            }
944                        }
945                    } else {
946                        _ps.executeBatch();
947                    }
948                    
949                    _ps.clearBatch();
950                    
951                    pks.forEach((pk) -> {
952                        session.getValueCache().remove(pk);
953                    });
954                }
955            } catch (SQLException se) {
956                throw new PersistenceDatabaseException(se);
957            }
958            
959            pks.forEach((pk) -> {
960                session.removed(pk, true);
961            });
962        }
963    }
964    
965    @Override
966    public boolean validPK(CarrierServiceDetailPK pk)
967            throws PersistenceDatabaseException {
968        boolean valid = false;
969        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
970        ResultSet _rs = null;
971        
972        try {
973            _ps.setLong(1, pk.getEntityId());
974            
975            _rs = _ps.executeQuery();
976            if(_rs.next()) {
977                long _count = _rs.getLong(1);
978                if(_rs.wasNull())
979                    _count = 0;
980                
981                if(_count == 1)
982                    valid = true;
983            }
984        } catch (SQLException se) {
985            throw new PersistenceDatabaseException(se);
986        } finally {
987            if(_rs != null) {
988                try {
989                    _rs.close();
990                } catch (SQLException se) {
991                    // do nothing
992                }
993            }
994        }
995        
996        return valid;
997    }
998    
999}