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