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