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