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