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