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 private static String PK_COLUMN = "hztsctr_harmonizedtariffschedulecodetranslationid";
082    final private static String ALL_COLUMNS = "hztsctr_harmonizedtariffschedulecodetranslationid, hztsctr_hztsc_harmonizedtariffschedulecodeid, hztsctr_lang_languageid, hztsctr_description, hztsctr_overviewmimetypeid, hztsctr_overview, hztsctr_fromtime, hztsctr_thrutime";
083    final public static String TABLE_NAME = "harmonizedtariffschedulecodetranslations";
084    
085    final public static String HZTSCTR_HARMONIZEDTARIFFSCHEDULECODETRANSLATIONID = "hztsctr_harmonizedtariffschedulecodetranslationid";
086    final public static String HZTSCTR_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID = "hztsctr_hztsc_harmonizedtariffschedulecodeid";
087    final public static String HZTSCTR_LANG_LANGUAGEID = "hztsctr_lang_languageid";
088    final public static String HZTSCTR_DESCRIPTION = "hztsctr_description";
089    final public static String HZTSCTR_OVERVIEWMIMETYPEID = "hztsctr_overviewmimetypeid";
090    final public static String HZTSCTR_OVERVIEW = "hztsctr_overview";
091    final public static String HZTSCTR_FROMTIME = "hztsctr_fromtime";
092    final public static String HZTSCTR_THRUTIME = "hztsctr_thrutime";
093    
094    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(HarmonizedTariffScheduleCodeTranslationConstants.COMPONENT_VENDOR_NAME, HarmonizedTariffScheduleCodeTranslationConstants.ENTITY_TYPE_NAME);
095    
096    /** Creates a new instance of HarmonizedTariffScheduleCodeTranslationFactory */
097    protected HarmonizedTariffScheduleCodeTranslationFactory() {
098        super();
099    }
100    
101    public static HarmonizedTariffScheduleCodeTranslationFactory getInstance() {
102        return CDI.current().select(HarmonizedTariffScheduleCodeTranslationFactory.class).get();
103    }
104    
105    @Override
106    public String getPKColumn() {
107        return PK_COLUMN;
108    }
109    
110    @Override
111    public String getAllColumns() {
112        return ALL_COLUMNS;
113    }
114    
115    @Override
116    public String getTableName() {
117        return TABLE_NAME;
118    }
119    
120    @Override
121    public String getComponentVendorName() {
122        return HarmonizedTariffScheduleCodeTranslationConstants.COMPONENT_VENDOR_NAME;
123    }
124    
125    @Override
126    public String getEntityTypeName() {
127        return HarmonizedTariffScheduleCodeTranslationConstants.ENTITY_TYPE_NAME;
128    }
129    
130    public PreparedStatement prepareStatement(String query) {
131        return session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, query);
132    }
133    
134    public HarmonizedTariffScheduleCodeTranslationPK getNextPK() {
135        return new HarmonizedTariffScheduleCodeTranslationPK(entityIdGenerator.getNextEntityId());
136    }
137    
138    public Set<HarmonizedTariffScheduleCodeTranslationPK> getPKsFromResultSetAsSet(ResultSet rs)
139            throws PersistenceDatabaseException {
140        Set<HarmonizedTariffScheduleCodeTranslationPK> _result = new HashSet<>();
141        
142        try {
143            while(rs.next()) {
144                _result.add(getPKFromResultSet(rs));
145            }
146        } catch (SQLException se) {
147            throw new PersistenceDatabaseException(se);
148        }
149        
150        return _result;
151    }
152    
153    public java.util.List<HarmonizedTariffScheduleCodeTranslationPK> getPKsFromResultSetAsList(ResultSet rs)
154            throws PersistenceDatabaseException {
155        java.util.List<HarmonizedTariffScheduleCodeTranslationPK> _result = new ArrayList<>();
156        
157        try {
158            while(rs.next()) {
159                _result.add(getPKFromResultSet(rs));
160            }
161        } catch (SQLException se) {
162            throw new PersistenceDatabaseException(se);
163        }
164        
165        return _result;
166    }
167    
168    public HarmonizedTariffScheduleCodeTranslationPK getPKFromResultSet(ResultSet rs)
169            throws PersistenceDatabaseException {
170        HarmonizedTariffScheduleCodeTranslationPK _result;
171        
172        try {
173            long hztsctr_harmonizedtariffschedulecodetranslationid = rs.getLong(HZTSCTR_HARMONIZEDTARIFFSCHEDULECODETRANSLATIONID);
174            Long _entityId = rs.wasNull() ? null : hztsctr_harmonizedtariffschedulecodetranslationid;
175            
176            _result = new HarmonizedTariffScheduleCodeTranslationPK(_entityId);
177        } catch (SQLException se) {
178            throw new PersistenceDatabaseException(se);
179        }
180        
181        return _result;
182    }
183    
184    public java.util.List<HarmonizedTariffScheduleCodeTranslationValue> getValuesFromPKs(Collection<HarmonizedTariffScheduleCodeTranslationPK> pks)
185            throws PersistenceDatabaseException {
186        java.util.List<HarmonizedTariffScheduleCodeTranslationValue> _values = new ArrayList<>(pks.size());
187        
188        for(HarmonizedTariffScheduleCodeTranslationPK _pk: pks) {
189            _values.add(getValueFromPK(_pk));
190        }
191        
192        return _values;
193    }
194    
195    public HarmonizedTariffScheduleCodeTranslationValue getValueFromPK(HarmonizedTariffScheduleCodeTranslationPK pk)
196            throws PersistenceDatabaseException {
197        HarmonizedTariffScheduleCodeTranslationValue _value;
198        
199        // See if we already have the entity in the session cache
200        HarmonizedTariffScheduleCodeTranslation _entity = (HarmonizedTariffScheduleCodeTranslation)session.getEntity(pk);
201        if(_entity == null)
202            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getHarmonizedTariffScheduleCodeTranslationValue();
203        else
204            _value = _entity.getHarmonizedTariffScheduleCodeTranslationValue();
205        
206        return _value;
207    }
208    
209    public java.util.List<HarmonizedTariffScheduleCodeTranslationValue> getValuesFromResultSet(ResultSet rs)
210            throws PersistenceDatabaseException {
211        java.util.List<HarmonizedTariffScheduleCodeTranslationValue> _result = new ArrayList<>();
212        
213        try {
214            while(rs.next()) {
215                _result.add(getValueFromResultSet(rs));
216            }
217        } catch (SQLException se) {
218            throw new PersistenceDatabaseException(se);
219        }
220        
221        return _result;
222    }
223    
224    public HarmonizedTariffScheduleCodeTranslationValue getValueFromResultSet(ResultSet rs)
225            throws PersistenceDatabaseException {
226        HarmonizedTariffScheduleCodeTranslationValue _value;
227        
228        try {
229            Long hztsctr_harmonizedtariffschedulecodetranslationid = rs.getLong(HZTSCTR_HARMONIZEDTARIFFSCHEDULECODETRANSLATIONID);
230            HarmonizedTariffScheduleCodeTranslationPK _pk = new HarmonizedTariffScheduleCodeTranslationPK(hztsctr_harmonizedtariffschedulecodetranslationid);
231            
232            // See if we already have the entity in the session cache
233            HarmonizedTariffScheduleCodeTranslation _entity = (HarmonizedTariffScheduleCodeTranslation)session.getEntity(_pk);
234            
235            if(_entity == null) {
236                Long hztsctr_hztsc_harmonizedtariffschedulecodeid = rs.getLong(HZTSCTR_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID);
237                if(rs.wasNull())
238                    hztsctr_hztsc_harmonizedtariffschedulecodeid = null;
239                
240                Long hztsctr_lang_languageid = rs.getLong(HZTSCTR_LANG_LANGUAGEID);
241                if(rs.wasNull())
242                    hztsctr_lang_languageid = null;
243                
244                String hztsctr_description = rs.getString(HZTSCTR_DESCRIPTION);
245                if(rs.wasNull())
246                    hztsctr_description = null;
247                
248                Long hztsctr_overviewmimetypeid = rs.getLong(HZTSCTR_OVERVIEWMIMETYPEID);
249                if(rs.wasNull())
250                    hztsctr_overviewmimetypeid = null;
251                
252                Clob hztsctr_overview = rs.getClob(HZTSCTR_OVERVIEW);
253                if(rs.wasNull())
254                    hztsctr_overview = null;
255                
256                Long hztsctr_fromtime = rs.getLong(HZTSCTR_FROMTIME);
257                if(rs.wasNull())
258                    hztsctr_fromtime = null;
259                
260                Long hztsctr_thrutime = rs.getLong(HZTSCTR_THRUTIME);
261                if(rs.wasNull())
262                    hztsctr_thrutime = null;
263                
264                _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);
265            } else
266                _value = _entity.getHarmonizedTariffScheduleCodeTranslationValue();
267        } catch (SQLException se) {
268            throw new PersistenceDatabaseException(se);
269        }
270        
271        return _value;
272    }
273    
274    public java.util.List<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromPKs(EntityPermission entityPermission, Collection<HarmonizedTariffScheduleCodeTranslationPK> pks)
275            throws PersistenceDatabaseException {
276        java.util.List<HarmonizedTariffScheduleCodeTranslation> _entities = new ArrayList<>(pks.size());
277        
278        for(HarmonizedTariffScheduleCodeTranslationPK _pk: pks) {
279            _entities.add(getEntityFromPK(entityPermission, _pk));
280        }
281        
282        return _entities;
283    }
284    
285    public HarmonizedTariffScheduleCodeTranslation getEntityFromValue(EntityPermission entityPermission, HarmonizedTariffScheduleCodeTranslationValue value) {
286        return getEntityFromPK(entityPermission, value.getPrimaryKey());
287    }
288    
289    public HarmonizedTariffScheduleCodeTranslation getEntityFromCache(HarmonizedTariffScheduleCodeTranslationPK pk) {
290        HarmonizedTariffScheduleCodeTranslationValue _value = (HarmonizedTariffScheduleCodeTranslationValue)session.getValueCache().get(pk);
291    
292        return _value == null ? null : new HarmonizedTariffScheduleCodeTranslation(_value, EntityPermission.READ_ONLY);
293    }
294    
295    public HarmonizedTariffScheduleCodeTranslation getEntityFromPK(EntityPermission entityPermission, HarmonizedTariffScheduleCodeTranslationPK pk)
296            throws PersistenceDatabaseException {
297        HarmonizedTariffScheduleCodeTranslation _entity;
298        
299        // See if we already have the entity in the session cache
300        _entity = (HarmonizedTariffScheduleCodeTranslation)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(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(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<HarmonizedTariffScheduleCodeTranslationPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
343            throws PersistenceDatabaseException {
344        Set<HarmonizedTariffScheduleCodeTranslationPK> _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<HarmonizedTariffScheduleCodeTranslationPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
371            throws PersistenceDatabaseException {
372        java.util.List<HarmonizedTariffScheduleCodeTranslationPK> _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 HarmonizedTariffScheduleCodeTranslationPK getPKFromQuery(PreparedStatement ps, final Object... params)
399            throws PersistenceDatabaseException {
400        HarmonizedTariffScheduleCodeTranslationPK _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<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
429            throws PersistenceDatabaseException {
430        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, queryMap.get(entityPermission));
431        
432        return getEntitiesFromQuery(entityPermission, ps, params);
433    }
434    
435    public java.util.List<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
436            throws PersistenceDatabaseException {
437        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, queryMap.get(entityPermission));
438        
439        return getEntitiesFromQuery(entityPermission, ps);
440    }
441    
442    public java.util.List<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
443            throws PersistenceDatabaseException {
444        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, query.getSQL());
445        
446        return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray());
447    }
448    
449    public java.util.List<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
450            throws PersistenceDatabaseException {
451        java.util.List<HarmonizedTariffScheduleCodeTranslation> _entities;
452        ResultSet _rs = null;
453        
454        try {
455            if(params.length != 0) {
456                Session.setQueryParams(ps, params);
457            }
458            
459            _rs = ps.executeQuery();
460            _entities = getEntitiesFromResultSet(entityPermission, _rs);
461            _rs.close();
462        } catch (SQLException se) {
463            throw new PersistenceDatabaseException(se);
464        } finally {
465            if(_rs != null) {
466                try {
467                    _rs.close();
468                } catch (SQLException se) {
469                    // do nothing
470                }
471            }
472        }
473        
474        return _entities;
475    }
476    
477    public HarmonizedTariffScheduleCodeTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
478            throws PersistenceDatabaseException {
479        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, queryMap.get(entityPermission));
480        
481        return getEntityFromQuery(entityPermission, ps, params);
482    }
483    
484    public HarmonizedTariffScheduleCodeTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
485            throws PersistenceDatabaseException {
486        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, queryMap.get(entityPermission));
487        
488        return getEntityFromQuery(entityPermission, ps);
489    }
490    
491    public HarmonizedTariffScheduleCodeTranslation getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
492            throws PersistenceDatabaseException {
493        PreparedStatement ps = session.prepareStatement(HarmonizedTariffScheduleCodeTranslationFactory.class, query.getSQL());
494        
495        return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray());
496    }
497    
498    public HarmonizedTariffScheduleCodeTranslation getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
499            throws PersistenceDatabaseException {
500        HarmonizedTariffScheduleCodeTranslation _entity = null;
501        ResultSet _rs = null;
502        
503        try {
504            if(params.length != 0) {
505                Session.setQueryParams(ps, params);
506            }
507            
508            _rs = ps.executeQuery();
509            if(_rs.next()) {
510                _entity = getEntityFromResultSet(entityPermission, _rs);
511            }
512            _rs.close();
513        } catch (SQLException se) {
514            throw new PersistenceDatabaseException(se);
515        } finally {
516            if(_rs != null) {
517                try {
518                    _rs.close();
519                } catch (SQLException se) {
520                    // do nothing
521                }
522            }
523        }
524        
525        return _entity;
526    }
527    
528    public java.util.List<HarmonizedTariffScheduleCodeTranslation> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
529            throws PersistenceDatabaseException {
530        java.util.List<HarmonizedTariffScheduleCodeTranslation> _result = new ArrayList<>();
531        
532        try {
533            while(rs.next()) {
534                _result.add(getEntityFromResultSet(entityPermission, rs));
535            }
536        } catch (SQLException se) {
537            throw new PersistenceDatabaseException(se);
538        }
539        
540        return _result;
541    }
542    
543    public HarmonizedTariffScheduleCodeTranslation getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
544            throws PersistenceDatabaseException {
545        HarmonizedTariffScheduleCodeTranslation _entity;
546        
547        try {
548            Long hztsctr_harmonizedtariffschedulecodetranslationid = rs.getLong(HZTSCTR_HARMONIZEDTARIFFSCHEDULECODETRANSLATIONID);
549            HarmonizedTariffScheduleCodeTranslationPK _pk = new HarmonizedTariffScheduleCodeTranslationPK(hztsctr_harmonizedtariffschedulecodetranslationid);
550            
551            // See if we already have the entity in the session cache
552            _entity = (HarmonizedTariffScheduleCodeTranslation)session.getEntity(_pk);
553            if(_entity != null) {
554                // If the requested permission is READ_WRITE, and the cached permission is
555                // READ_ONLY, then pretend that the cached object wasn't found, and create
556                // a new entity that is READ_WRITE.
557                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
558                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
559                        _entity = null;
560                }
561            }
562            boolean foundInSessionCache = _entity != null;
563            
564            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
565                _entity = getEntityFromCache(_pk);
566            }
567            
568            if(_entity == null) {
569                Long hztsctr_hztsc_harmonizedtariffschedulecodeid = rs.getLong(HZTSCTR_HZTSC_HARMONIZEDTARIFFSCHEDULECODEID);
570                if(rs.wasNull())
571                    hztsctr_hztsc_harmonizedtariffschedulecodeid = null;
572                
573                Long hztsctr_lang_languageid = rs.getLong(HZTSCTR_LANG_LANGUAGEID);
574                if(rs.wasNull())
575                    hztsctr_lang_languageid = null;
576                
577                String hztsctr_description = rs.getString(HZTSCTR_DESCRIPTION);
578                if(rs.wasNull())
579                    hztsctr_description = null;
580                
581                Long hztsctr_overviewmimetypeid = rs.getLong(HZTSCTR_OVERVIEWMIMETYPEID);
582                if(rs.wasNull())
583                    hztsctr_overviewmimetypeid = null;
584                
585                Clob hztsctr_overview = rs.getClob(HZTSCTR_OVERVIEW);
586                if(rs.wasNull())
587                    hztsctr_overview = null;
588                
589                Long hztsctr_fromtime = rs.getLong(HZTSCTR_FROMTIME);
590                if(rs.wasNull())
591                    hztsctr_fromtime = null;
592                
593                Long hztsctr_thrutime = rs.getLong(HZTSCTR_THRUTIME);
594                if(rs.wasNull())
595                    hztsctr_thrutime = null;
596                
597                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);
598                _entity = new HarmonizedTariffScheduleCodeTranslation(_value, entityPermission);
599            }
600            
601            if(!foundInSessionCache) {
602                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
603                    session.putReadOnlyEntity(_pk, _entity);
604                    session.getValueCache().put(_entity.getHarmonizedTariffScheduleCodeTranslationValue());
605                } else {
606                    session.putReadWriteEntity(_pk, _entity);
607                }
608            }
609        } catch (SQLException se) {
610            throw new PersistenceDatabaseException(se);
611        }
612        
613        return _entity;
614    }
615    
616    public HarmonizedTariffScheduleCodeTranslation create(HarmonizedTariffScheduleCode harmonizedTariffScheduleCode, Language language, String description, MimeType overviewMimeType, String overview, Long fromTime, Long thruTime)
617            throws PersistenceDatabaseException, PersistenceNotNullException {
618        return create(harmonizedTariffScheduleCode == null ? null : harmonizedTariffScheduleCode.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, overviewMimeType == null ? null : overviewMimeType.getPrimaryKey(), overview, fromTime, thruTime);
619    }
620    
621    private void bindForCreate(PreparedStatement _ps, HarmonizedTariffScheduleCodeTranslationValue _value)
622            throws SQLException {
623        _ps.setLong(1, _value.getEntityId());
624        
625        HarmonizedTariffScheduleCodePK hztsctr_hztsc_harmonizedtariffschedulecodeid = _value.getHarmonizedTariffScheduleCodePK();
626        if(hztsctr_hztsc_harmonizedtariffschedulecodeid == null)
627            _ps.setNull(2, Types.BIGINT);
628        else
629            _ps.setLong(2, hztsctr_hztsc_harmonizedtariffschedulecodeid.getEntityId());
630            
631        LanguagePK hztsctr_lang_languageid = _value.getLanguagePK();
632        if(hztsctr_lang_languageid == null)
633            _ps.setNull(3, Types.BIGINT);
634        else
635            _ps.setLong(3, hztsctr_lang_languageid.getEntityId());
636            
637        String hztsctr_description = _value.getDescription();
638        if(hztsctr_description == null)
639            _ps.setNull(4, Types.VARCHAR);
640        else
641            _ps.setString(4, hztsctr_description);
642            
643        MimeTypePK hztsctr_overviewmimetypeid = _value.getOverviewMimeTypePK();
644        if(hztsctr_overviewmimetypeid == null)
645            _ps.setNull(5, Types.BIGINT);
646        else
647            _ps.setLong(5, hztsctr_overviewmimetypeid.getEntityId());
648            
649        String hztsctr_overview = _value.getOverview();
650        if(hztsctr_overview == null)
651            _ps.setNull(6, Types.CLOB);
652        else
653            _ps.setCharacterStream(6, new StringReader(hztsctr_overview), hztsctr_overview.length());
654            
655        Long hztsctr_fromtime = _value.getFromTime();
656        if(hztsctr_fromtime == null)
657            _ps.setNull(7, Types.BIGINT);
658        else
659            _ps.setLong(7, hztsctr_fromtime);
660            
661        Long hztsctr_thrutime = _value.getThruTime();
662        if(hztsctr_thrutime == null)
663            _ps.setNull(8, Types.BIGINT);
664        else
665            _ps.setLong(8, hztsctr_thrutime);
666            
667    }
668    
669    public HarmonizedTariffScheduleCodeTranslation create(HarmonizedTariffScheduleCodePK harmonizedTariffScheduleCodePK, LanguagePK languagePK, String description, MimeTypePK overviewMimeTypePK, String overview, Long fromTime, Long thruTime)
670            throws PersistenceDatabaseException, PersistenceNotNullException {
671        HarmonizedTariffScheduleCodeTranslationPK _pk = getNextPK();
672        HarmonizedTariffScheduleCodeTranslationValue _value = new HarmonizedTariffScheduleCodeTranslationValue(_pk, harmonizedTariffScheduleCodePK, languagePK, description, overviewMimeTypePK, overview, fromTime, thruTime);
673        
674        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
675        
676        try {
677            bindForCreate(_ps, _value);
678            
679            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
680                int _count = _ps.executeUpdate();
681                
682                if(_count != 1) {
683                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
684                }
685            } else {
686                 _ps.executeUpdate();
687            }
688            
689            session.getValueCache().put(_value);
690        } catch (SQLException se) {
691            throw new PersistenceDatabaseException(se);
692        }
693        
694        HarmonizedTariffScheduleCodeTranslation _entity = new HarmonizedTariffScheduleCodeTranslation(_value, EntityPermission.READ_ONLY);
695        session.putReadOnlyEntity(_pk, _entity);
696        
697        return _entity;
698    }
699    
700    public void create(Collection<HarmonizedTariffScheduleCodeTranslationValue> _values)
701            throws PersistenceDatabaseException, PersistenceNotNullException {
702        int _size = _values.size();
703        
704        if(_size > 0) {
705            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
706            List<HarmonizedTariffScheduleCodeTranslationValue> _cacheValues = new ArrayList<>(_size);
707            
708            try {
709                for(HarmonizedTariffScheduleCodeTranslationValue _value : _values) {
710                    _value.setEntityId(entityIdGenerator.getNextEntityId());
711                    bindForCreate(_ps, _value);
712                    
713                    _ps.addBatch();
714                    
715                    _cacheValues.add(_value);
716                }
717                
718                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
719                    int[] _counts = _ps.executeBatch();
720                    
721                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
722                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
723                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
724                        }
725                    }
726                } else {
727                     _ps.executeBatch();
728                }
729                
730                _ps.clearBatch();
731            } catch (SQLException se) {
732                throw new PersistenceDatabaseException(se);
733            }
734            
735            _cacheValues.forEach((_cacheValue) -> {
736                HarmonizedTariffScheduleCodeTranslation _cacheEntity = new HarmonizedTariffScheduleCodeTranslation(_cacheValue, EntityPermission.READ_ONLY);
737                
738                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
739            });
740        }
741    }
742    
743    private boolean bindForStore(PreparedStatement _ps, HarmonizedTariffScheduleCodeTranslationValue _value)
744            throws SQLException {
745        boolean _hasBeenModified = _value.hasBeenModified();
746        
747        if(_hasBeenModified) {
748            HarmonizedTariffScheduleCodePK hztsctr_hztsc_harmonizedtariffschedulecodeid = _value.getHarmonizedTariffScheduleCodePK();
749            if(hztsctr_hztsc_harmonizedtariffschedulecodeid == null)
750                _ps.setNull(1, Types.BIGINT);
751            else
752                _ps.setLong(1, hztsctr_hztsc_harmonizedtariffschedulecodeid.getEntityId());
753            
754            LanguagePK hztsctr_lang_languageid = _value.getLanguagePK();
755            if(hztsctr_lang_languageid == null)
756                _ps.setNull(2, Types.BIGINT);
757            else
758                _ps.setLong(2, hztsctr_lang_languageid.getEntityId());
759            
760            String hztsctr_description = _value.getDescription();
761            if(hztsctr_description == null)
762                _ps.setNull(3, Types.VARCHAR);
763            else
764                _ps.setString(3, hztsctr_description);
765            
766            MimeTypePK hztsctr_overviewmimetypeid = _value.getOverviewMimeTypePK();
767            if(hztsctr_overviewmimetypeid == null)
768                _ps.setNull(4, Types.BIGINT);
769            else
770                _ps.setLong(4, hztsctr_overviewmimetypeid.getEntityId());
771            
772            String hztsctr_overview = _value.getOverview();
773            if(hztsctr_overview == null)
774                _ps.setNull(5, Types.CLOB);
775            else
776                _ps.setCharacterStream(5, new StringReader(hztsctr_overview), hztsctr_overview.length());
777            
778            Long hztsctr_fromtime = _value.getFromTime();
779            if(hztsctr_fromtime == null)
780                _ps.setNull(6, Types.BIGINT);
781            else
782                _ps.setLong(6, hztsctr_fromtime);
783            
784            Long hztsctr_thrutime = _value.getThruTime();
785            if(hztsctr_thrutime == null)
786                _ps.setNull(7, Types.BIGINT);
787            else
788                _ps.setLong(7, hztsctr_thrutime);
789            
790            _ps.setLong(8, _value.getPrimaryKey().getEntityId());
791            
792            _value.clearHasBeenModified();
793        }
794        
795        return _hasBeenModified;
796    }
797    
798    @Override
799    public void store(HarmonizedTariffScheduleCodeTranslation entity)
800            throws PersistenceDatabaseException {
801        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
802        
803        try {
804            HarmonizedTariffScheduleCodeTranslationValue _value = entity.getHarmonizedTariffScheduleCodeTranslationValue();
805            
806            if(bindForStore(_ps, _value)) {
807                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
808                    int _count = _ps.executeUpdate();
809                    
810                    if(_count != 1) {
811                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
812                    }
813                } else {
814                     _ps.executeUpdate();
815                }
816                
817                session.getValueCache().put(_value);
818            }
819        } catch (SQLException se) {
820            throw new PersistenceDatabaseException(se);
821        }
822    }
823    
824    @Override
825    public void store(Collection<HarmonizedTariffScheduleCodeTranslation> entities)
826            throws PersistenceDatabaseException {
827        if(entities.size() > 0) {
828            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
829            int _modifiedEntities = 0;
830            
831            try {
832                for(HarmonizedTariffScheduleCodeTranslation entity : entities) {
833                    if(bindForStore(_ps, entity.getHarmonizedTariffScheduleCodeTranslationValue())) {
834                        _ps.addBatch();
835                        _modifiedEntities++;
836                    }
837                }
838                
839                if(_modifiedEntities != 0) {
840                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
841                        int[] _counts = _ps.executeBatch();
842                        
843                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
844                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
845                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
846                            }
847                        }
848                    } else {
849                         _ps.executeBatch();
850                    }
851                    
852                    _ps.clearBatch();
853                    
854                    entities.forEach((entity) -> {
855                        session.getValueCache().put(entity.getHarmonizedTariffScheduleCodeTranslationValue());
856                    });
857                }
858            } catch (SQLException se) {
859                throw new PersistenceDatabaseException(se);
860            }
861        }
862    }
863    
864    @Override
865    public void remove(HarmonizedTariffScheduleCodeTranslation entity)
866            throws PersistenceDatabaseException {
867        remove(entity.getPrimaryKey());
868    }
869    
870    @Override
871    public void remove(HarmonizedTariffScheduleCodeTranslationPK pk)
872            throws PersistenceDatabaseException {
873        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
874        long _entityId = pk.getEntityId();
875        
876        try {
877            _ps.setLong(1, _entityId);
878            
879            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
880                int _count = _ps.executeUpdate();
881                
882                if(_count != 1) {
883                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
884                }
885            } else {
886                 _ps.executeUpdate();
887            }
888            
889            session.getValueCache().remove(pk);
890        } catch (SQLException se) {
891            throw new PersistenceDatabaseException(se);
892        }
893        
894        session.removed(pk, false);
895    }
896    
897    @Override
898    public void remove(Collection<HarmonizedTariffScheduleCodeTranslationPK> pks)
899            throws PersistenceDatabaseException {
900        if(pks.size() > 0) {
901            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
902            int _modifiedEntities = 0;
903            
904            try {
905                for(HarmonizedTariffScheduleCodeTranslationPK pk : pks) {
906                    long _entityId = pk.getEntityId();
907                    
908                    _ps.setLong(1, _entityId);
909                    
910                    _ps.addBatch();
911                    _modifiedEntities++;
912                }
913                
914                if(_modifiedEntities != 0) {
915                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
916                        int[] _counts = _ps.executeBatch();
917                        
918                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
919                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
920                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
921                            }
922                        }
923                    } else {
924                        _ps.executeBatch();
925                    }
926                    
927                    _ps.clearBatch();
928                    
929                    pks.forEach((pk) -> {
930                        session.getValueCache().remove(pk);
931                    });
932                }
933            } catch (SQLException se) {
934                throw new PersistenceDatabaseException(se);
935            }
936            
937            pks.forEach((pk) -> {
938                session.removed(pk, true);
939            });
940        }
941    }
942    
943    @Override
944    public boolean validPK(HarmonizedTariffScheduleCodeTranslationPK pk)
945            throws PersistenceDatabaseException {
946        boolean valid = false;
947        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
948        ResultSet _rs = null;
949        
950        try {
951            _ps.setLong(1, pk.getEntityId());
952            
953            _rs = _ps.executeQuery();
954            if(_rs.next()) {
955                long _count = _rs.getLong(1);
956                if(_rs.wasNull())
957                    _count = 0;
958                
959                if(_count == 1)
960                    valid = true;
961            }
962        } catch (SQLException se) {
963            throw new PersistenceDatabaseException(se);
964        } finally {
965            if(_rs != null) {
966                try {
967                    _rs.close();
968                } catch (SQLException se) {
969                    // do nothing
970                }
971            }
972        }
973        
974        return valid;
975    }
976    
977}