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