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