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