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