001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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 * ItemHarmonizedTariffScheduleCodeDetailFactory.java
021 */
022
023package com.echothree.model.data.item.server.factory;
024
025import com.echothree.model.data.item.common.pk.ItemHarmonizedTariffScheduleCodePK;
026import com.echothree.model.data.item.common.pk.ItemPK;
027import com.echothree.model.data.geo.common.pk.GeoCodePK;
028import com.echothree.model.data.item.common.pk.HarmonizedTariffScheduleCodeUseTypePK;
029import com.echothree.model.data.item.common.pk.HarmonizedTariffScheduleCodePK;
030
031import com.echothree.model.data.item.server.entity.ItemHarmonizedTariffScheduleCode;
032import com.echothree.model.data.item.server.entity.Item;
033import com.echothree.model.data.geo.server.entity.GeoCode;
034import com.echothree.model.data.item.server.entity.HarmonizedTariffScheduleCodeUseType;
035import com.echothree.model.data.item.server.entity.HarmonizedTariffScheduleCode;
036
037import com.echothree.model.data.item.common.ItemHarmonizedTariffScheduleCodeDetailConstants;
038import com.echothree.model.data.item.common.pk.ItemHarmonizedTariffScheduleCodeDetailPK;
039import com.echothree.model.data.item.server.value.ItemHarmonizedTariffScheduleCodeDetailValue;
040import com.echothree.model.data.item.server.entity.ItemHarmonizedTariffScheduleCodeDetail;
041import com.echothree.util.common.exception.PersistenceDatabaseException;
042import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
043import com.echothree.util.common.exception.PersistenceNotNullException;
044import com.echothree.util.server.persistence.BaseFactory;
045import com.echothree.util.server.persistence.EntityIdGenerator;
046import com.echothree.util.server.persistence.EntityPermission;
047import com.echothree.util.server.persistence.PersistenceDebugFlags;
048import com.echothree.util.server.persistence.Session;
049import com.echothree.util.server.persistence.ThreadSession;
050import java.sql.PreparedStatement;
051import java.sql.ResultSet;
052import java.sql.SQLException;
053import java.sql.Types;
054import java.io.ByteArrayInputStream;
055import java.io.StringReader;
056import java.util.ArrayList;
057import java.util.Collection;
058import java.util.HashSet;
059import java.util.List;
060import java.util.Map;
061import java.util.Set;
062import javax.enterprise.context.ApplicationScoped;
063import javax.enterprise.inject.spi.CDI;
064import org.apache.commons.logging.Log;
065import org.apache.commons.logging.LogFactory;
066
067@ApplicationScoped
068public class ItemHarmonizedTariffScheduleCodeDetailFactory
069        implements BaseFactory<ItemHarmonizedTariffScheduleCodeDetailPK, ItemHarmonizedTariffScheduleCodeDetail> {
070    
071    //final private static Log log = LogFactory.getLog(ItemHarmonizedTariffScheduleCodeDetailFactory.class);
072    
073    final private static String SQL_SELECT_READ_ONLY = "SELECT itmhztscdt_itemharmonizedtariffschedulecodedetailid, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid, itmhztscdt_itm_itemid, itmhztscdt_countrygeocodeid, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid, itmhztscdt_hztsc_harmonizedtariffschedulecodeid, itmhztscdt_fromtime, itmhztscdt_thrutime FROM itemharmonizedtariffschedulecodedetails WHERE itmhztscdt_itemharmonizedtariffschedulecodedetailid = ?";
074    final private static String SQL_SELECT_READ_WRITE = "SELECT itmhztscdt_itemharmonizedtariffschedulecodedetailid, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid, itmhztscdt_itm_itemid, itmhztscdt_countrygeocodeid, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid, itmhztscdt_hztsc_harmonizedtariffschedulecodeid, itmhztscdt_fromtime, itmhztscdt_thrutime FROM itemharmonizedtariffschedulecodedetails WHERE itmhztscdt_itemharmonizedtariffschedulecodedetailid = ? FOR UPDATE";
075    final private static String SQL_INSERT = "INSERT INTO itemharmonizedtariffschedulecodedetails (itmhztscdt_itemharmonizedtariffschedulecodedetailid, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid, itmhztscdt_itm_itemid, itmhztscdt_countrygeocodeid, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid, itmhztscdt_hztsc_harmonizedtariffschedulecodeid, itmhztscdt_fromtime, itmhztscdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
076    final private static String SQL_UPDATE = "UPDATE itemharmonizedtariffschedulecodedetails SET itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = ?, itmhztscdt_itm_itemid = ?, itmhztscdt_countrygeocodeid = ?, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = ?, itmhztscdt_hztsc_harmonizedtariffschedulecodeid = ?, itmhztscdt_fromtime = ?, itmhztscdt_thrutime = ? WHERE itmhztscdt_itemharmonizedtariffschedulecodedetailid = ?";
077    final private static String SQL_DELETE = "DELETE FROM itemharmonizedtariffschedulecodedetails WHERE itmhztscdt_itemharmonizedtariffschedulecodedetailid = ?";
078    final private static String SQL_VALID = "SELECT COUNT(*) FROM itemharmonizedtariffschedulecodedetails WHERE itmhztscdt_itemharmonizedtariffschedulecodedetailid = ?";
079    
080    final private static String PK_COLUMN = "itmhztscdt_itemharmonizedtariffschedulecodedetailid";
081    final private static String ALL_COLUMNS = "itmhztscdt_itemharmonizedtariffschedulecodedetailid, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid, itmhztscdt_itm_itemid, itmhztscdt_countrygeocodeid, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid, itmhztscdt_hztsc_harmonizedtariffschedulecodeid, itmhztscdt_fromtime, itmhztscdt_thrutime";
082    final public static String TABLE_NAME = "itemharmonizedtariffschedulecodedetails";
083    
084    final public static String ITMHZTSCDT_ITEMHARMONIZEDTARIFFSCHEDULECODEDETAILID = "itmhztscdt_itemharmonizedtariffschedulecodedetailid";
085    final public static String ITMHZTSCDT_ITMHZTSC_ITEMHARMONIZEDTARIFFSCHEDULECODEID = "itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid";
086    final public static String ITMHZTSCDT_ITM_ITEMID = "itmhztscdt_itm_itemid";
087    final public static String ITMHZTSCDT_COUNTRYGEOCODEID = "itmhztscdt_countrygeocodeid";
088    final public static String ITMHZTSCDT_HZTSCUTYP_HARMONIZEDTARIFFSCHEDULECODEUSETYPEID = "itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid";
089    final public static String ITMHZTSCDT_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID = "itmhztscdt_hztsc_harmonizedtariffschedulecodeid";
090    final public static String ITMHZTSCDT_FROMTIME = "itmhztscdt_fromtime";
091    final public static String ITMHZTSCDT_THRUTIME = "itmhztscdt_thrutime";
092    
093    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ItemHarmonizedTariffScheduleCodeDetailConstants.COMPONENT_VENDOR_NAME, ItemHarmonizedTariffScheduleCodeDetailConstants.ENTITY_TYPE_NAME);
094    
095    /** Creates a new instance of ItemHarmonizedTariffScheduleCodeDetailFactory */
096    protected ItemHarmonizedTariffScheduleCodeDetailFactory() {
097        super();
098    }
099    
100    public static ItemHarmonizedTariffScheduleCodeDetailFactory getInstance() {
101        return CDI.current().select(ItemHarmonizedTariffScheduleCodeDetailFactory.class).get();
102    }
103    
104    @Override
105    public String getPKColumn() {
106        return PK_COLUMN;
107    }
108    
109    @Override
110    public String getAllColumns() {
111        return ALL_COLUMNS;
112    }
113    
114    @Override
115    public String getTableName() {
116        return TABLE_NAME;
117    }
118    
119    @Override
120    public String getComponentVendorName() {
121        return ItemHarmonizedTariffScheduleCodeDetailConstants.COMPONENT_VENDOR_NAME;
122    }
123    
124    @Override
125    public String getEntityTypeName() {
126        return ItemHarmonizedTariffScheduleCodeDetailConstants.ENTITY_TYPE_NAME;
127    }
128    
129    public PreparedStatement prepareStatement(String query) {
130        return ThreadSession.currentSession().prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, query);
131    }
132    
133    public ItemHarmonizedTariffScheduleCodeDetailPK getNextPK() {
134        return new ItemHarmonizedTariffScheduleCodeDetailPK(entityIdGenerator.getNextEntityId());
135    }
136    
137    public Set<ItemHarmonizedTariffScheduleCodeDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
138            throws PersistenceDatabaseException {
139        Set<ItemHarmonizedTariffScheduleCodeDetailPK> _result = new HashSet<>();
140        
141        try {
142            while(rs.next()) {
143                _result.add(getPKFromResultSet(rs));
144            }
145        } catch (SQLException se) {
146            throw new PersistenceDatabaseException(se);
147        }
148        
149        return _result;
150    }
151    
152    public java.util.List<ItemHarmonizedTariffScheduleCodeDetailPK> getPKsFromResultSetAsList(ResultSet rs)
153            throws PersistenceDatabaseException {
154        java.util.List<ItemHarmonizedTariffScheduleCodeDetailPK> _result = new ArrayList<>();
155        
156        try {
157            while(rs.next()) {
158                _result.add(getPKFromResultSet(rs));
159            }
160        } catch (SQLException se) {
161            throw new PersistenceDatabaseException(se);
162        }
163        
164        return _result;
165    }
166    
167    public ItemHarmonizedTariffScheduleCodeDetailPK getPKFromResultSet(ResultSet rs)
168            throws PersistenceDatabaseException {
169        ItemHarmonizedTariffScheduleCodeDetailPK _result;
170        
171        try {
172            long itmhztscdt_itemharmonizedtariffschedulecodedetailid = rs.getLong(ITMHZTSCDT_ITEMHARMONIZEDTARIFFSCHEDULECODEDETAILID);
173            Long _entityId = rs.wasNull() ? null : itmhztscdt_itemharmonizedtariffschedulecodedetailid;
174            
175            _result = new ItemHarmonizedTariffScheduleCodeDetailPK(_entityId);
176        } catch (SQLException se) {
177            throw new PersistenceDatabaseException(se);
178        }
179        
180        return _result;
181    }
182    
183    public java.util.List<ItemHarmonizedTariffScheduleCodeDetailValue> getValuesFromPKs(Session session, Collection<ItemHarmonizedTariffScheduleCodeDetailPK> pks)
184            throws PersistenceDatabaseException {
185        java.util.List<ItemHarmonizedTariffScheduleCodeDetailValue> _values = new ArrayList<>(pks.size());
186        
187        for(ItemHarmonizedTariffScheduleCodeDetailPK _pk: pks) {
188            _values.add(getValueFromPK(session, _pk));
189        }
190        
191        return _values;
192    }
193    
194    public ItemHarmonizedTariffScheduleCodeDetailValue getValueFromPK(Session session, ItemHarmonizedTariffScheduleCodeDetailPK pk)
195            throws PersistenceDatabaseException {
196        ItemHarmonizedTariffScheduleCodeDetailValue _value;
197        
198        // See if we already have the entity in the session cache
199        ItemHarmonizedTariffScheduleCodeDetail _entity = (ItemHarmonizedTariffScheduleCodeDetail)session.getEntity(pk);
200        if(_entity == null)
201            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getItemHarmonizedTariffScheduleCodeDetailValue();
202        else
203            _value = _entity.getItemHarmonizedTariffScheduleCodeDetailValue();
204        
205        return _value;
206    }
207    
208    public java.util.List<ItemHarmonizedTariffScheduleCodeDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
209            throws PersistenceDatabaseException {
210        java.util.List<ItemHarmonizedTariffScheduleCodeDetailValue> _result = new ArrayList<>();
211        
212        try {
213            while(rs.next()) {
214                _result.add(getValueFromResultSet(session, rs));
215            }
216        } catch (SQLException se) {
217            throw new PersistenceDatabaseException(se);
218        }
219        
220        return _result;
221    }
222    
223    public ItemHarmonizedTariffScheduleCodeDetailValue getValueFromResultSet(Session session, ResultSet rs)
224            throws PersistenceDatabaseException {
225        ItemHarmonizedTariffScheduleCodeDetailValue _value;
226        
227        try {
228            Long itmhztscdt_itemharmonizedtariffschedulecodedetailid = rs.getLong(ITMHZTSCDT_ITEMHARMONIZEDTARIFFSCHEDULECODEDETAILID);
229            ItemHarmonizedTariffScheduleCodeDetailPK _pk = new ItemHarmonizedTariffScheduleCodeDetailPK(itmhztscdt_itemharmonizedtariffschedulecodedetailid);
230            
231            // See if we already have the entity in the session cache
232            ItemHarmonizedTariffScheduleCodeDetail _entity = (ItemHarmonizedTariffScheduleCodeDetail)session.getEntity(_pk);
233            
234            if(_entity == null) {
235                Long itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = rs.getLong(ITMHZTSCDT_ITMHZTSC_ITEMHARMONIZEDTARIFFSCHEDULECODEID);
236                if(rs.wasNull())
237                    itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = null;
238                
239                Long itmhztscdt_itm_itemid = rs.getLong(ITMHZTSCDT_ITM_ITEMID);
240                if(rs.wasNull())
241                    itmhztscdt_itm_itemid = null;
242                
243                Long itmhztscdt_countrygeocodeid = rs.getLong(ITMHZTSCDT_COUNTRYGEOCODEID);
244                if(rs.wasNull())
245                    itmhztscdt_countrygeocodeid = null;
246                
247                Long itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = rs.getLong(ITMHZTSCDT_HZTSCUTYP_HARMONIZEDTARIFFSCHEDULECODEUSETYPEID);
248                if(rs.wasNull())
249                    itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = null;
250                
251                Long itmhztscdt_hztsc_harmonizedtariffschedulecodeid = rs.getLong(ITMHZTSCDT_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID);
252                if(rs.wasNull())
253                    itmhztscdt_hztsc_harmonizedtariffschedulecodeid = null;
254                
255                Long itmhztscdt_fromtime = rs.getLong(ITMHZTSCDT_FROMTIME);
256                if(rs.wasNull())
257                    itmhztscdt_fromtime = null;
258                
259                Long itmhztscdt_thrutime = rs.getLong(ITMHZTSCDT_THRUTIME);
260                if(rs.wasNull())
261                    itmhztscdt_thrutime = null;
262                
263                _value = new ItemHarmonizedTariffScheduleCodeDetailValue(_pk, new ItemHarmonizedTariffScheduleCodePK(itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid), new ItemPK(itmhztscdt_itm_itemid), new GeoCodePK(itmhztscdt_countrygeocodeid), new HarmonizedTariffScheduleCodeUseTypePK(itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid), new HarmonizedTariffScheduleCodePK(itmhztscdt_hztsc_harmonizedtariffschedulecodeid), itmhztscdt_fromtime, itmhztscdt_thrutime);
264            } else
265                _value = _entity.getItemHarmonizedTariffScheduleCodeDetailValue();
266        } catch (SQLException se) {
267            throw new PersistenceDatabaseException(se);
268        }
269        
270        return _value;
271    }
272    
273    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ItemHarmonizedTariffScheduleCodeDetailPK> pks)
274            throws PersistenceDatabaseException {
275        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
276    }
277    
278    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<ItemHarmonizedTariffScheduleCodeDetailPK> pks)
279            throws PersistenceDatabaseException {
280        java.util.List<ItemHarmonizedTariffScheduleCodeDetail> _entities = new ArrayList<>(pks.size());
281        
282        for(ItemHarmonizedTariffScheduleCodeDetailPK _pk: pks) {
283            _entities.add(getEntityFromPK(session, entityPermission, _pk));
284        }
285        
286        return _entities;
287    }
288    
289    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromValue(EntityPermission entityPermission, ItemHarmonizedTariffScheduleCodeDetailValue value) {
290        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
291    }
292    
293    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromValue(Session session, EntityPermission entityPermission, ItemHarmonizedTariffScheduleCodeDetailValue value) {
294        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
295    }
296    
297    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromPK(EntityPermission entityPermission, ItemHarmonizedTariffScheduleCodeDetailPK pk)
298            throws PersistenceDatabaseException {
299        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
300    }
301    
302    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromCache(Session session, ItemHarmonizedTariffScheduleCodeDetailPK pk) {
303        ItemHarmonizedTariffScheduleCodeDetailValue _value = (ItemHarmonizedTariffScheduleCodeDetailValue)session.getValueCache().get(pk);
304    
305        return _value == null ? null : new ItemHarmonizedTariffScheduleCodeDetail(_value, EntityPermission.READ_ONLY);
306    }
307    
308    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromPK(Session session, EntityPermission entityPermission, ItemHarmonizedTariffScheduleCodeDetailPK pk)
309            throws PersistenceDatabaseException {
310        ItemHarmonizedTariffScheduleCodeDetail _entity;
311        
312        // See if we already have the entity in the session cache
313        _entity = (ItemHarmonizedTariffScheduleCodeDetail)session.getEntity(pk);
314        if(_entity != null) {
315            // If the requested permission is READ_WRITE, and the cached permission is
316            // READ_ONLY, then pretend that the cached object wasn't found, and create
317            // a new entity that is READ_WRITE.
318            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
319                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
320                    _entity = null;
321            }
322        }
323        
324        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
325            _entity = getEntityFromCache(session, pk);
326        }
327        
328        if(_entity == null) {
329            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
330            long _entityId = pk.getEntityId();
331            ResultSet _rs = null;
332            
333            try {
334                _ps.setLong(1, _entityId);
335                _rs = _ps.executeQuery();
336                if(_rs.next()) {
337                    _entity = getEntityFromResultSet(session, entityPermission, _rs);
338                }
339            } catch (SQLException se) {
340                throw new PersistenceDatabaseException(se);
341            } finally {
342                if(_rs != null) {
343                    try {
344                        _rs.close();
345                    } catch (SQLException se) {
346                        // do nothing
347                    }
348                }
349            }
350        }
351        
352        return _entity;
353    }
354    
355    public Set<ItemHarmonizedTariffScheduleCodeDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
356            throws PersistenceDatabaseException {
357        Set<ItemHarmonizedTariffScheduleCodeDetailPK> _pks;
358        ResultSet _rs = null;
359        
360        try {
361            if(params.length != 0) {
362                Session.setQueryParams(ps, params);
363            }
364            
365            _rs = ps.executeQuery();
366            _pks = getPKsFromResultSetAsSet(_rs);
367            _rs.close();
368        } catch (SQLException se) {
369            throw new PersistenceDatabaseException(se);
370        } finally {
371            if(_rs != null) {
372                try {
373                    _rs.close();
374                } catch (SQLException se) {
375                    // do nothing
376                }
377            }
378        }
379        
380        return _pks;
381    }
382    
383    public java.util.List<ItemHarmonizedTariffScheduleCodeDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
384            throws PersistenceDatabaseException {
385        java.util.List<ItemHarmonizedTariffScheduleCodeDetailPK> _pks;
386        ResultSet _rs = null;
387        
388        try {
389            if(params.length != 0) {
390                Session.setQueryParams(ps, params);
391            }
392            
393            _rs = ps.executeQuery();
394            _pks = getPKsFromResultSetAsList(_rs);
395            _rs.close();
396        } catch (SQLException se) {
397            throw new PersistenceDatabaseException(se);
398        } finally {
399            if(_rs != null) {
400                try {
401                    _rs.close();
402                } catch (SQLException se) {
403                    // do nothing
404                }
405            }
406        }
407        
408        return _pks;
409    }
410    
411    public ItemHarmonizedTariffScheduleCodeDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
412            throws PersistenceDatabaseException {
413        ItemHarmonizedTariffScheduleCodeDetailPK _pk = null;
414        ResultSet _rs = null;
415        
416        try {
417            if(params.length != 0) {
418                Session.setQueryParams(ps, params);
419            }
420            
421            _rs = ps.executeQuery();
422            if(_rs.next()) {
423                _pk = getPKFromResultSet(_rs);
424            }
425            _rs.close();
426        } catch (SQLException se) {
427            throw new PersistenceDatabaseException(se);
428        } finally {
429            if(_rs != null) {
430                try {
431                    _rs.close();
432                } catch (SQLException se) {
433                    // do nothing
434                }
435            }
436        }
437        
438        return _pk;
439    }
440    
441    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
442            throws PersistenceDatabaseException {
443        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
444        
445        return getEntitiesFromQuery(session, entityPermission, ps, params);
446    }
447    
448    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
449            throws PersistenceDatabaseException {
450        Session session = ThreadSession.currentSession();
451        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
452        
453        return getEntitiesFromQuery(session, entityPermission, ps, params);
454    }
455    
456    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
457            throws PersistenceDatabaseException {
458        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
459        
460        return getEntitiesFromQuery(session, entityPermission, ps);
461    }
462    
463    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
464            throws PersistenceDatabaseException {
465        Session session = ThreadSession.currentSession();
466        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
467        
468        return getEntitiesFromQuery(session, entityPermission, ps);
469    }
470    
471    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
472            throws PersistenceDatabaseException {
473        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
474    }
475    
476    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
477            throws PersistenceDatabaseException {
478        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
479    }
480    
481    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
482            throws PersistenceDatabaseException {
483        java.util.List<ItemHarmonizedTariffScheduleCodeDetail> _entities;
484        ResultSet _rs = null;
485        
486        try {
487            if(params.length != 0) {
488                Session.setQueryParams(ps, params);
489            }
490            
491            _rs = ps.executeQuery();
492            _entities = getEntitiesFromResultSet(session, entityPermission, _rs);
493            _rs.close();
494        } catch (SQLException se) {
495            throw new PersistenceDatabaseException(se);
496        } finally {
497            if(_rs != null) {
498                try {
499                    _rs.close();
500                } catch (SQLException se) {
501                    // do nothing
502                }
503            }
504        }
505        
506        return _entities;
507    }
508    
509    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
510            throws PersistenceDatabaseException {
511        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
512        
513        return getEntityFromQuery(session, entityPermission, ps, params);
514    }
515    
516    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
517            throws PersistenceDatabaseException {
518        Session session = ThreadSession.currentSession();
519        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
520        
521        return getEntityFromQuery(session, entityPermission, ps, params);
522    }
523    
524    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
525            throws PersistenceDatabaseException {
526        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
527        
528        return getEntityFromQuery(session, entityPermission, ps);
529    }
530    
531    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
532            throws PersistenceDatabaseException {
533        Session session = ThreadSession.currentSession();
534        PreparedStatement ps = session.prepareStatement(ItemHarmonizedTariffScheduleCodeDetailFactory.class, queryMap.get(entityPermission));
535        
536        return getEntityFromQuery(session, entityPermission, ps);
537    }
538    
539    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
540            throws PersistenceDatabaseException {
541        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
542    }
543    
544    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
545            throws PersistenceDatabaseException {
546        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
547    }
548    
549    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
550            throws PersistenceDatabaseException {
551        ItemHarmonizedTariffScheduleCodeDetail _entity = null;
552        ResultSet _rs = null;
553        
554        try {
555            if(params.length != 0) {
556                Session.setQueryParams(ps, params);
557            }
558            
559            _rs = ps.executeQuery();
560            if(_rs.next()) {
561                _entity = getEntityFromResultSet(session, entityPermission, _rs);
562            }
563            _rs.close();
564        } catch (SQLException se) {
565            throw new PersistenceDatabaseException(se);
566        } finally {
567            if(_rs != null) {
568                try {
569                    _rs.close();
570                } catch (SQLException se) {
571                    // do nothing
572                }
573            }
574        }
575        
576        return _entity;
577    }
578    
579    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
580            throws PersistenceDatabaseException {
581        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
582    }
583    
584    public java.util.List<ItemHarmonizedTariffScheduleCodeDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
585            throws PersistenceDatabaseException {
586        java.util.List<ItemHarmonizedTariffScheduleCodeDetail> _result = new ArrayList<>();
587        
588        try {
589            while(rs.next()) {
590                _result.add(getEntityFromResultSet(session, entityPermission, rs));
591            }
592        } catch (SQLException se) {
593            throw new PersistenceDatabaseException(se);
594        }
595        
596        return _result;
597    }
598    
599    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
600            throws PersistenceDatabaseException {
601        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
602    }
603    
604    public ItemHarmonizedTariffScheduleCodeDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
605            throws PersistenceDatabaseException {
606        ItemHarmonizedTariffScheduleCodeDetail _entity;
607        
608        try {
609            Long itmhztscdt_itemharmonizedtariffschedulecodedetailid = rs.getLong(ITMHZTSCDT_ITEMHARMONIZEDTARIFFSCHEDULECODEDETAILID);
610            ItemHarmonizedTariffScheduleCodeDetailPK _pk = new ItemHarmonizedTariffScheduleCodeDetailPK(itmhztscdt_itemharmonizedtariffschedulecodedetailid);
611            
612            // See if we already have the entity in the session cache
613            _entity = (ItemHarmonizedTariffScheduleCodeDetail)session.getEntity(_pk);
614            if(_entity != null) {
615                // If the requested permission is READ_WRITE, and the cached permission is
616                // READ_ONLY, then pretend that the cached object wasn't found, and create
617                // a new entity that is READ_WRITE.
618                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
619                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
620                        _entity = null;
621                }
622            }
623            boolean foundInSessionCache = _entity != null;
624            
625            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
626                _entity = getEntityFromCache(session, _pk);
627            }
628            
629            if(_entity == null) {
630                Long itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = rs.getLong(ITMHZTSCDT_ITMHZTSC_ITEMHARMONIZEDTARIFFSCHEDULECODEID);
631                if(rs.wasNull())
632                    itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = null;
633                
634                Long itmhztscdt_itm_itemid = rs.getLong(ITMHZTSCDT_ITM_ITEMID);
635                if(rs.wasNull())
636                    itmhztscdt_itm_itemid = null;
637                
638                Long itmhztscdt_countrygeocodeid = rs.getLong(ITMHZTSCDT_COUNTRYGEOCODEID);
639                if(rs.wasNull())
640                    itmhztscdt_countrygeocodeid = null;
641                
642                Long itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = rs.getLong(ITMHZTSCDT_HZTSCUTYP_HARMONIZEDTARIFFSCHEDULECODEUSETYPEID);
643                if(rs.wasNull())
644                    itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = null;
645                
646                Long itmhztscdt_hztsc_harmonizedtariffschedulecodeid = rs.getLong(ITMHZTSCDT_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID);
647                if(rs.wasNull())
648                    itmhztscdt_hztsc_harmonizedtariffschedulecodeid = null;
649                
650                Long itmhztscdt_fromtime = rs.getLong(ITMHZTSCDT_FROMTIME);
651                if(rs.wasNull())
652                    itmhztscdt_fromtime = null;
653                
654                Long itmhztscdt_thrutime = rs.getLong(ITMHZTSCDT_THRUTIME);
655                if(rs.wasNull())
656                    itmhztscdt_thrutime = null;
657                
658                ItemHarmonizedTariffScheduleCodeDetailValue _value = new ItemHarmonizedTariffScheduleCodeDetailValue(_pk, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid == null? null: new ItemHarmonizedTariffScheduleCodePK(itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid), itmhztscdt_itm_itemid == null? null: new ItemPK(itmhztscdt_itm_itemid), itmhztscdt_countrygeocodeid == null? null: new GeoCodePK(itmhztscdt_countrygeocodeid), itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid == null? null: new HarmonizedTariffScheduleCodeUseTypePK(itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid), itmhztscdt_hztsc_harmonizedtariffschedulecodeid == null? null: new HarmonizedTariffScheduleCodePK(itmhztscdt_hztsc_harmonizedtariffschedulecodeid), itmhztscdt_fromtime, itmhztscdt_thrutime);
659                _entity = new ItemHarmonizedTariffScheduleCodeDetail(_value, entityPermission);
660            }
661            
662            if(!foundInSessionCache) {
663                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
664                    session.putReadOnlyEntity(_pk, _entity);
665                    session.getValueCache().put(_entity.getItemHarmonizedTariffScheduleCodeDetailValue());
666                } else {
667                    session.putReadWriteEntity(_pk, _entity);
668                }
669            }
670        } catch (SQLException se) {
671            throw new PersistenceDatabaseException(se);
672        }
673        
674        return _entity;
675    }
676    
677    public ItemHarmonizedTariffScheduleCodeDetail create(Session session, ItemHarmonizedTariffScheduleCode itemHarmonizedTariffScheduleCode, Item item, GeoCode countryGeoCode, HarmonizedTariffScheduleCodeUseType harmonizedTariffScheduleCodeUseType, HarmonizedTariffScheduleCode harmonizedTariffScheduleCode, Long fromTime, Long thruTime)
678            throws PersistenceDatabaseException, PersistenceNotNullException {
679        return create(session, itemHarmonizedTariffScheduleCode == null ? null : itemHarmonizedTariffScheduleCode.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), countryGeoCode == null ? null : countryGeoCode.getPrimaryKey(), harmonizedTariffScheduleCodeUseType == null ? null : harmonizedTariffScheduleCodeUseType.getPrimaryKey(), harmonizedTariffScheduleCode == null ? null : harmonizedTariffScheduleCode.getPrimaryKey(), fromTime, thruTime);
680    }
681    
682    public ItemHarmonizedTariffScheduleCodeDetail create(ItemHarmonizedTariffScheduleCode itemHarmonizedTariffScheduleCode, Item item, GeoCode countryGeoCode, HarmonizedTariffScheduleCodeUseType harmonizedTariffScheduleCodeUseType, HarmonizedTariffScheduleCode harmonizedTariffScheduleCode, Long fromTime, Long thruTime)
683            throws PersistenceDatabaseException, PersistenceNotNullException {
684        return create(ThreadSession.currentSession(), itemHarmonizedTariffScheduleCode == null ? null : itemHarmonizedTariffScheduleCode.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), countryGeoCode == null ? null : countryGeoCode.getPrimaryKey(), harmonizedTariffScheduleCodeUseType == null ? null : harmonizedTariffScheduleCodeUseType.getPrimaryKey(), harmonizedTariffScheduleCode == null ? null : harmonizedTariffScheduleCode.getPrimaryKey(), fromTime, thruTime);
685    }
686    
687    private void bindForCreate(PreparedStatement _ps, ItemHarmonizedTariffScheduleCodeDetailValue _value)
688            throws SQLException {
689        _ps.setLong(1, _value.getEntityId());
690        
691        ItemHarmonizedTariffScheduleCodePK itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = _value.getItemHarmonizedTariffScheduleCodePK();
692        if(itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid == null)
693            _ps.setNull(2, Types.BIGINT);
694        else
695            _ps.setLong(2, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid.getEntityId());
696            
697        ItemPK itmhztscdt_itm_itemid = _value.getItemPK();
698        if(itmhztscdt_itm_itemid == null)
699            _ps.setNull(3, Types.BIGINT);
700        else
701            _ps.setLong(3, itmhztscdt_itm_itemid.getEntityId());
702            
703        GeoCodePK itmhztscdt_countrygeocodeid = _value.getCountryGeoCodePK();
704        if(itmhztscdt_countrygeocodeid == null)
705            _ps.setNull(4, Types.BIGINT);
706        else
707            _ps.setLong(4, itmhztscdt_countrygeocodeid.getEntityId());
708            
709        HarmonizedTariffScheduleCodeUseTypePK itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = _value.getHarmonizedTariffScheduleCodeUseTypePK();
710        if(itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid == null)
711            _ps.setNull(5, Types.BIGINT);
712        else
713            _ps.setLong(5, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid.getEntityId());
714            
715        HarmonizedTariffScheduleCodePK itmhztscdt_hztsc_harmonizedtariffschedulecodeid = _value.getHarmonizedTariffScheduleCodePK();
716        if(itmhztscdt_hztsc_harmonizedtariffschedulecodeid == null)
717            _ps.setNull(6, Types.BIGINT);
718        else
719            _ps.setLong(6, itmhztscdt_hztsc_harmonizedtariffschedulecodeid.getEntityId());
720            
721        Long itmhztscdt_fromtime = _value.getFromTime();
722        if(itmhztscdt_fromtime == null)
723            _ps.setNull(7, Types.BIGINT);
724        else
725            _ps.setLong(7, itmhztscdt_fromtime);
726            
727        Long itmhztscdt_thrutime = _value.getThruTime();
728        if(itmhztscdt_thrutime == null)
729            _ps.setNull(8, Types.BIGINT);
730        else
731            _ps.setLong(8, itmhztscdt_thrutime);
732            
733    }
734    
735    public ItemHarmonizedTariffScheduleCodeDetail create(Session session, ItemHarmonizedTariffScheduleCodePK itemHarmonizedTariffScheduleCodePK, ItemPK itemPK, GeoCodePK countryGeoCodePK, HarmonizedTariffScheduleCodeUseTypePK harmonizedTariffScheduleCodeUseTypePK, HarmonizedTariffScheduleCodePK harmonizedTariffScheduleCodePK, Long fromTime, Long thruTime)
736            throws PersistenceDatabaseException, PersistenceNotNullException {
737        ItemHarmonizedTariffScheduleCodeDetailPK _pk = getNextPK();
738        ItemHarmonizedTariffScheduleCodeDetailValue _value = new ItemHarmonizedTariffScheduleCodeDetailValue(_pk, itemHarmonizedTariffScheduleCodePK, itemPK, countryGeoCodePK, harmonizedTariffScheduleCodeUseTypePK, harmonizedTariffScheduleCodePK, fromTime, thruTime);
739        
740        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
741        
742        try {
743            bindForCreate(_ps, _value);
744            
745            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
746                int _count = _ps.executeUpdate();
747                
748                if(_count != 1) {
749                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
750                }
751            } else {
752                 _ps.executeUpdate();
753            }
754            
755            session.getValueCache().put(_value);
756        } catch (SQLException se) {
757            throw new PersistenceDatabaseException(se);
758        }
759        
760        ItemHarmonizedTariffScheduleCodeDetail _entity = new ItemHarmonizedTariffScheduleCodeDetail(_value, EntityPermission.READ_ONLY);
761        session.putReadOnlyEntity(_pk, _entity);
762        
763        return _entity;
764    }
765    
766    public ItemHarmonizedTariffScheduleCodeDetail create(ItemHarmonizedTariffScheduleCodePK itemHarmonizedTariffScheduleCodePK, ItemPK itemPK, GeoCodePK countryGeoCodePK, HarmonizedTariffScheduleCodeUseTypePK harmonizedTariffScheduleCodeUseTypePK, HarmonizedTariffScheduleCodePK harmonizedTariffScheduleCodePK, Long fromTime, Long thruTime)
767            throws PersistenceDatabaseException, PersistenceNotNullException {
768        return create(ThreadSession.currentSession(), itemHarmonizedTariffScheduleCodePK, itemPK, countryGeoCodePK, harmonizedTariffScheduleCodeUseTypePK, harmonizedTariffScheduleCodePK, fromTime, thruTime);
769    }
770    
771    public void create(Session session, Collection<ItemHarmonizedTariffScheduleCodeDetailValue> _values)
772            throws PersistenceDatabaseException, PersistenceNotNullException {
773        int _size = _values.size();
774        
775        if(_size > 0) {
776            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
777            List<ItemHarmonizedTariffScheduleCodeDetailValue> _cacheValues = new ArrayList<>(_size);
778            
779            try {
780                for(ItemHarmonizedTariffScheduleCodeDetailValue _value : _values) {
781                    _value.setEntityId(entityIdGenerator.getNextEntityId());
782                    bindForCreate(_ps, _value);
783                    
784                    _ps.addBatch();
785                    
786                    _cacheValues.add(_value);
787                }
788                
789                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
790                    int[] _counts = _ps.executeBatch();
791                    
792                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
793                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
794                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
795                        }
796                    }
797                } else {
798                     _ps.executeBatch();
799                }
800                
801                _ps.clearBatch();
802            } catch (SQLException se) {
803                throw new PersistenceDatabaseException(se);
804            }
805            
806            _cacheValues.forEach((_cacheValue) -> {
807                ItemHarmonizedTariffScheduleCodeDetail _cacheEntity = new ItemHarmonizedTariffScheduleCodeDetail(_cacheValue, EntityPermission.READ_ONLY);
808                
809                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
810            });
811        }
812    }
813    
814    public void create(Collection<ItemHarmonizedTariffScheduleCodeDetailValue> _values)
815            throws PersistenceDatabaseException, PersistenceNotNullException {
816        create(ThreadSession.currentSession(), _values);
817    }
818    
819    private boolean bindForStore(PreparedStatement _ps, ItemHarmonizedTariffScheduleCodeDetailValue _value)
820            throws SQLException {
821        boolean _hasBeenModified = _value.hasBeenModified();
822        
823        if(_hasBeenModified) {
824            ItemHarmonizedTariffScheduleCodePK itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid = _value.getItemHarmonizedTariffScheduleCodePK();
825            if(itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid == null)
826                _ps.setNull(1, Types.BIGINT);
827            else
828                _ps.setLong(1, itmhztscdt_itmhztsc_itemharmonizedtariffschedulecodeid.getEntityId());
829            
830            ItemPK itmhztscdt_itm_itemid = _value.getItemPK();
831            if(itmhztscdt_itm_itemid == null)
832                _ps.setNull(2, Types.BIGINT);
833            else
834                _ps.setLong(2, itmhztscdt_itm_itemid.getEntityId());
835            
836            GeoCodePK itmhztscdt_countrygeocodeid = _value.getCountryGeoCodePK();
837            if(itmhztscdt_countrygeocodeid == null)
838                _ps.setNull(3, Types.BIGINT);
839            else
840                _ps.setLong(3, itmhztscdt_countrygeocodeid.getEntityId());
841            
842            HarmonizedTariffScheduleCodeUseTypePK itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid = _value.getHarmonizedTariffScheduleCodeUseTypePK();
843            if(itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid == null)
844                _ps.setNull(4, Types.BIGINT);
845            else
846                _ps.setLong(4, itmhztscdt_hztscutyp_harmonizedtariffschedulecodeusetypeid.getEntityId());
847            
848            HarmonizedTariffScheduleCodePK itmhztscdt_hztsc_harmonizedtariffschedulecodeid = _value.getHarmonizedTariffScheduleCodePK();
849            if(itmhztscdt_hztsc_harmonizedtariffschedulecodeid == null)
850                _ps.setNull(5, Types.BIGINT);
851            else
852                _ps.setLong(5, itmhztscdt_hztsc_harmonizedtariffschedulecodeid.getEntityId());
853            
854            Long itmhztscdt_fromtime = _value.getFromTime();
855            if(itmhztscdt_fromtime == null)
856                _ps.setNull(6, Types.BIGINT);
857            else
858                _ps.setLong(6, itmhztscdt_fromtime);
859            
860            Long itmhztscdt_thrutime = _value.getThruTime();
861            if(itmhztscdt_thrutime == null)
862                _ps.setNull(7, Types.BIGINT);
863            else
864                _ps.setLong(7, itmhztscdt_thrutime);
865            
866            _ps.setLong(8, _value.getPrimaryKey().getEntityId());
867            
868            _value.clearHasBeenModified();
869        }
870        
871        return _hasBeenModified;
872    }
873    
874    @Override
875    public void store(Session session, ItemHarmonizedTariffScheduleCodeDetail entity)
876            throws PersistenceDatabaseException {
877        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
878        
879        try {
880            ItemHarmonizedTariffScheduleCodeDetailValue _value = entity.getItemHarmonizedTariffScheduleCodeDetailValue();
881            
882            if(bindForStore(_ps, _value)) {
883                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
884                    int _count = _ps.executeUpdate();
885                    
886                    if(_count != 1) {
887                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
888                    }
889                } else {
890                     _ps.executeUpdate();
891                }
892                
893                session.getValueCache().put(_value);
894            }
895        } catch (SQLException se) {
896            throw new PersistenceDatabaseException(se);
897        }
898    }
899    
900    @Override
901    public void store(Session session, Collection<ItemHarmonizedTariffScheduleCodeDetail> entities)
902            throws PersistenceDatabaseException {
903        if(entities.size() > 0) {
904            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
905            int _modifiedEntities = 0;
906            
907            try {
908                for(ItemHarmonizedTariffScheduleCodeDetail entity : entities) {
909                    if(bindForStore(_ps, entity.getItemHarmonizedTariffScheduleCodeDetailValue())) {
910                        _ps.addBatch();
911                        _modifiedEntities++;
912                    }
913                }
914                
915                if(_modifiedEntities != 0) {
916                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
917                        int[] _counts = _ps.executeBatch();
918                        
919                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
920                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
921                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
922                            }
923                        }
924                    } else {
925                         _ps.executeBatch();
926                    }
927                    
928                    _ps.clearBatch();
929                    
930                    entities.forEach((entity) -> {
931                        session.getValueCache().put(entity.getItemHarmonizedTariffScheduleCodeDetailValue());
932                    });
933                }
934            } catch (SQLException se) {
935                throw new PersistenceDatabaseException(se);
936            }
937        }
938    }
939    
940    @Override
941    public void store(Collection<ItemHarmonizedTariffScheduleCodeDetail> entities)
942            throws PersistenceDatabaseException {
943        store(ThreadSession.currentSession(), entities);
944    }
945    
946    @Override
947    public void remove(Session session, ItemHarmonizedTariffScheduleCodeDetail entity)
948            throws PersistenceDatabaseException {
949        remove(session, entity.getPrimaryKey());
950    }
951    
952    @Override
953    public void remove(Session session, ItemHarmonizedTariffScheduleCodeDetailPK pk)
954            throws PersistenceDatabaseException {
955        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
956        long _entityId = pk.getEntityId();
957        
958        try {
959            _ps.setLong(1, _entityId);
960            
961            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
962                int _count = _ps.executeUpdate();
963                
964                if(_count != 1) {
965                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
966                }
967            } else {
968                 _ps.executeUpdate();
969            }
970            
971            session.getValueCache().remove(pk);
972        } catch (SQLException se) {
973            throw new PersistenceDatabaseException(se);
974        }
975        
976        session.removed(pk, false);
977    }
978    
979    @Override
980    public void remove(Session session, Collection<ItemHarmonizedTariffScheduleCodeDetailPK> pks)
981            throws PersistenceDatabaseException {
982        if(pks.size() > 0) {
983            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
984            int _modifiedEntities = 0;
985            
986            try {
987                for(ItemHarmonizedTariffScheduleCodeDetailPK pk : pks) {
988                    long _entityId = pk.getEntityId();
989                    
990                    _ps.setLong(1, _entityId);
991                    
992                    _ps.addBatch();
993                    _modifiedEntities++;
994                }
995                
996                if(_modifiedEntities != 0) {
997                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
998                        int[] _counts = _ps.executeBatch();
999                        
1000                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1001                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1002                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1003                            }
1004                        }
1005                    } else {
1006                        _ps.executeBatch();
1007                    }
1008                    
1009                    _ps.clearBatch();
1010                    
1011                    pks.forEach((pk) -> {
1012                        session.getValueCache().remove(pk);
1013                    });
1014                }
1015            } catch (SQLException se) {
1016                throw new PersistenceDatabaseException(se);
1017            }
1018            
1019            pks.forEach((pk) -> {
1020                session.removed(pk, true);
1021            });
1022        }
1023    }
1024    
1025    @Override
1026    public void remove(Collection<ItemHarmonizedTariffScheduleCodeDetailPK> pks)
1027            throws PersistenceDatabaseException {
1028        remove(ThreadSession.currentSession(), pks);
1029    }
1030    
1031    @Override
1032    public boolean validPK(Session session, ItemHarmonizedTariffScheduleCodeDetailPK pk)
1033            throws PersistenceDatabaseException {
1034        boolean valid = false;
1035        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1036        ResultSet _rs = null;
1037        
1038        try {
1039            _ps.setLong(1, pk.getEntityId());
1040            
1041            _rs = _ps.executeQuery();
1042            if(_rs.next()) {
1043                long _count = _rs.getLong(1);
1044                if(_rs.wasNull())
1045                    _count = 0;
1046                
1047                if(_count == 1)
1048                    valid = true;
1049            }
1050        } catch (SQLException se) {
1051            throw new PersistenceDatabaseException(se);
1052        } finally {
1053            if(_rs != null) {
1054                try {
1055                    _rs.close();
1056                } catch (SQLException se) {
1057                    // do nothing
1058                }
1059            }
1060        }
1061        
1062        return valid;
1063    }
1064    
1065}