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