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