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