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 * TaxClassificationTranslationFactory.java
021 */
022
023package com.echothree.model.data.tax.server.factory;
024
025import com.echothree.model.data.tax.common.pk.TaxClassificationPK;
026import com.echothree.model.data.party.common.pk.LanguagePK;
027import com.echothree.model.data.core.common.pk.MimeTypePK;
028
029import com.echothree.model.data.tax.server.entity.TaxClassification;
030import com.echothree.model.data.party.server.entity.Language;
031import com.echothree.model.data.core.server.entity.MimeType;
032
033import com.echothree.model.data.tax.common.TaxClassificationTranslationConstants;
034import com.echothree.model.data.tax.common.pk.TaxClassificationTranslationPK;
035import com.echothree.model.data.tax.server.value.TaxClassificationTranslationValue;
036import com.echothree.model.data.tax.server.entity.TaxClassificationTranslation;
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 TaxClassificationTranslationFactory
067        implements BaseFactory<TaxClassificationTranslationPK, TaxClassificationTranslation> {
068    
069    @Inject
070    Session session;
071    
072    //private static final Logger log = LoggerFactory.getLogger(TaxClassificationTranslationFactory.class);
073    
074    final private static String SQL_SELECT_READ_ONLY = "SELECT txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?";
075    final private static String SQL_SELECT_READ_WRITE = "SELECT txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ? FOR UPDATE";
076    final private static String SQL_INSERT = "INSERT INTO taxclassificationtranslations (txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
077    final private static String SQL_UPDATE = "UPDATE taxclassificationtranslations SET txclsfntr_txclsfn_taxclassificationid = ?, txclsfntr_lang_languageid = ?, txclsfntr_description = ?, txclsfntr_overviewmimetypeid = ?, txclsfntr_overview = ?, txclsfntr_fromtime = ?, txclsfntr_thrutime = ? WHERE txclsfntr_taxclassificationtranslationid = ?";
078    final private static String SQL_DELETE = "DELETE FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?";
079    final private static String SQL_VALID = "SELECT COUNT(*) FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?";
080    
081    final public static String TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID = "txclsfntr_taxclassificationtranslationid";
082    final public static String TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID = "txclsfntr_txclsfn_taxclassificationid";
083    final public static String TXCLSFNTR_LANG_LANGUAGEID = "txclsfntr_lang_languageid";
084    final public static String TXCLSFNTR_DESCRIPTION = "txclsfntr_description";
085    final public static String TXCLSFNTR_OVERVIEWMIMETYPEID = "txclsfntr_overviewmimetypeid";
086    final public static String TXCLSFNTR_OVERVIEW = "txclsfntr_overview";
087    final public static String TXCLSFNTR_FROMTIME = "txclsfntr_fromtime";
088    final public static String TXCLSFNTR_THRUTIME = "txclsfntr_thrutime";
089    
090    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME, TaxClassificationTranslationConstants.ENTITY_TYPE_NAME);
091    
092    /** Creates a new instance of TaxClassificationTranslationFactory */
093    protected TaxClassificationTranslationFactory() {
094        super();
095    }
096    
097    public static TaxClassificationTranslationFactory getInstance() {
098        return CDI.current().select(TaxClassificationTranslationFactory.class).get();
099    }
100    
101    @Override
102    public String getComponentVendorName() {
103        return TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME;
104    }
105    
106    @Override
107    public String getEntityTypeName() {
108        return TaxClassificationTranslationConstants.ENTITY_TYPE_NAME;
109    }
110    
111    public PreparedStatement prepareStatement(String query) {
112        return session.prepareStatement(query);
113    }
114    
115    public TaxClassificationTranslationPK getNextPK() {
116        return new TaxClassificationTranslationPK(entityIdGenerator.getNextEntityId());
117    }
118    
119    public Set<TaxClassificationTranslationPK> getPKsFromResultSetAsSet(ResultSet rs)
120            throws PersistenceDatabaseException {
121        Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromResultSetAsList(ResultSet rs)
135            throws PersistenceDatabaseException {
136        java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromResultSet(ResultSet rs)
150            throws PersistenceDatabaseException {
151        TaxClassificationTranslationPK _result;
152        
153        try {
154            long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
155            Long _entityId = rs.wasNull() ? null : txclsfntr_taxclassificationtranslationid;
156            
157            _result = new TaxClassificationTranslationPK(_entityId);
158        } catch (SQLException se) {
159            throw new PersistenceDatabaseException(se);
160        }
161        
162        return _result;
163    }
164    
165    public java.util.List<TaxClassificationTranslationValue> getValuesFromPKs(Collection<TaxClassificationTranslationPK> pks)
166            throws PersistenceDatabaseException {
167        java.util.List<TaxClassificationTranslationValue> _values = new ArrayList<>(pks.size());
168        
169        for(TaxClassificationTranslationPK _pk: pks) {
170            _values.add(getValueFromPK(_pk));
171        }
172        
173        return _values;
174    }
175    
176    public TaxClassificationTranslationValue getValueFromPK(TaxClassificationTranslationPK pk)
177            throws PersistenceDatabaseException {
178        TaxClassificationTranslationValue _value;
179        
180        // See if we already have the entity in the session cache
181        TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(pk);
182        if(_entity == null)
183            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getTaxClassificationTranslationValue();
184        else
185            _value = _entity.getTaxClassificationTranslationValue();
186        
187        return _value;
188    }
189    
190    public java.util.List<TaxClassificationTranslationValue> getValuesFromResultSet(ResultSet rs)
191            throws PersistenceDatabaseException {
192        java.util.List<TaxClassificationTranslationValue> _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 TaxClassificationTranslationValue getValueFromResultSet(ResultSet rs)
206            throws PersistenceDatabaseException {
207        TaxClassificationTranslationValue _value;
208        
209        try {
210            Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
211            TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid);
212            
213            // See if we already have the entity in the session cache
214            TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(_pk);
215            
216            if(_entity == null) {
217                Long txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID);
218                if(rs.wasNull())
219                    txclsfntr_txclsfn_taxclassificationid = null;
220                
221                Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID);
222                if(rs.wasNull())
223                    txclsfntr_lang_languageid = null;
224                
225                String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION);
226                if(rs.wasNull())
227                    txclsfntr_description = null;
228                
229                Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID);
230                if(rs.wasNull())
231                    txclsfntr_overviewmimetypeid = null;
232                
233                Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW);
234                if(rs.wasNull())
235                    txclsfntr_overview = null;
236                
237                Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME);
238                if(rs.wasNull())
239                    txclsfntr_fromtime = null;
240                
241                Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME);
242                if(rs.wasNull())
243                    txclsfntr_thrutime = null;
244                
245                _value = new TaxClassificationTranslationValue(_pk, new TaxClassificationPK(txclsfntr_txclsfn_taxclassificationid), new LanguagePK(txclsfntr_lang_languageid), txclsfntr_description, new MimeTypePK(txclsfntr_overviewmimetypeid), txclsfntr_overview == null? null: txclsfntr_overview.getSubString(1L, (int)txclsfntr_overview.length()), txclsfntr_fromtime, txclsfntr_thrutime);
246            } else
247                _value = _entity.getTaxClassificationTranslationValue();
248        } catch (SQLException se) {
249            throw new PersistenceDatabaseException(se);
250        }
251        
252        return _value;
253    }
254    
255    public java.util.List<TaxClassificationTranslation> getEntitiesFromPKs(EntityPermission entityPermission, Collection<TaxClassificationTranslationPK> pks)
256            throws PersistenceDatabaseException {
257        java.util.List<TaxClassificationTranslation> _entities = new ArrayList<>(pks.size());
258        
259        for(TaxClassificationTranslationPK _pk: pks) {
260            _entities.add(getEntityFromPK(entityPermission, _pk));
261        }
262        
263        return _entities;
264    }
265    
266    public TaxClassificationTranslation getEntityFromValue(EntityPermission entityPermission, TaxClassificationTranslationValue value) {
267        return getEntityFromPK(entityPermission, value.getPrimaryKey());
268    }
269    
270    public TaxClassificationTranslation getEntityFromCache(TaxClassificationTranslationPK pk) {
271        TaxClassificationTranslationValue _value = (TaxClassificationTranslationValue)session.getValueCache().get(pk);
272    
273        return _value == null ? null : new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY);
274    }
275    
276    public TaxClassificationTranslation getEntityFromPK(EntityPermission entityPermission, TaxClassificationTranslationPK pk)
277            throws PersistenceDatabaseException {
278        TaxClassificationTranslation _entity;
279        
280        // See if we already have the entity in the session cache
281        _entity = (TaxClassificationTranslation)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<TaxClassificationTranslationPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
324            throws PersistenceDatabaseException {
325        Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
352            throws PersistenceDatabaseException {
353        java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromQuery(PreparedStatement ps, final Object... params)
380            throws PersistenceDatabaseException {
381        TaxClassificationTranslationPK _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<TaxClassificationTranslation> 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<TaxClassificationTranslation> 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<TaxClassificationTranslation> 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<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
431            throws PersistenceDatabaseException {
432        java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation 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 TaxClassificationTranslation 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 TaxClassificationTranslation 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 TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
480            throws PersistenceDatabaseException {
481        TaxClassificationTranslation _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<TaxClassificationTranslation> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
510            throws PersistenceDatabaseException {
511        java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
525            throws PersistenceDatabaseException {
526        TaxClassificationTranslation _entity;
527        
528        try {
529            Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
530            TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid);
531            
532            // See if we already have the entity in the session cache
533            _entity = (TaxClassificationTranslation)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 txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID);
551                if(rs.wasNull())
552                    txclsfntr_txclsfn_taxclassificationid = null;
553                
554                Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID);
555                if(rs.wasNull())
556                    txclsfntr_lang_languageid = null;
557                
558                String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION);
559                if(rs.wasNull())
560                    txclsfntr_description = null;
561                
562                Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID);
563                if(rs.wasNull())
564                    txclsfntr_overviewmimetypeid = null;
565                
566                Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW);
567                if(rs.wasNull())
568                    txclsfntr_overview = null;
569                
570                Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME);
571                if(rs.wasNull())
572                    txclsfntr_fromtime = null;
573                
574                Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME);
575                if(rs.wasNull())
576                    txclsfntr_thrutime = null;
577                
578                TaxClassificationTranslationValue _value = new TaxClassificationTranslationValue(_pk, txclsfntr_txclsfn_taxclassificationid == null? null: new TaxClassificationPK(txclsfntr_txclsfn_taxclassificationid), txclsfntr_lang_languageid == null? null: new LanguagePK(txclsfntr_lang_languageid), txclsfntr_description, txclsfntr_overviewmimetypeid == null? null: new MimeTypePK(txclsfntr_overviewmimetypeid), txclsfntr_overview == null? null: txclsfntr_overview.getSubString(1L, (int)txclsfntr_overview.length()), txclsfntr_fromtime, txclsfntr_thrutime);
579                _entity = new TaxClassificationTranslation(_value, entityPermission);
580            }
581            
582            if(!foundInSessionCache) {
583                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
584                    session.putReadOnlyEntity(_pk, _entity);
585                    session.getValueCache().put(_entity.getTaxClassificationTranslationValue());
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 TaxClassificationTranslation create(TaxClassification taxClassification, Language language, String description, MimeType overviewMimeType, String overview, Long fromTime, Long thruTime)
598            throws PersistenceDatabaseException, PersistenceNotNullException {
599        return create(taxClassification == null ? null : taxClassification.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, overviewMimeType == null ? null : overviewMimeType.getPrimaryKey(), overview, fromTime, thruTime);
600    }
601    
602    private void bindForCreate(PreparedStatement _ps, TaxClassificationTranslationValue _value)
603            throws SQLException {
604        _ps.setLong(1, _value.getEntityId());
605        
606        TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK();
607        if(txclsfntr_txclsfn_taxclassificationid == null)
608            _ps.setNull(2, Types.BIGINT);
609        else
610            _ps.setLong(2, txclsfntr_txclsfn_taxclassificationid.getEntityId());
611            
612        LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK();
613        if(txclsfntr_lang_languageid == null)
614            _ps.setNull(3, Types.BIGINT);
615        else
616            _ps.setLong(3, txclsfntr_lang_languageid.getEntityId());
617            
618        String txclsfntr_description = _value.getDescription();
619        if(txclsfntr_description == null)
620            _ps.setNull(4, Types.VARCHAR);
621        else
622            _ps.setString(4, txclsfntr_description);
623            
624        MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK();
625        if(txclsfntr_overviewmimetypeid == null)
626            _ps.setNull(5, Types.BIGINT);
627        else
628            _ps.setLong(5, txclsfntr_overviewmimetypeid.getEntityId());
629            
630        String txclsfntr_overview = _value.getOverview();
631        if(txclsfntr_overview == null)
632            _ps.setNull(6, Types.CLOB);
633        else
634            _ps.setCharacterStream(6, new StringReader(txclsfntr_overview), txclsfntr_overview.length());
635            
636        Long txclsfntr_fromtime = _value.getFromTime();
637        if(txclsfntr_fromtime == null)
638            _ps.setNull(7, Types.BIGINT);
639        else
640            _ps.setLong(7, txclsfntr_fromtime);
641            
642        Long txclsfntr_thrutime = _value.getThruTime();
643        if(txclsfntr_thrutime == null)
644            _ps.setNull(8, Types.BIGINT);
645        else
646            _ps.setLong(8, txclsfntr_thrutime);
647            
648    }
649    
650    public TaxClassificationTranslation create(TaxClassificationPK taxClassificationPK, LanguagePK languagePK, String description, MimeTypePK overviewMimeTypePK, String overview, Long fromTime, Long thruTime)
651            throws PersistenceDatabaseException, PersistenceNotNullException {
652        TaxClassificationTranslationPK _pk = getNextPK();
653        TaxClassificationTranslationValue _value = new TaxClassificationTranslationValue(_pk, taxClassificationPK, 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        TaxClassificationTranslation _entity = new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY);
676        session.putReadOnlyEntity(_pk, _entity);
677        
678        return _entity;
679    }
680    
681    public void create(Collection<TaxClassificationTranslationValue> _values)
682            throws PersistenceDatabaseException, PersistenceNotNullException {
683        int _size = _values.size();
684        
685        if(_size > 0) {
686            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
687            List<TaxClassificationTranslationValue> _cacheValues = new ArrayList<>(_size);
688            
689            try {
690                for(TaxClassificationTranslationValue _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                TaxClassificationTranslation _cacheEntity = new TaxClassificationTranslation(_cacheValue, EntityPermission.READ_ONLY);
718                
719                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
720            });
721        }
722    }
723    
724    private boolean bindForStore(PreparedStatement _ps, TaxClassificationTranslationValue _value)
725            throws SQLException {
726        boolean _hasBeenModified = _value.hasBeenModified();
727        
728        if(_hasBeenModified) {
729            TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK();
730            if(txclsfntr_txclsfn_taxclassificationid == null)
731                _ps.setNull(1, Types.BIGINT);
732            else
733                _ps.setLong(1, txclsfntr_txclsfn_taxclassificationid.getEntityId());
734            
735            LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK();
736            if(txclsfntr_lang_languageid == null)
737                _ps.setNull(2, Types.BIGINT);
738            else
739                _ps.setLong(2, txclsfntr_lang_languageid.getEntityId());
740            
741            String txclsfntr_description = _value.getDescription();
742            if(txclsfntr_description == null)
743                _ps.setNull(3, Types.VARCHAR);
744            else
745                _ps.setString(3, txclsfntr_description);
746            
747            MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK();
748            if(txclsfntr_overviewmimetypeid == null)
749                _ps.setNull(4, Types.BIGINT);
750            else
751                _ps.setLong(4, txclsfntr_overviewmimetypeid.getEntityId());
752            
753            String txclsfntr_overview = _value.getOverview();
754            if(txclsfntr_overview == null)
755                _ps.setNull(5, Types.CLOB);
756            else
757                _ps.setCharacterStream(5, new StringReader(txclsfntr_overview), txclsfntr_overview.length());
758            
759            Long txclsfntr_fromtime = _value.getFromTime();
760            if(txclsfntr_fromtime == null)
761                _ps.setNull(6, Types.BIGINT);
762            else
763                _ps.setLong(6, txclsfntr_fromtime);
764            
765            Long txclsfntr_thrutime = _value.getThruTime();
766            if(txclsfntr_thrutime == null)
767                _ps.setNull(7, Types.BIGINT);
768            else
769                _ps.setLong(7, txclsfntr_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(TaxClassificationTranslation entity)
781            throws PersistenceDatabaseException {
782        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
783        
784        try {
785            TaxClassificationTranslationValue _value = entity.getTaxClassificationTranslationValue();
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<TaxClassificationTranslation> 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(TaxClassificationTranslation entity : entities) {
814                    if(bindForStore(_ps, entity.getTaxClassificationTranslationValue())) {
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.getTaxClassificationTranslationValue());
837                    });
838                }
839            } catch (SQLException se) {
840                throw new PersistenceDatabaseException(se);
841            }
842        }
843    }
844    
845    @Override
846    public void remove(TaxClassificationTranslation entity)
847            throws PersistenceDatabaseException {
848        remove(entity.getPrimaryKey());
849    }
850    
851    @Override
852    public void remove(TaxClassificationTranslationPK 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<TaxClassificationTranslationPK> 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(TaxClassificationTranslationPK 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(TaxClassificationTranslationPK 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}