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