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 private static String PK_COLUMN = "txclsfntr_taxclassificationtranslationid";
082    final private static String ALL_COLUMNS = "txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime";
083    final public static String TABLE_NAME = "taxclassificationtranslations";
084    
085    final public static String TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID = "txclsfntr_taxclassificationtranslationid";
086    final public static String TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID = "txclsfntr_txclsfn_taxclassificationid";
087    final public static String TXCLSFNTR_LANG_LANGUAGEID = "txclsfntr_lang_languageid";
088    final public static String TXCLSFNTR_DESCRIPTION = "txclsfntr_description";
089    final public static String TXCLSFNTR_OVERVIEWMIMETYPEID = "txclsfntr_overviewmimetypeid";
090    final public static String TXCLSFNTR_OVERVIEW = "txclsfntr_overview";
091    final public static String TXCLSFNTR_FROMTIME = "txclsfntr_fromtime";
092    final public static String TXCLSFNTR_THRUTIME = "txclsfntr_thrutime";
093    
094    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME, TaxClassificationTranslationConstants.ENTITY_TYPE_NAME);
095    
096    /** Creates a new instance of TaxClassificationTranslationFactory */
097    protected TaxClassificationTranslationFactory() {
098        super();
099    }
100    
101    public static TaxClassificationTranslationFactory getInstance() {
102        return CDI.current().select(TaxClassificationTranslationFactory.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 TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME;
123    }
124    
125    @Override
126    public String getEntityTypeName() {
127        return TaxClassificationTranslationConstants.ENTITY_TYPE_NAME;
128    }
129    
130    public PreparedStatement prepareStatement(String query) {
131        return session.prepareStatement(TaxClassificationTranslationFactory.class, query);
132    }
133    
134    public TaxClassificationTranslationPK getNextPK() {
135        return new TaxClassificationTranslationPK(entityIdGenerator.getNextEntityId());
136    }
137    
138    public Set<TaxClassificationTranslationPK> getPKsFromResultSetAsSet(ResultSet rs)
139            throws PersistenceDatabaseException {
140        Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromResultSetAsList(ResultSet rs)
154            throws PersistenceDatabaseException {
155        java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromResultSet(ResultSet rs)
169            throws PersistenceDatabaseException {
170        TaxClassificationTranslationPK _result;
171        
172        try {
173            long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
174            Long _entityId = rs.wasNull() ? null : txclsfntr_taxclassificationtranslationid;
175            
176            _result = new TaxClassificationTranslationPK(_entityId);
177        } catch (SQLException se) {
178            throw new PersistenceDatabaseException(se);
179        }
180        
181        return _result;
182    }
183    
184    public java.util.List<TaxClassificationTranslationValue> getValuesFromPKs(Collection<TaxClassificationTranslationPK> pks)
185            throws PersistenceDatabaseException {
186        java.util.List<TaxClassificationTranslationValue> _values = new ArrayList<>(pks.size());
187        
188        for(TaxClassificationTranslationPK _pk: pks) {
189            _values.add(getValueFromPK(_pk));
190        }
191        
192        return _values;
193    }
194    
195    public TaxClassificationTranslationValue getValueFromPK(TaxClassificationTranslationPK pk)
196            throws PersistenceDatabaseException {
197        TaxClassificationTranslationValue _value;
198        
199        // See if we already have the entity in the session cache
200        TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(pk);
201        if(_entity == null)
202            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getTaxClassificationTranslationValue();
203        else
204            _value = _entity.getTaxClassificationTranslationValue();
205        
206        return _value;
207    }
208    
209    public java.util.List<TaxClassificationTranslationValue> getValuesFromResultSet(ResultSet rs)
210            throws PersistenceDatabaseException {
211        java.util.List<TaxClassificationTranslationValue> _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 TaxClassificationTranslationValue getValueFromResultSet(ResultSet rs)
225            throws PersistenceDatabaseException {
226        TaxClassificationTranslationValue _value;
227        
228        try {
229            Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
230            TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid);
231            
232            // See if we already have the entity in the session cache
233            TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(_pk);
234            
235            if(_entity == null) {
236                Long txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID);
237                if(rs.wasNull())
238                    txclsfntr_txclsfn_taxclassificationid = null;
239                
240                Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID);
241                if(rs.wasNull())
242                    txclsfntr_lang_languageid = null;
243                
244                String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION);
245                if(rs.wasNull())
246                    txclsfntr_description = null;
247                
248                Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID);
249                if(rs.wasNull())
250                    txclsfntr_overviewmimetypeid = null;
251                
252                Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW);
253                if(rs.wasNull())
254                    txclsfntr_overview = null;
255                
256                Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME);
257                if(rs.wasNull())
258                    txclsfntr_fromtime = null;
259                
260                Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME);
261                if(rs.wasNull())
262                    txclsfntr_thrutime = null;
263                
264                _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);
265            } else
266                _value = _entity.getTaxClassificationTranslationValue();
267        } catch (SQLException se) {
268            throw new PersistenceDatabaseException(se);
269        }
270        
271        return _value;
272    }
273    
274    public java.util.List<TaxClassificationTranslation> getEntitiesFromPKs(EntityPermission entityPermission, Collection<TaxClassificationTranslationPK> pks)
275            throws PersistenceDatabaseException {
276        java.util.List<TaxClassificationTranslation> _entities = new ArrayList<>(pks.size());
277        
278        for(TaxClassificationTranslationPK _pk: pks) {
279            _entities.add(getEntityFromPK(entityPermission, _pk));
280        }
281        
282        return _entities;
283    }
284    
285    public TaxClassificationTranslation getEntityFromValue(EntityPermission entityPermission, TaxClassificationTranslationValue value) {
286        return getEntityFromPK(entityPermission, value.getPrimaryKey());
287    }
288    
289    public TaxClassificationTranslation getEntityFromCache(TaxClassificationTranslationPK pk) {
290        TaxClassificationTranslationValue _value = (TaxClassificationTranslationValue)session.getValueCache().get(pk);
291    
292        return _value == null ? null : new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY);
293    }
294    
295    public TaxClassificationTranslation getEntityFromPK(EntityPermission entityPermission, TaxClassificationTranslationPK pk)
296            throws PersistenceDatabaseException {
297        TaxClassificationTranslation _entity;
298        
299        // See if we already have the entity in the session cache
300        _entity = (TaxClassificationTranslation)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<TaxClassificationTranslationPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
343            throws PersistenceDatabaseException {
344        Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
371            throws PersistenceDatabaseException {
372        java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromQuery(PreparedStatement ps, final Object... params)
399            throws PersistenceDatabaseException {
400        TaxClassificationTranslationPK _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<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
429            throws PersistenceDatabaseException {
430        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission));
431        
432        return getEntitiesFromQuery(entityPermission, ps, params);
433    }
434    
435    public java.util.List<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
436            throws PersistenceDatabaseException {
437        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission));
438        
439        return getEntitiesFromQuery(entityPermission, ps);
440    }
441    
442    public java.util.List<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
443            throws PersistenceDatabaseException {
444        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, query.getSQL());
445        
446        return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray());
447    }
448    
449    public java.util.List<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
450            throws PersistenceDatabaseException {
451        java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
478            throws PersistenceDatabaseException {
479        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission));
480        
481        return getEntityFromQuery(entityPermission, ps, params);
482    }
483    
484    public TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
485            throws PersistenceDatabaseException {
486        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission));
487        
488        return getEntityFromQuery(entityPermission, ps);
489    }
490    
491    public TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
492            throws PersistenceDatabaseException {
493        PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, query.getSQL());
494        
495        return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray());
496    }
497    
498    public TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
499            throws PersistenceDatabaseException {
500        TaxClassificationTranslation _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<TaxClassificationTranslation> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
529            throws PersistenceDatabaseException {
530        java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
544            throws PersistenceDatabaseException {
545        TaxClassificationTranslation _entity;
546        
547        try {
548            Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID);
549            TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid);
550            
551            // See if we already have the entity in the session cache
552            _entity = (TaxClassificationTranslation)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 txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID);
570                if(rs.wasNull())
571                    txclsfntr_txclsfn_taxclassificationid = null;
572                
573                Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID);
574                if(rs.wasNull())
575                    txclsfntr_lang_languageid = null;
576                
577                String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION);
578                if(rs.wasNull())
579                    txclsfntr_description = null;
580                
581                Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID);
582                if(rs.wasNull())
583                    txclsfntr_overviewmimetypeid = null;
584                
585                Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW);
586                if(rs.wasNull())
587                    txclsfntr_overview = null;
588                
589                Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME);
590                if(rs.wasNull())
591                    txclsfntr_fromtime = null;
592                
593                Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME);
594                if(rs.wasNull())
595                    txclsfntr_thrutime = null;
596                
597                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);
598                _entity = new TaxClassificationTranslation(_value, entityPermission);
599            }
600            
601            if(!foundInSessionCache) {
602                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
603                    session.putReadOnlyEntity(_pk, _entity);
604                    session.getValueCache().put(_entity.getTaxClassificationTranslationValue());
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 TaxClassificationTranslation create(TaxClassification taxClassification, Language language, String description, MimeType overviewMimeType, String overview, Long fromTime, Long thruTime)
617            throws PersistenceDatabaseException, PersistenceNotNullException {
618        return create(taxClassification == null ? null : taxClassification.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, overviewMimeType == null ? null : overviewMimeType.getPrimaryKey(), overview, fromTime, thruTime);
619    }
620    
621    private void bindForCreate(PreparedStatement _ps, TaxClassificationTranslationValue _value)
622            throws SQLException {
623        _ps.setLong(1, _value.getEntityId());
624        
625        TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK();
626        if(txclsfntr_txclsfn_taxclassificationid == null)
627            _ps.setNull(2, Types.BIGINT);
628        else
629            _ps.setLong(2, txclsfntr_txclsfn_taxclassificationid.getEntityId());
630            
631        LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK();
632        if(txclsfntr_lang_languageid == null)
633            _ps.setNull(3, Types.BIGINT);
634        else
635            _ps.setLong(3, txclsfntr_lang_languageid.getEntityId());
636            
637        String txclsfntr_description = _value.getDescription();
638        if(txclsfntr_description == null)
639            _ps.setNull(4, Types.VARCHAR);
640        else
641            _ps.setString(4, txclsfntr_description);
642            
643        MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK();
644        if(txclsfntr_overviewmimetypeid == null)
645            _ps.setNull(5, Types.BIGINT);
646        else
647            _ps.setLong(5, txclsfntr_overviewmimetypeid.getEntityId());
648            
649        String txclsfntr_overview = _value.getOverview();
650        if(txclsfntr_overview == null)
651            _ps.setNull(6, Types.CLOB);
652        else
653            _ps.setCharacterStream(6, new StringReader(txclsfntr_overview), txclsfntr_overview.length());
654            
655        Long txclsfntr_fromtime = _value.getFromTime();
656        if(txclsfntr_fromtime == null)
657            _ps.setNull(7, Types.BIGINT);
658        else
659            _ps.setLong(7, txclsfntr_fromtime);
660            
661        Long txclsfntr_thrutime = _value.getThruTime();
662        if(txclsfntr_thrutime == null)
663            _ps.setNull(8, Types.BIGINT);
664        else
665            _ps.setLong(8, txclsfntr_thrutime);
666            
667    }
668    
669    public TaxClassificationTranslation create(TaxClassificationPK taxClassificationPK, LanguagePK languagePK, String description, MimeTypePK overviewMimeTypePK, String overview, Long fromTime, Long thruTime)
670            throws PersistenceDatabaseException, PersistenceNotNullException {
671        TaxClassificationTranslationPK _pk = getNextPK();
672        TaxClassificationTranslationValue _value = new TaxClassificationTranslationValue(_pk, taxClassificationPK, 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        TaxClassificationTranslation _entity = new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY);
695        session.putReadOnlyEntity(_pk, _entity);
696        
697        return _entity;
698    }
699    
700    public void create(Collection<TaxClassificationTranslationValue> _values)
701            throws PersistenceDatabaseException, PersistenceNotNullException {
702        int _size = _values.size();
703        
704        if(_size > 0) {
705            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
706            List<TaxClassificationTranslationValue> _cacheValues = new ArrayList<>(_size);
707            
708            try {
709                for(TaxClassificationTranslationValue _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                TaxClassificationTranslation _cacheEntity = new TaxClassificationTranslation(_cacheValue, EntityPermission.READ_ONLY);
737                
738                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
739            });
740        }
741    }
742    
743    private boolean bindForStore(PreparedStatement _ps, TaxClassificationTranslationValue _value)
744            throws SQLException {
745        boolean _hasBeenModified = _value.hasBeenModified();
746        
747        if(_hasBeenModified) {
748            TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK();
749            if(txclsfntr_txclsfn_taxclassificationid == null)
750                _ps.setNull(1, Types.BIGINT);
751            else
752                _ps.setLong(1, txclsfntr_txclsfn_taxclassificationid.getEntityId());
753            
754            LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK();
755            if(txclsfntr_lang_languageid == null)
756                _ps.setNull(2, Types.BIGINT);
757            else
758                _ps.setLong(2, txclsfntr_lang_languageid.getEntityId());
759            
760            String txclsfntr_description = _value.getDescription();
761            if(txclsfntr_description == null)
762                _ps.setNull(3, Types.VARCHAR);
763            else
764                _ps.setString(3, txclsfntr_description);
765            
766            MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK();
767            if(txclsfntr_overviewmimetypeid == null)
768                _ps.setNull(4, Types.BIGINT);
769            else
770                _ps.setLong(4, txclsfntr_overviewmimetypeid.getEntityId());
771            
772            String txclsfntr_overview = _value.getOverview();
773            if(txclsfntr_overview == null)
774                _ps.setNull(5, Types.CLOB);
775            else
776                _ps.setCharacterStream(5, new StringReader(txclsfntr_overview), txclsfntr_overview.length());
777            
778            Long txclsfntr_fromtime = _value.getFromTime();
779            if(txclsfntr_fromtime == null)
780                _ps.setNull(6, Types.BIGINT);
781            else
782                _ps.setLong(6, txclsfntr_fromtime);
783            
784            Long txclsfntr_thrutime = _value.getThruTime();
785            if(txclsfntr_thrutime == null)
786                _ps.setNull(7, Types.BIGINT);
787            else
788                _ps.setLong(7, txclsfntr_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(TaxClassificationTranslation entity)
800            throws PersistenceDatabaseException {
801        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
802        
803        try {
804            TaxClassificationTranslationValue _value = entity.getTaxClassificationTranslationValue();
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<TaxClassificationTranslation> 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(TaxClassificationTranslation entity : entities) {
833                    if(bindForStore(_ps, entity.getTaxClassificationTranslationValue())) {
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.getTaxClassificationTranslationValue());
856                    });
857                }
858            } catch (SQLException se) {
859                throw new PersistenceDatabaseException(se);
860            }
861        }
862    }
863    
864    @Override
865    public void remove(TaxClassificationTranslation entity)
866            throws PersistenceDatabaseException {
867        remove(entity.getPrimaryKey());
868    }
869    
870    @Override
871    public void remove(TaxClassificationTranslationPK 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<TaxClassificationTranslationPK> 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(TaxClassificationTranslationPK 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(TaxClassificationTranslationPK 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}