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