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