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