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