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