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