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