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