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