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