001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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 * OrderLineDetailFactory.java
021 */
022
023package com.echothree.model.data.order.server.factory;
024
025import com.echothree.model.data.order.common.pk.OrderLinePK;
026import com.echothree.model.data.order.common.pk.OrderPK;
027import com.echothree.model.data.order.common.pk.OrderShipmentGroupPK;
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;
031import com.echothree.model.data.cancellationpolicy.common.pk.CancellationPolicyPK;
032import com.echothree.model.data.returnpolicy.common.pk.ReturnPolicyPK;
033
034import com.echothree.model.data.order.server.entity.OrderLine;
035import com.echothree.model.data.order.server.entity.Order;
036import com.echothree.model.data.order.server.entity.OrderShipmentGroup;
037import com.echothree.model.data.item.server.entity.Item;
038import com.echothree.model.data.inventory.server.entity.InventoryCondition;
039import com.echothree.model.data.uom.server.entity.UnitOfMeasureType;
040import com.echothree.model.data.cancellationpolicy.server.entity.CancellationPolicy;
041import com.echothree.model.data.returnpolicy.server.entity.ReturnPolicy;
042
043import com.echothree.model.data.order.common.OrderLineDetailConstants;
044import com.echothree.model.data.order.common.pk.OrderLineDetailPK;
045import com.echothree.model.data.order.server.value.OrderLineDetailValue;
046import com.echothree.model.data.order.server.entity.OrderLineDetail;
047import com.echothree.util.common.exception.PersistenceDatabaseException;
048import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
049import com.echothree.util.common.exception.PersistenceNotNullException;
050import com.echothree.util.server.persistence.BaseFactory;
051import com.echothree.util.server.persistence.EntityIdGenerator;
052import com.echothree.util.server.persistence.EntityPermission;
053import com.echothree.util.server.persistence.PersistenceDebugFlags;
054import com.echothree.util.server.persistence.Session;
055import com.echothree.util.server.persistence.ThreadSession;
056import java.sql.PreparedStatement;
057import java.sql.ResultSet;
058import java.sql.SQLException;
059import java.sql.Types;
060import java.io.ByteArrayInputStream;
061import java.io.StringReader;
062import java.util.ArrayList;
063import java.util.Collection;
064import java.util.HashSet;
065import java.util.List;
066import java.util.Map;
067import java.util.Set;
068import javax.enterprise.context.ApplicationScoped;
069import javax.enterprise.inject.spi.CDI;
070import org.apache.commons.logging.Log;
071import org.apache.commons.logging.LogFactory;
072
073@ApplicationScoped
074public class OrderLineDetailFactory
075        implements BaseFactory<OrderLineDetailPK, OrderLineDetail> {
076    
077    //final private static Log log = LogFactory.getLog(OrderLineDetailFactory.class);
078    
079    final private static String SQL_SELECT_READ_ONLY = "SELECT ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?";
080    final private static String SQL_SELECT_READ_WRITE = "SELECT ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime FROM orderlinedetails WHERE ordldt_orderlinedetailid = ? FOR UPDATE";
081    final private static String SQL_INSERT = "INSERT INTO orderlinedetails (ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
082    final private static String SQL_UPDATE = "UPDATE orderlinedetails SET ordldt_ordl_orderlineid = ?, ordldt_ord_orderid = ?, ordldt_orderlinesequence = ?, ordldt_parentorderlineid = ?, ordldt_ordshpgrp_ordershipmentgroupid = ?, ordldt_itm_itemid = ?, ordldt_invcon_inventoryconditionid = ?, ordldt_uomt_unitofmeasuretypeid = ?, ordldt_quantity = ?, ordldt_unitamount = ?, ordldt_description = ?, ordldt_cnclplcy_cancellationpolicyid = ?, ordldt_rtnplcy_returnpolicyid = ?, ordldt_taxable = ?, ordldt_fromtime = ?, ordldt_thrutime = ? WHERE ordldt_orderlinedetailid = ?";
083    final private static String SQL_DELETE = "DELETE FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?";
084    final private static String SQL_VALID = "SELECT COUNT(*) FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?";
085    
086    final private static String PK_COLUMN = "ordldt_orderlinedetailid";
087    final private static String ALL_COLUMNS = "ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime";
088    final public static String TABLE_NAME = "orderlinedetails";
089    
090    final public static String ORDLDT_ORDERLINEDETAILID = "ordldt_orderlinedetailid";
091    final public static String ORDLDT_ORDL_ORDERLINEID = "ordldt_ordl_orderlineid";
092    final public static String ORDLDT_ORD_ORDERID = "ordldt_ord_orderid";
093    final public static String ORDLDT_ORDERLINESEQUENCE = "ordldt_orderlinesequence";
094    final public static String ORDLDT_PARENTORDERLINEID = "ordldt_parentorderlineid";
095    final public static String ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID = "ordldt_ordshpgrp_ordershipmentgroupid";
096    final public static String ORDLDT_ITM_ITEMID = "ordldt_itm_itemid";
097    final public static String ORDLDT_INVCON_INVENTORYCONDITIONID = "ordldt_invcon_inventoryconditionid";
098    final public static String ORDLDT_UOMT_UNITOFMEASURETYPEID = "ordldt_uomt_unitofmeasuretypeid";
099    final public static String ORDLDT_QUANTITY = "ordldt_quantity";
100    final public static String ORDLDT_UNITAMOUNT = "ordldt_unitamount";
101    final public static String ORDLDT_DESCRIPTION = "ordldt_description";
102    final public static String ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID = "ordldt_cnclplcy_cancellationpolicyid";
103    final public static String ORDLDT_RTNPLCY_RETURNPOLICYID = "ordldt_rtnplcy_returnpolicyid";
104    final public static String ORDLDT_TAXABLE = "ordldt_taxable";
105    final public static String ORDLDT_FROMTIME = "ordldt_fromtime";
106    final public static String ORDLDT_THRUTIME = "ordldt_thrutime";
107    
108    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(OrderLineDetailConstants.COMPONENT_VENDOR_NAME, OrderLineDetailConstants.ENTITY_TYPE_NAME);
109    
110    /** Creates a new instance of OrderLineDetailFactory */
111    protected OrderLineDetailFactory() {
112        super();
113    }
114    
115    public static OrderLineDetailFactory getInstance() {
116        return CDI.current().select(OrderLineDetailFactory.class).get();
117    }
118    
119    @Override
120    public String getPKColumn() {
121        return PK_COLUMN;
122    }
123    
124    @Override
125    public String getAllColumns() {
126        return ALL_COLUMNS;
127    }
128    
129    @Override
130    public String getTableName() {
131        return TABLE_NAME;
132    }
133    
134    @Override
135    public String getComponentVendorName() {
136        return OrderLineDetailConstants.COMPONENT_VENDOR_NAME;
137    }
138    
139    @Override
140    public String getEntityTypeName() {
141        return OrderLineDetailConstants.ENTITY_TYPE_NAME;
142    }
143    
144    public PreparedStatement prepareStatement(String query) {
145        return ThreadSession.currentSession().prepareStatement(OrderLineDetailFactory.class, query);
146    }
147    
148    public OrderLineDetailPK getNextPK() {
149        return new OrderLineDetailPK(entityIdGenerator.getNextEntityId());
150    }
151    
152    public Set<OrderLineDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
153            throws PersistenceDatabaseException {
154        Set<OrderLineDetailPK> _result = new HashSet<>();
155        
156        try {
157            while(rs.next()) {
158                _result.add(getPKFromResultSet(rs));
159            }
160        } catch (SQLException se) {
161            throw new PersistenceDatabaseException(se);
162        }
163        
164        return _result;
165    }
166    
167    public java.util.List<OrderLineDetailPK> getPKsFromResultSetAsList(ResultSet rs)
168            throws PersistenceDatabaseException {
169        java.util.List<OrderLineDetailPK> _result = new ArrayList<>();
170        
171        try {
172            while(rs.next()) {
173                _result.add(getPKFromResultSet(rs));
174            }
175        } catch (SQLException se) {
176            throw new PersistenceDatabaseException(se);
177        }
178        
179        return _result;
180    }
181    
182    public OrderLineDetailPK getPKFromResultSet(ResultSet rs)
183            throws PersistenceDatabaseException {
184        OrderLineDetailPK _result;
185        
186        try {
187            long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID);
188            Long _entityId = rs.wasNull() ? null : ordldt_orderlinedetailid;
189            
190            _result = new OrderLineDetailPK(_entityId);
191        } catch (SQLException se) {
192            throw new PersistenceDatabaseException(se);
193        }
194        
195        return _result;
196    }
197    
198    public java.util.List<OrderLineDetailValue> getValuesFromPKs(Session session, Collection<OrderLineDetailPK> pks)
199            throws PersistenceDatabaseException {
200        java.util.List<OrderLineDetailValue> _values = new ArrayList<>(pks.size());
201        
202        for(OrderLineDetailPK _pk: pks) {
203            _values.add(getValueFromPK(session, _pk));
204        }
205        
206        return _values;
207    }
208    
209    public OrderLineDetailValue getValueFromPK(Session session, OrderLineDetailPK pk)
210            throws PersistenceDatabaseException {
211        OrderLineDetailValue _value;
212        
213        // See if we already have the entity in the session cache
214        OrderLineDetail _entity = (OrderLineDetail)session.getEntity(pk);
215        if(_entity == null)
216            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getOrderLineDetailValue();
217        else
218            _value = _entity.getOrderLineDetailValue();
219        
220        return _value;
221    }
222    
223    public java.util.List<OrderLineDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
224            throws PersistenceDatabaseException {
225        java.util.List<OrderLineDetailValue> _result = new ArrayList<>();
226        
227        try {
228            while(rs.next()) {
229                _result.add(getValueFromResultSet(session, rs));
230            }
231        } catch (SQLException se) {
232            throw new PersistenceDatabaseException(se);
233        }
234        
235        return _result;
236    }
237    
238    public OrderLineDetailValue getValueFromResultSet(Session session, ResultSet rs)
239            throws PersistenceDatabaseException {
240        OrderLineDetailValue _value;
241        
242        try {
243            Long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID);
244            OrderLineDetailPK _pk = new OrderLineDetailPK(ordldt_orderlinedetailid);
245            
246            // See if we already have the entity in the session cache
247            OrderLineDetail _entity = (OrderLineDetail)session.getEntity(_pk);
248            
249            if(_entity == null) {
250                Long ordldt_ordl_orderlineid = rs.getLong(ORDLDT_ORDL_ORDERLINEID);
251                if(rs.wasNull())
252                    ordldt_ordl_orderlineid = null;
253                
254                Long ordldt_ord_orderid = rs.getLong(ORDLDT_ORD_ORDERID);
255                if(rs.wasNull())
256                    ordldt_ord_orderid = null;
257                
258                Integer ordldt_orderlinesequence = rs.getInt(ORDLDT_ORDERLINESEQUENCE);
259                if(rs.wasNull())
260                    ordldt_orderlinesequence = null;
261                
262                Long ordldt_parentorderlineid = rs.getLong(ORDLDT_PARENTORDERLINEID);
263                if(rs.wasNull())
264                    ordldt_parentorderlineid = null;
265                
266                Long ordldt_ordshpgrp_ordershipmentgroupid = rs.getLong(ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID);
267                if(rs.wasNull())
268                    ordldt_ordshpgrp_ordershipmentgroupid = null;
269                
270                Long ordldt_itm_itemid = rs.getLong(ORDLDT_ITM_ITEMID);
271                if(rs.wasNull())
272                    ordldt_itm_itemid = null;
273                
274                Long ordldt_invcon_inventoryconditionid = rs.getLong(ORDLDT_INVCON_INVENTORYCONDITIONID);
275                if(rs.wasNull())
276                    ordldt_invcon_inventoryconditionid = null;
277                
278                Long ordldt_uomt_unitofmeasuretypeid = rs.getLong(ORDLDT_UOMT_UNITOFMEASURETYPEID);
279                if(rs.wasNull())
280                    ordldt_uomt_unitofmeasuretypeid = null;
281                
282                Long ordldt_quantity = rs.getLong(ORDLDT_QUANTITY);
283                if(rs.wasNull())
284                    ordldt_quantity = null;
285                
286                Long ordldt_unitamount = rs.getLong(ORDLDT_UNITAMOUNT);
287                if(rs.wasNull())
288                    ordldt_unitamount = null;
289                
290                String ordldt_description = rs.getString(ORDLDT_DESCRIPTION);
291                if(rs.wasNull())
292                    ordldt_description = null;
293                
294                Long ordldt_cnclplcy_cancellationpolicyid = rs.getLong(ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID);
295                if(rs.wasNull())
296                    ordldt_cnclplcy_cancellationpolicyid = null;
297                
298                Long ordldt_rtnplcy_returnpolicyid = rs.getLong(ORDLDT_RTNPLCY_RETURNPOLICYID);
299                if(rs.wasNull())
300                    ordldt_rtnplcy_returnpolicyid = null;
301                
302                Boolean ordldt_taxable = rs.getInt(ORDLDT_TAXABLE) == 1;
303                if(rs.wasNull())
304                    ordldt_taxable = null;
305                
306                Long ordldt_fromtime = rs.getLong(ORDLDT_FROMTIME);
307                if(rs.wasNull())
308                    ordldt_fromtime = null;
309                
310                Long ordldt_thrutime = rs.getLong(ORDLDT_THRUTIME);
311                if(rs.wasNull())
312                    ordldt_thrutime = null;
313                
314                _value = new OrderLineDetailValue(_pk, new OrderLinePK(ordldt_ordl_orderlineid), new OrderPK(ordldt_ord_orderid), ordldt_orderlinesequence, new OrderLinePK(ordldt_parentorderlineid), new OrderShipmentGroupPK(ordldt_ordshpgrp_ordershipmentgroupid), new ItemPK(ordldt_itm_itemid), new InventoryConditionPK(ordldt_invcon_inventoryconditionid), new UnitOfMeasureTypePK(ordldt_uomt_unitofmeasuretypeid), ordldt_quantity, ordldt_unitamount, ordldt_description, new CancellationPolicyPK(ordldt_cnclplcy_cancellationpolicyid), new ReturnPolicyPK(ordldt_rtnplcy_returnpolicyid), ordldt_taxable, ordldt_fromtime, ordldt_thrutime);
315            } else
316                _value = _entity.getOrderLineDetailValue();
317        } catch (SQLException se) {
318            throw new PersistenceDatabaseException(se);
319        }
320        
321        return _value;
322    }
323    
324    public java.util.List<OrderLineDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<OrderLineDetailPK> pks)
325            throws PersistenceDatabaseException {
326        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
327    }
328    
329    public java.util.List<OrderLineDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<OrderLineDetailPK> pks)
330            throws PersistenceDatabaseException {
331        java.util.List<OrderLineDetail> _entities = new ArrayList<>(pks.size());
332        
333        for(OrderLineDetailPK _pk: pks) {
334            _entities.add(getEntityFromPK(session, entityPermission, _pk));
335        }
336        
337        return _entities;
338    }
339    
340    public OrderLineDetail getEntityFromValue(EntityPermission entityPermission, OrderLineDetailValue value) {
341        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
342    }
343    
344    public OrderLineDetail getEntityFromValue(Session session, EntityPermission entityPermission, OrderLineDetailValue value) {
345        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
346    }
347    
348    public OrderLineDetail getEntityFromPK(EntityPermission entityPermission, OrderLineDetailPK pk)
349            throws PersistenceDatabaseException {
350        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
351    }
352    
353    public OrderLineDetail getEntityFromCache(Session session, OrderLineDetailPK pk) {
354        OrderLineDetailValue _value = (OrderLineDetailValue)session.getValueCache().get(pk);
355    
356        return _value == null ? null : new OrderLineDetail(_value, EntityPermission.READ_ONLY);
357    }
358    
359    public OrderLineDetail getEntityFromPK(Session session, EntityPermission entityPermission, OrderLineDetailPK pk)
360            throws PersistenceDatabaseException {
361        OrderLineDetail _entity;
362        
363        // See if we already have the entity in the session cache
364        _entity = (OrderLineDetail)session.getEntity(pk);
365        if(_entity != null) {
366            // If the requested permission is READ_WRITE, and the cached permission is
367            // READ_ONLY, then pretend that the cached object wasn't found, and create
368            // a new entity that is READ_WRITE.
369            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
370                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
371                    _entity = null;
372            }
373        }
374        
375        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
376            _entity = getEntityFromCache(session, pk);
377        }
378        
379        if(_entity == null) {
380            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
381            long _entityId = pk.getEntityId();
382            ResultSet _rs = null;
383            
384            try {
385                _ps.setLong(1, _entityId);
386                _rs = _ps.executeQuery();
387                if(_rs.next()) {
388                    _entity = getEntityFromResultSet(session, entityPermission, _rs);
389                }
390            } catch (SQLException se) {
391                throw new PersistenceDatabaseException(se);
392            } finally {
393                if(_rs != null) {
394                    try {
395                        _rs.close();
396                    } catch (SQLException se) {
397                        // do nothing
398                    }
399                }
400            }
401        }
402        
403        return _entity;
404    }
405    
406    public Set<OrderLineDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
407            throws PersistenceDatabaseException {
408        Set<OrderLineDetailPK> _pks;
409        ResultSet _rs = null;
410        
411        try {
412            if(params.length != 0) {
413                Session.setQueryParams(ps, params);
414            }
415            
416            _rs = ps.executeQuery();
417            _pks = getPKsFromResultSetAsSet(_rs);
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 _pks;
432    }
433    
434    public java.util.List<OrderLineDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
435            throws PersistenceDatabaseException {
436        java.util.List<OrderLineDetailPK> _pks;
437        ResultSet _rs = null;
438        
439        try {
440            if(params.length != 0) {
441                Session.setQueryParams(ps, params);
442            }
443            
444            _rs = ps.executeQuery();
445            _pks = getPKsFromResultSetAsList(_rs);
446            _rs.close();
447        } catch (SQLException se) {
448            throw new PersistenceDatabaseException(se);
449        } finally {
450            if(_rs != null) {
451                try {
452                    _rs.close();
453                } catch (SQLException se) {
454                    // do nothing
455                }
456            }
457        }
458        
459        return _pks;
460    }
461    
462    public OrderLineDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
463            throws PersistenceDatabaseException {
464        OrderLineDetailPK _pk = null;
465        ResultSet _rs = null;
466        
467        try {
468            if(params.length != 0) {
469                Session.setQueryParams(ps, params);
470            }
471            
472            _rs = ps.executeQuery();
473            if(_rs.next()) {
474                _pk = getPKFromResultSet(_rs);
475            }
476            _rs.close();
477        } catch (SQLException se) {
478            throw new PersistenceDatabaseException(se);
479        } finally {
480            if(_rs != null) {
481                try {
482                    _rs.close();
483                } catch (SQLException se) {
484                    // do nothing
485                }
486            }
487        }
488        
489        return _pk;
490    }
491    
492    public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
493            throws PersistenceDatabaseException {
494        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
495        
496        return getEntitiesFromQuery(session, entityPermission, ps, params);
497    }
498    
499    public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
500            throws PersistenceDatabaseException {
501        Session session = ThreadSession.currentSession();
502        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
503        
504        return getEntitiesFromQuery(session, entityPermission, ps, params);
505    }
506    
507    public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
508            throws PersistenceDatabaseException {
509        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
510        
511        return getEntitiesFromQuery(session, entityPermission, ps);
512    }
513    
514    public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
515            throws PersistenceDatabaseException {
516        Session session = ThreadSession.currentSession();
517        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
518        
519        return getEntitiesFromQuery(session, entityPermission, ps);
520    }
521    
522    public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
523            throws PersistenceDatabaseException {
524        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
525    }
526    
527    public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
528            throws PersistenceDatabaseException {
529        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
530    }
531    
532    public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
533            throws PersistenceDatabaseException {
534        java.util.List<OrderLineDetail> _entities;
535        ResultSet _rs = null;
536        
537        try {
538            if(params.length != 0) {
539                Session.setQueryParams(ps, params);
540            }
541            
542            _rs = ps.executeQuery();
543            _entities = getEntitiesFromResultSet(session, entityPermission, _rs);
544            _rs.close();
545        } catch (SQLException se) {
546            throw new PersistenceDatabaseException(se);
547        } finally {
548            if(_rs != null) {
549                try {
550                    _rs.close();
551                } catch (SQLException se) {
552                    // do nothing
553                }
554            }
555        }
556        
557        return _entities;
558    }
559    
560    public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
561            throws PersistenceDatabaseException {
562        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
563        
564        return getEntityFromQuery(session, entityPermission, ps, params);
565    }
566    
567    public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
568            throws PersistenceDatabaseException {
569        Session session = ThreadSession.currentSession();
570        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
571        
572        return getEntityFromQuery(session, entityPermission, ps, params);
573    }
574    
575    public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
576            throws PersistenceDatabaseException {
577        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
578        
579        return getEntityFromQuery(session, entityPermission, ps);
580    }
581    
582    public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
583            throws PersistenceDatabaseException {
584        Session session = ThreadSession.currentSession();
585        PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission));
586        
587        return getEntityFromQuery(session, entityPermission, ps);
588    }
589    
590    public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
591            throws PersistenceDatabaseException {
592        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
593    }
594    
595    public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
596            throws PersistenceDatabaseException {
597        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
598    }
599    
600    public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
601            throws PersistenceDatabaseException {
602        OrderLineDetail _entity = null;
603        ResultSet _rs = null;
604        
605        try {
606            if(params.length != 0) {
607                Session.setQueryParams(ps, params);
608            }
609            
610            _rs = ps.executeQuery();
611            if(_rs.next()) {
612                _entity = getEntityFromResultSet(session, entityPermission, _rs);
613            }
614            _rs.close();
615        } catch (SQLException se) {
616            throw new PersistenceDatabaseException(se);
617        } finally {
618            if(_rs != null) {
619                try {
620                    _rs.close();
621                } catch (SQLException se) {
622                    // do nothing
623                }
624            }
625        }
626        
627        return _entity;
628    }
629    
630    public java.util.List<OrderLineDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
631            throws PersistenceDatabaseException {
632        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
633    }
634    
635    public java.util.List<OrderLineDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
636            throws PersistenceDatabaseException {
637        java.util.List<OrderLineDetail> _result = new ArrayList<>();
638        
639        try {
640            while(rs.next()) {
641                _result.add(getEntityFromResultSet(session, entityPermission, rs));
642            }
643        } catch (SQLException se) {
644            throw new PersistenceDatabaseException(se);
645        }
646        
647        return _result;
648    }
649    
650    public OrderLineDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
651            throws PersistenceDatabaseException {
652        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
653    }
654    
655    public OrderLineDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
656            throws PersistenceDatabaseException {
657        OrderLineDetail _entity;
658        
659        try {
660            Long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID);
661            OrderLineDetailPK _pk = new OrderLineDetailPK(ordldt_orderlinedetailid);
662            
663            // See if we already have the entity in the session cache
664            _entity = (OrderLineDetail)session.getEntity(_pk);
665            if(_entity != null) {
666                // If the requested permission is READ_WRITE, and the cached permission is
667                // READ_ONLY, then pretend that the cached object wasn't found, and create
668                // a new entity that is READ_WRITE.
669                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
670                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
671                        _entity = null;
672                }
673            }
674            boolean foundInSessionCache = _entity != null;
675            
676            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
677                _entity = getEntityFromCache(session, _pk);
678            }
679            
680            if(_entity == null) {
681                Long ordldt_ordl_orderlineid = rs.getLong(ORDLDT_ORDL_ORDERLINEID);
682                if(rs.wasNull())
683                    ordldt_ordl_orderlineid = null;
684                
685                Long ordldt_ord_orderid = rs.getLong(ORDLDT_ORD_ORDERID);
686                if(rs.wasNull())
687                    ordldt_ord_orderid = null;
688                
689                Integer ordldt_orderlinesequence = rs.getInt(ORDLDT_ORDERLINESEQUENCE);
690                if(rs.wasNull())
691                    ordldt_orderlinesequence = null;
692                
693                Long ordldt_parentorderlineid = rs.getLong(ORDLDT_PARENTORDERLINEID);
694                if(rs.wasNull())
695                    ordldt_parentorderlineid = null;
696                
697                Long ordldt_ordshpgrp_ordershipmentgroupid = rs.getLong(ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID);
698                if(rs.wasNull())
699                    ordldt_ordshpgrp_ordershipmentgroupid = null;
700                
701                Long ordldt_itm_itemid = rs.getLong(ORDLDT_ITM_ITEMID);
702                if(rs.wasNull())
703                    ordldt_itm_itemid = null;
704                
705                Long ordldt_invcon_inventoryconditionid = rs.getLong(ORDLDT_INVCON_INVENTORYCONDITIONID);
706                if(rs.wasNull())
707                    ordldt_invcon_inventoryconditionid = null;
708                
709                Long ordldt_uomt_unitofmeasuretypeid = rs.getLong(ORDLDT_UOMT_UNITOFMEASURETYPEID);
710                if(rs.wasNull())
711                    ordldt_uomt_unitofmeasuretypeid = null;
712                
713                Long ordldt_quantity = rs.getLong(ORDLDT_QUANTITY);
714                if(rs.wasNull())
715                    ordldt_quantity = null;
716                
717                Long ordldt_unitamount = rs.getLong(ORDLDT_UNITAMOUNT);
718                if(rs.wasNull())
719                    ordldt_unitamount = null;
720                
721                String ordldt_description = rs.getString(ORDLDT_DESCRIPTION);
722                if(rs.wasNull())
723                    ordldt_description = null;
724                
725                Long ordldt_cnclplcy_cancellationpolicyid = rs.getLong(ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID);
726                if(rs.wasNull())
727                    ordldt_cnclplcy_cancellationpolicyid = null;
728                
729                Long ordldt_rtnplcy_returnpolicyid = rs.getLong(ORDLDT_RTNPLCY_RETURNPOLICYID);
730                if(rs.wasNull())
731                    ordldt_rtnplcy_returnpolicyid = null;
732                
733                Boolean ordldt_taxable = rs.getInt(ORDLDT_TAXABLE) == 1;
734                if(rs.wasNull())
735                    ordldt_taxable = null;
736                
737                Long ordldt_fromtime = rs.getLong(ORDLDT_FROMTIME);
738                if(rs.wasNull())
739                    ordldt_fromtime = null;
740                
741                Long ordldt_thrutime = rs.getLong(ORDLDT_THRUTIME);
742                if(rs.wasNull())
743                    ordldt_thrutime = null;
744                
745                OrderLineDetailValue _value = new OrderLineDetailValue(_pk, ordldt_ordl_orderlineid == null? null: new OrderLinePK(ordldt_ordl_orderlineid), ordldt_ord_orderid == null? null: new OrderPK(ordldt_ord_orderid), ordldt_orderlinesequence, ordldt_parentorderlineid == null? null: new OrderLinePK(ordldt_parentorderlineid), ordldt_ordshpgrp_ordershipmentgroupid == null? null: new OrderShipmentGroupPK(ordldt_ordshpgrp_ordershipmentgroupid), ordldt_itm_itemid == null? null: new ItemPK(ordldt_itm_itemid), ordldt_invcon_inventoryconditionid == null? null: new InventoryConditionPK(ordldt_invcon_inventoryconditionid), ordldt_uomt_unitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(ordldt_uomt_unitofmeasuretypeid), ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid == null? null: new CancellationPolicyPK(ordldt_cnclplcy_cancellationpolicyid), ordldt_rtnplcy_returnpolicyid == null? null: new ReturnPolicyPK(ordldt_rtnplcy_returnpolicyid), ordldt_taxable, ordldt_fromtime, ordldt_thrutime);
746                _entity = new OrderLineDetail(_value, entityPermission);
747            }
748            
749            if(!foundInSessionCache) {
750                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
751                    session.putReadOnlyEntity(_pk, _entity);
752                    session.getValueCache().put(_entity.getOrderLineDetailValue());
753                } else {
754                    session.putReadWriteEntity(_pk, _entity);
755                }
756            }
757        } catch (SQLException se) {
758            throw new PersistenceDatabaseException(se);
759        }
760        
761        return _entity;
762    }
763    
764    public OrderLineDetail create(Session session, OrderLine orderLine, Order order, Integer orderLineSequence, OrderLine parentOrderLine, OrderShipmentGroup orderShipmentGroup, Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Long quantity, Long unitAmount, String description, CancellationPolicy cancellationPolicy, ReturnPolicy returnPolicy, Boolean taxable, Long fromTime, Long thruTime)
765            throws PersistenceDatabaseException, PersistenceNotNullException {
766        return create(session, orderLine == null ? null : orderLine.getPrimaryKey(), order == null ? null : order.getPrimaryKey(), orderLineSequence, parentOrderLine == null ? null : parentOrderLine.getPrimaryKey(), orderShipmentGroup == null ? null : orderShipmentGroup.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), quantity, unitAmount, description, cancellationPolicy == null ? null : cancellationPolicy.getPrimaryKey(), returnPolicy == null ? null : returnPolicy.getPrimaryKey(), taxable, fromTime, thruTime);
767    }
768    
769    public OrderLineDetail create(OrderLine orderLine, Order order, Integer orderLineSequence, OrderLine parentOrderLine, OrderShipmentGroup orderShipmentGroup, Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Long quantity, Long unitAmount, String description, CancellationPolicy cancellationPolicy, ReturnPolicy returnPolicy, Boolean taxable, Long fromTime, Long thruTime)
770            throws PersistenceDatabaseException, PersistenceNotNullException {
771        return create(ThreadSession.currentSession(), orderLine == null ? null : orderLine.getPrimaryKey(), order == null ? null : order.getPrimaryKey(), orderLineSequence, parentOrderLine == null ? null : parentOrderLine.getPrimaryKey(), orderShipmentGroup == null ? null : orderShipmentGroup.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), quantity, unitAmount, description, cancellationPolicy == null ? null : cancellationPolicy.getPrimaryKey(), returnPolicy == null ? null : returnPolicy.getPrimaryKey(), taxable, fromTime, thruTime);
772    }
773    
774    private void bindForCreate(PreparedStatement _ps, OrderLineDetailValue _value)
775            throws SQLException {
776        _ps.setLong(1, _value.getEntityId());
777        
778        OrderLinePK ordldt_ordl_orderlineid = _value.getOrderLinePK();
779        if(ordldt_ordl_orderlineid == null)
780            _ps.setNull(2, Types.BIGINT);
781        else
782            _ps.setLong(2, ordldt_ordl_orderlineid.getEntityId());
783            
784        OrderPK ordldt_ord_orderid = _value.getOrderPK();
785        if(ordldt_ord_orderid == null)
786            _ps.setNull(3, Types.BIGINT);
787        else
788            _ps.setLong(3, ordldt_ord_orderid.getEntityId());
789            
790        Integer ordldt_orderlinesequence = _value.getOrderLineSequence();
791        if(ordldt_orderlinesequence == null)
792            _ps.setNull(4, Types.INTEGER);
793        else
794            _ps.setInt(4, ordldt_orderlinesequence);
795            
796        OrderLinePK ordldt_parentorderlineid = _value.getParentOrderLinePK();
797        if(ordldt_parentorderlineid == null)
798            _ps.setNull(5, Types.BIGINT);
799        else
800            _ps.setLong(5, ordldt_parentorderlineid.getEntityId());
801            
802        OrderShipmentGroupPK ordldt_ordshpgrp_ordershipmentgroupid = _value.getOrderShipmentGroupPK();
803        if(ordldt_ordshpgrp_ordershipmentgroupid == null)
804            _ps.setNull(6, Types.BIGINT);
805        else
806            _ps.setLong(6, ordldt_ordshpgrp_ordershipmentgroupid.getEntityId());
807            
808        ItemPK ordldt_itm_itemid = _value.getItemPK();
809        if(ordldt_itm_itemid == null)
810            _ps.setNull(7, Types.BIGINT);
811        else
812            _ps.setLong(7, ordldt_itm_itemid.getEntityId());
813            
814        InventoryConditionPK ordldt_invcon_inventoryconditionid = _value.getInventoryConditionPK();
815        if(ordldt_invcon_inventoryconditionid == null)
816            _ps.setNull(8, Types.BIGINT);
817        else
818            _ps.setLong(8, ordldt_invcon_inventoryconditionid.getEntityId());
819            
820        UnitOfMeasureTypePK ordldt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK();
821        if(ordldt_uomt_unitofmeasuretypeid == null)
822            _ps.setNull(9, Types.BIGINT);
823        else
824            _ps.setLong(9, ordldt_uomt_unitofmeasuretypeid.getEntityId());
825            
826        Long ordldt_quantity = _value.getQuantity();
827        if(ordldt_quantity == null)
828            _ps.setNull(10, Types.BIGINT);
829        else
830            _ps.setLong(10, ordldt_quantity);
831            
832        Long ordldt_unitamount = _value.getUnitAmount();
833        if(ordldt_unitamount == null)
834            _ps.setNull(11, Types.BIGINT);
835        else
836            _ps.setLong(11, ordldt_unitamount);
837            
838        String ordldt_description = _value.getDescription();
839        if(ordldt_description == null)
840            _ps.setNull(12, Types.VARCHAR);
841        else
842            _ps.setString(12, ordldt_description);
843            
844        CancellationPolicyPK ordldt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK();
845        if(ordldt_cnclplcy_cancellationpolicyid == null)
846            _ps.setNull(13, Types.BIGINT);
847        else
848            _ps.setLong(13, ordldt_cnclplcy_cancellationpolicyid.getEntityId());
849            
850        ReturnPolicyPK ordldt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK();
851        if(ordldt_rtnplcy_returnpolicyid == null)
852            _ps.setNull(14, Types.BIGINT);
853        else
854            _ps.setLong(14, ordldt_rtnplcy_returnpolicyid.getEntityId());
855            
856        Boolean ordldt_taxable = _value.getTaxable();
857        if(ordldt_taxable == null)
858            _ps.setNull(15, Types.BIT);
859        else
860            _ps.setInt(15, ordldt_taxable? 1: 0);
861            
862        Long ordldt_fromtime = _value.getFromTime();
863        if(ordldt_fromtime == null)
864            _ps.setNull(16, Types.BIGINT);
865        else
866            _ps.setLong(16, ordldt_fromtime);
867            
868        Long ordldt_thrutime = _value.getThruTime();
869        if(ordldt_thrutime == null)
870            _ps.setNull(17, Types.BIGINT);
871        else
872            _ps.setLong(17, ordldt_thrutime);
873            
874    }
875    
876    public OrderLineDetail create(Session session, OrderLinePK orderLinePK, OrderPK orderPK, Integer orderLineSequence, OrderLinePK parentOrderLinePK, OrderShipmentGroupPK orderShipmentGroupPK, ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long quantity, Long unitAmount, String description, CancellationPolicyPK cancellationPolicyPK, ReturnPolicyPK returnPolicyPK, Boolean taxable, Long fromTime, Long thruTime)
877            throws PersistenceDatabaseException, PersistenceNotNullException {
878        OrderLineDetailPK _pk = getNextPK();
879        OrderLineDetailValue _value = new OrderLineDetailValue(_pk, orderLinePK, orderPK, orderLineSequence, parentOrderLinePK, orderShipmentGroupPK, itemPK, inventoryConditionPK, unitOfMeasureTypePK, quantity, unitAmount, description, cancellationPolicyPK, returnPolicyPK, taxable, fromTime, thruTime);
880        
881        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
882        
883        try {
884            bindForCreate(_ps, _value);
885            
886            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
887                int _count = _ps.executeUpdate();
888                
889                if(_count != 1) {
890                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
891                }
892            } else {
893                 _ps.executeUpdate();
894            }
895            
896            session.getValueCache().put(_value);
897        } catch (SQLException se) {
898            throw new PersistenceDatabaseException(se);
899        }
900        
901        OrderLineDetail _entity = new OrderLineDetail(_value, EntityPermission.READ_ONLY);
902        session.putReadOnlyEntity(_pk, _entity);
903        
904        return _entity;
905    }
906    
907    public OrderLineDetail create(OrderLinePK orderLinePK, OrderPK orderPK, Integer orderLineSequence, OrderLinePK parentOrderLinePK, OrderShipmentGroupPK orderShipmentGroupPK, ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long quantity, Long unitAmount, String description, CancellationPolicyPK cancellationPolicyPK, ReturnPolicyPK returnPolicyPK, Boolean taxable, Long fromTime, Long thruTime)
908            throws PersistenceDatabaseException, PersistenceNotNullException {
909        return create(ThreadSession.currentSession(), orderLinePK, orderPK, orderLineSequence, parentOrderLinePK, orderShipmentGroupPK, itemPK, inventoryConditionPK, unitOfMeasureTypePK, quantity, unitAmount, description, cancellationPolicyPK, returnPolicyPK, taxable, fromTime, thruTime);
910    }
911    
912    public void create(Session session, Collection<OrderLineDetailValue> _values)
913            throws PersistenceDatabaseException, PersistenceNotNullException {
914        int _size = _values.size();
915        
916        if(_size > 0) {
917            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
918            List<OrderLineDetailValue> _cacheValues = new ArrayList<>(_size);
919            
920            try {
921                for(OrderLineDetailValue _value : _values) {
922                    _value.setEntityId(entityIdGenerator.getNextEntityId());
923                    bindForCreate(_ps, _value);
924                    
925                    _ps.addBatch();
926                    
927                    _cacheValues.add(_value);
928                }
929                
930                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
931                    int[] _counts = _ps.executeBatch();
932                    
933                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
934                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
935                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
936                        }
937                    }
938                } else {
939                     _ps.executeBatch();
940                }
941                
942                _ps.clearBatch();
943            } catch (SQLException se) {
944                throw new PersistenceDatabaseException(se);
945            }
946            
947            _cacheValues.forEach((_cacheValue) -> {
948                OrderLineDetail _cacheEntity = new OrderLineDetail(_cacheValue, EntityPermission.READ_ONLY);
949                
950                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
951            });
952        }
953    }
954    
955    public void create(Collection<OrderLineDetailValue> _values)
956            throws PersistenceDatabaseException, PersistenceNotNullException {
957        create(ThreadSession.currentSession(), _values);
958    }
959    
960    private boolean bindForStore(PreparedStatement _ps, OrderLineDetailValue _value)
961            throws SQLException {
962        boolean _hasBeenModified = _value.hasBeenModified();
963        
964        if(_hasBeenModified) {
965            OrderLinePK ordldt_ordl_orderlineid = _value.getOrderLinePK();
966            if(ordldt_ordl_orderlineid == null)
967                _ps.setNull(1, Types.BIGINT);
968            else
969                _ps.setLong(1, ordldt_ordl_orderlineid.getEntityId());
970            
971            OrderPK ordldt_ord_orderid = _value.getOrderPK();
972            if(ordldt_ord_orderid == null)
973                _ps.setNull(2, Types.BIGINT);
974            else
975                _ps.setLong(2, ordldt_ord_orderid.getEntityId());
976            
977            Integer ordldt_orderlinesequence = _value.getOrderLineSequence();
978            if(ordldt_orderlinesequence == null)
979                _ps.setNull(3, Types.INTEGER);
980            else
981                _ps.setInt(3, ordldt_orderlinesequence);
982            
983            OrderLinePK ordldt_parentorderlineid = _value.getParentOrderLinePK();
984            if(ordldt_parentorderlineid == null)
985                _ps.setNull(4, Types.BIGINT);
986            else
987                _ps.setLong(4, ordldt_parentorderlineid.getEntityId());
988            
989            OrderShipmentGroupPK ordldt_ordshpgrp_ordershipmentgroupid = _value.getOrderShipmentGroupPK();
990            if(ordldt_ordshpgrp_ordershipmentgroupid == null)
991                _ps.setNull(5, Types.BIGINT);
992            else
993                _ps.setLong(5, ordldt_ordshpgrp_ordershipmentgroupid.getEntityId());
994            
995            ItemPK ordldt_itm_itemid = _value.getItemPK();
996            if(ordldt_itm_itemid == null)
997                _ps.setNull(6, Types.BIGINT);
998            else
999                _ps.setLong(6, ordldt_itm_itemid.getEntityId());
1000            
1001            InventoryConditionPK ordldt_invcon_inventoryconditionid = _value.getInventoryConditionPK();
1002            if(ordldt_invcon_inventoryconditionid == null)
1003                _ps.setNull(7, Types.BIGINT);
1004            else
1005                _ps.setLong(7, ordldt_invcon_inventoryconditionid.getEntityId());
1006            
1007            UnitOfMeasureTypePK ordldt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK();
1008            if(ordldt_uomt_unitofmeasuretypeid == null)
1009                _ps.setNull(8, Types.BIGINT);
1010            else
1011                _ps.setLong(8, ordldt_uomt_unitofmeasuretypeid.getEntityId());
1012            
1013            Long ordldt_quantity = _value.getQuantity();
1014            if(ordldt_quantity == null)
1015                _ps.setNull(9, Types.BIGINT);
1016            else
1017                _ps.setLong(9, ordldt_quantity);
1018            
1019            Long ordldt_unitamount = _value.getUnitAmount();
1020            if(ordldt_unitamount == null)
1021                _ps.setNull(10, Types.BIGINT);
1022            else
1023                _ps.setLong(10, ordldt_unitamount);
1024            
1025            String ordldt_description = _value.getDescription();
1026            if(ordldt_description == null)
1027                _ps.setNull(11, Types.VARCHAR);
1028            else
1029                _ps.setString(11, ordldt_description);
1030            
1031            CancellationPolicyPK ordldt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK();
1032            if(ordldt_cnclplcy_cancellationpolicyid == null)
1033                _ps.setNull(12, Types.BIGINT);
1034            else
1035                _ps.setLong(12, ordldt_cnclplcy_cancellationpolicyid.getEntityId());
1036            
1037            ReturnPolicyPK ordldt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK();
1038            if(ordldt_rtnplcy_returnpolicyid == null)
1039                _ps.setNull(13, Types.BIGINT);
1040            else
1041                _ps.setLong(13, ordldt_rtnplcy_returnpolicyid.getEntityId());
1042            
1043            Boolean ordldt_taxable = _value.getTaxable();
1044            if(ordldt_taxable == null)
1045                _ps.setNull(14, Types.BIT);
1046            else
1047                _ps.setInt(14, ordldt_taxable? 1: 0);
1048            
1049            Long ordldt_fromtime = _value.getFromTime();
1050            if(ordldt_fromtime == null)
1051                _ps.setNull(15, Types.BIGINT);
1052            else
1053                _ps.setLong(15, ordldt_fromtime);
1054            
1055            Long ordldt_thrutime = _value.getThruTime();
1056            if(ordldt_thrutime == null)
1057                _ps.setNull(16, Types.BIGINT);
1058            else
1059                _ps.setLong(16, ordldt_thrutime);
1060            
1061            _ps.setLong(17, _value.getPrimaryKey().getEntityId());
1062            
1063            _value.clearHasBeenModified();
1064        }
1065        
1066        return _hasBeenModified;
1067    }
1068    
1069    @Override
1070    public void store(Session session, OrderLineDetail entity)
1071            throws PersistenceDatabaseException {
1072        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1073        
1074        try {
1075            OrderLineDetailValue _value = entity.getOrderLineDetailValue();
1076            
1077            if(bindForStore(_ps, _value)) {
1078                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1079                    int _count = _ps.executeUpdate();
1080                    
1081                    if(_count != 1) {
1082                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1083                    }
1084                } else {
1085                     _ps.executeUpdate();
1086                }
1087                
1088                session.getValueCache().put(_value);
1089            }
1090        } catch (SQLException se) {
1091            throw new PersistenceDatabaseException(se);
1092        }
1093    }
1094    
1095    @Override
1096    public void store(Session session, Collection<OrderLineDetail> entities)
1097            throws PersistenceDatabaseException {
1098        if(entities.size() > 0) {
1099            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1100            int _modifiedEntities = 0;
1101            
1102            try {
1103                for(OrderLineDetail entity : entities) {
1104                    if(bindForStore(_ps, entity.getOrderLineDetailValue())) {
1105                        _ps.addBatch();
1106                        _modifiedEntities++;
1107                    }
1108                }
1109                
1110                if(_modifiedEntities != 0) {
1111                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1112                        int[] _counts = _ps.executeBatch();
1113                        
1114                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1115                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1116                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1117                            }
1118                        }
1119                    } else {
1120                         _ps.executeBatch();
1121                    }
1122                    
1123                    _ps.clearBatch();
1124                    
1125                    entities.forEach((entity) -> {
1126                        session.getValueCache().put(entity.getOrderLineDetailValue());
1127                    });
1128                }
1129            } catch (SQLException se) {
1130                throw new PersistenceDatabaseException(se);
1131            }
1132        }
1133    }
1134    
1135    @Override
1136    public void store(Collection<OrderLineDetail> entities)
1137            throws PersistenceDatabaseException {
1138        store(ThreadSession.currentSession(), entities);
1139    }
1140    
1141    @Override
1142    public void remove(Session session, OrderLineDetail entity)
1143            throws PersistenceDatabaseException {
1144        remove(session, entity.getPrimaryKey());
1145    }
1146    
1147    @Override
1148    public void remove(Session session, OrderLineDetailPK pk)
1149            throws PersistenceDatabaseException {
1150        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1151        long _entityId = pk.getEntityId();
1152        
1153        try {
1154            _ps.setLong(1, _entityId);
1155            
1156            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1157                int _count = _ps.executeUpdate();
1158                
1159                if(_count != 1) {
1160                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1161                }
1162            } else {
1163                 _ps.executeUpdate();
1164            }
1165            
1166            session.getValueCache().remove(pk);
1167        } catch (SQLException se) {
1168            throw new PersistenceDatabaseException(se);
1169        }
1170        
1171        session.removed(pk, false);
1172    }
1173    
1174    @Override
1175    public void remove(Session session, Collection<OrderLineDetailPK> pks)
1176            throws PersistenceDatabaseException {
1177        if(pks.size() > 0) {
1178            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1179            int _modifiedEntities = 0;
1180            
1181            try {
1182                for(OrderLineDetailPK pk : pks) {
1183                    long _entityId = pk.getEntityId();
1184                    
1185                    _ps.setLong(1, _entityId);
1186                    
1187                    _ps.addBatch();
1188                    _modifiedEntities++;
1189                }
1190                
1191                if(_modifiedEntities != 0) {
1192                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1193                        int[] _counts = _ps.executeBatch();
1194                        
1195                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1196                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1197                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1198                            }
1199                        }
1200                    } else {
1201                        _ps.executeBatch();
1202                    }
1203                    
1204                    _ps.clearBatch();
1205                    
1206                    pks.forEach((pk) -> {
1207                        session.getValueCache().remove(pk);
1208                    });
1209                }
1210            } catch (SQLException se) {
1211                throw new PersistenceDatabaseException(se);
1212            }
1213            
1214            pks.forEach((pk) -> {
1215                session.removed(pk, true);
1216            });
1217        }
1218    }
1219    
1220    @Override
1221    public void remove(Collection<OrderLineDetailPK> pks)
1222            throws PersistenceDatabaseException {
1223        remove(ThreadSession.currentSession(), pks);
1224    }
1225    
1226    @Override
1227    public boolean validPK(Session session, OrderLineDetailPK pk)
1228            throws PersistenceDatabaseException {
1229        boolean valid = false;
1230        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1231        ResultSet _rs = null;
1232        
1233        try {
1234            _ps.setLong(1, pk.getEntityId());
1235            
1236            _rs = _ps.executeQuery();
1237            if(_rs.next()) {
1238                long _count = _rs.getLong(1);
1239                if(_rs.wasNull())
1240                    _count = 0;
1241                
1242                if(_count == 1)
1243                    valid = true;
1244            }
1245        } catch (SQLException se) {
1246            throw new PersistenceDatabaseException(se);
1247        } finally {
1248            if(_rs != null) {
1249                try {
1250                    _rs.close();
1251                } catch (SQLException se) {
1252                    // do nothing
1253                }
1254            }
1255        }
1256        
1257        return valid;
1258    }
1259    
1260}