001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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 * PostalAddressLineDetailFactory.java
021 */
022
023package com.echothree.model.data.contact.server.factory;
024
025import com.echothree.model.data.contact.common.pk.PostalAddressLinePK;
026import com.echothree.model.data.contact.common.pk.PostalAddressFormatPK;
027
028import com.echothree.model.data.contact.server.entity.PostalAddressLine;
029import com.echothree.model.data.contact.server.entity.PostalAddressFormat;
030
031import com.echothree.model.data.contact.common.PostalAddressLineDetailConstants;
032import com.echothree.model.data.contact.common.pk.PostalAddressLineDetailPK;
033import com.echothree.model.data.contact.server.value.PostalAddressLineDetailValue;
034import com.echothree.model.data.contact.server.entity.PostalAddressLineDetail;
035import com.echothree.util.common.exception.PersistenceDatabaseException;
036import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
037import com.echothree.util.common.exception.PersistenceNotNullException;
038import com.echothree.util.server.persistence.BaseFactory;
039import com.echothree.util.server.persistence.EntityIdGenerator;
040import com.echothree.util.server.persistence.EntityPermission;
041import com.echothree.util.server.persistence.PersistenceDebugFlags;
042import com.echothree.util.server.persistence.Session;
043import com.echothree.util.server.persistence.ThreadSession;
044import java.sql.PreparedStatement;
045import java.sql.ResultSet;
046import java.sql.SQLException;
047import java.sql.Types;
048import java.io.ByteArrayInputStream;
049import java.io.StringReader;
050import java.util.ArrayList;
051import java.util.Collection;
052import java.util.HashSet;
053import java.util.List;
054import java.util.Map;
055import java.util.Set;
056import javax.enterprise.context.ApplicationScoped;
057import javax.enterprise.inject.spi.CDI;
058import org.apache.commons.logging.Log;
059import org.apache.commons.logging.LogFactory;
060
061@ApplicationScoped
062public class PostalAddressLineDetailFactory
063        implements BaseFactory<PostalAddressLineDetailPK, PostalAddressLineDetail> {
064    
065    //final private static Log log = LogFactory.getLog(PostalAddressLineDetailFactory.class);
066    
067    final private static String SQL_SELECT_READ_ONLY = "SELECT pstaldt_postaladdresslinedetailid, pstaldt_pstal_postaladdresslineid, pstaldt_pstafmt_postaladdressformatid, pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime FROM postaladdresslinedetails WHERE pstaldt_postaladdresslinedetailid = ?";
068    final private static String SQL_SELECT_READ_WRITE = "SELECT pstaldt_postaladdresslinedetailid, pstaldt_pstal_postaladdresslineid, pstaldt_pstafmt_postaladdressformatid, pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime FROM postaladdresslinedetails WHERE pstaldt_postaladdresslinedetailid = ? FOR UPDATE";
069    final private static String SQL_INSERT = "INSERT INTO postaladdresslinedetails (pstaldt_postaladdresslinedetailid, pstaldt_pstal_postaladdresslineid, pstaldt_pstafmt_postaladdressformatid, pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
070    final private static String SQL_UPDATE = "UPDATE postaladdresslinedetails SET pstaldt_pstal_postaladdresslineid = ?, pstaldt_pstafmt_postaladdressformatid = ?, pstaldt_postaladdresslinesortorder = ?, pstaldt_prefix = ?, pstaldt_alwaysincludeprefix = ?, pstaldt_suffix = ?, pstaldt_alwaysincludesuffix = ?, pstaldt_collapseifempty = ?, pstaldt_fromtime = ?, pstaldt_thrutime = ? WHERE pstaldt_postaladdresslinedetailid = ?";
071    final private static String SQL_DELETE = "DELETE FROM postaladdresslinedetails WHERE pstaldt_postaladdresslinedetailid = ?";
072    final private static String SQL_VALID = "SELECT COUNT(*) FROM postaladdresslinedetails WHERE pstaldt_postaladdresslinedetailid = ?";
073    
074    final private static String PK_COLUMN = "pstaldt_postaladdresslinedetailid";
075    final private static String ALL_COLUMNS = "pstaldt_postaladdresslinedetailid, pstaldt_pstal_postaladdresslineid, pstaldt_pstafmt_postaladdressformatid, pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime";
076    final public static String TABLE_NAME = "postaladdresslinedetails";
077    
078    final public static String PSTALDT_POSTALADDRESSLINEDETAILID = "pstaldt_postaladdresslinedetailid";
079    final public static String PSTALDT_PSTAL_POSTALADDRESSLINEID = "pstaldt_pstal_postaladdresslineid";
080    final public static String PSTALDT_PSTAFMT_POSTALADDRESSFORMATID = "pstaldt_pstafmt_postaladdressformatid";
081    final public static String PSTALDT_POSTALADDRESSLINESORTORDER = "pstaldt_postaladdresslinesortorder";
082    final public static String PSTALDT_PREFIX = "pstaldt_prefix";
083    final public static String PSTALDT_ALWAYSINCLUDEPREFIX = "pstaldt_alwaysincludeprefix";
084    final public static String PSTALDT_SUFFIX = "pstaldt_suffix";
085    final public static String PSTALDT_ALWAYSINCLUDESUFFIX = "pstaldt_alwaysincludesuffix";
086    final public static String PSTALDT_COLLAPSEIFEMPTY = "pstaldt_collapseifempty";
087    final public static String PSTALDT_FROMTIME = "pstaldt_fromtime";
088    final public static String PSTALDT_THRUTIME = "pstaldt_thrutime";
089    
090    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(PostalAddressLineDetailConstants.COMPONENT_VENDOR_NAME, PostalAddressLineDetailConstants.ENTITY_TYPE_NAME);
091    
092    /** Creates a new instance of PostalAddressLineDetailFactory */
093    protected PostalAddressLineDetailFactory() {
094        super();
095    }
096    
097    public static PostalAddressLineDetailFactory getInstance() {
098        return CDI.current().select(PostalAddressLineDetailFactory.class).get();
099    }
100    
101    @Override
102    public String getPKColumn() {
103        return PK_COLUMN;
104    }
105    
106    @Override
107    public String getAllColumns() {
108        return ALL_COLUMNS;
109    }
110    
111    @Override
112    public String getTableName() {
113        return TABLE_NAME;
114    }
115    
116    @Override
117    public String getComponentVendorName() {
118        return PostalAddressLineDetailConstants.COMPONENT_VENDOR_NAME;
119    }
120    
121    @Override
122    public String getEntityTypeName() {
123        return PostalAddressLineDetailConstants.ENTITY_TYPE_NAME;
124    }
125    
126    public PreparedStatement prepareStatement(String query) {
127        return ThreadSession.currentSession().prepareStatement(PostalAddressLineDetailFactory.class, query);
128    }
129    
130    public PostalAddressLineDetailPK getNextPK() {
131        return new PostalAddressLineDetailPK(entityIdGenerator.getNextEntityId());
132    }
133    
134    public Set<PostalAddressLineDetailPK> getPKsFromResultSetAsSet(ResultSet rs)
135            throws PersistenceDatabaseException {
136        Set<PostalAddressLineDetailPK> _result = new HashSet<>();
137        
138        try {
139            while(rs.next()) {
140                _result.add(getPKFromResultSet(rs));
141            }
142        } catch (SQLException se) {
143            throw new PersistenceDatabaseException(se);
144        }
145        
146        return _result;
147    }
148    
149    public java.util.List<PostalAddressLineDetailPK> getPKsFromResultSetAsList(ResultSet rs)
150            throws PersistenceDatabaseException {
151        java.util.List<PostalAddressLineDetailPK> _result = new ArrayList<>();
152        
153        try {
154            while(rs.next()) {
155                _result.add(getPKFromResultSet(rs));
156            }
157        } catch (SQLException se) {
158            throw new PersistenceDatabaseException(se);
159        }
160        
161        return _result;
162    }
163    
164    public PostalAddressLineDetailPK getPKFromResultSet(ResultSet rs)
165            throws PersistenceDatabaseException {
166        PostalAddressLineDetailPK _result;
167        
168        try {
169            long pstaldt_postaladdresslinedetailid = rs.getLong(PSTALDT_POSTALADDRESSLINEDETAILID);
170            Long _entityId = rs.wasNull() ? null : pstaldt_postaladdresslinedetailid;
171            
172            _result = new PostalAddressLineDetailPK(_entityId);
173        } catch (SQLException se) {
174            throw new PersistenceDatabaseException(se);
175        }
176        
177        return _result;
178    }
179    
180    public java.util.List<PostalAddressLineDetailValue> getValuesFromPKs(Session session, Collection<PostalAddressLineDetailPK> pks)
181            throws PersistenceDatabaseException {
182        java.util.List<PostalAddressLineDetailValue> _values = new ArrayList<>(pks.size());
183        
184        for(PostalAddressLineDetailPK _pk: pks) {
185            _values.add(getValueFromPK(session, _pk));
186        }
187        
188        return _values;
189    }
190    
191    public PostalAddressLineDetailValue getValueFromPK(Session session, PostalAddressLineDetailPK pk)
192            throws PersistenceDatabaseException {
193        PostalAddressLineDetailValue _value;
194        
195        // See if we already have the entity in the session cache
196        PostalAddressLineDetail _entity = (PostalAddressLineDetail)session.getEntity(pk);
197        if(_entity == null)
198            _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getPostalAddressLineDetailValue();
199        else
200            _value = _entity.getPostalAddressLineDetailValue();
201        
202        return _value;
203    }
204    
205    public java.util.List<PostalAddressLineDetailValue> getValuesFromResultSet(Session session, ResultSet rs)
206            throws PersistenceDatabaseException {
207        java.util.List<PostalAddressLineDetailValue> _result = new ArrayList<>();
208        
209        try {
210            while(rs.next()) {
211                _result.add(getValueFromResultSet(session, rs));
212            }
213        } catch (SQLException se) {
214            throw new PersistenceDatabaseException(se);
215        }
216        
217        return _result;
218    }
219    
220    public PostalAddressLineDetailValue getValueFromResultSet(Session session, ResultSet rs)
221            throws PersistenceDatabaseException {
222        PostalAddressLineDetailValue _value;
223        
224        try {
225            Long pstaldt_postaladdresslinedetailid = rs.getLong(PSTALDT_POSTALADDRESSLINEDETAILID);
226            PostalAddressLineDetailPK _pk = new PostalAddressLineDetailPK(pstaldt_postaladdresslinedetailid);
227            
228            // See if we already have the entity in the session cache
229            PostalAddressLineDetail _entity = (PostalAddressLineDetail)session.getEntity(_pk);
230            
231            if(_entity == null) {
232                Long pstaldt_pstal_postaladdresslineid = rs.getLong(PSTALDT_PSTAL_POSTALADDRESSLINEID);
233                if(rs.wasNull())
234                    pstaldt_pstal_postaladdresslineid = null;
235                
236                Long pstaldt_pstafmt_postaladdressformatid = rs.getLong(PSTALDT_PSTAFMT_POSTALADDRESSFORMATID);
237                if(rs.wasNull())
238                    pstaldt_pstafmt_postaladdressformatid = null;
239                
240                Integer pstaldt_postaladdresslinesortorder = rs.getInt(PSTALDT_POSTALADDRESSLINESORTORDER);
241                if(rs.wasNull())
242                    pstaldt_postaladdresslinesortorder = null;
243                
244                String pstaldt_prefix = rs.getString(PSTALDT_PREFIX);
245                if(rs.wasNull())
246                    pstaldt_prefix = null;
247                
248                Boolean pstaldt_alwaysincludeprefix = rs.getInt(PSTALDT_ALWAYSINCLUDEPREFIX) == 1;
249                if(rs.wasNull())
250                    pstaldt_alwaysincludeprefix = null;
251                
252                String pstaldt_suffix = rs.getString(PSTALDT_SUFFIX);
253                if(rs.wasNull())
254                    pstaldt_suffix = null;
255                
256                Boolean pstaldt_alwaysincludesuffix = rs.getInt(PSTALDT_ALWAYSINCLUDESUFFIX) == 1;
257                if(rs.wasNull())
258                    pstaldt_alwaysincludesuffix = null;
259                
260                Boolean pstaldt_collapseifempty = rs.getInt(PSTALDT_COLLAPSEIFEMPTY) == 1;
261                if(rs.wasNull())
262                    pstaldt_collapseifempty = null;
263                
264                Long pstaldt_fromtime = rs.getLong(PSTALDT_FROMTIME);
265                if(rs.wasNull())
266                    pstaldt_fromtime = null;
267                
268                Long pstaldt_thrutime = rs.getLong(PSTALDT_THRUTIME);
269                if(rs.wasNull())
270                    pstaldt_thrutime = null;
271                
272                _value = new PostalAddressLineDetailValue(_pk, new PostalAddressLinePK(pstaldt_pstal_postaladdresslineid), new PostalAddressFormatPK(pstaldt_pstafmt_postaladdressformatid), pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime);
273            } else
274                _value = _entity.getPostalAddressLineDetailValue();
275        } catch (SQLException se) {
276            throw new PersistenceDatabaseException(se);
277        }
278        
279        return _value;
280    }
281    
282    public java.util.List<PostalAddressLineDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<PostalAddressLineDetailPK> pks)
283            throws PersistenceDatabaseException {
284        return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks);
285    }
286    
287    public java.util.List<PostalAddressLineDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<PostalAddressLineDetailPK> pks)
288            throws PersistenceDatabaseException {
289        java.util.List<PostalAddressLineDetail> _entities = new ArrayList<>(pks.size());
290        
291        for(PostalAddressLineDetailPK _pk: pks) {
292            _entities.add(getEntityFromPK(session, entityPermission, _pk));
293        }
294        
295        return _entities;
296    }
297    
298    public PostalAddressLineDetail getEntityFromValue(EntityPermission entityPermission, PostalAddressLineDetailValue value) {
299        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey());
300    }
301    
302    public PostalAddressLineDetail getEntityFromValue(Session session, EntityPermission entityPermission, PostalAddressLineDetailValue value) {
303        return getEntityFromPK(session, entityPermission, value.getPrimaryKey());
304    }
305    
306    public PostalAddressLineDetail getEntityFromPK(EntityPermission entityPermission, PostalAddressLineDetailPK pk)
307            throws PersistenceDatabaseException {
308        return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk);
309    }
310    
311    public PostalAddressLineDetail getEntityFromCache(Session session, PostalAddressLineDetailPK pk) {
312        PostalAddressLineDetailValue _value = (PostalAddressLineDetailValue)session.getValueCache().get(pk);
313    
314        return _value == null ? null : new PostalAddressLineDetail(_value, EntityPermission.READ_ONLY);
315    }
316    
317    public PostalAddressLineDetail getEntityFromPK(Session session, EntityPermission entityPermission, PostalAddressLineDetailPK pk)
318            throws PersistenceDatabaseException {
319        PostalAddressLineDetail _entity;
320        
321        // See if we already have the entity in the session cache
322        _entity = (PostalAddressLineDetail)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<PostalAddressLineDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
365            throws PersistenceDatabaseException {
366        Set<PostalAddressLineDetailPK> _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<PostalAddressLineDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
393            throws PersistenceDatabaseException {
394        java.util.List<PostalAddressLineDetailPK> _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 PostalAddressLineDetailPK getPKFromQuery(PreparedStatement ps, final Object... params)
421            throws PersistenceDatabaseException {
422        PostalAddressLineDetailPK _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<PostalAddressLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
451            throws PersistenceDatabaseException {
452        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
453        
454        return getEntitiesFromQuery(session, entityPermission, ps, params);
455    }
456    
457    public java.util.List<PostalAddressLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
458            throws PersistenceDatabaseException {
459        Session session = ThreadSession.currentSession();
460        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
461        
462        return getEntitiesFromQuery(session, entityPermission, ps, params);
463    }
464    
465    public java.util.List<PostalAddressLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
466            throws PersistenceDatabaseException {
467        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
468        
469        return getEntitiesFromQuery(session, entityPermission, ps);
470    }
471    
472    public java.util.List<PostalAddressLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
473            throws PersistenceDatabaseException {
474        Session session = ThreadSession.currentSession();
475        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
476        
477        return getEntitiesFromQuery(session, entityPermission, ps);
478    }
479    
480    public java.util.List<PostalAddressLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps)
481            throws PersistenceDatabaseException {
482        return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps);
483    }
484    
485    public java.util.List<PostalAddressLineDetail> 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<PostalAddressLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
491            throws PersistenceDatabaseException {
492        java.util.List<PostalAddressLineDetail> _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 PostalAddressLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
519            throws PersistenceDatabaseException {
520        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
521        
522        return getEntityFromQuery(session, entityPermission, ps, params);
523    }
524    
525    public PostalAddressLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
526            throws PersistenceDatabaseException {
527        Session session = ThreadSession.currentSession();
528        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
529        
530        return getEntityFromQuery(session, entityPermission, ps, params);
531    }
532    
533    public PostalAddressLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
534            throws PersistenceDatabaseException {
535        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
536        
537        return getEntityFromQuery(session, entityPermission, ps);
538    }
539    
540    public PostalAddressLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
541            throws PersistenceDatabaseException {
542        Session session = ThreadSession.currentSession();
543        PreparedStatement ps = session.prepareStatement(PostalAddressLineDetailFactory.class, queryMap.get(entityPermission));
544        
545        return getEntityFromQuery(session, entityPermission, ps);
546    }
547    
548    public PostalAddressLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps)
549            throws PersistenceDatabaseException {
550        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps);
551    }
552    
553    public PostalAddressLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
554            throws PersistenceDatabaseException {
555        return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params);
556    }
557    
558    public PostalAddressLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params)
559            throws PersistenceDatabaseException {
560        PostalAddressLineDetail _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<PostalAddressLineDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
589            throws PersistenceDatabaseException {
590        return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
591    }
592    
593    public java.util.List<PostalAddressLineDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
594            throws PersistenceDatabaseException {
595        java.util.List<PostalAddressLineDetail> _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 PostalAddressLineDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
609            throws PersistenceDatabaseException {
610        return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs);
611    }
612    
613    public PostalAddressLineDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs)
614            throws PersistenceDatabaseException {
615        PostalAddressLineDetail _entity;
616        
617        try {
618            Long pstaldt_postaladdresslinedetailid = rs.getLong(PSTALDT_POSTALADDRESSLINEDETAILID);
619            PostalAddressLineDetailPK _pk = new PostalAddressLineDetailPK(pstaldt_postaladdresslinedetailid);
620            
621            // See if we already have the entity in the session cache
622            _entity = (PostalAddressLineDetail)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 pstaldt_pstal_postaladdresslineid = rs.getLong(PSTALDT_PSTAL_POSTALADDRESSLINEID);
640                if(rs.wasNull())
641                    pstaldt_pstal_postaladdresslineid = null;
642                
643                Long pstaldt_pstafmt_postaladdressformatid = rs.getLong(PSTALDT_PSTAFMT_POSTALADDRESSFORMATID);
644                if(rs.wasNull())
645                    pstaldt_pstafmt_postaladdressformatid = null;
646                
647                Integer pstaldt_postaladdresslinesortorder = rs.getInt(PSTALDT_POSTALADDRESSLINESORTORDER);
648                if(rs.wasNull())
649                    pstaldt_postaladdresslinesortorder = null;
650                
651                String pstaldt_prefix = rs.getString(PSTALDT_PREFIX);
652                if(rs.wasNull())
653                    pstaldt_prefix = null;
654                
655                Boolean pstaldt_alwaysincludeprefix = rs.getInt(PSTALDT_ALWAYSINCLUDEPREFIX) == 1;
656                if(rs.wasNull())
657                    pstaldt_alwaysincludeprefix = null;
658                
659                String pstaldt_suffix = rs.getString(PSTALDT_SUFFIX);
660                if(rs.wasNull())
661                    pstaldt_suffix = null;
662                
663                Boolean pstaldt_alwaysincludesuffix = rs.getInt(PSTALDT_ALWAYSINCLUDESUFFIX) == 1;
664                if(rs.wasNull())
665                    pstaldt_alwaysincludesuffix = null;
666                
667                Boolean pstaldt_collapseifempty = rs.getInt(PSTALDT_COLLAPSEIFEMPTY) == 1;
668                if(rs.wasNull())
669                    pstaldt_collapseifempty = null;
670                
671                Long pstaldt_fromtime = rs.getLong(PSTALDT_FROMTIME);
672                if(rs.wasNull())
673                    pstaldt_fromtime = null;
674                
675                Long pstaldt_thrutime = rs.getLong(PSTALDT_THRUTIME);
676                if(rs.wasNull())
677                    pstaldt_thrutime = null;
678                
679                PostalAddressLineDetailValue _value = new PostalAddressLineDetailValue(_pk, pstaldt_pstal_postaladdresslineid == null? null: new PostalAddressLinePK(pstaldt_pstal_postaladdresslineid), pstaldt_pstafmt_postaladdressformatid == null? null: new PostalAddressFormatPK(pstaldt_pstafmt_postaladdressformatid), pstaldt_postaladdresslinesortorder, pstaldt_prefix, pstaldt_alwaysincludeprefix, pstaldt_suffix, pstaldt_alwaysincludesuffix, pstaldt_collapseifempty, pstaldt_fromtime, pstaldt_thrutime);
680                _entity = new PostalAddressLineDetail(_value, entityPermission);
681            }
682            
683            if(!foundInSessionCache) {
684                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
685                    session.putReadOnlyEntity(_pk, _entity);
686                    session.getValueCache().put(_entity.getPostalAddressLineDetailValue());
687                } else {
688                    session.putReadWriteEntity(_pk, _entity);
689                }
690            }
691        } catch (SQLException se) {
692            throw new PersistenceDatabaseException(se);
693        }
694        
695        return _entity;
696    }
697    
698    public PostalAddressLineDetail create(Session session, PostalAddressLine postalAddressLine, PostalAddressFormat postalAddressFormat, Integer postalAddressLineSortOrder, String prefix, Boolean alwaysIncludePrefix, String suffix, Boolean alwaysIncludeSuffix, Boolean collapseIfEmpty, Long fromTime, Long thruTime)
699            throws PersistenceDatabaseException, PersistenceNotNullException {
700        return create(session, postalAddressLine == null ? null : postalAddressLine.getPrimaryKey(), postalAddressFormat == null ? null : postalAddressFormat.getPrimaryKey(), postalAddressLineSortOrder, prefix, alwaysIncludePrefix, suffix, alwaysIncludeSuffix, collapseIfEmpty, fromTime, thruTime);
701    }
702    
703    public PostalAddressLineDetail create(PostalAddressLine postalAddressLine, PostalAddressFormat postalAddressFormat, Integer postalAddressLineSortOrder, String prefix, Boolean alwaysIncludePrefix, String suffix, Boolean alwaysIncludeSuffix, Boolean collapseIfEmpty, Long fromTime, Long thruTime)
704            throws PersistenceDatabaseException, PersistenceNotNullException {
705        return create(ThreadSession.currentSession(), postalAddressLine == null ? null : postalAddressLine.getPrimaryKey(), postalAddressFormat == null ? null : postalAddressFormat.getPrimaryKey(), postalAddressLineSortOrder, prefix, alwaysIncludePrefix, suffix, alwaysIncludeSuffix, collapseIfEmpty, fromTime, thruTime);
706    }
707    
708    private void bindForCreate(PreparedStatement _ps, PostalAddressLineDetailValue _value)
709            throws SQLException {
710        _ps.setLong(1, _value.getEntityId());
711        
712        PostalAddressLinePK pstaldt_pstal_postaladdresslineid = _value.getPostalAddressLinePK();
713        if(pstaldt_pstal_postaladdresslineid == null)
714            _ps.setNull(2, Types.BIGINT);
715        else
716            _ps.setLong(2, pstaldt_pstal_postaladdresslineid.getEntityId());
717            
718        PostalAddressFormatPK pstaldt_pstafmt_postaladdressformatid = _value.getPostalAddressFormatPK();
719        if(pstaldt_pstafmt_postaladdressformatid == null)
720            _ps.setNull(3, Types.BIGINT);
721        else
722            _ps.setLong(3, pstaldt_pstafmt_postaladdressformatid.getEntityId());
723            
724        Integer pstaldt_postaladdresslinesortorder = _value.getPostalAddressLineSortOrder();
725        if(pstaldt_postaladdresslinesortorder == null)
726            _ps.setNull(4, Types.INTEGER);
727        else
728            _ps.setInt(4, pstaldt_postaladdresslinesortorder);
729            
730        String pstaldt_prefix = _value.getPrefix();
731        if(pstaldt_prefix == null)
732            _ps.setNull(5, Types.VARCHAR);
733        else
734            _ps.setString(5, pstaldt_prefix);
735            
736        Boolean pstaldt_alwaysincludeprefix = _value.getAlwaysIncludePrefix();
737        if(pstaldt_alwaysincludeprefix == null)
738            _ps.setNull(6, Types.BIT);
739        else
740            _ps.setInt(6, pstaldt_alwaysincludeprefix? 1: 0);
741            
742        String pstaldt_suffix = _value.getSuffix();
743        if(pstaldt_suffix == null)
744            _ps.setNull(7, Types.VARCHAR);
745        else
746            _ps.setString(7, pstaldt_suffix);
747            
748        Boolean pstaldt_alwaysincludesuffix = _value.getAlwaysIncludeSuffix();
749        if(pstaldt_alwaysincludesuffix == null)
750            _ps.setNull(8, Types.BIT);
751        else
752            _ps.setInt(8, pstaldt_alwaysincludesuffix? 1: 0);
753            
754        Boolean pstaldt_collapseifempty = _value.getCollapseIfEmpty();
755        if(pstaldt_collapseifempty == null)
756            _ps.setNull(9, Types.BIT);
757        else
758            _ps.setInt(9, pstaldt_collapseifempty? 1: 0);
759            
760        Long pstaldt_fromtime = _value.getFromTime();
761        if(pstaldt_fromtime == null)
762            _ps.setNull(10, Types.BIGINT);
763        else
764            _ps.setLong(10, pstaldt_fromtime);
765            
766        Long pstaldt_thrutime = _value.getThruTime();
767        if(pstaldt_thrutime == null)
768            _ps.setNull(11, Types.BIGINT);
769        else
770            _ps.setLong(11, pstaldt_thrutime);
771            
772    }
773    
774    public PostalAddressLineDetail create(Session session, PostalAddressLinePK postalAddressLinePK, PostalAddressFormatPK postalAddressFormatPK, Integer postalAddressLineSortOrder, String prefix, Boolean alwaysIncludePrefix, String suffix, Boolean alwaysIncludeSuffix, Boolean collapseIfEmpty, Long fromTime, Long thruTime)
775            throws PersistenceDatabaseException, PersistenceNotNullException {
776        PostalAddressLineDetailPK _pk = getNextPK();
777        PostalAddressLineDetailValue _value = new PostalAddressLineDetailValue(_pk, postalAddressLinePK, postalAddressFormatPK, postalAddressLineSortOrder, prefix, alwaysIncludePrefix, suffix, alwaysIncludeSuffix, collapseIfEmpty, fromTime, thruTime);
778        
779        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
780        
781        try {
782            bindForCreate(_ps, _value);
783            
784            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
785                int _count = _ps.executeUpdate();
786                
787                if(_count != 1) {
788                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
789                }
790            } else {
791                 _ps.executeUpdate();
792            }
793            
794            session.getValueCache().put(_value);
795        } catch (SQLException se) {
796            throw new PersistenceDatabaseException(se);
797        }
798        
799        PostalAddressLineDetail _entity = new PostalAddressLineDetail(_value, EntityPermission.READ_ONLY);
800        session.putReadOnlyEntity(_pk, _entity);
801        
802        return _entity;
803    }
804    
805    public PostalAddressLineDetail create(PostalAddressLinePK postalAddressLinePK, PostalAddressFormatPK postalAddressFormatPK, Integer postalAddressLineSortOrder, String prefix, Boolean alwaysIncludePrefix, String suffix, Boolean alwaysIncludeSuffix, Boolean collapseIfEmpty, Long fromTime, Long thruTime)
806            throws PersistenceDatabaseException, PersistenceNotNullException {
807        return create(ThreadSession.currentSession(), postalAddressLinePK, postalAddressFormatPK, postalAddressLineSortOrder, prefix, alwaysIncludePrefix, suffix, alwaysIncludeSuffix, collapseIfEmpty, fromTime, thruTime);
808    }
809    
810    public void create(Session session, Collection<PostalAddressLineDetailValue> _values)
811            throws PersistenceDatabaseException, PersistenceNotNullException {
812        int _size = _values.size();
813        
814        if(_size > 0) {
815            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
816            List<PostalAddressLineDetailValue> _cacheValues = new ArrayList<>(_size);
817            
818            try {
819                for(PostalAddressLineDetailValue _value : _values) {
820                    _value.setEntityId(entityIdGenerator.getNextEntityId());
821                    bindForCreate(_ps, _value);
822                    
823                    _ps.addBatch();
824                    
825                    _cacheValues.add(_value);
826                }
827                
828                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
829                    int[] _counts = _ps.executeBatch();
830                    
831                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
832                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
833                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
834                        }
835                    }
836                } else {
837                     _ps.executeBatch();
838                }
839                
840                _ps.clearBatch();
841            } catch (SQLException se) {
842                throw new PersistenceDatabaseException(se);
843            }
844            
845            _cacheValues.forEach((_cacheValue) -> {
846                PostalAddressLineDetail _cacheEntity = new PostalAddressLineDetail(_cacheValue, EntityPermission.READ_ONLY);
847                
848                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
849            });
850        }
851    }
852    
853    public void create(Collection<PostalAddressLineDetailValue> _values)
854            throws PersistenceDatabaseException, PersistenceNotNullException {
855        create(ThreadSession.currentSession(), _values);
856    }
857    
858    private boolean bindForStore(PreparedStatement _ps, PostalAddressLineDetailValue _value)
859            throws SQLException {
860        boolean _hasBeenModified = _value.hasBeenModified();
861        
862        if(_hasBeenModified) {
863            PostalAddressLinePK pstaldt_pstal_postaladdresslineid = _value.getPostalAddressLinePK();
864            if(pstaldt_pstal_postaladdresslineid == null)
865                _ps.setNull(1, Types.BIGINT);
866            else
867                _ps.setLong(1, pstaldt_pstal_postaladdresslineid.getEntityId());
868            
869            PostalAddressFormatPK pstaldt_pstafmt_postaladdressformatid = _value.getPostalAddressFormatPK();
870            if(pstaldt_pstafmt_postaladdressformatid == null)
871                _ps.setNull(2, Types.BIGINT);
872            else
873                _ps.setLong(2, pstaldt_pstafmt_postaladdressformatid.getEntityId());
874            
875            Integer pstaldt_postaladdresslinesortorder = _value.getPostalAddressLineSortOrder();
876            if(pstaldt_postaladdresslinesortorder == null)
877                _ps.setNull(3, Types.INTEGER);
878            else
879                _ps.setInt(3, pstaldt_postaladdresslinesortorder);
880            
881            String pstaldt_prefix = _value.getPrefix();
882            if(pstaldt_prefix == null)
883                _ps.setNull(4, Types.VARCHAR);
884            else
885                _ps.setString(4, pstaldt_prefix);
886            
887            Boolean pstaldt_alwaysincludeprefix = _value.getAlwaysIncludePrefix();
888            if(pstaldt_alwaysincludeprefix == null)
889                _ps.setNull(5, Types.BIT);
890            else
891                _ps.setInt(5, pstaldt_alwaysincludeprefix? 1: 0);
892            
893            String pstaldt_suffix = _value.getSuffix();
894            if(pstaldt_suffix == null)
895                _ps.setNull(6, Types.VARCHAR);
896            else
897                _ps.setString(6, pstaldt_suffix);
898            
899            Boolean pstaldt_alwaysincludesuffix = _value.getAlwaysIncludeSuffix();
900            if(pstaldt_alwaysincludesuffix == null)
901                _ps.setNull(7, Types.BIT);
902            else
903                _ps.setInt(7, pstaldt_alwaysincludesuffix? 1: 0);
904            
905            Boolean pstaldt_collapseifempty = _value.getCollapseIfEmpty();
906            if(pstaldt_collapseifempty == null)
907                _ps.setNull(8, Types.BIT);
908            else
909                _ps.setInt(8, pstaldt_collapseifempty? 1: 0);
910            
911            Long pstaldt_fromtime = _value.getFromTime();
912            if(pstaldt_fromtime == null)
913                _ps.setNull(9, Types.BIGINT);
914            else
915                _ps.setLong(9, pstaldt_fromtime);
916            
917            Long pstaldt_thrutime = _value.getThruTime();
918            if(pstaldt_thrutime == null)
919                _ps.setNull(10, Types.BIGINT);
920            else
921                _ps.setLong(10, pstaldt_thrutime);
922            
923            _ps.setLong(11, _value.getPrimaryKey().getEntityId());
924            
925            _value.clearHasBeenModified();
926        }
927        
928        return _hasBeenModified;
929    }
930    
931    @Override
932    public void store(Session session, PostalAddressLineDetail entity)
933            throws PersistenceDatabaseException {
934        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
935        
936        try {
937            PostalAddressLineDetailValue _value = entity.getPostalAddressLineDetailValue();
938            
939            if(bindForStore(_ps, _value)) {
940                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
941                    int _count = _ps.executeUpdate();
942                    
943                    if(_count != 1) {
944                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
945                    }
946                } else {
947                     _ps.executeUpdate();
948                }
949                
950                session.getValueCache().put(_value);
951            }
952        } catch (SQLException se) {
953            throw new PersistenceDatabaseException(se);
954        }
955    }
956    
957    @Override
958    public void store(Session session, Collection<PostalAddressLineDetail> entities)
959            throws PersistenceDatabaseException {
960        if(entities.size() > 0) {
961            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
962            int _modifiedEntities = 0;
963            
964            try {
965                for(PostalAddressLineDetail entity : entities) {
966                    if(bindForStore(_ps, entity.getPostalAddressLineDetailValue())) {
967                        _ps.addBatch();
968                        _modifiedEntities++;
969                    }
970                }
971                
972                if(_modifiedEntities != 0) {
973                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
974                        int[] _counts = _ps.executeBatch();
975                        
976                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
977                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
978                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
979                            }
980                        }
981                    } else {
982                         _ps.executeBatch();
983                    }
984                    
985                    _ps.clearBatch();
986                    
987                    entities.forEach((entity) -> {
988                        session.getValueCache().put(entity.getPostalAddressLineDetailValue());
989                    });
990                }
991            } catch (SQLException se) {
992                throw new PersistenceDatabaseException(se);
993            }
994        }
995    }
996    
997    @Override
998    public void store(Collection<PostalAddressLineDetail> entities)
999            throws PersistenceDatabaseException {
1000        store(ThreadSession.currentSession(), entities);
1001    }
1002    
1003    @Override
1004    public void remove(Session session, PostalAddressLineDetail entity)
1005            throws PersistenceDatabaseException {
1006        remove(session, entity.getPrimaryKey());
1007    }
1008    
1009    @Override
1010    public void remove(Session session, PostalAddressLineDetailPK pk)
1011            throws PersistenceDatabaseException {
1012        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1013        long _entityId = pk.getEntityId();
1014        
1015        try {
1016            _ps.setLong(1, _entityId);
1017            
1018            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1019                int _count = _ps.executeUpdate();
1020                
1021                if(_count != 1) {
1022                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1023                }
1024            } else {
1025                 _ps.executeUpdate();
1026            }
1027            
1028            session.getValueCache().remove(pk);
1029        } catch (SQLException se) {
1030            throw new PersistenceDatabaseException(se);
1031        }
1032        
1033        session.removed(pk, false);
1034    }
1035    
1036    @Override
1037    public void remove(Session session, Collection<PostalAddressLineDetailPK> pks)
1038            throws PersistenceDatabaseException {
1039        if(pks.size() > 0) {
1040            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1041            int _modifiedEntities = 0;
1042            
1043            try {
1044                for(PostalAddressLineDetailPK pk : pks) {
1045                    long _entityId = pk.getEntityId();
1046                    
1047                    _ps.setLong(1, _entityId);
1048                    
1049                    _ps.addBatch();
1050                    _modifiedEntities++;
1051                }
1052                
1053                if(_modifiedEntities != 0) {
1054                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1055                        int[] _counts = _ps.executeBatch();
1056                        
1057                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1058                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1059                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1060                            }
1061                        }
1062                    } else {
1063                        _ps.executeBatch();
1064                    }
1065                    
1066                    _ps.clearBatch();
1067                    
1068                    pks.forEach((pk) -> {
1069                        session.getValueCache().remove(pk);
1070                    });
1071                }
1072            } catch (SQLException se) {
1073                throw new PersistenceDatabaseException(se);
1074            }
1075            
1076            pks.forEach((pk) -> {
1077                session.removed(pk, true);
1078            });
1079        }
1080    }
1081    
1082    @Override
1083    public void remove(Collection<PostalAddressLineDetailPK> pks)
1084            throws PersistenceDatabaseException {
1085        remove(ThreadSession.currentSession(), pks);
1086    }
1087    
1088    @Override
1089    public boolean validPK(Session session, PostalAddressLineDetailPK pk)
1090            throws PersistenceDatabaseException {
1091        boolean valid = false;
1092        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1093        ResultSet _rs = null;
1094        
1095        try {
1096            _ps.setLong(1, pk.getEntityId());
1097            
1098            _rs = _ps.executeQuery();
1099            if(_rs.next()) {
1100                long _count = _rs.getLong(1);
1101                if(_rs.wasNull())
1102                    _count = 0;
1103                
1104                if(_count == 1)
1105                    valid = true;
1106            }
1107        } catch (SQLException se) {
1108            throw new PersistenceDatabaseException(se);
1109        } finally {
1110            if(_rs != null) {
1111                try {
1112                    _rs.close();
1113                } catch (SQLException se) {
1114                    // do nothing
1115                }
1116            }
1117        }
1118        
1119        return valid;
1120    }
1121    
1122}