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