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