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