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