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 * ShipmentPackageDetailFactory.java
021 */
022
023package com.echothree.model.data.shipment.server.factory;
024
025import com.echothree.model.data.shipment.common.pk.ShipmentPackagePK;
026import com.echothree.model.data.shipment.common.pk.ShipmentTypePK;
027import com.echothree.model.data.shipment.common.pk.ShipmentPK;
028import com.echothree.model.data.warehouse.common.pk.PackageTypePK;
029import com.echothree.model.data.uom.common.pk.UnitOfMeasureTypePK;
030
031import com.echothree.model.data.shipment.server.entity.ShipmentPackage;
032import com.echothree.model.data.shipment.server.entity.ShipmentType;
033import com.echothree.model.data.shipment.server.entity.Shipment;
034import com.echothree.model.data.warehouse.server.entity.PackageType;
035import com.echothree.model.data.uom.server.entity.UnitOfMeasureType;
036
037import com.echothree.model.data.shipment.common.ShipmentPackageDetailConstants;
038import com.echothree.model.data.shipment.common.pk.ShipmentPackageDetailPK;
039import com.echothree.model.data.shipment.server.value.ShipmentPackageDetailValue;
040import com.echothree.model.data.shipment.server.entity.ShipmentPackageDetail;
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 ShipmentPackageDetailFactory
066        implements BaseFactory<ShipmentPackageDetailPK, ShipmentPackageDetail> {
067    
068    //final private static Log log = LogFactory.getLog(ShipmentPackageDetailFactory.class);
069    
070    final private static String SQL_SELECT_READ_ONLY = "SELECT shppckgdt_shipmentpackagedetailid, shppckgdt_shppckg_shipmentpackageid, shppckgdt_shptyp_shipmenttypeid, shppckgdt_shipmentpackagename, shppckgdt_parentshipmentpackageid, shppckgdt_shp_shipmentid, shppckgdt_pckgtyp_packagetypeid, shppckgdt_uomt_unitofmeasuretypeid, shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime FROM shipmentpackagedetails WHERE shppckgdt_shipmentpackagedetailid = ?";
071    final private static String SQL_SELECT_READ_WRITE = "SELECT shppckgdt_shipmentpackagedetailid, shppckgdt_shppckg_shipmentpackageid, shppckgdt_shptyp_shipmenttypeid, shppckgdt_shipmentpackagename, shppckgdt_parentshipmentpackageid, shppckgdt_shp_shipmentid, shppckgdt_pckgtyp_packagetypeid, shppckgdt_uomt_unitofmeasuretypeid, shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime FROM shipmentpackagedetails WHERE shppckgdt_shipmentpackagedetailid = ? FOR UPDATE";
072    final private static String SQL_INSERT = "INSERT INTO shipmentpackagedetails (shppckgdt_shipmentpackagedetailid, shppckgdt_shppckg_shipmentpackageid, shppckgdt_shptyp_shipmenttypeid, shppckgdt_shipmentpackagename, shppckgdt_parentshipmentpackageid, shppckgdt_shp_shipmentid, shppckgdt_pckgtyp_packagetypeid, shppckgdt_uomt_unitofmeasuretypeid, shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
073    final private static String SQL_UPDATE = "UPDATE shipmentpackagedetails SET shppckgdt_shppckg_shipmentpackageid = ?, shppckgdt_shptyp_shipmenttypeid = ?, shppckgdt_shipmentpackagename = ?, shppckgdt_parentshipmentpackageid = ?, shppckgdt_shp_shipmentid = ?, shppckgdt_pckgtyp_packagetypeid = ?, shppckgdt_uomt_unitofmeasuretypeid = ?, shppckgdt_weight = ?, shppckgdt_fromtime = ?, shppckgdt_thrutime = ? WHERE shppckgdt_shipmentpackagedetailid = ?";
074    final private static String SQL_DELETE = "DELETE FROM shipmentpackagedetails WHERE shppckgdt_shipmentpackagedetailid = ?";
075    final private static String SQL_VALID = "SELECT COUNT(*) FROM shipmentpackagedetails WHERE shppckgdt_shipmentpackagedetailid = ?";
076    
077    final private static String PK_COLUMN = "shppckgdt_shipmentpackagedetailid";
078    final private static String ALL_COLUMNS = "shppckgdt_shipmentpackagedetailid, shppckgdt_shppckg_shipmentpackageid, shppckgdt_shptyp_shipmenttypeid, shppckgdt_shipmentpackagename, shppckgdt_parentshipmentpackageid, shppckgdt_shp_shipmentid, shppckgdt_pckgtyp_packagetypeid, shppckgdt_uomt_unitofmeasuretypeid, shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime";
079    final public static String TABLE_NAME = "shipmentpackagedetails";
080    
081    final public static String SHPPCKGDT_SHIPMENTPACKAGEDETAILID = "shppckgdt_shipmentpackagedetailid";
082    final public static String SHPPCKGDT_SHPPCKG_SHIPMENTPACKAGEID = "shppckgdt_shppckg_shipmentpackageid";
083    final public static String SHPPCKGDT_SHPTYP_SHIPMENTTYPEID = "shppckgdt_shptyp_shipmenttypeid";
084    final public static String SHPPCKGDT_SHIPMENTPACKAGENAME = "shppckgdt_shipmentpackagename";
085    final public static String SHPPCKGDT_PARENTSHIPMENTPACKAGEID = "shppckgdt_parentshipmentpackageid";
086    final public static String SHPPCKGDT_SHP_SHIPMENTID = "shppckgdt_shp_shipmentid";
087    final public static String SHPPCKGDT_PCKGTYP_PACKAGETYPEID = "shppckgdt_pckgtyp_packagetypeid";
088    final public static String SHPPCKGDT_UOMT_UNITOFMEASURETYPEID = "shppckgdt_uomt_unitofmeasuretypeid";
089    final public static String SHPPCKGDT_WEIGHT = "shppckgdt_weight";
090    final public static String SHPPCKGDT_FROMTIME = "shppckgdt_fromtime";
091    final public static String SHPPCKGDT_THRUTIME = "shppckgdt_thrutime";
092    
093    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ShipmentPackageDetailConstants.COMPONENT_VENDOR_NAME, ShipmentPackageDetailConstants.ENTITY_TYPE_NAME);
094    
095    /** Creates a new instance of ShipmentPackageDetailFactory */
096    private ShipmentPackageDetailFactory() {
097        super();
098    }
099    
100    private static class ShipmentPackageDetailFactoryHolder {
101        static ShipmentPackageDetailFactory instance = new ShipmentPackageDetailFactory();
102    }
103    
104    public static ShipmentPackageDetailFactory getInstance() {
105        return ShipmentPackageDetailFactoryHolder.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 ShipmentPackageDetailConstants.COMPONENT_VENDOR_NAME;
126    }
127    
128    @Override
129    public String getEntityTypeName() {
130        return ShipmentPackageDetailConstants.ENTITY_TYPE_NAME;
131    }
132    
133    public PreparedStatement prepareStatement(String query) {
134        return ThreadSession.currentSession().prepareStatement(ShipmentPackageDetailFactory.class, query);
135    }
136    
137    public ShipmentPackageDetailPK getNextPK() {
138        return new ShipmentPackageDetailPK(entityIdGenerator.getNextEntityId());
139    }
140    
141    public Set<ShipmentPackageDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
142            throws PersistenceDatabaseException {
143        Set<ShipmentPackageDetailPK> _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<ShipmentPackageDetailPK> getPKsFromResultSetAsList(ResultSet rs)
157            throws PersistenceDatabaseException {
158        java.util.List<ShipmentPackageDetailPK> _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 ShipmentPackageDetailPK getPKFromResultSet(ResultSet rs)
172            throws PersistenceDatabaseException {
173        ShipmentPackageDetailPK _result;
174        
175        try {
176            long shppckgdt_shipmentpackagedetailid = rs.getLong(SHPPCKGDT_SHIPMENTPACKAGEDETAILID);
177            Long _entityId = rs.wasNull() ? null : shppckgdt_shipmentpackagedetailid;
178            
179            _result = new ShipmentPackageDetailPK(_entityId);
180        } catch (SQLException se) {
181            throw new PersistenceDatabaseException(se);
182        }
183        
184        return _result;
185    }
186    
187    public java.util.List<ShipmentPackageDetailValue> getValuesFromPKs(Session session, Collection<ShipmentPackageDetailPK> pks)
188            throws PersistenceDatabaseException {
189        java.util.List<ShipmentPackageDetailValue> _values = new ArrayList<>(pks.size());
190        
191        for(ShipmentPackageDetailPK _pk: pks) {
192            _values.add(getValueFromPK(session, _pk));
193        }
194        
195        return _values;
196    }
197    
198    public ShipmentPackageDetailValue getValueFromPK(Session session, ShipmentPackageDetailPK pk)
199            throws PersistenceDatabaseException {
200        ShipmentPackageDetailValue _value;
201        
202        // See if we already have the entity in the session cache
203        ShipmentPackageDetail _entity = (ShipmentPackageDetail)session.getEntity(pk);
204        if(_entity == null)
205            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getShipmentPackageDetailValue();
206        else
207            _value = _entity.getShipmentPackageDetailValue();
208        
209        return _value;
210    }
211    
212    public java.util.List<ShipmentPackageDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
213            throws PersistenceDatabaseException {
214        java.util.List<ShipmentPackageDetailValue> _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 ShipmentPackageDetailValue getValueFromResultSet(Session session, ResultSet rs)
228            throws PersistenceDatabaseException {
229        ShipmentPackageDetailValue _value;
230        
231        try {
232            Long shppckgdt_shipmentpackagedetailid = rs.getLong(SHPPCKGDT_SHIPMENTPACKAGEDETAILID);
233            ShipmentPackageDetailPK _pk = new ShipmentPackageDetailPK(shppckgdt_shipmentpackagedetailid);
234            
235            // See if we already have the entity in the session cache
236            ShipmentPackageDetail _entity = (ShipmentPackageDetail)session.getEntity(_pk);
237            
238            if(_entity == null) {
239                Long shppckgdt_shppckg_shipmentpackageid = rs.getLong(SHPPCKGDT_SHPPCKG_SHIPMENTPACKAGEID);
240                if(rs.wasNull())
241                    shppckgdt_shppckg_shipmentpackageid = null;
242                
243                Long shppckgdt_shptyp_shipmenttypeid = rs.getLong(SHPPCKGDT_SHPTYP_SHIPMENTTYPEID);
244                if(rs.wasNull())
245                    shppckgdt_shptyp_shipmenttypeid = null;
246                
247                String shppckgdt_shipmentpackagename = rs.getString(SHPPCKGDT_SHIPMENTPACKAGENAME);
248                if(rs.wasNull())
249                    shppckgdt_shipmentpackagename = null;
250                
251                Long shppckgdt_parentshipmentpackageid = rs.getLong(SHPPCKGDT_PARENTSHIPMENTPACKAGEID);
252                if(rs.wasNull())
253                    shppckgdt_parentshipmentpackageid = null;
254                
255                Long shppckgdt_shp_shipmentid = rs.getLong(SHPPCKGDT_SHP_SHIPMENTID);
256                if(rs.wasNull())
257                    shppckgdt_shp_shipmentid = null;
258                
259                Long shppckgdt_pckgtyp_packagetypeid = rs.getLong(SHPPCKGDT_PCKGTYP_PACKAGETYPEID);
260                if(rs.wasNull())
261                    shppckgdt_pckgtyp_packagetypeid = null;
262                
263                Long shppckgdt_uomt_unitofmeasuretypeid = rs.getLong(SHPPCKGDT_UOMT_UNITOFMEASURETYPEID);
264                if(rs.wasNull())
265                    shppckgdt_uomt_unitofmeasuretypeid = null;
266                
267                Long shppckgdt_weight = rs.getLong(SHPPCKGDT_WEIGHT);
268                if(rs.wasNull())
269                    shppckgdt_weight = null;
270                
271                Long shppckgdt_fromtime = rs.getLong(SHPPCKGDT_FROMTIME);
272                if(rs.wasNull())
273                    shppckgdt_fromtime = null;
274                
275                Long shppckgdt_thrutime = rs.getLong(SHPPCKGDT_THRUTIME);
276                if(rs.wasNull())
277                    shppckgdt_thrutime = null;
278                
279                _value = new ShipmentPackageDetailValue(_pk, new ShipmentPackagePK(shppckgdt_shppckg_shipmentpackageid), new ShipmentTypePK(shppckgdt_shptyp_shipmenttypeid), shppckgdt_shipmentpackagename, new ShipmentPackagePK(shppckgdt_parentshipmentpackageid), new ShipmentPK(shppckgdt_shp_shipmentid), new PackageTypePK(shppckgdt_pckgtyp_packagetypeid), new UnitOfMeasureTypePK(shppckgdt_uomt_unitofmeasuretypeid), shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime);
280            } else
281                _value = _entity.getShipmentPackageDetailValue();
282        } catch (SQLException se) {
283            throw new PersistenceDatabaseException(se);
284        }
285        
286        return _value;
287    }
288    
289    public java.util.List<ShipmentPackageDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ShipmentPackageDetailPK> pks)
290            throws PersistenceDatabaseException {
291        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
292    }
293    
294    public java.util.List<ShipmentPackageDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<ShipmentPackageDetailPK> pks)
295            throws PersistenceDatabaseException {
296        java.util.List<ShipmentPackageDetail> _entities = new ArrayList<>(pks.size());
297        
298        for(ShipmentPackageDetailPK _pk: pks) {
299            _entities.add(getEntityFromPK(session, entityPermission, _pk));
300        }
301        
302        return _entities;
303    }
304    
305    public ShipmentPackageDetail getEntityFromValue(EntityPermission entityPermission, ShipmentPackageDetailValue value) {
306        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
307    }
308    
309    public ShipmentPackageDetail getEntityFromValue(Session session, EntityPermission entityPermission, ShipmentPackageDetailValue value) {
310        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
311    }
312    
313    public ShipmentPackageDetail getEntityFromPK(EntityPermission entityPermission, ShipmentPackageDetailPK pk)
314            throws PersistenceDatabaseException {
315        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
316    }
317    
318    public ShipmentPackageDetail getEntityFromCache(Session session, ShipmentPackageDetailPK pk) {
319        ShipmentPackageDetailValue _value = (ShipmentPackageDetailValue)session.getValueCache().get(pk);
320    
321        return _value == null ? null : new ShipmentPackageDetail(_value, EntityPermission.READ_ONLY);
322    }
323    
324    public ShipmentPackageDetail getEntityFromPK(Session session, EntityPermission entityPermission, ShipmentPackageDetailPK pk)
325            throws PersistenceDatabaseException {
326        ShipmentPackageDetail _entity;
327        
328        // See if we already have the entity in the session cache
329        _entity = (ShipmentPackageDetail)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<ShipmentPackageDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
372            throws PersistenceDatabaseException {
373        Set<ShipmentPackageDetailPK> _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<ShipmentPackageDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
400            throws PersistenceDatabaseException {
401        java.util.List<ShipmentPackageDetailPK> _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 ShipmentPackageDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
428            throws PersistenceDatabaseException {
429        ShipmentPackageDetailPK _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<ShipmentPackageDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
458            throws PersistenceDatabaseException {
459        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
460        
461        return getEntitiesFromQuery(session, entityPermission, ps, params);
462    }
463    
464    public java.util.List<ShipmentPackageDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
465            throws PersistenceDatabaseException {
466        Session session = ThreadSession.currentSession();
467        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
468        
469        return getEntitiesFromQuery(session, entityPermission, ps, params);
470    }
471    
472    public java.util.List<ShipmentPackageDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
473            throws PersistenceDatabaseException {
474        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
475        
476        return getEntitiesFromQuery(session, entityPermission, ps);
477    }
478    
479    public java.util.List<ShipmentPackageDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
480            throws PersistenceDatabaseException {
481        Session session = ThreadSession.currentSession();
482        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
483        
484        return getEntitiesFromQuery(session, entityPermission, ps);
485    }
486    
487    public java.util.List<ShipmentPackageDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
488            throws PersistenceDatabaseException {
489        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
490    }
491    
492    public java.util.List<ShipmentPackageDetail> 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<ShipmentPackageDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
498            throws PersistenceDatabaseException {
499        java.util.List<ShipmentPackageDetail> _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 ShipmentPackageDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
526            throws PersistenceDatabaseException {
527        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
528        
529        return getEntityFromQuery(session, entityPermission, ps, params);
530    }
531    
532    public ShipmentPackageDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
533            throws PersistenceDatabaseException {
534        Session session = ThreadSession.currentSession();
535        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
536        
537        return getEntityFromQuery(session, entityPermission, ps, params);
538    }
539    
540    public ShipmentPackageDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
541            throws PersistenceDatabaseException {
542        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
543        
544        return getEntityFromQuery(session, entityPermission, ps);
545    }
546    
547    public ShipmentPackageDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
548            throws PersistenceDatabaseException {
549        Session session = ThreadSession.currentSession();
550        PreparedStatement ps = session.prepareStatement(ShipmentPackageDetailFactory.class, queryMap.get(entityPermission));
551        
552        return getEntityFromQuery(session, entityPermission, ps);
553    }
554    
555    public ShipmentPackageDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
556            throws PersistenceDatabaseException {
557        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
558    }
559    
560    public ShipmentPackageDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
561            throws PersistenceDatabaseException {
562        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
563    }
564    
565    public ShipmentPackageDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
566            throws PersistenceDatabaseException {
567        ShipmentPackageDetail _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<ShipmentPackageDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
596            throws PersistenceDatabaseException {
597        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
598    }
599    
600    public java.util.List<ShipmentPackageDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
601            throws PersistenceDatabaseException {
602        java.util.List<ShipmentPackageDetail> _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 ShipmentPackageDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
616            throws PersistenceDatabaseException {
617        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
618    }
619    
620    public ShipmentPackageDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
621            throws PersistenceDatabaseException {
622        ShipmentPackageDetail _entity;
623        
624        try {
625            Long shppckgdt_shipmentpackagedetailid = rs.getLong(SHPPCKGDT_SHIPMENTPACKAGEDETAILID);
626            ShipmentPackageDetailPK _pk = new ShipmentPackageDetailPK(shppckgdt_shipmentpackagedetailid);
627            
628            // See if we already have the entity in the session cache
629            _entity = (ShipmentPackageDetail)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 shppckgdt_shppckg_shipmentpackageid = rs.getLong(SHPPCKGDT_SHPPCKG_SHIPMENTPACKAGEID);
647                if(rs.wasNull())
648                    shppckgdt_shppckg_shipmentpackageid = null;
649                
650                Long shppckgdt_shptyp_shipmenttypeid = rs.getLong(SHPPCKGDT_SHPTYP_SHIPMENTTYPEID);
651                if(rs.wasNull())
652                    shppckgdt_shptyp_shipmenttypeid = null;
653                
654                String shppckgdt_shipmentpackagename = rs.getString(SHPPCKGDT_SHIPMENTPACKAGENAME);
655                if(rs.wasNull())
656                    shppckgdt_shipmentpackagename = null;
657                
658                Long shppckgdt_parentshipmentpackageid = rs.getLong(SHPPCKGDT_PARENTSHIPMENTPACKAGEID);
659                if(rs.wasNull())
660                    shppckgdt_parentshipmentpackageid = null;
661                
662                Long shppckgdt_shp_shipmentid = rs.getLong(SHPPCKGDT_SHP_SHIPMENTID);
663                if(rs.wasNull())
664                    shppckgdt_shp_shipmentid = null;
665                
666                Long shppckgdt_pckgtyp_packagetypeid = rs.getLong(SHPPCKGDT_PCKGTYP_PACKAGETYPEID);
667                if(rs.wasNull())
668                    shppckgdt_pckgtyp_packagetypeid = null;
669                
670                Long shppckgdt_uomt_unitofmeasuretypeid = rs.getLong(SHPPCKGDT_UOMT_UNITOFMEASURETYPEID);
671                if(rs.wasNull())
672                    shppckgdt_uomt_unitofmeasuretypeid = null;
673                
674                Long shppckgdt_weight = rs.getLong(SHPPCKGDT_WEIGHT);
675                if(rs.wasNull())
676                    shppckgdt_weight = null;
677                
678                Long shppckgdt_fromtime = rs.getLong(SHPPCKGDT_FROMTIME);
679                if(rs.wasNull())
680                    shppckgdt_fromtime = null;
681                
682                Long shppckgdt_thrutime = rs.getLong(SHPPCKGDT_THRUTIME);
683                if(rs.wasNull())
684                    shppckgdt_thrutime = null;
685                
686                ShipmentPackageDetailValue _value = new ShipmentPackageDetailValue(_pk, shppckgdt_shppckg_shipmentpackageid == null? null: new ShipmentPackagePK(shppckgdt_shppckg_shipmentpackageid), shppckgdt_shptyp_shipmenttypeid == null? null: new ShipmentTypePK(shppckgdt_shptyp_shipmenttypeid), shppckgdt_shipmentpackagename, shppckgdt_parentshipmentpackageid == null? null: new ShipmentPackagePK(shppckgdt_parentshipmentpackageid), shppckgdt_shp_shipmentid == null? null: new ShipmentPK(shppckgdt_shp_shipmentid), shppckgdt_pckgtyp_packagetypeid == null? null: new PackageTypePK(shppckgdt_pckgtyp_packagetypeid), shppckgdt_uomt_unitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(shppckgdt_uomt_unitofmeasuretypeid), shppckgdt_weight, shppckgdt_fromtime, shppckgdt_thrutime);
687                _entity = new ShipmentPackageDetail(_value, entityPermission);
688            }
689            
690            if(!foundInSessionCache) {
691                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
692                    session.putReadOnlyEntity(_pk, _entity);
693                    session.getValueCache().put(_entity.getShipmentPackageDetailValue());
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 ShipmentPackageDetail create(Session session, ShipmentPackage shipmentPackage, ShipmentType shipmentType, String shipmentPackageName, ShipmentPackage parentShipmentPackage, Shipment shipment, PackageType packageType, UnitOfMeasureType unitOfMeasureType, Long weight, Long fromTime, Long thruTime)
706            throws PersistenceDatabaseException, PersistenceNotNullException {
707        return create(session, shipmentPackage == null ? null : shipmentPackage.getPrimaryKey(), shipmentType == null ? null : shipmentType.getPrimaryKey(), shipmentPackageName, parentShipmentPackage == null ? null : parentShipmentPackage.getPrimaryKey(), shipment == null ? null : shipment.getPrimaryKey(), packageType == null ? null : packageType.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), weight, fromTime, thruTime);
708    }
709    
710    public ShipmentPackageDetail create(ShipmentPackage shipmentPackage, ShipmentType shipmentType, String shipmentPackageName, ShipmentPackage parentShipmentPackage, Shipment shipment, PackageType packageType, UnitOfMeasureType unitOfMeasureType, Long weight, Long fromTime, Long thruTime)
711            throws PersistenceDatabaseException, PersistenceNotNullException {
712        return create(ThreadSession.currentSession(), shipmentPackage == null ? null : shipmentPackage.getPrimaryKey(), shipmentType == null ? null : shipmentType.getPrimaryKey(), shipmentPackageName, parentShipmentPackage == null ? null : parentShipmentPackage.getPrimaryKey(), shipment == null ? null : shipment.getPrimaryKey(), packageType == null ? null : packageType.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), weight, fromTime, thruTime);
713    }
714    
715    private void bindForCreate(PreparedStatement _ps, ShipmentPackageDetailValue _value)
716            throws SQLException {
717        _ps.setLong(1, _value.getEntityId());
718        
719        ShipmentPackagePK shppckgdt_shppckg_shipmentpackageid = _value.getShipmentPackagePK();
720        if(shppckgdt_shppckg_shipmentpackageid == null)
721            _ps.setNull(2, Types.BIGINT);
722        else
723            _ps.setLong(2, shppckgdt_shppckg_shipmentpackageid.getEntityId());
724            
725        ShipmentTypePK shppckgdt_shptyp_shipmenttypeid = _value.getShipmentTypePK();
726        if(shppckgdt_shptyp_shipmenttypeid == null)
727            _ps.setNull(3, Types.BIGINT);
728        else
729            _ps.setLong(3, shppckgdt_shptyp_shipmenttypeid.getEntityId());
730            
731        String shppckgdt_shipmentpackagename = _value.getShipmentPackageName();
732        if(shppckgdt_shipmentpackagename == null)
733            _ps.setNull(4, Types.VARCHAR);
734        else
735            _ps.setString(4, shppckgdt_shipmentpackagename);
736            
737        ShipmentPackagePK shppckgdt_parentshipmentpackageid = _value.getParentShipmentPackagePK();
738        if(shppckgdt_parentshipmentpackageid == null)
739            _ps.setNull(5, Types.BIGINT);
740        else
741            _ps.setLong(5, shppckgdt_parentshipmentpackageid.getEntityId());
742            
743        ShipmentPK shppckgdt_shp_shipmentid = _value.getShipmentPK();
744        if(shppckgdt_shp_shipmentid == null)
745            _ps.setNull(6, Types.BIGINT);
746        else
747            _ps.setLong(6, shppckgdt_shp_shipmentid.getEntityId());
748            
749        PackageTypePK shppckgdt_pckgtyp_packagetypeid = _value.getPackageTypePK();
750        if(shppckgdt_pckgtyp_packagetypeid == null)
751            _ps.setNull(7, Types.BIGINT);
752        else
753            _ps.setLong(7, shppckgdt_pckgtyp_packagetypeid.getEntityId());
754            
755        UnitOfMeasureTypePK shppckgdt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK();
756        if(shppckgdt_uomt_unitofmeasuretypeid == null)
757            _ps.setNull(8, Types.BIGINT);
758        else
759            _ps.setLong(8, shppckgdt_uomt_unitofmeasuretypeid.getEntityId());
760            
761        Long shppckgdt_weight = _value.getWeight();
762        if(shppckgdt_weight == null)
763            _ps.setNull(9, Types.BIGINT);
764        else
765            _ps.setLong(9, shppckgdt_weight);
766            
767        Long shppckgdt_fromtime = _value.getFromTime();
768        if(shppckgdt_fromtime == null)
769            _ps.setNull(10, Types.BIGINT);
770        else
771            _ps.setLong(10, shppckgdt_fromtime);
772            
773        Long shppckgdt_thrutime = _value.getThruTime();
774        if(shppckgdt_thrutime == null)
775            _ps.setNull(11, Types.BIGINT);
776        else
777            _ps.setLong(11, shppckgdt_thrutime);
778            
779    }
780    
781    public ShipmentPackageDetail create(Session session, ShipmentPackagePK shipmentPackagePK, ShipmentTypePK shipmentTypePK, String shipmentPackageName, ShipmentPackagePK parentShipmentPackagePK, ShipmentPK shipmentPK, PackageTypePK packageTypePK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long weight, Long fromTime, Long thruTime)
782            throws PersistenceDatabaseException, PersistenceNotNullException {
783        ShipmentPackageDetailPK _pk = getNextPK();
784        ShipmentPackageDetailValue _value = new ShipmentPackageDetailValue(_pk, shipmentPackagePK, shipmentTypePK, shipmentPackageName, parentShipmentPackagePK, shipmentPK, packageTypePK, unitOfMeasureTypePK, weight, 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        ShipmentPackageDetail _entity = new ShipmentPackageDetail(_value, EntityPermission.READ_ONLY);
807        session.putReadOnlyEntity(_pk, _entity);
808        
809        return _entity;
810    }
811    
812    public ShipmentPackageDetail create(ShipmentPackagePK shipmentPackagePK, ShipmentTypePK shipmentTypePK, String shipmentPackageName, ShipmentPackagePK parentShipmentPackagePK, ShipmentPK shipmentPK, PackageTypePK packageTypePK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long weight, Long fromTime, Long thruTime)
813            throws PersistenceDatabaseException, PersistenceNotNullException {
814        return create(ThreadSession.currentSession(), shipmentPackagePK, shipmentTypePK, shipmentPackageName, parentShipmentPackagePK, shipmentPK, packageTypePK, unitOfMeasureTypePK, weight, fromTime, thruTime);
815    }
816    
817    public void create(Session session, Collection<ShipmentPackageDetailValue> _values)
818            throws PersistenceDatabaseException, PersistenceNotNullException {
819        int _size = _values.size();
820        
821        if(_size > 0) {
822            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
823            List<ShipmentPackageDetailValue> _cacheValues = new ArrayList<>(_size);
824            
825            try {
826                for(ShipmentPackageDetailValue _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                ShipmentPackageDetail _cacheEntity = new ShipmentPackageDetail(_cacheValue, EntityPermission.READ_ONLY);
854                
855                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
856            });
857        }
858    }
859    
860    public void create(Collection<ShipmentPackageDetailValue> _values)
861            throws PersistenceDatabaseException, PersistenceNotNullException {
862        create(ThreadSession.currentSession(), _values);
863    }
864    
865    private boolean bindForStore(PreparedStatement _ps, ShipmentPackageDetailValue _value)
866            throws SQLException {
867        boolean _hasBeenModified = _value.hasBeenModified();
868        
869        if(_hasBeenModified) {
870            ShipmentPackagePK shppckgdt_shppckg_shipmentpackageid = _value.getShipmentPackagePK();
871            if(shppckgdt_shppckg_shipmentpackageid == null)
872                _ps.setNull(1, Types.BIGINT);
873            else
874                _ps.setLong(1, shppckgdt_shppckg_shipmentpackageid.getEntityId());
875            
876            ShipmentTypePK shppckgdt_shptyp_shipmenttypeid = _value.getShipmentTypePK();
877            if(shppckgdt_shptyp_shipmenttypeid == null)
878                _ps.setNull(2, Types.BIGINT);
879            else
880                _ps.setLong(2, shppckgdt_shptyp_shipmenttypeid.getEntityId());
881            
882            String shppckgdt_shipmentpackagename = _value.getShipmentPackageName();
883            if(shppckgdt_shipmentpackagename == null)
884                _ps.setNull(3, Types.VARCHAR);
885            else
886                _ps.setString(3, shppckgdt_shipmentpackagename);
887            
888            ShipmentPackagePK shppckgdt_parentshipmentpackageid = _value.getParentShipmentPackagePK();
889            if(shppckgdt_parentshipmentpackageid == null)
890                _ps.setNull(4, Types.BIGINT);
891            else
892                _ps.setLong(4, shppckgdt_parentshipmentpackageid.getEntityId());
893            
894            ShipmentPK shppckgdt_shp_shipmentid = _value.getShipmentPK();
895            if(shppckgdt_shp_shipmentid == null)
896                _ps.setNull(5, Types.BIGINT);
897            else
898                _ps.setLong(5, shppckgdt_shp_shipmentid.getEntityId());
899            
900            PackageTypePK shppckgdt_pckgtyp_packagetypeid = _value.getPackageTypePK();
901            if(shppckgdt_pckgtyp_packagetypeid == null)
902                _ps.setNull(6, Types.BIGINT);
903            else
904                _ps.setLong(6, shppckgdt_pckgtyp_packagetypeid.getEntityId());
905            
906            UnitOfMeasureTypePK shppckgdt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK();
907            if(shppckgdt_uomt_unitofmeasuretypeid == null)
908                _ps.setNull(7, Types.BIGINT);
909            else
910                _ps.setLong(7, shppckgdt_uomt_unitofmeasuretypeid.getEntityId());
911            
912            Long shppckgdt_weight = _value.getWeight();
913            if(shppckgdt_weight == null)
914                _ps.setNull(8, Types.BIGINT);
915            else
916                _ps.setLong(8, shppckgdt_weight);
917            
918            Long shppckgdt_fromtime = _value.getFromTime();
919            if(shppckgdt_fromtime == null)
920                _ps.setNull(9, Types.BIGINT);
921            else
922                _ps.setLong(9, shppckgdt_fromtime);
923            
924            Long shppckgdt_thrutime = _value.getThruTime();
925            if(shppckgdt_thrutime == null)
926                _ps.setNull(10, Types.BIGINT);
927            else
928                _ps.setLong(10, shppckgdt_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, ShipmentPackageDetail entity)
940            throws PersistenceDatabaseException {
941        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
942        
943        try {
944            ShipmentPackageDetailValue _value = entity.getShipmentPackageDetailValue();
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<ShipmentPackageDetail> 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(ShipmentPackageDetail entity : entities) {
973                    if(bindForStore(_ps, entity.getShipmentPackageDetailValue())) {
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.getShipmentPackageDetailValue());
996                    });
997                }
998            } catch (SQLException se) {
999                throw new PersistenceDatabaseException(se);
1000            }
1001        }
1002    }
1003    
1004    @Override
1005    public void store(Collection<ShipmentPackageDetail> entities)
1006            throws PersistenceDatabaseException {
1007        store(ThreadSession.currentSession(), entities);
1008    }
1009    
1010    @Override
1011    public void remove(Session session, ShipmentPackageDetail entity)
1012            throws PersistenceDatabaseException {
1013        remove(session, entity.getPrimaryKey());
1014    }
1015    
1016    @Override
1017    public void remove(Session session, ShipmentPackageDetailPK 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<ShipmentPackageDetailPK> 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(ShipmentPackageDetailPK 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<ShipmentPackageDetailPK> pks)
1091            throws PersistenceDatabaseException {
1092        remove(ThreadSession.currentSession(), pks);
1093    }
1094    
1095    @Override
1096    public boolean validPK(Session session, ShipmentPackageDetailPK 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}