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