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