001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 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 * CampaignContentDetailFactory.java
021 */
022
023package com.echothree.model.data.campaign.server.factory;
024
025import com.echothree.model.data.campaign.common.pk.CampaignContentPK;
026
027import com.echothree.model.data.campaign.server.entity.CampaignContent;
028
029import com.echothree.model.data.campaign.common.CampaignContentDetailConstants;
030import com.echothree.model.data.campaign.common.pk.CampaignContentDetailPK;
031import com.echothree.model.data.campaign.server.value.CampaignContentDetailValue;
032import com.echothree.model.data.campaign.server.entity.CampaignContentDetail;
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 com.echothree.util.server.persistence.ThreadSession;
042import java.sql.Clob;
043import java.sql.PreparedStatement;
044import java.sql.ResultSet;
045import java.sql.SQLException;
046import java.sql.Types;
047import java.io.ByteArrayInputStream;
048import java.io.StringReader;
049import java.util.ArrayList;
050import java.util.Collection;
051import java.util.HashSet;
052import java.util.List;
053import java.util.Map;
054import java.util.Set;
055import org.apache.commons.logging.Log;
056import org.apache.commons.logging.LogFactory;
057
058public class CampaignContentDetailFactory
059        implements BaseFactory<CampaignContentDetailPK, CampaignContentDetail> {
060    
061    //final private static Log log = LogFactory.getLog(CampaignContentDetailFactory.class);
062    
063    final private static String SQL_SELECT_READ_ONLY = "SELECT cmpgncntdt_campaigncontentdetailid, cmpgncntdt_cmpgncnt_campaigncontentid, cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value, cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime FROM campaigncontentdetails WHERE cmpgncntdt_campaigncontentdetailid = ?";
064    final private static String SQL_SELECT_READ_WRITE = "SELECT cmpgncntdt_campaigncontentdetailid, cmpgncntdt_cmpgncnt_campaigncontentid, cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value, cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime FROM campaigncontentdetails WHERE cmpgncntdt_campaigncontentdetailid = ? FOR UPDATE";
065    final private static String SQL_INSERT = "INSERT INTO campaigncontentdetails (cmpgncntdt_campaigncontentdetailid, cmpgncntdt_cmpgncnt_campaigncontentid, cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value, cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
066    final private static String SQL_UPDATE = "UPDATE campaigncontentdetails SET cmpgncntdt_cmpgncnt_campaigncontentid = ?, cmpgncntdt_campaigncontentname = ?, cmpgncntdt_valuesha1hash = ?, cmpgncntdt_value = ?, cmpgncntdt_isdefault = ?, cmpgncntdt_sortorder = ?, cmpgncntdt_fromtime = ?, cmpgncntdt_thrutime = ? WHERE cmpgncntdt_campaigncontentdetailid = ?";
067    final private static String SQL_DELETE = "DELETE FROM campaigncontentdetails WHERE cmpgncntdt_campaigncontentdetailid = ?";
068    final private static String SQL_VALID = "SELECT COUNT(*) FROM campaigncontentdetails WHERE cmpgncntdt_campaigncontentdetailid = ?";
069    
070    final private static String PK_COLUMN = "cmpgncntdt_campaigncontentdetailid";
071    final private static String ALL_COLUMNS = "cmpgncntdt_campaigncontentdetailid, cmpgncntdt_cmpgncnt_campaigncontentid, cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value, cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime";
072    final public static String TABLE_NAME = "campaigncontentdetails";
073    
074    final public static String CMPGNCNTDT_CAMPAIGNCONTENTDETAILID = "cmpgncntdt_campaigncontentdetailid";
075    final public static String CMPGNCNTDT_CMPGNCNT_CAMPAIGNCONTENTID = "cmpgncntdt_cmpgncnt_campaigncontentid";
076    final public static String CMPGNCNTDT_CAMPAIGNCONTENTNAME = "cmpgncntdt_campaigncontentname";
077    final public static String CMPGNCNTDT_VALUESHA1HASH = "cmpgncntdt_valuesha1hash";
078    final public static String CMPGNCNTDT_VALUE = "cmpgncntdt_value";
079    final public static String CMPGNCNTDT_ISDEFAULT = "cmpgncntdt_isdefault";
080    final public static String CMPGNCNTDT_SORTORDER = "cmpgncntdt_sortorder";
081    final public static String CMPGNCNTDT_FROMTIME = "cmpgncntdt_fromtime";
082    final public static String CMPGNCNTDT_THRUTIME = "cmpgncntdt_thrutime";
083    
084    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CampaignContentDetailConstants.COMPONENT_VENDOR_NAME, CampaignContentDetailConstants.ENTITY_TYPE_NAME);
085    
086    /** Creates a new instance of CampaignContentDetailFactory */
087    private CampaignContentDetailFactory() {
088        super();
089    }
090    
091    private static class CampaignContentDetailFactoryHolder {
092        static CampaignContentDetailFactory instance = new CampaignContentDetailFactory();
093    }
094    
095    public static CampaignContentDetailFactory getInstance() {
096        return CampaignContentDetailFactoryHolder.instance;
097    }
098    
099    @Override
100    public String getPKColumn() {
101        return PK_COLUMN;
102    }
103    
104    @Override
105    public String getAllColumns() {
106        return ALL_COLUMNS;
107    }
108    
109    @Override
110    public String getTableName() {
111        return TABLE_NAME;
112    }
113    
114    @Override
115    public String getComponentVendorName() {
116        return CampaignContentDetailConstants.COMPONENT_VENDOR_NAME;
117    }
118    
119    @Override
120    public String getEntityTypeName() {
121        return CampaignContentDetailConstants.ENTITY_TYPE_NAME;
122    }
123    
124    public PreparedStatement prepareStatement(String query) {
125        return ThreadSession.currentSession().prepareStatement(CampaignContentDetailFactory.class, query);
126    }
127    
128    public CampaignContentDetailPK getNextPK() {
129        return new CampaignContentDetailPK(entityIdGenerator.getNextEntityId());
130    }
131    
132    public Set<CampaignContentDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
133            throws PersistenceDatabaseException {
134        Set<CampaignContentDetailPK> _result = new HashSet<>();
135        
136        try {
137            while(rs.next()) {
138                _result.add(getPKFromResultSet(rs));
139            }
140        } catch (SQLException se) {
141            throw new PersistenceDatabaseException(se);
142        }
143        
144        return _result;
145    }
146    
147    public java.util.List<CampaignContentDetailPK> getPKsFromResultSetAsList(ResultSet rs)
148            throws PersistenceDatabaseException {
149        java.util.List<CampaignContentDetailPK> _result = new ArrayList<>();
150        
151        try {
152            while(rs.next()) {
153                _result.add(getPKFromResultSet(rs));
154            }
155        } catch (SQLException se) {
156            throw new PersistenceDatabaseException(se);
157        }
158        
159        return _result;
160    }
161    
162    public CampaignContentDetailPK getPKFromResultSet(ResultSet rs)
163            throws PersistenceDatabaseException {
164        CampaignContentDetailPK _result;
165        
166        try {
167            long cmpgncntdt_campaigncontentdetailid = rs.getLong(CMPGNCNTDT_CAMPAIGNCONTENTDETAILID);
168            Long _entityId = rs.wasNull() ? null : cmpgncntdt_campaigncontentdetailid;
169            
170            _result = new CampaignContentDetailPK(_entityId);
171        } catch (SQLException se) {
172            throw new PersistenceDatabaseException(se);
173        }
174        
175        return _result;
176    }
177    
178    public java.util.List<CampaignContentDetailValue> getValuesFromPKs(Session session, Collection<CampaignContentDetailPK> pks)
179            throws PersistenceDatabaseException {
180        java.util.List<CampaignContentDetailValue> _values = new ArrayList<>(pks.size());
181        
182        for(CampaignContentDetailPK _pk: pks) {
183            _values.add(getValueFromPK(session, _pk));
184        }
185        
186        return _values;
187    }
188    
189    public CampaignContentDetailValue getValueFromPK(Session session, CampaignContentDetailPK pk)
190            throws PersistenceDatabaseException {
191        CampaignContentDetailValue _value;
192        
193        // See if we already have the entity in the session cache
194        CampaignContentDetail _entity = (CampaignContentDetail)session.getEntity(pk);
195        if(_entity == null)
196            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getCampaignContentDetailValue();
197        else
198            _value = _entity.getCampaignContentDetailValue();
199        
200        return _value;
201    }
202    
203    public java.util.List<CampaignContentDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
204            throws PersistenceDatabaseException {
205        java.util.List<CampaignContentDetailValue> _result = new ArrayList<>();
206        
207        try {
208            while(rs.next()) {
209                _result.add(getValueFromResultSet(session, rs));
210            }
211        } catch (SQLException se) {
212            throw new PersistenceDatabaseException(se);
213        }
214        
215        return _result;
216    }
217    
218    public CampaignContentDetailValue getValueFromResultSet(Session session, ResultSet rs)
219            throws PersistenceDatabaseException {
220        CampaignContentDetailValue _value;
221        
222        try {
223            Long cmpgncntdt_campaigncontentdetailid = rs.getLong(CMPGNCNTDT_CAMPAIGNCONTENTDETAILID);
224            CampaignContentDetailPK _pk = new CampaignContentDetailPK(cmpgncntdt_campaigncontentdetailid);
225            
226            // See if we already have the entity in the session cache
227            CampaignContentDetail _entity = (CampaignContentDetail)session.getEntity(_pk);
228            
229            if(_entity == null) {
230                Long cmpgncntdt_cmpgncnt_campaigncontentid = rs.getLong(CMPGNCNTDT_CMPGNCNT_CAMPAIGNCONTENTID);
231                if(rs.wasNull())
232                    cmpgncntdt_cmpgncnt_campaigncontentid = null;
233                
234                String cmpgncntdt_campaigncontentname = rs.getString(CMPGNCNTDT_CAMPAIGNCONTENTNAME);
235                if(rs.wasNull())
236                    cmpgncntdt_campaigncontentname = null;
237                
238                String cmpgncntdt_valuesha1hash = rs.getString(CMPGNCNTDT_VALUESHA1HASH);
239                if(rs.wasNull())
240                    cmpgncntdt_valuesha1hash = null;
241                
242                Clob cmpgncntdt_value = rs.getClob(CMPGNCNTDT_VALUE);
243                if(rs.wasNull())
244                    cmpgncntdt_value = null;
245                
246                Boolean cmpgncntdt_isdefault = rs.getInt(CMPGNCNTDT_ISDEFAULT) == 1;
247                if(rs.wasNull())
248                    cmpgncntdt_isdefault = null;
249                
250                Integer cmpgncntdt_sortorder = rs.getInt(CMPGNCNTDT_SORTORDER);
251                if(rs.wasNull())
252                    cmpgncntdt_sortorder = null;
253                
254                Long cmpgncntdt_fromtime = rs.getLong(CMPGNCNTDT_FROMTIME);
255                if(rs.wasNull())
256                    cmpgncntdt_fromtime = null;
257                
258                Long cmpgncntdt_thrutime = rs.getLong(CMPGNCNTDT_THRUTIME);
259                if(rs.wasNull())
260                    cmpgncntdt_thrutime = null;
261                
262                _value = new CampaignContentDetailValue(_pk, new CampaignContentPK(cmpgncntdt_cmpgncnt_campaigncontentid), cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value == null? null: cmpgncntdt_value.getSubString(1L, (int)cmpgncntdt_value.length()), cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime);
263            } else
264                _value = _entity.getCampaignContentDetailValue();
265        } catch (SQLException se) {
266            throw new PersistenceDatabaseException(se);
267        }
268        
269        return _value;
270    }
271    
272    public java.util.List<CampaignContentDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CampaignContentDetailPK> pks)
273            throws PersistenceDatabaseException {
274        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
275    }
276    
277    public java.util.List<CampaignContentDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<CampaignContentDetailPK> pks)
278            throws PersistenceDatabaseException {
279        java.util.List<CampaignContentDetail> _entities = new ArrayList<>(pks.size());
280        
281        for(CampaignContentDetailPK _pk: pks) {
282            _entities.add(getEntityFromPK(session, entityPermission, _pk));
283        }
284        
285        return _entities;
286    }
287    
288    public CampaignContentDetail getEntityFromValue(EntityPermission entityPermission, CampaignContentDetailValue value) {
289        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
290    }
291    
292    public CampaignContentDetail getEntityFromValue(Session session, EntityPermission entityPermission, CampaignContentDetailValue value) {
293        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
294    }
295    
296    public CampaignContentDetail getEntityFromPK(EntityPermission entityPermission, CampaignContentDetailPK pk)
297            throws PersistenceDatabaseException {
298        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
299    }
300    
301    public CampaignContentDetail getEntityFromCache(Session session, CampaignContentDetailPK pk) {
302        CampaignContentDetailValue _value = (CampaignContentDetailValue)session.getValueCache().get(pk);
303    
304        return _value == null ? null : new CampaignContentDetail(_value, EntityPermission.READ_ONLY);
305    }
306    
307    public CampaignContentDetail getEntityFromPK(Session session, EntityPermission entityPermission, CampaignContentDetailPK pk)
308            throws PersistenceDatabaseException {
309        CampaignContentDetail _entity;
310        
311        // See if we already have the entity in the session cache
312        _entity = (CampaignContentDetail)session.getEntity(pk);
313        if(_entity != null) {
314            // If the requested permission is READ_WRITE, and the cached permission is
315            // READ_ONLY, then pretend that the cached object wasn't found, and create
316            // a new entity that is READ_WRITE.
317            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
318                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
319                    _entity = null;
320            }
321        }
322        
323        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
324            _entity = getEntityFromCache(session, pk);
325        }
326        
327        if(_entity == null) {
328            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
329            long _entityId = pk.getEntityId();
330            ResultSet _rs = null;
331            
332            try {
333                _ps.setLong(1, _entityId);
334                _rs = _ps.executeQuery();
335                if(_rs.next()) {
336                    _entity = getEntityFromResultSet(session, entityPermission, _rs);
337                }
338            } catch (SQLException se) {
339                throw new PersistenceDatabaseException(se);
340            } finally {
341                if(_rs != null) {
342                    try {
343                        _rs.close();
344                    } catch (SQLException se) {
345                        // do nothing
346                    }
347                }
348            }
349        }
350        
351        return _entity;
352    }
353    
354    public Set<CampaignContentDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
355            throws PersistenceDatabaseException {
356        Set<CampaignContentDetailPK> _pks;
357        ResultSet _rs = null;
358        
359        try {
360            if(params.length != 0) {
361                Session.setQueryParams(ps, params);
362            }
363            
364            _rs = ps.executeQuery();
365            _pks = getPKsFromResultSetAsSet(_rs);
366            _rs.close();
367        } catch (SQLException se) {
368            throw new PersistenceDatabaseException(se);
369        } finally {
370            if(_rs != null) {
371                try {
372                    _rs.close();
373                } catch (SQLException se) {
374                    // do nothing
375                }
376            }
377        }
378        
379        return _pks;
380    }
381    
382    public java.util.List<CampaignContentDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
383            throws PersistenceDatabaseException {
384        java.util.List<CampaignContentDetailPK> _pks;
385        ResultSet _rs = null;
386        
387        try {
388            if(params.length != 0) {
389                Session.setQueryParams(ps, params);
390            }
391            
392            _rs = ps.executeQuery();
393            _pks = getPKsFromResultSetAsList(_rs);
394            _rs.close();
395        } catch (SQLException se) {
396            throw new PersistenceDatabaseException(se);
397        } finally {
398            if(_rs != null) {
399                try {
400                    _rs.close();
401                } catch (SQLException se) {
402                    // do nothing
403                }
404            }
405        }
406        
407        return _pks;
408    }
409    
410    public CampaignContentDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
411            throws PersistenceDatabaseException {
412        CampaignContentDetailPK _pk = null;
413        ResultSet _rs = null;
414        
415        try {
416            if(params.length != 0) {
417                Session.setQueryParams(ps, params);
418            }
419            
420            _rs = ps.executeQuery();
421            if(_rs.next()) {
422                _pk = getPKFromResultSet(_rs);
423            }
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 _pk;
438    }
439    
440    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
441            throws PersistenceDatabaseException {
442        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
443        
444        return getEntitiesFromQuery(session, entityPermission, ps, params);
445    }
446    
447    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
448            throws PersistenceDatabaseException {
449        Session session = ThreadSession.currentSession();
450        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
451        
452        return getEntitiesFromQuery(session, entityPermission, ps, params);
453    }
454    
455    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
456            throws PersistenceDatabaseException {
457        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
458        
459        return getEntitiesFromQuery(session, entityPermission, ps);
460    }
461    
462    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
463            throws PersistenceDatabaseException {
464        Session session = ThreadSession.currentSession();
465        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
466        
467        return getEntitiesFromQuery(session, entityPermission, ps);
468    }
469    
470    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
471            throws PersistenceDatabaseException {
472        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
473    }
474    
475    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
476            throws PersistenceDatabaseException {
477        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
478    }
479    
480    public java.util.List<CampaignContentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
481            throws PersistenceDatabaseException {
482        java.util.List<CampaignContentDetail> _entities;
483        ResultSet _rs = null;
484        
485        try {
486            if(params.length != 0) {
487                Session.setQueryParams(ps, params);
488            }
489            
490            _rs = ps.executeQuery();
491            _entities = getEntitiesFromResultSet(session, entityPermission, _rs);
492            _rs.close();
493        } catch (SQLException se) {
494            throw new PersistenceDatabaseException(se);
495        } finally {
496            if(_rs != null) {
497                try {
498                    _rs.close();
499                } catch (SQLException se) {
500                    // do nothing
501                }
502            }
503        }
504        
505        return _entities;
506    }
507    
508    public CampaignContentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
509            throws PersistenceDatabaseException {
510        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
511        
512        return getEntityFromQuery(session, entityPermission, ps, params);
513    }
514    
515    public CampaignContentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
516            throws PersistenceDatabaseException {
517        Session session = ThreadSession.currentSession();
518        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
519        
520        return getEntityFromQuery(session, entityPermission, ps, params);
521    }
522    
523    public CampaignContentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
524            throws PersistenceDatabaseException {
525        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
526        
527        return getEntityFromQuery(session, entityPermission, ps);
528    }
529    
530    public CampaignContentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
531            throws PersistenceDatabaseException {
532        Session session = ThreadSession.currentSession();
533        PreparedStatement ps = session.prepareStatement(CampaignContentDetailFactory.class, queryMap.get(entityPermission));
534        
535        return getEntityFromQuery(session, entityPermission, ps);
536    }
537    
538    public CampaignContentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
539            throws PersistenceDatabaseException {
540        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
541    }
542    
543    public CampaignContentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
544            throws PersistenceDatabaseException {
545        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
546    }
547    
548    public CampaignContentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
549            throws PersistenceDatabaseException {
550        CampaignContentDetail _entity = null;
551        ResultSet _rs = null;
552        
553        try {
554            if(params.length != 0) {
555                Session.setQueryParams(ps, params);
556            }
557            
558            _rs = ps.executeQuery();
559            if(_rs.next()) {
560                _entity = getEntityFromResultSet(session, entityPermission, _rs);
561            }
562            _rs.close();
563        } catch (SQLException se) {
564            throw new PersistenceDatabaseException(se);
565        } finally {
566            if(_rs != null) {
567                try {
568                    _rs.close();
569                } catch (SQLException se) {
570                    // do nothing
571                }
572            }
573        }
574        
575        return _entity;
576    }
577    
578    public java.util.List<CampaignContentDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
579            throws PersistenceDatabaseException {
580        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
581    }
582    
583    public java.util.List<CampaignContentDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
584            throws PersistenceDatabaseException {
585        java.util.List<CampaignContentDetail> _result = new ArrayList<>();
586        
587        try {
588            while(rs.next()) {
589                _result.add(getEntityFromResultSet(session, entityPermission, rs));
590            }
591        } catch (SQLException se) {
592            throw new PersistenceDatabaseException(se);
593        }
594        
595        return _result;
596    }
597    
598    public CampaignContentDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
599            throws PersistenceDatabaseException {
600        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
601    }
602    
603    public CampaignContentDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
604            throws PersistenceDatabaseException {
605        CampaignContentDetail _entity;
606        
607        try {
608            Long cmpgncntdt_campaigncontentdetailid = rs.getLong(CMPGNCNTDT_CAMPAIGNCONTENTDETAILID);
609            CampaignContentDetailPK _pk = new CampaignContentDetailPK(cmpgncntdt_campaigncontentdetailid);
610            
611            // See if we already have the entity in the session cache
612            _entity = (CampaignContentDetail)session.getEntity(_pk);
613            if(_entity != null) {
614                // If the requested permission is READ_WRITE, and the cached permission is
615                // READ_ONLY, then pretend that the cached object wasn't found, and create
616                // a new entity that is READ_WRITE.
617                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
618                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
619                        _entity = null;
620                }
621            }
622            boolean foundInSessionCache = _entity != null;
623            
624            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
625                _entity = getEntityFromCache(session, _pk);
626            }
627            
628            if(_entity == null) {
629                Long cmpgncntdt_cmpgncnt_campaigncontentid = rs.getLong(CMPGNCNTDT_CMPGNCNT_CAMPAIGNCONTENTID);
630                if(rs.wasNull())
631                    cmpgncntdt_cmpgncnt_campaigncontentid = null;
632                
633                String cmpgncntdt_campaigncontentname = rs.getString(CMPGNCNTDT_CAMPAIGNCONTENTNAME);
634                if(rs.wasNull())
635                    cmpgncntdt_campaigncontentname = null;
636                
637                String cmpgncntdt_valuesha1hash = rs.getString(CMPGNCNTDT_VALUESHA1HASH);
638                if(rs.wasNull())
639                    cmpgncntdt_valuesha1hash = null;
640                
641                Clob cmpgncntdt_value = rs.getClob(CMPGNCNTDT_VALUE);
642                if(rs.wasNull())
643                    cmpgncntdt_value = null;
644                
645                Boolean cmpgncntdt_isdefault = rs.getInt(CMPGNCNTDT_ISDEFAULT) == 1;
646                if(rs.wasNull())
647                    cmpgncntdt_isdefault = null;
648                
649                Integer cmpgncntdt_sortorder = rs.getInt(CMPGNCNTDT_SORTORDER);
650                if(rs.wasNull())
651                    cmpgncntdt_sortorder = null;
652                
653                Long cmpgncntdt_fromtime = rs.getLong(CMPGNCNTDT_FROMTIME);
654                if(rs.wasNull())
655                    cmpgncntdt_fromtime = null;
656                
657                Long cmpgncntdt_thrutime = rs.getLong(CMPGNCNTDT_THRUTIME);
658                if(rs.wasNull())
659                    cmpgncntdt_thrutime = null;
660                
661                CampaignContentDetailValue _value = new CampaignContentDetailValue(_pk, cmpgncntdt_cmpgncnt_campaigncontentid == null? null: new CampaignContentPK(cmpgncntdt_cmpgncnt_campaigncontentid), cmpgncntdt_campaigncontentname, cmpgncntdt_valuesha1hash, cmpgncntdt_value == null? null: cmpgncntdt_value.getSubString(1L, (int)cmpgncntdt_value.length()), cmpgncntdt_isdefault, cmpgncntdt_sortorder, cmpgncntdt_fromtime, cmpgncntdt_thrutime);
662                _entity = new CampaignContentDetail(_value, entityPermission);
663            }
664            
665            if(!foundInSessionCache) {
666                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
667                    session.putReadOnlyEntity(_pk, _entity);
668                    session.getValueCache().put(_entity.getCampaignContentDetailValue());
669                } else {
670                    session.putReadWriteEntity(_pk, _entity);
671                }
672            }
673        } catch (SQLException se) {
674            throw new PersistenceDatabaseException(se);
675        }
676        
677        return _entity;
678    }
679    
680    public CampaignContentDetail create(Session session, CampaignContent campaignContent, String campaignContentName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
681            throws PersistenceDatabaseException, PersistenceNotNullException {
682        return create(session, campaignContent == null ? null : campaignContent.getPrimaryKey(), campaignContentName, valueSha1Hash, value, isDefault, sortOrder, fromTime, thruTime);
683    }
684    
685    public CampaignContentDetail create(CampaignContent campaignContent, String campaignContentName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
686            throws PersistenceDatabaseException, PersistenceNotNullException {
687        return create(ThreadSession.currentSession(), campaignContent == null ? null : campaignContent.getPrimaryKey(), campaignContentName, valueSha1Hash, value, isDefault, sortOrder, fromTime, thruTime);
688    }
689    
690    private void bindForCreate(PreparedStatement _ps, CampaignContentDetailValue _value)
691            throws SQLException {
692        _ps.setLong(1, _value.getEntityId());
693        
694        CampaignContentPK cmpgncntdt_cmpgncnt_campaigncontentid = _value.getCampaignContentPK();
695        if(cmpgncntdt_cmpgncnt_campaigncontentid == null)
696            _ps.setNull(2, Types.BIGINT);
697        else
698            _ps.setLong(2, cmpgncntdt_cmpgncnt_campaigncontentid.getEntityId());
699            
700        String cmpgncntdt_campaigncontentname = _value.getCampaignContentName();
701        if(cmpgncntdt_campaigncontentname == null)
702            _ps.setNull(3, Types.VARCHAR);
703        else
704            _ps.setString(3, cmpgncntdt_campaigncontentname);
705            
706        String cmpgncntdt_valuesha1hash = _value.getValueSha1Hash();
707        if(cmpgncntdt_valuesha1hash == null)
708            _ps.setNull(4, Types.VARCHAR);
709        else
710            _ps.setString(4, cmpgncntdt_valuesha1hash);
711            
712        String cmpgncntdt_value = _value.getValue();
713        if(cmpgncntdt_value == null)
714            _ps.setNull(5, Types.CLOB);
715        else
716            _ps.setCharacterStream(5, new StringReader(cmpgncntdt_value), cmpgncntdt_value.length());
717            
718        Boolean cmpgncntdt_isdefault = _value.getIsDefault();
719        if(cmpgncntdt_isdefault == null)
720            _ps.setNull(6, Types.BIT);
721        else
722            _ps.setInt(6, cmpgncntdt_isdefault? 1: 0);
723            
724        Integer cmpgncntdt_sortorder = _value.getSortOrder();
725        if(cmpgncntdt_sortorder == null)
726            _ps.setNull(7, Types.INTEGER);
727        else
728            _ps.setInt(7, cmpgncntdt_sortorder);
729            
730        Long cmpgncntdt_fromtime = _value.getFromTime();
731        if(cmpgncntdt_fromtime == null)
732            _ps.setNull(8, Types.BIGINT);
733        else
734            _ps.setLong(8, cmpgncntdt_fromtime);
735            
736        Long cmpgncntdt_thrutime = _value.getThruTime();
737        if(cmpgncntdt_thrutime == null)
738            _ps.setNull(9, Types.BIGINT);
739        else
740            _ps.setLong(9, cmpgncntdt_thrutime);
741            
742    }
743    
744    public CampaignContentDetail create(Session session, CampaignContentPK campaignContentPK, String campaignContentName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
745            throws PersistenceDatabaseException, PersistenceNotNullException {
746        CampaignContentDetailPK _pk = getNextPK();
747        CampaignContentDetailValue _value = new CampaignContentDetailValue(_pk, campaignContentPK, campaignContentName, valueSha1Hash, value, isDefault, sortOrder, fromTime, thruTime);
748        
749        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
750        
751        try {
752            bindForCreate(_ps, _value);
753            
754            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
755                int _count = _ps.executeUpdate();
756                
757                if(_count != 1) {
758                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
759                }
760            } else {
761                 _ps.executeUpdate();
762            }
763            
764            session.getValueCache().put(_value);
765        } catch (SQLException se) {
766            throw new PersistenceDatabaseException(se);
767        }
768        
769        CampaignContentDetail _entity = new CampaignContentDetail(_value, EntityPermission.READ_ONLY);
770        session.putReadOnlyEntity(_pk, _entity);
771        
772        return _entity;
773    }
774    
775    public CampaignContentDetail create(CampaignContentPK campaignContentPK, String campaignContentName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime)
776            throws PersistenceDatabaseException, PersistenceNotNullException {
777        return create(ThreadSession.currentSession(), campaignContentPK, campaignContentName, valueSha1Hash, value, isDefault, sortOrder, fromTime, thruTime);
778    }
779    
780    public void create(Session session, Collection<CampaignContentDetailValue> _values)
781            throws PersistenceDatabaseException, PersistenceNotNullException {
782        int _size = _values.size();
783        
784        if(_size > 0) {
785            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
786            List<CampaignContentDetailValue> _cacheValues = new ArrayList<>(_size);
787            
788            try {
789                for(CampaignContentDetailValue _value : _values) {
790                    _value.setEntityId(entityIdGenerator.getNextEntityId());
791                    bindForCreate(_ps, _value);
792                    
793                    _ps.addBatch();
794                    
795                    _cacheValues.add(_value);
796                }
797                
798                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
799                    int[] _counts = _ps.executeBatch();
800                    
801                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
802                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
803                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
804                        }
805                    }
806                } else {
807                     _ps.executeBatch();
808                }
809                
810                _ps.clearBatch();
811            } catch (SQLException se) {
812                throw new PersistenceDatabaseException(se);
813            }
814            
815            _cacheValues.forEach((_cacheValue) -> {
816                CampaignContentDetail _cacheEntity = new CampaignContentDetail(_cacheValue, EntityPermission.READ_ONLY);
817                
818                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
819            });
820        }
821    }
822    
823    public void create(Collection<CampaignContentDetailValue> _values)
824            throws PersistenceDatabaseException, PersistenceNotNullException {
825        create(ThreadSession.currentSession(), _values);
826    }
827    
828    private boolean bindForStore(PreparedStatement _ps, CampaignContentDetailValue _value)
829            throws SQLException {
830        boolean _hasBeenModified = _value.hasBeenModified();
831        
832        if(_hasBeenModified) {
833            CampaignContentPK cmpgncntdt_cmpgncnt_campaigncontentid = _value.getCampaignContentPK();
834            if(cmpgncntdt_cmpgncnt_campaigncontentid == null)
835                _ps.setNull(1, Types.BIGINT);
836            else
837                _ps.setLong(1, cmpgncntdt_cmpgncnt_campaigncontentid.getEntityId());
838            
839            String cmpgncntdt_campaigncontentname = _value.getCampaignContentName();
840            if(cmpgncntdt_campaigncontentname == null)
841                _ps.setNull(2, Types.VARCHAR);
842            else
843                _ps.setString(2, cmpgncntdt_campaigncontentname);
844            
845            String cmpgncntdt_valuesha1hash = _value.getValueSha1Hash();
846            if(cmpgncntdt_valuesha1hash == null)
847                _ps.setNull(3, Types.VARCHAR);
848            else
849                _ps.setString(3, cmpgncntdt_valuesha1hash);
850            
851            String cmpgncntdt_value = _value.getValue();
852            if(cmpgncntdt_value == null)
853                _ps.setNull(4, Types.CLOB);
854            else
855                _ps.setCharacterStream(4, new StringReader(cmpgncntdt_value), cmpgncntdt_value.length());
856            
857            Boolean cmpgncntdt_isdefault = _value.getIsDefault();
858            if(cmpgncntdt_isdefault == null)
859                _ps.setNull(5, Types.BIT);
860            else
861                _ps.setInt(5, cmpgncntdt_isdefault? 1: 0);
862            
863            Integer cmpgncntdt_sortorder = _value.getSortOrder();
864            if(cmpgncntdt_sortorder == null)
865                _ps.setNull(6, Types.INTEGER);
866            else
867                _ps.setInt(6, cmpgncntdt_sortorder);
868            
869            Long cmpgncntdt_fromtime = _value.getFromTime();
870            if(cmpgncntdt_fromtime == null)
871                _ps.setNull(7, Types.BIGINT);
872            else
873                _ps.setLong(7, cmpgncntdt_fromtime);
874            
875            Long cmpgncntdt_thrutime = _value.getThruTime();
876            if(cmpgncntdt_thrutime == null)
877                _ps.setNull(8, Types.BIGINT);
878            else
879                _ps.setLong(8, cmpgncntdt_thrutime);
880            
881            _ps.setLong(9, _value.getPrimaryKey().getEntityId());
882            
883            _value.clearHasBeenModified();
884        }
885        
886        return _hasBeenModified;
887    }
888    
889    @Override
890    public void store(Session session, CampaignContentDetail entity)
891            throws PersistenceDatabaseException {
892        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
893        
894        try {
895            CampaignContentDetailValue _value = entity.getCampaignContentDetailValue();
896            
897            if(bindForStore(_ps, _value)) {
898                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
899                    int _count = _ps.executeUpdate();
900                    
901                    if(_count != 1) {
902                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
903                    }
904                } else {
905                     _ps.executeUpdate();
906                }
907                
908                session.getValueCache().put(_value);
909            }
910        } catch (SQLException se) {
911            throw new PersistenceDatabaseException(se);
912        }
913    }
914    
915    @Override
916    public void store(Session session, Collection<CampaignContentDetail> entities)
917            throws PersistenceDatabaseException {
918        if(entities.size() > 0) {
919            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
920            int _modifiedEntities = 0;
921            
922            try {
923                for(CampaignContentDetail entity : entities) {
924                    if(bindForStore(_ps, entity.getCampaignContentDetailValue())) {
925                        _ps.addBatch();
926                        _modifiedEntities++;
927                    }
928                }
929                
930                if(_modifiedEntities != 0) {
931                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
932                        int[] _counts = _ps.executeBatch();
933                        
934                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
935                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
936                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
937                            }
938                        }
939                    } else {
940                         _ps.executeBatch();
941                    }
942                    
943                    _ps.clearBatch();
944                    
945                    entities.forEach((entity) -> {
946                        session.getValueCache().put(entity.getCampaignContentDetailValue());
947                    });
948                }
949            } catch (SQLException se) {
950                throw new PersistenceDatabaseException(se);
951            }
952        }
953    }
954    
955    @Override
956    public void store(Collection<CampaignContentDetail> entities)
957            throws PersistenceDatabaseException {
958        store(ThreadSession.currentSession(), entities);
959    }
960    
961    @Override
962    public void remove(Session session, CampaignContentDetail entity)
963            throws PersistenceDatabaseException {
964        remove(session, entity.getPrimaryKey());
965    }
966    
967    @Override
968    public void remove(Session session, CampaignContentDetailPK pk)
969            throws PersistenceDatabaseException {
970        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
971        long _entityId = pk.getEntityId();
972        
973        try {
974            _ps.setLong(1, _entityId);
975            
976            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
977                int _count = _ps.executeUpdate();
978                
979                if(_count != 1) {
980                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
981                }
982            } else {
983                 _ps.executeUpdate();
984            }
985            
986            session.getValueCache().remove(pk);
987        } catch (SQLException se) {
988            throw new PersistenceDatabaseException(se);
989        }
990        
991        session.removed(pk, false);
992    }
993    
994    @Override
995    public void remove(Session session, Collection<CampaignContentDetailPK> pks)
996            throws PersistenceDatabaseException {
997        if(pks.size() > 0) {
998            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
999            int _modifiedEntities = 0;
1000            
1001            try {
1002                for(CampaignContentDetailPK pk : pks) {
1003                    long _entityId = pk.getEntityId();
1004                    
1005                    _ps.setLong(1, _entityId);
1006                    
1007                    _ps.addBatch();
1008                    _modifiedEntities++;
1009                }
1010                
1011                if(_modifiedEntities != 0) {
1012                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1013                        int[] _counts = _ps.executeBatch();
1014                        
1015                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1016                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1017                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1018                            }
1019                        }
1020                    } else {
1021                        _ps.executeBatch();
1022                    }
1023                    
1024                    _ps.clearBatch();
1025                    
1026                    pks.forEach((pk) -> {
1027                        session.getValueCache().remove(pk);
1028                    });
1029                }
1030            } catch (SQLException se) {
1031                throw new PersistenceDatabaseException(se);
1032            }
1033            
1034            pks.forEach((pk) -> {
1035                session.removed(pk, true);
1036            });
1037        }
1038    }
1039    
1040    @Override
1041    public void remove(Collection<CampaignContentDetailPK> pks)
1042            throws PersistenceDatabaseException {
1043        remove(ThreadSession.currentSession(), pks);
1044    }
1045    
1046    @Override
1047    public boolean validPK(Session session, CampaignContentDetailPK pk)
1048            throws PersistenceDatabaseException {
1049        boolean valid = false;
1050        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1051        ResultSet _rs = null;
1052        
1053        try {
1054            _ps.setLong(1, pk.getEntityId());
1055            
1056            _rs = _ps.executeQuery();
1057            if(_rs.next()) {
1058                long _count = _rs.getLong(1);
1059                if(_rs.wasNull())
1060                    _count = 0;
1061                
1062                if(_count == 1)
1063                    valid = true;
1064            }
1065        } catch (SQLException se) {
1066            throw new PersistenceDatabaseException(se);
1067        } finally {
1068            if(_rs != null) {
1069                try {
1070                    _rs.close();
1071                } catch (SQLException se) {
1072                    // do nothing
1073                }
1074            }
1075        }
1076        
1077        return valid;
1078    }
1079    
1080}