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