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