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