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