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 * ItemDetailFactory.java
021 */
022
023package com.echothree.model.data.item.server.factory;
024
025import com.echothree.model.data.item.common.pk.ItemPK;
026import com.echothree.model.data.item.common.pk.ItemTypePK;
027import com.echothree.model.data.item.common.pk.ItemUseTypePK;
028import com.echothree.model.data.item.common.pk.ItemCategoryPK;
029import com.echothree.model.data.accounting.common.pk.ItemAccountingCategoryPK;
030import com.echothree.model.data.vendor.common.pk.ItemPurchasingCategoryPK;
031import com.echothree.model.data.party.common.pk.PartyPK;
032import com.echothree.model.data.item.common.pk.ItemDeliveryTypePK;
033import com.echothree.model.data.item.common.pk.ItemInventoryTypePK;
034import com.echothree.model.data.sequence.common.pk.SequencePK;
035import com.echothree.model.data.uom.common.pk.UnitOfMeasureKindPK;
036import com.echothree.model.data.item.common.pk.ItemPriceTypePK;
037import com.echothree.model.data.cancellationpolicy.common.pk.CancellationPolicyPK;
038import com.echothree.model.data.returnpolicy.common.pk.ReturnPolicyPK;
039import com.echothree.model.data.style.common.pk.StylePathPK;
040
041import com.echothree.model.data.item.server.entity.Item;
042import com.echothree.model.data.item.server.entity.ItemType;
043import com.echothree.model.data.item.server.entity.ItemUseType;
044import com.echothree.model.data.item.server.entity.ItemCategory;
045import com.echothree.model.data.accounting.server.entity.ItemAccountingCategory;
046import com.echothree.model.data.vendor.server.entity.ItemPurchasingCategory;
047import com.echothree.model.data.party.server.entity.Party;
048import com.echothree.model.data.item.server.entity.ItemDeliveryType;
049import com.echothree.model.data.item.server.entity.ItemInventoryType;
050import com.echothree.model.data.sequence.server.entity.Sequence;
051import com.echothree.model.data.uom.server.entity.UnitOfMeasureKind;
052import com.echothree.model.data.item.server.entity.ItemPriceType;
053import com.echothree.model.data.cancellationpolicy.server.entity.CancellationPolicy;
054import com.echothree.model.data.returnpolicy.server.entity.ReturnPolicy;
055import com.echothree.model.data.style.server.entity.StylePath;
056
057import com.echothree.model.data.item.common.ItemDetailConstants;
058import com.echothree.model.data.item.common.pk.ItemDetailPK;
059import com.echothree.model.data.item.server.value.ItemDetailValue;
060import com.echothree.model.data.item.server.entity.ItemDetail;
061import com.echothree.util.common.exception.PersistenceDatabaseException;
062import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
063import com.echothree.util.common.exception.PersistenceNotNullException;
064import com.echothree.util.server.persistence.BaseFactory;
065import com.echothree.util.server.persistence.EntityIdGenerator;
066import com.echothree.util.server.persistence.EntityPermission;
067import com.echothree.util.server.persistence.PersistenceDebugFlags;
068import com.echothree.util.server.persistence.Session;
069import java.sql.PreparedStatement;
070import java.sql.ResultSet;
071import java.sql.SQLException;
072import java.sql.Types;
073import java.io.ByteArrayInputStream;
074import java.io.StringReader;
075import java.util.ArrayList;
076import java.util.Collection;
077import java.util.HashSet;
078import java.util.List;
079import java.util.Map;
080import java.util.Set;
081import javax.enterprise.context.ApplicationScoped;
082import javax.enterprise.inject.spi.CDI;
083import javax.inject.Inject;
084import org.jooq.ResultQuery;
085import org.slf4j.Logger;
086import org.slf4j.LoggerFactory;
087
088@ApplicationScoped
089public class ItemDetailFactory
090        implements BaseFactory<ItemDetailPK, ItemDetail> {
091    
092    @Inject
093    Session session;
094    
095    //private static final Logger log = LoggerFactory.getLogger(ItemDetailFactory.class);
096    
097    final private static String SQL_SELECT_READ_ONLY = "SELECT itmdt_itemdetailid, itmdt_itm_itemid, itmdt_itemname, itmdt_ityp_itemtypeid, itmdt_iutyp_itemusetypeid, itmdt_ic_itemcategoryid, itmdt_iactgc_itemaccountingcategoryid, itmdt_iprchc_itempurchasingcategoryid, itmdt_companypartyid, itmdt_idlvrtyp_itemdeliverytypeid, itmdt_iinvtyp_iteminventorytypeid, itmdt_inventoryserialized, itmdt_serialnumbersequenceid, itmdt_shippingchargeexempt, itmdt_shippingstarttime, itmdt_shippingendtime, itmdt_salesorderstarttime, itmdt_salesorderendtime, itmdt_purchaseorderstarttime, itmdt_purchaseorderendtime, itmdt_allowclubdiscounts, itmdt_allowcoupondiscounts, itmdt_allowassociatepayments, itmdt_uomk_unitofmeasurekindid, itmdt_ipt_itempricetypeid, itmdt_cnclplcy_cancellationpolicyid, itmdt_rtnplcy_returnpolicyid, itmdt_stylpth_stylepathid, itmdt_fromtime, itmdt_thrutime FROM itemdetails WHERE itmdt_itemdetailid = ?";
098    final private static String SQL_SELECT_READ_WRITE = "SELECT itmdt_itemdetailid, itmdt_itm_itemid, itmdt_itemname, itmdt_ityp_itemtypeid, itmdt_iutyp_itemusetypeid, itmdt_ic_itemcategoryid, itmdt_iactgc_itemaccountingcategoryid, itmdt_iprchc_itempurchasingcategoryid, itmdt_companypartyid, itmdt_idlvrtyp_itemdeliverytypeid, itmdt_iinvtyp_iteminventorytypeid, itmdt_inventoryserialized, itmdt_serialnumbersequenceid, itmdt_shippingchargeexempt, itmdt_shippingstarttime, itmdt_shippingendtime, itmdt_salesorderstarttime, itmdt_salesorderendtime, itmdt_purchaseorderstarttime, itmdt_purchaseorderendtime, itmdt_allowclubdiscounts, itmdt_allowcoupondiscounts, itmdt_allowassociatepayments, itmdt_uomk_unitofmeasurekindid, itmdt_ipt_itempricetypeid, itmdt_cnclplcy_cancellationpolicyid, itmdt_rtnplcy_returnpolicyid, itmdt_stylpth_stylepathid, itmdt_fromtime, itmdt_thrutime FROM itemdetails WHERE itmdt_itemdetailid = ? FOR UPDATE";
099    final private static String SQL_INSERT = "INSERT INTO itemdetails (itmdt_itemdetailid, itmdt_itm_itemid, itmdt_itemname, itmdt_ityp_itemtypeid, itmdt_iutyp_itemusetypeid, itmdt_ic_itemcategoryid, itmdt_iactgc_itemaccountingcategoryid, itmdt_iprchc_itempurchasingcategoryid, itmdt_companypartyid, itmdt_idlvrtyp_itemdeliverytypeid, itmdt_iinvtyp_iteminventorytypeid, itmdt_inventoryserialized, itmdt_serialnumbersequenceid, itmdt_shippingchargeexempt, itmdt_shippingstarttime, itmdt_shippingendtime, itmdt_salesorderstarttime, itmdt_salesorderendtime, itmdt_purchaseorderstarttime, itmdt_purchaseorderendtime, itmdt_allowclubdiscounts, itmdt_allowcoupondiscounts, itmdt_allowassociatepayments, itmdt_uomk_unitofmeasurekindid, itmdt_ipt_itempricetypeid, itmdt_cnclplcy_cancellationpolicyid, itmdt_rtnplcy_returnpolicyid, itmdt_stylpth_stylepathid, itmdt_fromtime, itmdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
100    final private static String SQL_UPDATE = "UPDATE itemdetails SET itmdt_itm_itemid = ?, itmdt_itemname = ?, itmdt_ityp_itemtypeid = ?, itmdt_iutyp_itemusetypeid = ?, itmdt_ic_itemcategoryid = ?, itmdt_iactgc_itemaccountingcategoryid = ?, itmdt_iprchc_itempurchasingcategoryid = ?, itmdt_companypartyid = ?, itmdt_idlvrtyp_itemdeliverytypeid = ?, itmdt_iinvtyp_iteminventorytypeid = ?, itmdt_inventoryserialized = ?, itmdt_serialnumbersequenceid = ?, itmdt_shippingchargeexempt = ?, itmdt_shippingstarttime = ?, itmdt_shippingendtime = ?, itmdt_salesorderstarttime = ?, itmdt_salesorderendtime = ?, itmdt_purchaseorderstarttime = ?, itmdt_purchaseorderendtime = ?, itmdt_allowclubdiscounts = ?, itmdt_allowcoupondiscounts = ?, itmdt_allowassociatepayments = ?, itmdt_uomk_unitofmeasurekindid = ?, itmdt_ipt_itempricetypeid = ?, itmdt_cnclplcy_cancellationpolicyid = ?, itmdt_rtnplcy_returnpolicyid = ?, itmdt_stylpth_stylepathid = ?, itmdt_fromtime = ?, itmdt_thrutime = ? WHERE itmdt_itemdetailid = ?";
101    final private static String SQL_DELETE = "DELETE FROM itemdetails WHERE itmdt_itemdetailid = ?";
102    final private static String SQL_VALID = "SELECT COUNT(*) FROM itemdetails WHERE itmdt_itemdetailid = ?";
103    
104    final public static String ITMDT_ITEMDETAILID = "itmdt_itemdetailid";
105    final public static String ITMDT_ITM_ITEMID = "itmdt_itm_itemid";
106    final public static String ITMDT_ITEMNAME = "itmdt_itemname";
107    final public static String ITMDT_ITYP_ITEMTYPEID = "itmdt_ityp_itemtypeid";
108    final public static String ITMDT_IUTYP_ITEMUSETYPEID = "itmdt_iutyp_itemusetypeid";
109    final public static String ITMDT_IC_ITEMCATEGORYID = "itmdt_ic_itemcategoryid";
110    final public static String ITMDT_IACTGC_ITEMACCOUNTINGCATEGORYID = "itmdt_iactgc_itemaccountingcategoryid";
111    final public static String ITMDT_IPRCHC_ITEMPURCHASINGCATEGORYID = "itmdt_iprchc_itempurchasingcategoryid";
112    final public static String ITMDT_COMPANYPARTYID = "itmdt_companypartyid";
113    final public static String ITMDT_IDLVRTYP_ITEMDELIVERYTYPEID = "itmdt_idlvrtyp_itemdeliverytypeid";
114    final public static String ITMDT_IINVTYP_ITEMINVENTORYTYPEID = "itmdt_iinvtyp_iteminventorytypeid";
115    final public static String ITMDT_INVENTORYSERIALIZED = "itmdt_inventoryserialized";
116    final public static String ITMDT_SERIALNUMBERSEQUENCEID = "itmdt_serialnumbersequenceid";
117    final public static String ITMDT_SHIPPINGCHARGEEXEMPT = "itmdt_shippingchargeexempt";
118    final public static String ITMDT_SHIPPINGSTARTTIME = "itmdt_shippingstarttime";
119    final public static String ITMDT_SHIPPINGENDTIME = "itmdt_shippingendtime";
120    final public static String ITMDT_SALESORDERSTARTTIME = "itmdt_salesorderstarttime";
121    final public static String ITMDT_SALESORDERENDTIME = "itmdt_salesorderendtime";
122    final public static String ITMDT_PURCHASEORDERSTARTTIME = "itmdt_purchaseorderstarttime";
123    final public static String ITMDT_PURCHASEORDERENDTIME = "itmdt_purchaseorderendtime";
124    final public static String ITMDT_ALLOWCLUBDISCOUNTS = "itmdt_allowclubdiscounts";
125    final public static String ITMDT_ALLOWCOUPONDISCOUNTS = "itmdt_allowcoupondiscounts";
126    final public static String ITMDT_ALLOWASSOCIATEPAYMENTS = "itmdt_allowassociatepayments";
127    final public static String ITMDT_UOMK_UNITOFMEASUREKINDID = "itmdt_uomk_unitofmeasurekindid";
128    final public static String ITMDT_IPT_ITEMPRICETYPEID = "itmdt_ipt_itempricetypeid";
129    final public static String ITMDT_CNCLPLCY_CANCELLATIONPOLICYID = "itmdt_cnclplcy_cancellationpolicyid";
130    final public static String ITMDT_RTNPLCY_RETURNPOLICYID = "itmdt_rtnplcy_returnpolicyid";
131    final public static String ITMDT_STYLPTH_STYLEPATHID = "itmdt_stylpth_stylepathid";
132    final public static String ITMDT_FROMTIME = "itmdt_fromtime";
133    final public static String ITMDT_THRUTIME = "itmdt_thrutime";
134    
135    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ItemDetailConstants.COMPONENT_VENDOR_NAME, ItemDetailConstants.ENTITY_TYPE_NAME);
136    
137    /** Creates a new instance of ItemDetailFactory */
138    protected ItemDetailFactory() {
139        super();
140    }
141    
142    public static ItemDetailFactory getInstance() {
143        return CDI.current().select(ItemDetailFactory.class).get();
144    }
145    
146    @Override
147    public String getComponentVendorName() {
148        return ItemDetailConstants.COMPONENT_VENDOR_NAME;
149    }
150    
151    @Override
152    public String getEntityTypeName() {
153        return ItemDetailConstants.ENTITY_TYPE_NAME;
154    }
155    
156    public PreparedStatement prepareStatement(String query) {
157        return session.prepareStatement(query);
158    }
159    
160    public ItemDetailPK getNextPK() {
161        return new ItemDetailPK(entityIdGenerator.getNextEntityId());
162    }
163    
164    public Set<ItemDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
165            throws PersistenceDatabaseException {
166        Set<ItemDetailPK> _result = new HashSet<>();
167        
168        try {
169            while(rs.next()) {
170                _result.add(getPKFromResultSet(rs));
171            }
172        } catch (SQLException se) {
173            throw new PersistenceDatabaseException(se);
174        }
175        
176        return _result;
177    }
178    
179    public java.util.List<ItemDetailPK> getPKsFromResultSetAsList(ResultSet rs)
180            throws PersistenceDatabaseException {
181        java.util.List<ItemDetailPK> _result = new ArrayList<>();
182        
183        try {
184            while(rs.next()) {
185                _result.add(getPKFromResultSet(rs));
186            }
187        } catch (SQLException se) {
188            throw new PersistenceDatabaseException(se);
189        }
190        
191        return _result;
192    }
193    
194    public ItemDetailPK getPKFromResultSet(ResultSet rs)
195            throws PersistenceDatabaseException {
196        ItemDetailPK _result;
197        
198        try {
199            long itmdt_itemdetailid = rs.getLong(ITMDT_ITEMDETAILID);
200            Long _entityId = rs.wasNull() ? null : itmdt_itemdetailid;
201            
202            _result = new ItemDetailPK(_entityId);
203        } catch (SQLException se) {
204            throw new PersistenceDatabaseException(se);
205        }
206        
207        return _result;
208    }
209    
210    public java.util.List<ItemDetailValue> getValuesFromPKs(Collection<ItemDetailPK> pks)
211            throws PersistenceDatabaseException {
212        java.util.List<ItemDetailValue> _values = new ArrayList<>(pks.size());
213        
214        for(ItemDetailPK _pk: pks) {
215            _values.add(getValueFromPK(_pk));
216        }
217        
218        return _values;
219    }
220    
221    public ItemDetailValue getValueFromPK(ItemDetailPK pk)
222            throws PersistenceDatabaseException {
223        ItemDetailValue _value;
224        
225        // See if we already have the entity in the session cache
226        ItemDetail _entity = (ItemDetail)session.getEntity(pk);
227        if(_entity == null)
228            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getItemDetailValue();
229        else
230            _value = _entity.getItemDetailValue();
231        
232        return _value;
233    }
234    
235    public java.util.List<ItemDetailValue> getValuesFromResultSet(ResultSet rs)
236            throws PersistenceDatabaseException {
237        java.util.List<ItemDetailValue> _result = new ArrayList<>();
238        
239        try {
240            while(rs.next()) {
241                _result.add(getValueFromResultSet(rs));
242            }
243        } catch (SQLException se) {
244            throw new PersistenceDatabaseException(se);
245        }
246        
247        return _result;
248    }
249    
250    public ItemDetailValue getValueFromResultSet(ResultSet rs)
251            throws PersistenceDatabaseException {
252        ItemDetailValue _value;
253        
254        try {
255            Long itmdt_itemdetailid = rs.getLong(ITMDT_ITEMDETAILID);
256            ItemDetailPK _pk = new ItemDetailPK(itmdt_itemdetailid);
257            
258            // See if we already have the entity in the session cache
259            ItemDetail _entity = (ItemDetail)session.getEntity(_pk);
260            
261            if(_entity == null) {
262                Long itmdt_itm_itemid = rs.getLong(ITMDT_ITM_ITEMID);
263                if(rs.wasNull())
264                    itmdt_itm_itemid = null;
265                
266                String itmdt_itemname = rs.getString(ITMDT_ITEMNAME);
267                if(rs.wasNull())
268                    itmdt_itemname = null;
269                
270                Long itmdt_ityp_itemtypeid = rs.getLong(ITMDT_ITYP_ITEMTYPEID);
271                if(rs.wasNull())
272                    itmdt_ityp_itemtypeid = null;
273                
274                Long itmdt_iutyp_itemusetypeid = rs.getLong(ITMDT_IUTYP_ITEMUSETYPEID);
275                if(rs.wasNull())
276                    itmdt_iutyp_itemusetypeid = null;
277                
278                Long itmdt_ic_itemcategoryid = rs.getLong(ITMDT_IC_ITEMCATEGORYID);
279                if(rs.wasNull())
280                    itmdt_ic_itemcategoryid = null;
281                
282                Long itmdt_iactgc_itemaccountingcategoryid = rs.getLong(ITMDT_IACTGC_ITEMACCOUNTINGCATEGORYID);
283                if(rs.wasNull())
284                    itmdt_iactgc_itemaccountingcategoryid = null;
285                
286                Long itmdt_iprchc_itempurchasingcategoryid = rs.getLong(ITMDT_IPRCHC_ITEMPURCHASINGCATEGORYID);
287                if(rs.wasNull())
288                    itmdt_iprchc_itempurchasingcategoryid = null;
289                
290                Long itmdt_companypartyid = rs.getLong(ITMDT_COMPANYPARTYID);
291                if(rs.wasNull())
292                    itmdt_companypartyid = null;
293                
294                Long itmdt_idlvrtyp_itemdeliverytypeid = rs.getLong(ITMDT_IDLVRTYP_ITEMDELIVERYTYPEID);
295                if(rs.wasNull())
296                    itmdt_idlvrtyp_itemdeliverytypeid = null;
297                
298                Long itmdt_iinvtyp_iteminventorytypeid = rs.getLong(ITMDT_IINVTYP_ITEMINVENTORYTYPEID);
299                if(rs.wasNull())
300                    itmdt_iinvtyp_iteminventorytypeid = null;
301                
302                Boolean itmdt_inventoryserialized = rs.getInt(ITMDT_INVENTORYSERIALIZED) == 1;
303                if(rs.wasNull())
304                    itmdt_inventoryserialized = null;
305                
306                Long itmdt_serialnumbersequenceid = rs.getLong(ITMDT_SERIALNUMBERSEQUENCEID);
307                if(rs.wasNull())
308                    itmdt_serialnumbersequenceid = null;
309                
310                Boolean itmdt_shippingchargeexempt = rs.getInt(ITMDT_SHIPPINGCHARGEEXEMPT) == 1;
311                if(rs.wasNull())
312                    itmdt_shippingchargeexempt = null;
313                
314                Long itmdt_shippingstarttime = rs.getLong(ITMDT_SHIPPINGSTARTTIME);
315                if(rs.wasNull())
316                    itmdt_shippingstarttime = null;
317                
318                Long itmdt_shippingendtime = rs.getLong(ITMDT_SHIPPINGENDTIME);
319                if(rs.wasNull())
320                    itmdt_shippingendtime = null;
321                
322                Long itmdt_salesorderstarttime = rs.getLong(ITMDT_SALESORDERSTARTTIME);
323                if(rs.wasNull())
324                    itmdt_salesorderstarttime = null;
325                
326                Long itmdt_salesorderendtime = rs.getLong(ITMDT_SALESORDERENDTIME);
327                if(rs.wasNull())
328                    itmdt_salesorderendtime = null;
329                
330                Long itmdt_purchaseorderstarttime = rs.getLong(ITMDT_PURCHASEORDERSTARTTIME);
331                if(rs.wasNull())
332                    itmdt_purchaseorderstarttime = null;
333                
334                Long itmdt_purchaseorderendtime = rs.getLong(ITMDT_PURCHASEORDERENDTIME);
335                if(rs.wasNull())
336                    itmdt_purchaseorderendtime = null;
337                
338                Boolean itmdt_allowclubdiscounts = rs.getInt(ITMDT_ALLOWCLUBDISCOUNTS) == 1;
339                if(rs.wasNull())
340                    itmdt_allowclubdiscounts = null;
341                
342                Boolean itmdt_allowcoupondiscounts = rs.getInt(ITMDT_ALLOWCOUPONDISCOUNTS) == 1;
343                if(rs.wasNull())
344                    itmdt_allowcoupondiscounts = null;
345                
346                Boolean itmdt_allowassociatepayments = rs.getInt(ITMDT_ALLOWASSOCIATEPAYMENTS) == 1;
347                if(rs.wasNull())
348                    itmdt_allowassociatepayments = null;
349                
350                Long itmdt_uomk_unitofmeasurekindid = rs.getLong(ITMDT_UOMK_UNITOFMEASUREKINDID);
351                if(rs.wasNull())
352                    itmdt_uomk_unitofmeasurekindid = null;
353                
354                Long itmdt_ipt_itempricetypeid = rs.getLong(ITMDT_IPT_ITEMPRICETYPEID);
355                if(rs.wasNull())
356                    itmdt_ipt_itempricetypeid = null;
357                
358                Long itmdt_cnclplcy_cancellationpolicyid = rs.getLong(ITMDT_CNCLPLCY_CANCELLATIONPOLICYID);
359                if(rs.wasNull())
360                    itmdt_cnclplcy_cancellationpolicyid = null;
361                
362                Long itmdt_rtnplcy_returnpolicyid = rs.getLong(ITMDT_RTNPLCY_RETURNPOLICYID);
363                if(rs.wasNull())
364                    itmdt_rtnplcy_returnpolicyid = null;
365                
366                Long itmdt_stylpth_stylepathid = rs.getLong(ITMDT_STYLPTH_STYLEPATHID);
367                if(rs.wasNull())
368                    itmdt_stylpth_stylepathid = null;
369                
370                Long itmdt_fromtime = rs.getLong(ITMDT_FROMTIME);
371                if(rs.wasNull())
372                    itmdt_fromtime = null;
373                
374                Long itmdt_thrutime = rs.getLong(ITMDT_THRUTIME);
375                if(rs.wasNull())
376                    itmdt_thrutime = null;
377                
378                _value = new ItemDetailValue(_pk, new ItemPK(itmdt_itm_itemid), itmdt_itemname, new ItemTypePK(itmdt_ityp_itemtypeid), new ItemUseTypePK(itmdt_iutyp_itemusetypeid), new ItemCategoryPK(itmdt_ic_itemcategoryid), new ItemAccountingCategoryPK(itmdt_iactgc_itemaccountingcategoryid), new ItemPurchasingCategoryPK(itmdt_iprchc_itempurchasingcategoryid), new PartyPK(itmdt_companypartyid), new ItemDeliveryTypePK(itmdt_idlvrtyp_itemdeliverytypeid), new ItemInventoryTypePK(itmdt_iinvtyp_iteminventorytypeid), itmdt_inventoryserialized, new SequencePK(itmdt_serialnumbersequenceid), itmdt_shippingchargeexempt, itmdt_shippingstarttime, itmdt_shippingendtime, itmdt_salesorderstarttime, itmdt_salesorderendtime, itmdt_purchaseorderstarttime, itmdt_purchaseorderendtime, itmdt_allowclubdiscounts, itmdt_allowcoupondiscounts, itmdt_allowassociatepayments, new UnitOfMeasureKindPK(itmdt_uomk_unitofmeasurekindid), new ItemPriceTypePK(itmdt_ipt_itempricetypeid), new CancellationPolicyPK(itmdt_cnclplcy_cancellationpolicyid), new ReturnPolicyPK(itmdt_rtnplcy_returnpolicyid), new StylePathPK(itmdt_stylpth_stylepathid), itmdt_fromtime, itmdt_thrutime);
379            } else
380                _value = _entity.getItemDetailValue();
381        } catch (SQLException se) {
382            throw new PersistenceDatabaseException(se);
383        }
384        
385        return _value;
386    }
387    
388    public java.util.List<ItemDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ItemDetailPK> pks)
389            throws PersistenceDatabaseException {
390        java.util.List<ItemDetail> _entities = new ArrayList<>(pks.size());
391        
392        for(ItemDetailPK _pk: pks) {
393            _entities.add(getEntityFromPK(entityPermission, _pk));
394        }
395        
396        return _entities;
397    }
398    
399    public ItemDetail getEntityFromValue(EntityPermission entityPermission, ItemDetailValue value) {
400        return getEntityFromPK(entityPermission, value.getPrimaryKey());
401    }
402    
403    public ItemDetail getEntityFromCache(ItemDetailPK pk) {
404        ItemDetailValue _value = (ItemDetailValue)session.getValueCache().get(pk);
405    
406        return _value == null ? null : new ItemDetail(_value, EntityPermission.READ_ONLY);
407    }
408    
409    public ItemDetail getEntityFromPK(EntityPermission entityPermission, ItemDetailPK pk)
410            throws PersistenceDatabaseException {
411        ItemDetail _entity;
412        
413        // See if we already have the entity in the session cache
414        _entity = (ItemDetail)session.getEntity(pk);
415        if(_entity != null) {
416            // If the requested permission is READ_WRITE, and the cached permission is
417            // READ_ONLY, then pretend that the cached object wasn't found, and create
418            // a new entity that is READ_WRITE.
419            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
420                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
421                    _entity = null;
422            }
423        }
424        
425        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
426            _entity = getEntityFromCache(pk);
427        }
428        
429        if(_entity == null) {
430            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
431            long _entityId = pk.getEntityId();
432            ResultSet _rs = null;
433            
434            try {
435                _ps.setLong(1, _entityId);
436                _rs = _ps.executeQuery();
437                if(_rs.next()) {
438                    _entity = getEntityFromResultSet(entityPermission, _rs);
439                }
440            } catch (SQLException se) {
441                throw new PersistenceDatabaseException(se);
442            } finally {
443                if(_rs != null) {
444                    try {
445                        _rs.close();
446                    } catch (SQLException se) {
447                        // do nothing
448                    }
449                }
450            }
451        }
452        
453        return _entity;
454    }
455    
456    public Set<ItemDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
457            throws PersistenceDatabaseException {
458        Set<ItemDetailPK> _pks;
459        ResultSet _rs = null;
460        
461        try {
462            if(params.length != 0) {
463                Session.setQueryParams(ps, params);
464            }
465            
466            _rs = ps.executeQuery();
467            _pks = getPKsFromResultSetAsSet(_rs);
468            _rs.close();
469        } catch (SQLException se) {
470            throw new PersistenceDatabaseException(se);
471        } finally {
472            if(_rs != null) {
473                try {
474                    _rs.close();
475                } catch (SQLException se) {
476                    // do nothing
477                }
478            }
479        }
480        
481        return _pks;
482    }
483    
484    public java.util.List<ItemDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
485            throws PersistenceDatabaseException {
486        java.util.List<ItemDetailPK> _pks;
487        ResultSet _rs = null;
488        
489        try {
490            if(params.length != 0) {
491                Session.setQueryParams(ps, params);
492            }
493            
494            _rs = ps.executeQuery();
495            _pks = getPKsFromResultSetAsList(_rs);
496            _rs.close();
497        } catch (SQLException se) {
498            throw new PersistenceDatabaseException(se);
499        } finally {
500            if(_rs != null) {
501                try {
502                    _rs.close();
503                } catch (SQLException se) {
504                    // do nothing
505                }
506            }
507        }
508        
509        return _pks;
510    }
511    
512    public ItemDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
513            throws PersistenceDatabaseException {
514        ItemDetailPK _pk = null;
515        ResultSet _rs = null;
516        
517        try {
518            if(params.length != 0) {
519                Session.setQueryParams(ps, params);
520            }
521            
522            _rs = ps.executeQuery();
523            if(_rs.next()) {
524                _pk = getPKFromResultSet(_rs);
525            }
526            _rs.close();
527        } catch (SQLException se) {
528            throw new PersistenceDatabaseException(se);
529        } finally {
530            if(_rs != null) {
531                try {
532                    _rs.close();
533                } catch (SQLException se) {
534                    // do nothing
535                }
536            }
537        }
538        
539        return _pk;
540    }
541    
542    public java.util.List<ItemDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
543            throws PersistenceDatabaseException {
544        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
545        
546        return getEntitiesFromQuery(entityPermission, ps, params);
547    }
548    
549    public java.util.List<ItemDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
550            throws PersistenceDatabaseException {
551        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
552        
553        return getEntitiesFromQuery(entityPermission, ps);
554    }
555    
556    public java.util.List<ItemDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
557            throws PersistenceDatabaseException {
558        PreparedStatement ps = session.prepareStatement(query.getSQL());
559        
560        return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray());
561    }
562    
563    public java.util.List<ItemDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
564            throws PersistenceDatabaseException {
565        java.util.List<ItemDetail> _entities;
566        ResultSet _rs = null;
567        
568        try {
569            if(params.length != 0) {
570                Session.setQueryParams(ps, params);
571            }
572            
573            _rs = ps.executeQuery();
574            _entities = getEntitiesFromResultSet(entityPermission, _rs);
575            _rs.close();
576        } catch (SQLException se) {
577            throw new PersistenceDatabaseException(se);
578        } finally {
579            if(_rs != null) {
580                try {
581                    _rs.close();
582                } catch (SQLException se) {
583                    // do nothing
584                }
585            }
586        }
587        
588        return _entities;
589    }
590    
591    public ItemDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
592            throws PersistenceDatabaseException {
593        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
594        
595        return getEntityFromQuery(entityPermission, ps, params);
596    }
597    
598    public ItemDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
599            throws PersistenceDatabaseException {
600        PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission));
601        
602        return getEntityFromQuery(entityPermission, ps);
603    }
604    
605    public ItemDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
606            throws PersistenceDatabaseException {
607        PreparedStatement ps = session.prepareStatement(query.getSQL());
608        
609        return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray());
610    }
611    
612    public ItemDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
613            throws PersistenceDatabaseException {
614        ItemDetail _entity = null;
615        ResultSet _rs = null;
616        
617        try {
618            if(params.length != 0) {
619                Session.setQueryParams(ps, params);
620            }
621            
622            _rs = ps.executeQuery();
623            if(_rs.next()) {
624                _entity = getEntityFromResultSet(entityPermission, _rs);
625            }
626            _rs.close();
627        } catch (SQLException se) {
628            throw new PersistenceDatabaseException(se);
629        } finally {
630            if(_rs != null) {
631                try {
632                    _rs.close();
633                } catch (SQLException se) {
634                    // do nothing
635                }
636            }
637        }
638        
639        return _entity;
640    }
641    
642    public java.util.List<ItemDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
643            throws PersistenceDatabaseException {
644        java.util.List<ItemDetail> _result = new ArrayList<>();
645        
646        try {
647            while(rs.next()) {
648                _result.add(getEntityFromResultSet(entityPermission, rs));
649            }
650        } catch (SQLException se) {
651            throw new PersistenceDatabaseException(se);
652        }
653        
654        return _result;
655    }
656    
657    public ItemDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
658            throws PersistenceDatabaseException {
659        ItemDetail _entity;
660        
661        try {
662            Long itmdt_itemdetailid = rs.getLong(ITMDT_ITEMDETAILID);
663            ItemDetailPK _pk = new ItemDetailPK(itmdt_itemdetailid);
664            
665            // See if we already have the entity in the session cache
666            _entity = (ItemDetail)session.getEntity(_pk);
667            if(_entity != null) {
668                // If the requested permission is READ_WRITE, and the cached permission is
669                // READ_ONLY, then pretend that the cached object wasn't found, and create
670                // a new entity that is READ_WRITE.
671                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
672                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
673                        _entity = null;
674                }
675            }
676            boolean foundInSessionCache = _entity != null;
677            
678            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
679                _entity = getEntityFromCache(_pk);
680            }
681            
682            if(_entity == null) {
683                Long itmdt_itm_itemid = rs.getLong(ITMDT_ITM_ITEMID);
684                if(rs.wasNull())
685                    itmdt_itm_itemid = null;
686                
687                String itmdt_itemname = rs.getString(ITMDT_ITEMNAME);
688                if(rs.wasNull())
689                    itmdt_itemname = null;
690                
691                Long itmdt_ityp_itemtypeid = rs.getLong(ITMDT_ITYP_ITEMTYPEID);
692                if(rs.wasNull())
693                    itmdt_ityp_itemtypeid = null;
694                
695                Long itmdt_iutyp_itemusetypeid = rs.getLong(ITMDT_IUTYP_ITEMUSETYPEID);
696                if(rs.wasNull())
697                    itmdt_iutyp_itemusetypeid = null;
698                
699                Long itmdt_ic_itemcategoryid = rs.getLong(ITMDT_IC_ITEMCATEGORYID);
700                if(rs.wasNull())
701                    itmdt_ic_itemcategoryid = null;
702                
703                Long itmdt_iactgc_itemaccountingcategoryid = rs.getLong(ITMDT_IACTGC_ITEMACCOUNTINGCATEGORYID);
704                if(rs.wasNull())
705                    itmdt_iactgc_itemaccountingcategoryid = null;
706                
707                Long itmdt_iprchc_itempurchasingcategoryid = rs.getLong(ITMDT_IPRCHC_ITEMPURCHASINGCATEGORYID);
708                if(rs.wasNull())
709                    itmdt_iprchc_itempurchasingcategoryid = null;
710                
711                Long itmdt_companypartyid = rs.getLong(ITMDT_COMPANYPARTYID);
712                if(rs.wasNull())
713                    itmdt_companypartyid = null;
714                
715                Long itmdt_idlvrtyp_itemdeliverytypeid = rs.getLong(ITMDT_IDLVRTYP_ITEMDELIVERYTYPEID);
716                if(rs.wasNull())
717                    itmdt_idlvrtyp_itemdeliverytypeid = null;
718                
719                Long itmdt_iinvtyp_iteminventorytypeid = rs.getLong(ITMDT_IINVTYP_ITEMINVENTORYTYPEID);
720                if(rs.wasNull())
721                    itmdt_iinvtyp_iteminventorytypeid = null;
722                
723                Boolean itmdt_inventoryserialized = rs.getInt(ITMDT_INVENTORYSERIALIZED) == 1;
724                if(rs.wasNull())
725                    itmdt_inventoryserialized = null;
726                
727                Long itmdt_serialnumbersequenceid = rs.getLong(ITMDT_SERIALNUMBERSEQUENCEID);
728                if(rs.wasNull())
729                    itmdt_serialnumbersequenceid = null;
730                
731                Boolean itmdt_shippingchargeexempt = rs.getInt(ITMDT_SHIPPINGCHARGEEXEMPT) == 1;
732                if(rs.wasNull())
733                    itmdt_shippingchargeexempt = null;
734                
735                Long itmdt_shippingstarttime = rs.getLong(ITMDT_SHIPPINGSTARTTIME);
736                if(rs.wasNull())
737                    itmdt_shippingstarttime = null;
738                
739                Long itmdt_shippingendtime = rs.getLong(ITMDT_SHIPPINGENDTIME);
740                if(rs.wasNull())
741                    itmdt_shippingendtime = null;
742                
743                Long itmdt_salesorderstarttime = rs.getLong(ITMDT_SALESORDERSTARTTIME);
744                if(rs.wasNull())
745                    itmdt_salesorderstarttime = null;
746                
747                Long itmdt_salesorderendtime = rs.getLong(ITMDT_SALESORDERENDTIME);
748                if(rs.wasNull())
749                    itmdt_salesorderendtime = null;
750                
751                Long itmdt_purchaseorderstarttime = rs.getLong(ITMDT_PURCHASEORDERSTARTTIME);
752                if(rs.wasNull())
753                    itmdt_purchaseorderstarttime = null;
754                
755                Long itmdt_purchaseorderendtime = rs.getLong(ITMDT_PURCHASEORDERENDTIME);
756                if(rs.wasNull())
757                    itmdt_purchaseorderendtime = null;
758                
759                Boolean itmdt_allowclubdiscounts = rs.getInt(ITMDT_ALLOWCLUBDISCOUNTS) == 1;
760                if(rs.wasNull())
761                    itmdt_allowclubdiscounts = null;
762                
763                Boolean itmdt_allowcoupondiscounts = rs.getInt(ITMDT_ALLOWCOUPONDISCOUNTS) == 1;
764                if(rs.wasNull())
765                    itmdt_allowcoupondiscounts = null;
766                
767                Boolean itmdt_allowassociatepayments = rs.getInt(ITMDT_ALLOWASSOCIATEPAYMENTS) == 1;
768                if(rs.wasNull())
769                    itmdt_allowassociatepayments = null;
770                
771                Long itmdt_uomk_unitofmeasurekindid = rs.getLong(ITMDT_UOMK_UNITOFMEASUREKINDID);
772                if(rs.wasNull())
773                    itmdt_uomk_unitofmeasurekindid = null;
774                
775                Long itmdt_ipt_itempricetypeid = rs.getLong(ITMDT_IPT_ITEMPRICETYPEID);
776                if(rs.wasNull())
777                    itmdt_ipt_itempricetypeid = null;
778                
779                Long itmdt_cnclplcy_cancellationpolicyid = rs.getLong(ITMDT_CNCLPLCY_CANCELLATIONPOLICYID);
780                if(rs.wasNull())
781                    itmdt_cnclplcy_cancellationpolicyid = null;
782                
783                Long itmdt_rtnplcy_returnpolicyid = rs.getLong(ITMDT_RTNPLCY_RETURNPOLICYID);
784                if(rs.wasNull())
785                    itmdt_rtnplcy_returnpolicyid = null;
786                
787                Long itmdt_stylpth_stylepathid = rs.getLong(ITMDT_STYLPTH_STYLEPATHID);
788                if(rs.wasNull())
789                    itmdt_stylpth_stylepathid = null;
790                
791                Long itmdt_fromtime = rs.getLong(ITMDT_FROMTIME);
792                if(rs.wasNull())
793                    itmdt_fromtime = null;
794                
795                Long itmdt_thrutime = rs.getLong(ITMDT_THRUTIME);
796                if(rs.wasNull())
797                    itmdt_thrutime = null;
798                
799                ItemDetailValue _value = new ItemDetailValue(_pk, itmdt_itm_itemid == null? null: new ItemPK(itmdt_itm_itemid), itmdt_itemname, itmdt_ityp_itemtypeid == null? null: new ItemTypePK(itmdt_ityp_itemtypeid), itmdt_iutyp_itemusetypeid == null? null: new ItemUseTypePK(itmdt_iutyp_itemusetypeid), itmdt_ic_itemcategoryid == null? null: new ItemCategoryPK(itmdt_ic_itemcategoryid), itmdt_iactgc_itemaccountingcategoryid == null? null: new ItemAccountingCategoryPK(itmdt_iactgc_itemaccountingcategoryid), itmdt_iprchc_itempurchasingcategoryid == null? null: new ItemPurchasingCategoryPK(itmdt_iprchc_itempurchasingcategoryid), itmdt_companypartyid == null? null: new PartyPK(itmdt_companypartyid), itmdt_idlvrtyp_itemdeliverytypeid == null? null: new ItemDeliveryTypePK(itmdt_idlvrtyp_itemdeliverytypeid), itmdt_iinvtyp_iteminventorytypeid == null? null: new ItemInventoryTypePK(itmdt_iinvtyp_iteminventorytypeid), itmdt_inventoryserialized, itmdt_serialnumbersequenceid == null? null: new SequencePK(itmdt_serialnumbersequenceid), itmdt_shippingchargeexempt, itmdt_shippingstarttime, itmdt_shippingendtime, itmdt_salesorderstarttime, itmdt_salesorderendtime, itmdt_purchaseorderstarttime, itmdt_purchaseorderendtime, itmdt_allowclubdiscounts, itmdt_allowcoupondiscounts, itmdt_allowassociatepayments, itmdt_uomk_unitofmeasurekindid == null? null: new UnitOfMeasureKindPK(itmdt_uomk_unitofmeasurekindid), itmdt_ipt_itempricetypeid == null? null: new ItemPriceTypePK(itmdt_ipt_itempricetypeid), itmdt_cnclplcy_cancellationpolicyid == null? null: new CancellationPolicyPK(itmdt_cnclplcy_cancellationpolicyid), itmdt_rtnplcy_returnpolicyid == null? null: new ReturnPolicyPK(itmdt_rtnplcy_returnpolicyid), itmdt_stylpth_stylepathid == null? null: new StylePathPK(itmdt_stylpth_stylepathid), itmdt_fromtime, itmdt_thrutime);
800                _entity = new ItemDetail(_value, entityPermission);
801            }
802            
803            if(!foundInSessionCache) {
804                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
805                    session.putReadOnlyEntity(_pk, _entity);
806                    session.getValueCache().put(_entity.getItemDetailValue());
807                } else {
808                    session.putReadWriteEntity(_pk, _entity);
809                }
810            }
811        } catch (SQLException se) {
812            throw new PersistenceDatabaseException(se);
813        }
814        
815        return _entity;
816    }
817    
818    public ItemDetail create(Item item, String itemName, ItemType itemType, ItemUseType itemUseType, ItemCategory itemCategory, ItemAccountingCategory itemAccountingCategory, ItemPurchasingCategory itemPurchasingCategory, Party companyParty, ItemDeliveryType itemDeliveryType, ItemInventoryType itemInventoryType, Boolean inventorySerialized, Sequence serialNumberSequence, Boolean shippingChargeExempt, Long shippingStartTime, Long shippingEndTime, Long salesOrderStartTime, Long salesOrderEndTime, Long purchaseOrderStartTime, Long purchaseOrderEndTime, Boolean allowClubDiscounts, Boolean allowCouponDiscounts, Boolean allowAssociatePayments, UnitOfMeasureKind unitOfMeasureKind, ItemPriceType itemPriceType, CancellationPolicy cancellationPolicy, ReturnPolicy returnPolicy, StylePath stylePath, Long fromTime, Long thruTime)
819            throws PersistenceDatabaseException, PersistenceNotNullException {
820        return create(item == null ? null : item.getPrimaryKey(), itemName, itemType == null ? null : itemType.getPrimaryKey(), itemUseType == null ? null : itemUseType.getPrimaryKey(), itemCategory == null ? null : itemCategory.getPrimaryKey(), itemAccountingCategory == null ? null : itemAccountingCategory.getPrimaryKey(), itemPurchasingCategory == null ? null : itemPurchasingCategory.getPrimaryKey(), companyParty == null ? null : companyParty.getPrimaryKey(), itemDeliveryType == null ? null : itemDeliveryType.getPrimaryKey(), itemInventoryType == null ? null : itemInventoryType.getPrimaryKey(), inventorySerialized, serialNumberSequence == null ? null : serialNumberSequence.getPrimaryKey(), shippingChargeExempt, shippingStartTime, shippingEndTime, salesOrderStartTime, salesOrderEndTime, purchaseOrderStartTime, purchaseOrderEndTime, allowClubDiscounts, allowCouponDiscounts, allowAssociatePayments, unitOfMeasureKind == null ? null : unitOfMeasureKind.getPrimaryKey(), itemPriceType == null ? null : itemPriceType.getPrimaryKey(), cancellationPolicy == null ? null : cancellationPolicy.getPrimaryKey(), returnPolicy == null ? null : returnPolicy.getPrimaryKey(), stylePath == null ? null : stylePath.getPrimaryKey(), fromTime, thruTime);
821    }
822    
823    private void bindForCreate(PreparedStatement _ps, ItemDetailValue _value)
824            throws SQLException {
825        _ps.setLong(1, _value.getEntityId());
826        
827        ItemPK itmdt_itm_itemid = _value.getItemPK();
828        if(itmdt_itm_itemid == null)
829            _ps.setNull(2, Types.BIGINT);
830        else
831            _ps.setLong(2, itmdt_itm_itemid.getEntityId());
832            
833        String itmdt_itemname = _value.getItemName();
834        if(itmdt_itemname == null)
835            _ps.setNull(3, Types.VARCHAR);
836        else
837            _ps.setString(3, itmdt_itemname);
838            
839        ItemTypePK itmdt_ityp_itemtypeid = _value.getItemTypePK();
840        if(itmdt_ityp_itemtypeid == null)
841            _ps.setNull(4, Types.BIGINT);
842        else
843            _ps.setLong(4, itmdt_ityp_itemtypeid.getEntityId());
844            
845        ItemUseTypePK itmdt_iutyp_itemusetypeid = _value.getItemUseTypePK();
846        if(itmdt_iutyp_itemusetypeid == null)
847            _ps.setNull(5, Types.BIGINT);
848        else
849            _ps.setLong(5, itmdt_iutyp_itemusetypeid.getEntityId());
850            
851        ItemCategoryPK itmdt_ic_itemcategoryid = _value.getItemCategoryPK();
852        if(itmdt_ic_itemcategoryid == null)
853            _ps.setNull(6, Types.BIGINT);
854        else
855            _ps.setLong(6, itmdt_ic_itemcategoryid.getEntityId());
856            
857        ItemAccountingCategoryPK itmdt_iactgc_itemaccountingcategoryid = _value.getItemAccountingCategoryPK();
858        if(itmdt_iactgc_itemaccountingcategoryid == null)
859            _ps.setNull(7, Types.BIGINT);
860        else
861            _ps.setLong(7, itmdt_iactgc_itemaccountingcategoryid.getEntityId());
862            
863        ItemPurchasingCategoryPK itmdt_iprchc_itempurchasingcategoryid = _value.getItemPurchasingCategoryPK();
864        if(itmdt_iprchc_itempurchasingcategoryid == null)
865            _ps.setNull(8, Types.BIGINT);
866        else
867            _ps.setLong(8, itmdt_iprchc_itempurchasingcategoryid.getEntityId());
868            
869        PartyPK itmdt_companypartyid = _value.getCompanyPartyPK();
870        if(itmdt_companypartyid == null)
871            _ps.setNull(9, Types.BIGINT);
872        else
873            _ps.setLong(9, itmdt_companypartyid.getEntityId());
874            
875        ItemDeliveryTypePK itmdt_idlvrtyp_itemdeliverytypeid = _value.getItemDeliveryTypePK();
876        if(itmdt_idlvrtyp_itemdeliverytypeid == null)
877            _ps.setNull(10, Types.BIGINT);
878        else
879            _ps.setLong(10, itmdt_idlvrtyp_itemdeliverytypeid.getEntityId());
880            
881        ItemInventoryTypePK itmdt_iinvtyp_iteminventorytypeid = _value.getItemInventoryTypePK();
882        if(itmdt_iinvtyp_iteminventorytypeid == null)
883            _ps.setNull(11, Types.BIGINT);
884        else
885            _ps.setLong(11, itmdt_iinvtyp_iteminventorytypeid.getEntityId());
886            
887        Boolean itmdt_inventoryserialized = _value.getInventorySerialized();
888        if(itmdt_inventoryserialized == null)
889            _ps.setNull(12, Types.BIT);
890        else
891            _ps.setInt(12, itmdt_inventoryserialized? 1: 0);
892            
893        SequencePK itmdt_serialnumbersequenceid = _value.getSerialNumberSequencePK();
894        if(itmdt_serialnumbersequenceid == null)
895            _ps.setNull(13, Types.BIGINT);
896        else
897            _ps.setLong(13, itmdt_serialnumbersequenceid.getEntityId());
898            
899        Boolean itmdt_shippingchargeexempt = _value.getShippingChargeExempt();
900        if(itmdt_shippingchargeexempt == null)
901            _ps.setNull(14, Types.BIT);
902        else
903            _ps.setInt(14, itmdt_shippingchargeexempt? 1: 0);
904            
905        Long itmdt_shippingstarttime = _value.getShippingStartTime();
906        if(itmdt_shippingstarttime == null)
907            _ps.setNull(15, Types.BIGINT);
908        else
909            _ps.setLong(15, itmdt_shippingstarttime);
910            
911        Long itmdt_shippingendtime = _value.getShippingEndTime();
912        if(itmdt_shippingendtime == null)
913            _ps.setNull(16, Types.BIGINT);
914        else
915            _ps.setLong(16, itmdt_shippingendtime);
916            
917        Long itmdt_salesorderstarttime = _value.getSalesOrderStartTime();
918        if(itmdt_salesorderstarttime == null)
919            _ps.setNull(17, Types.BIGINT);
920        else
921            _ps.setLong(17, itmdt_salesorderstarttime);
922            
923        Long itmdt_salesorderendtime = _value.getSalesOrderEndTime();
924        if(itmdt_salesorderendtime == null)
925            _ps.setNull(18, Types.BIGINT);
926        else
927            _ps.setLong(18, itmdt_salesorderendtime);
928            
929        Long itmdt_purchaseorderstarttime = _value.getPurchaseOrderStartTime();
930        if(itmdt_purchaseorderstarttime == null)
931            _ps.setNull(19, Types.BIGINT);
932        else
933            _ps.setLong(19, itmdt_purchaseorderstarttime);
934            
935        Long itmdt_purchaseorderendtime = _value.getPurchaseOrderEndTime();
936        if(itmdt_purchaseorderendtime == null)
937            _ps.setNull(20, Types.BIGINT);
938        else
939            _ps.setLong(20, itmdt_purchaseorderendtime);
940            
941        Boolean itmdt_allowclubdiscounts = _value.getAllowClubDiscounts();
942        if(itmdt_allowclubdiscounts == null)
943            _ps.setNull(21, Types.BIT);
944        else
945            _ps.setInt(21, itmdt_allowclubdiscounts? 1: 0);
946            
947        Boolean itmdt_allowcoupondiscounts = _value.getAllowCouponDiscounts();
948        if(itmdt_allowcoupondiscounts == null)
949            _ps.setNull(22, Types.BIT);
950        else
951            _ps.setInt(22, itmdt_allowcoupondiscounts? 1: 0);
952            
953        Boolean itmdt_allowassociatepayments = _value.getAllowAssociatePayments();
954        if(itmdt_allowassociatepayments == null)
955            _ps.setNull(23, Types.BIT);
956        else
957            _ps.setInt(23, itmdt_allowassociatepayments? 1: 0);
958            
959        UnitOfMeasureKindPK itmdt_uomk_unitofmeasurekindid = _value.getUnitOfMeasureKindPK();
960        if(itmdt_uomk_unitofmeasurekindid == null)
961            _ps.setNull(24, Types.BIGINT);
962        else
963            _ps.setLong(24, itmdt_uomk_unitofmeasurekindid.getEntityId());
964            
965        ItemPriceTypePK itmdt_ipt_itempricetypeid = _value.getItemPriceTypePK();
966        if(itmdt_ipt_itempricetypeid == null)
967            _ps.setNull(25, Types.BIGINT);
968        else
969            _ps.setLong(25, itmdt_ipt_itempricetypeid.getEntityId());
970            
971        CancellationPolicyPK itmdt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK();
972        if(itmdt_cnclplcy_cancellationpolicyid == null)
973            _ps.setNull(26, Types.BIGINT);
974        else
975            _ps.setLong(26, itmdt_cnclplcy_cancellationpolicyid.getEntityId());
976            
977        ReturnPolicyPK itmdt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK();
978        if(itmdt_rtnplcy_returnpolicyid == null)
979            _ps.setNull(27, Types.BIGINT);
980        else
981            _ps.setLong(27, itmdt_rtnplcy_returnpolicyid.getEntityId());
982            
983        StylePathPK itmdt_stylpth_stylepathid = _value.getStylePathPK();
984        if(itmdt_stylpth_stylepathid == null)
985            _ps.setNull(28, Types.BIGINT);
986        else
987            _ps.setLong(28, itmdt_stylpth_stylepathid.getEntityId());
988            
989        Long itmdt_fromtime = _value.getFromTime();
990        if(itmdt_fromtime == null)
991            _ps.setNull(29, Types.BIGINT);
992        else
993            _ps.setLong(29, itmdt_fromtime);
994            
995        Long itmdt_thrutime = _value.getThruTime();
996        if(itmdt_thrutime == null)
997            _ps.setNull(30, Types.BIGINT);
998        else
999            _ps.setLong(30, itmdt_thrutime);
1000            
1001    }
1002    
1003    public ItemDetail create(ItemPK itemPK, String itemName, ItemTypePK itemTypePK, ItemUseTypePK itemUseTypePK, ItemCategoryPK itemCategoryPK, ItemAccountingCategoryPK itemAccountingCategoryPK, ItemPurchasingCategoryPK itemPurchasingCategoryPK, PartyPK companyPartyPK, ItemDeliveryTypePK itemDeliveryTypePK, ItemInventoryTypePK itemInventoryTypePK, Boolean inventorySerialized, SequencePK serialNumberSequencePK, Boolean shippingChargeExempt, Long shippingStartTime, Long shippingEndTime, Long salesOrderStartTime, Long salesOrderEndTime, Long purchaseOrderStartTime, Long purchaseOrderEndTime, Boolean allowClubDiscounts, Boolean allowCouponDiscounts, Boolean allowAssociatePayments, UnitOfMeasureKindPK unitOfMeasureKindPK, ItemPriceTypePK itemPriceTypePK, CancellationPolicyPK cancellationPolicyPK, ReturnPolicyPK returnPolicyPK, StylePathPK stylePathPK, Long fromTime, Long thruTime)
1004            throws PersistenceDatabaseException, PersistenceNotNullException {
1005        ItemDetailPK _pk = getNextPK();
1006        ItemDetailValue _value = new ItemDetailValue(_pk, itemPK, itemName, itemTypePK, itemUseTypePK, itemCategoryPK, itemAccountingCategoryPK, itemPurchasingCategoryPK, companyPartyPK, itemDeliveryTypePK, itemInventoryTypePK, inventorySerialized, serialNumberSequencePK, shippingChargeExempt, shippingStartTime, shippingEndTime, salesOrderStartTime, salesOrderEndTime, purchaseOrderStartTime, purchaseOrderEndTime, allowClubDiscounts, allowCouponDiscounts, allowAssociatePayments, unitOfMeasureKindPK, itemPriceTypePK, cancellationPolicyPK, returnPolicyPK, stylePathPK, fromTime, thruTime);
1007        
1008        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
1009        
1010        try {
1011            bindForCreate(_ps, _value);
1012            
1013            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
1014                int _count = _ps.executeUpdate();
1015                
1016                if(_count != 1) {
1017                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
1018                }
1019            } else {
1020                 _ps.executeUpdate();
1021            }
1022            
1023            session.getValueCache().put(_value);
1024        } catch (SQLException se) {
1025            throw new PersistenceDatabaseException(se);
1026        }
1027        
1028        ItemDetail _entity = new ItemDetail(_value, EntityPermission.READ_ONLY);
1029        session.putReadOnlyEntity(_pk, _entity);
1030        
1031        return _entity;
1032    }
1033    
1034    public void create(Collection<ItemDetailValue> _values)
1035            throws PersistenceDatabaseException, PersistenceNotNullException {
1036        int _size = _values.size();
1037        
1038        if(_size > 0) {
1039            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
1040            List<ItemDetailValue> _cacheValues = new ArrayList<>(_size);
1041            
1042            try {
1043                for(ItemDetailValue _value : _values) {
1044                    _value.setEntityId(entityIdGenerator.getNextEntityId());
1045                    bindForCreate(_ps, _value);
1046                    
1047                    _ps.addBatch();
1048                    
1049                    _cacheValues.add(_value);
1050                }
1051                
1052                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
1053                    int[] _counts = _ps.executeBatch();
1054                    
1055                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
1056                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1057                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1058                        }
1059                    }
1060                } else {
1061                     _ps.executeBatch();
1062                }
1063                
1064                _ps.clearBatch();
1065            } catch (SQLException se) {
1066                throw new PersistenceDatabaseException(se);
1067            }
1068            
1069            _cacheValues.forEach((_cacheValue) -> {
1070                ItemDetail _cacheEntity = new ItemDetail(_cacheValue, EntityPermission.READ_ONLY);
1071                
1072                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
1073            });
1074        }
1075    }
1076    
1077    private boolean bindForStore(PreparedStatement _ps, ItemDetailValue _value)
1078            throws SQLException {
1079        boolean _hasBeenModified = _value.hasBeenModified();
1080        
1081        if(_hasBeenModified) {
1082            ItemPK itmdt_itm_itemid = _value.getItemPK();
1083            if(itmdt_itm_itemid == null)
1084                _ps.setNull(1, Types.BIGINT);
1085            else
1086                _ps.setLong(1, itmdt_itm_itemid.getEntityId());
1087            
1088            String itmdt_itemname = _value.getItemName();
1089            if(itmdt_itemname == null)
1090                _ps.setNull(2, Types.VARCHAR);
1091            else
1092                _ps.setString(2, itmdt_itemname);
1093            
1094            ItemTypePK itmdt_ityp_itemtypeid = _value.getItemTypePK();
1095            if(itmdt_ityp_itemtypeid == null)
1096                _ps.setNull(3, Types.BIGINT);
1097            else
1098                _ps.setLong(3, itmdt_ityp_itemtypeid.getEntityId());
1099            
1100            ItemUseTypePK itmdt_iutyp_itemusetypeid = _value.getItemUseTypePK();
1101            if(itmdt_iutyp_itemusetypeid == null)
1102                _ps.setNull(4, Types.BIGINT);
1103            else
1104                _ps.setLong(4, itmdt_iutyp_itemusetypeid.getEntityId());
1105            
1106            ItemCategoryPK itmdt_ic_itemcategoryid = _value.getItemCategoryPK();
1107            if(itmdt_ic_itemcategoryid == null)
1108                _ps.setNull(5, Types.BIGINT);
1109            else
1110                _ps.setLong(5, itmdt_ic_itemcategoryid.getEntityId());
1111            
1112            ItemAccountingCategoryPK itmdt_iactgc_itemaccountingcategoryid = _value.getItemAccountingCategoryPK();
1113            if(itmdt_iactgc_itemaccountingcategoryid == null)
1114                _ps.setNull(6, Types.BIGINT);
1115            else
1116                _ps.setLong(6, itmdt_iactgc_itemaccountingcategoryid.getEntityId());
1117            
1118            ItemPurchasingCategoryPK itmdt_iprchc_itempurchasingcategoryid = _value.getItemPurchasingCategoryPK();
1119            if(itmdt_iprchc_itempurchasingcategoryid == null)
1120                _ps.setNull(7, Types.BIGINT);
1121            else
1122                _ps.setLong(7, itmdt_iprchc_itempurchasingcategoryid.getEntityId());
1123            
1124            PartyPK itmdt_companypartyid = _value.getCompanyPartyPK();
1125            if(itmdt_companypartyid == null)
1126                _ps.setNull(8, Types.BIGINT);
1127            else
1128                _ps.setLong(8, itmdt_companypartyid.getEntityId());
1129            
1130            ItemDeliveryTypePK itmdt_idlvrtyp_itemdeliverytypeid = _value.getItemDeliveryTypePK();
1131            if(itmdt_idlvrtyp_itemdeliverytypeid == null)
1132                _ps.setNull(9, Types.BIGINT);
1133            else
1134                _ps.setLong(9, itmdt_idlvrtyp_itemdeliverytypeid.getEntityId());
1135            
1136            ItemInventoryTypePK itmdt_iinvtyp_iteminventorytypeid = _value.getItemInventoryTypePK();
1137            if(itmdt_iinvtyp_iteminventorytypeid == null)
1138                _ps.setNull(10, Types.BIGINT);
1139            else
1140                _ps.setLong(10, itmdt_iinvtyp_iteminventorytypeid.getEntityId());
1141            
1142            Boolean itmdt_inventoryserialized = _value.getInventorySerialized();
1143            if(itmdt_inventoryserialized == null)
1144                _ps.setNull(11, Types.BIT);
1145            else
1146                _ps.setInt(11, itmdt_inventoryserialized? 1: 0);
1147            
1148            SequencePK itmdt_serialnumbersequenceid = _value.getSerialNumberSequencePK();
1149            if(itmdt_serialnumbersequenceid == null)
1150                _ps.setNull(12, Types.BIGINT);
1151            else
1152                _ps.setLong(12, itmdt_serialnumbersequenceid.getEntityId());
1153            
1154            Boolean itmdt_shippingchargeexempt = _value.getShippingChargeExempt();
1155            if(itmdt_shippingchargeexempt == null)
1156                _ps.setNull(13, Types.BIT);
1157            else
1158                _ps.setInt(13, itmdt_shippingchargeexempt? 1: 0);
1159            
1160            Long itmdt_shippingstarttime = _value.getShippingStartTime();
1161            if(itmdt_shippingstarttime == null)
1162                _ps.setNull(14, Types.BIGINT);
1163            else
1164                _ps.setLong(14, itmdt_shippingstarttime);
1165            
1166            Long itmdt_shippingendtime = _value.getShippingEndTime();
1167            if(itmdt_shippingendtime == null)
1168                _ps.setNull(15, Types.BIGINT);
1169            else
1170                _ps.setLong(15, itmdt_shippingendtime);
1171            
1172            Long itmdt_salesorderstarttime = _value.getSalesOrderStartTime();
1173            if(itmdt_salesorderstarttime == null)
1174                _ps.setNull(16, Types.BIGINT);
1175            else
1176                _ps.setLong(16, itmdt_salesorderstarttime);
1177            
1178            Long itmdt_salesorderendtime = _value.getSalesOrderEndTime();
1179            if(itmdt_salesorderendtime == null)
1180                _ps.setNull(17, Types.BIGINT);
1181            else
1182                _ps.setLong(17, itmdt_salesorderendtime);
1183            
1184            Long itmdt_purchaseorderstarttime = _value.getPurchaseOrderStartTime();
1185            if(itmdt_purchaseorderstarttime == null)
1186                _ps.setNull(18, Types.BIGINT);
1187            else
1188                _ps.setLong(18, itmdt_purchaseorderstarttime);
1189            
1190            Long itmdt_purchaseorderendtime = _value.getPurchaseOrderEndTime();
1191            if(itmdt_purchaseorderendtime == null)
1192                _ps.setNull(19, Types.BIGINT);
1193            else
1194                _ps.setLong(19, itmdt_purchaseorderendtime);
1195            
1196            Boolean itmdt_allowclubdiscounts = _value.getAllowClubDiscounts();
1197            if(itmdt_allowclubdiscounts == null)
1198                _ps.setNull(20, Types.BIT);
1199            else
1200                _ps.setInt(20, itmdt_allowclubdiscounts? 1: 0);
1201            
1202            Boolean itmdt_allowcoupondiscounts = _value.getAllowCouponDiscounts();
1203            if(itmdt_allowcoupondiscounts == null)
1204                _ps.setNull(21, Types.BIT);
1205            else
1206                _ps.setInt(21, itmdt_allowcoupondiscounts? 1: 0);
1207            
1208            Boolean itmdt_allowassociatepayments = _value.getAllowAssociatePayments();
1209            if(itmdt_allowassociatepayments == null)
1210                _ps.setNull(22, Types.BIT);
1211            else
1212                _ps.setInt(22, itmdt_allowassociatepayments? 1: 0);
1213            
1214            UnitOfMeasureKindPK itmdt_uomk_unitofmeasurekindid = _value.getUnitOfMeasureKindPK();
1215            if(itmdt_uomk_unitofmeasurekindid == null)
1216                _ps.setNull(23, Types.BIGINT);
1217            else
1218                _ps.setLong(23, itmdt_uomk_unitofmeasurekindid.getEntityId());
1219            
1220            ItemPriceTypePK itmdt_ipt_itempricetypeid = _value.getItemPriceTypePK();
1221            if(itmdt_ipt_itempricetypeid == null)
1222                _ps.setNull(24, Types.BIGINT);
1223            else
1224                _ps.setLong(24, itmdt_ipt_itempricetypeid.getEntityId());
1225            
1226            CancellationPolicyPK itmdt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK();
1227            if(itmdt_cnclplcy_cancellationpolicyid == null)
1228                _ps.setNull(25, Types.BIGINT);
1229            else
1230                _ps.setLong(25, itmdt_cnclplcy_cancellationpolicyid.getEntityId());
1231            
1232            ReturnPolicyPK itmdt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK();
1233            if(itmdt_rtnplcy_returnpolicyid == null)
1234                _ps.setNull(26, Types.BIGINT);
1235            else
1236                _ps.setLong(26, itmdt_rtnplcy_returnpolicyid.getEntityId());
1237            
1238            StylePathPK itmdt_stylpth_stylepathid = _value.getStylePathPK();
1239            if(itmdt_stylpth_stylepathid == null)
1240                _ps.setNull(27, Types.BIGINT);
1241            else
1242                _ps.setLong(27, itmdt_stylpth_stylepathid.getEntityId());
1243            
1244            Long itmdt_fromtime = _value.getFromTime();
1245            if(itmdt_fromtime == null)
1246                _ps.setNull(28, Types.BIGINT);
1247            else
1248                _ps.setLong(28, itmdt_fromtime);
1249            
1250            Long itmdt_thrutime = _value.getThruTime();
1251            if(itmdt_thrutime == null)
1252                _ps.setNull(29, Types.BIGINT);
1253            else
1254                _ps.setLong(29, itmdt_thrutime);
1255            
1256            _ps.setLong(30, _value.getPrimaryKey().getEntityId());
1257            
1258            _value.clearHasBeenModified();
1259        }
1260        
1261        return _hasBeenModified;
1262    }
1263    
1264    @Override
1265    public void store(ItemDetail entity)
1266            throws PersistenceDatabaseException {
1267        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1268        
1269        try {
1270            ItemDetailValue _value = entity.getItemDetailValue();
1271            
1272            if(bindForStore(_ps, _value)) {
1273                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1274                    int _count = _ps.executeUpdate();
1275                    
1276                    if(_count != 1) {
1277                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1278                    }
1279                } else {
1280                     _ps.executeUpdate();
1281                }
1282                
1283                session.getValueCache().put(_value);
1284            }
1285        } catch (SQLException se) {
1286            throw new PersistenceDatabaseException(se);
1287        }
1288    }
1289    
1290    @Override
1291    public void store(Collection<ItemDetail> entities)
1292            throws PersistenceDatabaseException {
1293        if(entities.size() > 0) {
1294            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1295            int _modifiedEntities = 0;
1296            
1297            try {
1298                for(ItemDetail entity : entities) {
1299                    if(bindForStore(_ps, entity.getItemDetailValue())) {
1300                        _ps.addBatch();
1301                        _modifiedEntities++;
1302                    }
1303                }
1304                
1305                if(_modifiedEntities != 0) {
1306                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1307                        int[] _counts = _ps.executeBatch();
1308                        
1309                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1310                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1311                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1312                            }
1313                        }
1314                    } else {
1315                         _ps.executeBatch();
1316                    }
1317                    
1318                    _ps.clearBatch();
1319                    
1320                    entities.forEach((entity) -> {
1321                        session.getValueCache().put(entity.getItemDetailValue());
1322                    });
1323                }
1324            } catch (SQLException se) {
1325                throw new PersistenceDatabaseException(se);
1326            }
1327        }
1328    }
1329    
1330    @Override
1331    public void remove(ItemDetail entity)
1332            throws PersistenceDatabaseException {
1333        remove(entity.getPrimaryKey());
1334    }
1335    
1336    @Override
1337    public void remove(ItemDetailPK pk)
1338            throws PersistenceDatabaseException {
1339        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1340        long _entityId = pk.getEntityId();
1341        
1342        try {
1343            _ps.setLong(1, _entityId);
1344            
1345            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1346                int _count = _ps.executeUpdate();
1347                
1348                if(_count != 1) {
1349                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1350                }
1351            } else {
1352                 _ps.executeUpdate();
1353            }
1354            
1355            session.getValueCache().remove(pk);
1356        } catch (SQLException se) {
1357            throw new PersistenceDatabaseException(se);
1358        }
1359        
1360        session.removed(pk, false);
1361    }
1362    
1363    @Override
1364    public void remove(Collection<ItemDetailPK> pks)
1365            throws PersistenceDatabaseException {
1366        if(pks.size() > 0) {
1367            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1368            int _modifiedEntities = 0;
1369            
1370            try {
1371                for(ItemDetailPK pk : pks) {
1372                    long _entityId = pk.getEntityId();
1373                    
1374                    _ps.setLong(1, _entityId);
1375                    
1376                    _ps.addBatch();
1377                    _modifiedEntities++;
1378                }
1379                
1380                if(_modifiedEntities != 0) {
1381                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1382                        int[] _counts = _ps.executeBatch();
1383                        
1384                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1385                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1386                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1387                            }
1388                        }
1389                    } else {
1390                        _ps.executeBatch();
1391                    }
1392                    
1393                    _ps.clearBatch();
1394                    
1395                    pks.forEach((pk) -> {
1396                        session.getValueCache().remove(pk);
1397                    });
1398                }
1399            } catch (SQLException se) {
1400                throw new PersistenceDatabaseException(se);
1401            }
1402            
1403            pks.forEach((pk) -> {
1404                session.removed(pk, true);
1405            });
1406        }
1407    }
1408    
1409    @Override
1410    public boolean validPK(ItemDetailPK pk)
1411            throws PersistenceDatabaseException {
1412        boolean valid = false;
1413        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1414        ResultSet _rs = null;
1415        
1416        try {
1417            _ps.setLong(1, pk.getEntityId());
1418            
1419            _rs = _ps.executeQuery();
1420            if(_rs.next()) {
1421                long _count = _rs.getLong(1);
1422                if(_rs.wasNull())
1423                    _count = 0;
1424                
1425                if(_count == 1)
1426                    valid = true;
1427            }
1428        } catch (SQLException se) {
1429            throw new PersistenceDatabaseException(se);
1430        } finally {
1431            if(_rs != null) {
1432                try {
1433                    _rs.close();
1434                } catch (SQLException se) {
1435                    // do nothing
1436                }
1437            }
1438        }
1439        
1440        return valid;
1441    }
1442    
1443}