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