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