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