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