001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * ContactPostalAddressFactory.java
021 */
022
023package com.echothree.model.data.contact.server.factory;
024
025import com.echothree.model.data.contact.common.pk.ContactMechanismPK;
026import com.echothree.model.data.party.common.pk.PersonalTitlePK;
027import com.echothree.model.data.party.common.pk.NameSuffixPK;
028import com.echothree.model.data.geo.common.pk.GeoCodePK;
029
030import com.echothree.model.data.contact.server.entity.ContactMechanism;
031import com.echothree.model.data.party.server.entity.PersonalTitle;
032import com.echothree.model.data.party.server.entity.NameSuffix;
033import com.echothree.model.data.geo.server.entity.GeoCode;
034
035import com.echothree.model.data.contact.common.ContactPostalAddressConstants;
036import com.echothree.model.data.contact.common.pk.ContactPostalAddressPK;
037import com.echothree.model.data.contact.server.value.ContactPostalAddressValue;
038import com.echothree.model.data.contact.server.entity.ContactPostalAddress;
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 java.sql.PreparedStatement;
048import java.sql.ResultSet;
049import java.sql.SQLException;
050import java.sql.Types;
051import java.io.ByteArrayInputStream;
052import java.io.StringReader;
053import java.util.ArrayList;
054import java.util.Collection;
055import java.util.HashSet;
056import java.util.List;
057import java.util.Map;
058import java.util.Set;
059import javax.enterprise.context.ApplicationScoped;
060import javax.enterprise.inject.spi.CDI;
061import javax.inject.Inject;
062import org.slf4j.Logger;
063import org.slf4j.LoggerFactory;
064
065@ApplicationScoped
066public class ContactPostalAddressFactory
067        implements BaseFactory<ContactPostalAddressPK, ContactPostalAddress> {
068    
069    @Inject
070    Session session;
071    
072    //private static final Logger log = LoggerFactory.getLogger(ContactPostalAddressFactory.class);
073    
074    final private static String SQL_SELECT_READ_ONLY = "SELECT ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?";
075    final private static String SQL_SELECT_READ_WRITE = "SELECT ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ? FOR UPDATE";
076    final private static String SQL_INSERT = "INSERT INTO contactpostaladdresses (ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
077    final private static String SQL_UPDATE = "UPDATE contactpostaladdresses SET ctpa_cmch_contactmechanismid = ?, ctpa_pert_personaltitleid = ?, ctpa_firstname = ?, ctpa_firstnamesdx = ?, ctpa_middlename = ?, ctpa_middlenamesdx = ?, ctpa_lastname = ?, ctpa_lastnamesdx = ?, ctpa_nsfx_namesuffixid = ?, ctpa_companyname = ?, ctpa_attention = ?, ctpa_address1 = ?, ctpa_address2 = ?, ctpa_address3 = ?, ctpa_city = ?, ctpa_citygeocodeid = ?, ctpa_countygeocodeid = ?, ctpa_state = ?, ctpa_stategeocodeid = ?, ctpa_postalcode = ?, ctpa_postalcodegeocodeid = ?, ctpa_countrygeocodeid = ?, ctpa_iscommercial = ?, ctpa_fromtime = ?, ctpa_thrutime = ? WHERE ctpa_contactpostaladdressid = ?";
078    final private static String SQL_DELETE = "DELETE FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?";
079    final private static String SQL_VALID = "SELECT COUNT(*) FROM contactpostaladdresses WHERE ctpa_contactpostaladdressid = ?";
080    
081    final private static String PK_COLUMN = "ctpa_contactpostaladdressid";
082    final private static String ALL_COLUMNS = "ctpa_contactpostaladdressid, ctpa_cmch_contactmechanismid, ctpa_pert_personaltitleid, ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid, ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid, ctpa_countygeocodeid, ctpa_state, ctpa_stategeocodeid, ctpa_postalcode, ctpa_postalcodegeocodeid, ctpa_countrygeocodeid, ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime";
083    final public static String TABLE_NAME = "contactpostaladdresses";
084    
085    final public static String CTPA_CONTACTPOSTALADDRESSID = "ctpa_contactpostaladdressid";
086    final public static String CTPA_CMCH_CONTACTMECHANISMID = "ctpa_cmch_contactmechanismid";
087    final public static String CTPA_PERT_PERSONALTITLEID = "ctpa_pert_personaltitleid";
088    final public static String CTPA_FIRSTNAME = "ctpa_firstname";
089    final public static String CTPA_FIRSTNAMESDX = "ctpa_firstnamesdx";
090    final public static String CTPA_MIDDLENAME = "ctpa_middlename";
091    final public static String CTPA_MIDDLENAMESDX = "ctpa_middlenamesdx";
092    final public static String CTPA_LASTNAME = "ctpa_lastname";
093    final public static String CTPA_LASTNAMESDX = "ctpa_lastnamesdx";
094    final public static String CTPA_NSFX_NAMESUFFIXID = "ctpa_nsfx_namesuffixid";
095    final public static String CTPA_COMPANYNAME = "ctpa_companyname";
096    final public static String CTPA_ATTENTION = "ctpa_attention";
097    final public static String CTPA_ADDRESS1 = "ctpa_address1";
098    final public static String CTPA_ADDRESS2 = "ctpa_address2";
099    final public static String CTPA_ADDRESS3 = "ctpa_address3";
100    final public static String CTPA_CITY = "ctpa_city";
101    final public static String CTPA_CITYGEOCODEID = "ctpa_citygeocodeid";
102    final public static String CTPA_COUNTYGEOCODEID = "ctpa_countygeocodeid";
103    final public static String CTPA_STATE = "ctpa_state";
104    final public static String CTPA_STATEGEOCODEID = "ctpa_stategeocodeid";
105    final public static String CTPA_POSTALCODE = "ctpa_postalcode";
106    final public static String CTPA_POSTALCODEGEOCODEID = "ctpa_postalcodegeocodeid";
107    final public static String CTPA_COUNTRYGEOCODEID = "ctpa_countrygeocodeid";
108    final public static String CTPA_ISCOMMERCIAL = "ctpa_iscommercial";
109    final public static String CTPA_FROMTIME = "ctpa_fromtime";
110    final public static String CTPA_THRUTIME = "ctpa_thrutime";
111    
112    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ContactPostalAddressConstants.COMPONENT_VENDOR_NAME, ContactPostalAddressConstants.ENTITY_TYPE_NAME);
113    
114    /** Creates a new instance of ContactPostalAddressFactory */
115    protected ContactPostalAddressFactory() {
116        super();
117    }
118    
119    public static ContactPostalAddressFactory getInstance() {
120        return CDI.current().select(ContactPostalAddressFactory.class).get();
121    }
122    
123    @Override
124    public String getPKColumn() {
125        return PK_COLUMN;
126    }
127    
128    @Override
129    public String getAllColumns() {
130        return ALL_COLUMNS;
131    }
132    
133    @Override
134    public String getTableName() {
135        return TABLE_NAME;
136    }
137    
138    @Override
139    public String getComponentVendorName() {
140        return ContactPostalAddressConstants.COMPONENT_VENDOR_NAME;
141    }
142    
143    @Override
144    public String getEntityTypeName() {
145        return ContactPostalAddressConstants.ENTITY_TYPE_NAME;
146    }
147    
148    public PreparedStatement prepareStatement(String query) {
149        return session.prepareStatement(ContactPostalAddressFactory.class, query);
150    }
151    
152    public ContactPostalAddressPK getNextPK() {
153        return new ContactPostalAddressPK(entityIdGenerator.getNextEntityId());
154    }
155    
156    public Set<ContactPostalAddressPK> getPKsFromResultSetAsSet(ResultSet rs)
157            throws PersistenceDatabaseException {
158        Set<ContactPostalAddressPK> _result = new HashSet<>();
159        
160        try {
161            while(rs.next()) {
162                _result.add(getPKFromResultSet(rs));
163            }
164        } catch (SQLException se) {
165            throw new PersistenceDatabaseException(se);
166        }
167        
168        return _result;
169    }
170    
171    public java.util.List<ContactPostalAddressPK> getPKsFromResultSetAsList(ResultSet rs)
172            throws PersistenceDatabaseException {
173        java.util.List<ContactPostalAddressPK> _result = new ArrayList<>();
174        
175        try {
176            while(rs.next()) {
177                _result.add(getPKFromResultSet(rs));
178            }
179        } catch (SQLException se) {
180            throw new PersistenceDatabaseException(se);
181        }
182        
183        return _result;
184    }
185    
186    public ContactPostalAddressPK getPKFromResultSet(ResultSet rs)
187            throws PersistenceDatabaseException {
188        ContactPostalAddressPK _result;
189        
190        try {
191            long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID);
192            Long _entityId = rs.wasNull() ? null : ctpa_contactpostaladdressid;
193            
194            _result = new ContactPostalAddressPK(_entityId);
195        } catch (SQLException se) {
196            throw new PersistenceDatabaseException(se);
197        }
198        
199        return _result;
200    }
201    
202    public java.util.List<ContactPostalAddressValue> getValuesFromPKs(Collection<ContactPostalAddressPK> pks)
203            throws PersistenceDatabaseException {
204        java.util.List<ContactPostalAddressValue> _values = new ArrayList<>(pks.size());
205        
206        for(ContactPostalAddressPK _pk: pks) {
207            _values.add(getValueFromPK(_pk));
208        }
209        
210        return _values;
211    }
212    
213    public ContactPostalAddressValue getValueFromPK(ContactPostalAddressPK pk)
214            throws PersistenceDatabaseException {
215        ContactPostalAddressValue _value;
216        
217        // See if we already have the entity in the session cache
218        ContactPostalAddress _entity = (ContactPostalAddress)session.getEntity(pk);
219        if(_entity == null)
220            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getContactPostalAddressValue();
221        else
222            _value = _entity.getContactPostalAddressValue();
223        
224        return _value;
225    }
226    
227    public java.util.List<ContactPostalAddressValue> getValuesFromResultSet(ResultSet rs)
228            throws PersistenceDatabaseException {
229        java.util.List<ContactPostalAddressValue> _result = new ArrayList<>();
230        
231        try {
232            while(rs.next()) {
233                _result.add(getValueFromResultSet(rs));
234            }
235        } catch (SQLException se) {
236            throw new PersistenceDatabaseException(se);
237        }
238        
239        return _result;
240    }
241    
242    public ContactPostalAddressValue getValueFromResultSet(ResultSet rs)
243            throws PersistenceDatabaseException {
244        ContactPostalAddressValue _value;
245        
246        try {
247            Long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID);
248            ContactPostalAddressPK _pk = new ContactPostalAddressPK(ctpa_contactpostaladdressid);
249            
250            // See if we already have the entity in the session cache
251            ContactPostalAddress _entity = (ContactPostalAddress)session.getEntity(_pk);
252            
253            if(_entity == null) {
254                Long ctpa_cmch_contactmechanismid = rs.getLong(CTPA_CMCH_CONTACTMECHANISMID);
255                if(rs.wasNull())
256                    ctpa_cmch_contactmechanismid = null;
257                
258                Long ctpa_pert_personaltitleid = rs.getLong(CTPA_PERT_PERSONALTITLEID);
259                if(rs.wasNull())
260                    ctpa_pert_personaltitleid = null;
261                
262                String ctpa_firstname = rs.getString(CTPA_FIRSTNAME);
263                if(rs.wasNull())
264                    ctpa_firstname = null;
265                
266                String ctpa_firstnamesdx = rs.getString(CTPA_FIRSTNAMESDX);
267                if(rs.wasNull())
268                    ctpa_firstnamesdx = null;
269                
270                String ctpa_middlename = rs.getString(CTPA_MIDDLENAME);
271                if(rs.wasNull())
272                    ctpa_middlename = null;
273                
274                String ctpa_middlenamesdx = rs.getString(CTPA_MIDDLENAMESDX);
275                if(rs.wasNull())
276                    ctpa_middlenamesdx = null;
277                
278                String ctpa_lastname = rs.getString(CTPA_LASTNAME);
279                if(rs.wasNull())
280                    ctpa_lastname = null;
281                
282                String ctpa_lastnamesdx = rs.getString(CTPA_LASTNAMESDX);
283                if(rs.wasNull())
284                    ctpa_lastnamesdx = null;
285                
286                Long ctpa_nsfx_namesuffixid = rs.getLong(CTPA_NSFX_NAMESUFFIXID);
287                if(rs.wasNull())
288                    ctpa_nsfx_namesuffixid = null;
289                
290                String ctpa_companyname = rs.getString(CTPA_COMPANYNAME);
291                if(rs.wasNull())
292                    ctpa_companyname = null;
293                
294                String ctpa_attention = rs.getString(CTPA_ATTENTION);
295                if(rs.wasNull())
296                    ctpa_attention = null;
297                
298                String ctpa_address1 = rs.getString(CTPA_ADDRESS1);
299                if(rs.wasNull())
300                    ctpa_address1 = null;
301                
302                String ctpa_address2 = rs.getString(CTPA_ADDRESS2);
303                if(rs.wasNull())
304                    ctpa_address2 = null;
305                
306                String ctpa_address3 = rs.getString(CTPA_ADDRESS3);
307                if(rs.wasNull())
308                    ctpa_address3 = null;
309                
310                String ctpa_city = rs.getString(CTPA_CITY);
311                if(rs.wasNull())
312                    ctpa_city = null;
313                
314                Long ctpa_citygeocodeid = rs.getLong(CTPA_CITYGEOCODEID);
315                if(rs.wasNull())
316                    ctpa_citygeocodeid = null;
317                
318                Long ctpa_countygeocodeid = rs.getLong(CTPA_COUNTYGEOCODEID);
319                if(rs.wasNull())
320                    ctpa_countygeocodeid = null;
321                
322                String ctpa_state = rs.getString(CTPA_STATE);
323                if(rs.wasNull())
324                    ctpa_state = null;
325                
326                Long ctpa_stategeocodeid = rs.getLong(CTPA_STATEGEOCODEID);
327                if(rs.wasNull())
328                    ctpa_stategeocodeid = null;
329                
330                String ctpa_postalcode = rs.getString(CTPA_POSTALCODE);
331                if(rs.wasNull())
332                    ctpa_postalcode = null;
333                
334                Long ctpa_postalcodegeocodeid = rs.getLong(CTPA_POSTALCODEGEOCODEID);
335                if(rs.wasNull())
336                    ctpa_postalcodegeocodeid = null;
337                
338                Long ctpa_countrygeocodeid = rs.getLong(CTPA_COUNTRYGEOCODEID);
339                if(rs.wasNull())
340                    ctpa_countrygeocodeid = null;
341                
342                Boolean ctpa_iscommercial = rs.getInt(CTPA_ISCOMMERCIAL) == 1;
343                if(rs.wasNull())
344                    ctpa_iscommercial = null;
345                
346                Long ctpa_fromtime = rs.getLong(CTPA_FROMTIME);
347                if(rs.wasNull())
348                    ctpa_fromtime = null;
349                
350                Long ctpa_thrutime = rs.getLong(CTPA_THRUTIME);
351                if(rs.wasNull())
352                    ctpa_thrutime = null;
353                
354                _value = new ContactPostalAddressValue(_pk, new ContactMechanismPK(ctpa_cmch_contactmechanismid), new PersonalTitlePK(ctpa_pert_personaltitleid), ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, new NameSuffixPK(ctpa_nsfx_namesuffixid), ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, new GeoCodePK(ctpa_citygeocodeid), new GeoCodePK(ctpa_countygeocodeid), ctpa_state, new GeoCodePK(ctpa_stategeocodeid), ctpa_postalcode, new GeoCodePK(ctpa_postalcodegeocodeid), new GeoCodePK(ctpa_countrygeocodeid), ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime);
355            } else
356                _value = _entity.getContactPostalAddressValue();
357        } catch (SQLException se) {
358            throw new PersistenceDatabaseException(se);
359        }
360        
361        return _value;
362    }
363    
364    public java.util.List<ContactPostalAddress> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ContactPostalAddressPK> pks)
365            throws PersistenceDatabaseException {
366        java.util.List<ContactPostalAddress> _entities = new ArrayList<>(pks.size());
367        
368        for(ContactPostalAddressPK _pk: pks) {
369            _entities.add(getEntityFromPK(entityPermission, _pk));
370        }
371        
372        return _entities;
373    }
374    
375    public ContactPostalAddress getEntityFromValue(EntityPermission entityPermission, ContactPostalAddressValue value) {
376        return getEntityFromPK(entityPermission, value.getPrimaryKey());
377    }
378    
379    public ContactPostalAddress getEntityFromCache(ContactPostalAddressPK pk) {
380        ContactPostalAddressValue _value = (ContactPostalAddressValue)session.getValueCache().get(pk);
381    
382        return _value == null ? null : new ContactPostalAddress(_value, EntityPermission.READ_ONLY);
383    }
384    
385    public ContactPostalAddress getEntityFromPK(EntityPermission entityPermission, ContactPostalAddressPK pk)
386            throws PersistenceDatabaseException {
387        ContactPostalAddress _entity;
388        
389        // See if we already have the entity in the session cache
390        _entity = (ContactPostalAddress)session.getEntity(pk);
391        if(_entity != null) {
392            // If the requested permission is READ_WRITE, and the cached permission is
393            // READ_ONLY, then pretend that the cached object wasn't found, and create
394            // a new entity that is READ_WRITE.
395            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
396                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
397                    _entity = null;
398            }
399        }
400        
401        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
402            _entity = getEntityFromCache(pk);
403        }
404        
405        if(_entity == null) {
406            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
407            long _entityId = pk.getEntityId();
408            ResultSet _rs = null;
409            
410            try {
411                _ps.setLong(1, _entityId);
412                _rs = _ps.executeQuery();
413                if(_rs.next()) {
414                    _entity = getEntityFromResultSet(entityPermission, _rs);
415                }
416            } catch (SQLException se) {
417                throw new PersistenceDatabaseException(se);
418            } finally {
419                if(_rs != null) {
420                    try {
421                        _rs.close();
422                    } catch (SQLException se) {
423                        // do nothing
424                    }
425                }
426            }
427        }
428        
429        return _entity;
430    }
431    
432    public Set<ContactPostalAddressPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
433            throws PersistenceDatabaseException {
434        Set<ContactPostalAddressPK> _pks;
435        ResultSet _rs = null;
436        
437        try {
438            if(params.length != 0) {
439                Session.setQueryParams(ps, params);
440            }
441            
442            _rs = ps.executeQuery();
443            _pks = getPKsFromResultSetAsSet(_rs);
444            _rs.close();
445        } catch (SQLException se) {
446            throw new PersistenceDatabaseException(se);
447        } finally {
448            if(_rs != null) {
449                try {
450                    _rs.close();
451                } catch (SQLException se) {
452                    // do nothing
453                }
454            }
455        }
456        
457        return _pks;
458    }
459    
460    public java.util.List<ContactPostalAddressPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
461            throws PersistenceDatabaseException {
462        java.util.List<ContactPostalAddressPK> _pks;
463        ResultSet _rs = null;
464        
465        try {
466            if(params.length != 0) {
467                Session.setQueryParams(ps, params);
468            }
469            
470            _rs = ps.executeQuery();
471            _pks = getPKsFromResultSetAsList(_rs);
472            _rs.close();
473        } catch (SQLException se) {
474            throw new PersistenceDatabaseException(se);
475        } finally {
476            if(_rs != null) {
477                try {
478                    _rs.close();
479                } catch (SQLException se) {
480                    // do nothing
481                }
482            }
483        }
484        
485        return _pks;
486    }
487    
488    public ContactPostalAddressPK getPKFromQuery(PreparedStatement ps, final Object... params)
489            throws PersistenceDatabaseException {
490        ContactPostalAddressPK _pk = null;
491        ResultSet _rs = null;
492        
493        try {
494            if(params.length != 0) {
495                Session.setQueryParams(ps, params);
496            }
497            
498            _rs = ps.executeQuery();
499            if(_rs.next()) {
500                _pk = getPKFromResultSet(_rs);
501            }
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 _pk;
516    }
517    
518    public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
519            throws PersistenceDatabaseException {
520        PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission));
521        
522        return getEntitiesFromQuery(entityPermission, ps, params);
523    }
524    
525    public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
526            throws PersistenceDatabaseException {
527        PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission));
528        
529        return getEntitiesFromQuery(entityPermission, ps);
530    }
531    
532    public java.util.List<ContactPostalAddress> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
533            throws PersistenceDatabaseException {
534        java.util.List<ContactPostalAddress> _entities;
535        ResultSet _rs = null;
536        
537        try {
538            if(params.length != 0) {
539                Session.setQueryParams(ps, params);
540            }
541            
542            _rs = ps.executeQuery();
543            _entities = getEntitiesFromResultSet(entityPermission, _rs);
544            _rs.close();
545        } catch (SQLException se) {
546            throw new PersistenceDatabaseException(se);
547        } finally {
548            if(_rs != null) {
549                try {
550                    _rs.close();
551                } catch (SQLException se) {
552                    // do nothing
553                }
554            }
555        }
556        
557        return _entities;
558    }
559    
560    public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
561            throws PersistenceDatabaseException {
562        PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission));
563        
564        return getEntityFromQuery(entityPermission, ps, params);
565    }
566    
567    public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
568            throws PersistenceDatabaseException {
569        PreparedStatement ps = session.prepareStatement(ContactPostalAddressFactory.class, queryMap.get(entityPermission));
570        
571        return getEntityFromQuery(entityPermission, ps);
572    }
573    
574    public ContactPostalAddress getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
575            throws PersistenceDatabaseException {
576        ContactPostalAddress _entity = null;
577        ResultSet _rs = null;
578        
579        try {
580            if(params.length != 0) {
581                Session.setQueryParams(ps, params);
582            }
583            
584            _rs = ps.executeQuery();
585            if(_rs.next()) {
586                _entity = getEntityFromResultSet(entityPermission, _rs);
587            }
588            _rs.close();
589        } catch (SQLException se) {
590            throw new PersistenceDatabaseException(se);
591        } finally {
592            if(_rs != null) {
593                try {
594                    _rs.close();
595                } catch (SQLException se) {
596                    // do nothing
597                }
598            }
599        }
600        
601        return _entity;
602    }
603    
604    public java.util.List<ContactPostalAddress> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
605            throws PersistenceDatabaseException {
606        java.util.List<ContactPostalAddress> _result = new ArrayList<>();
607        
608        try {
609            while(rs.next()) {
610                _result.add(getEntityFromResultSet(entityPermission, rs));
611            }
612        } catch (SQLException se) {
613            throw new PersistenceDatabaseException(se);
614        }
615        
616        return _result;
617    }
618    
619    public ContactPostalAddress getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
620            throws PersistenceDatabaseException {
621        ContactPostalAddress _entity;
622        
623        try {
624            Long ctpa_contactpostaladdressid = rs.getLong(CTPA_CONTACTPOSTALADDRESSID);
625            ContactPostalAddressPK _pk = new ContactPostalAddressPK(ctpa_contactpostaladdressid);
626            
627            // See if we already have the entity in the session cache
628            _entity = (ContactPostalAddress)session.getEntity(_pk);
629            if(_entity != null) {
630                // If the requested permission is READ_WRITE, and the cached permission is
631                // READ_ONLY, then pretend that the cached object wasn't found, and create
632                // a new entity that is READ_WRITE.
633                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
634                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
635                        _entity = null;
636                }
637            }
638            boolean foundInSessionCache = _entity != null;
639            
640            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
641                _entity = getEntityFromCache(_pk);
642            }
643            
644            if(_entity == null) {
645                Long ctpa_cmch_contactmechanismid = rs.getLong(CTPA_CMCH_CONTACTMECHANISMID);
646                if(rs.wasNull())
647                    ctpa_cmch_contactmechanismid = null;
648                
649                Long ctpa_pert_personaltitleid = rs.getLong(CTPA_PERT_PERSONALTITLEID);
650                if(rs.wasNull())
651                    ctpa_pert_personaltitleid = null;
652                
653                String ctpa_firstname = rs.getString(CTPA_FIRSTNAME);
654                if(rs.wasNull())
655                    ctpa_firstname = null;
656                
657                String ctpa_firstnamesdx = rs.getString(CTPA_FIRSTNAMESDX);
658                if(rs.wasNull())
659                    ctpa_firstnamesdx = null;
660                
661                String ctpa_middlename = rs.getString(CTPA_MIDDLENAME);
662                if(rs.wasNull())
663                    ctpa_middlename = null;
664                
665                String ctpa_middlenamesdx = rs.getString(CTPA_MIDDLENAMESDX);
666                if(rs.wasNull())
667                    ctpa_middlenamesdx = null;
668                
669                String ctpa_lastname = rs.getString(CTPA_LASTNAME);
670                if(rs.wasNull())
671                    ctpa_lastname = null;
672                
673                String ctpa_lastnamesdx = rs.getString(CTPA_LASTNAMESDX);
674                if(rs.wasNull())
675                    ctpa_lastnamesdx = null;
676                
677                Long ctpa_nsfx_namesuffixid = rs.getLong(CTPA_NSFX_NAMESUFFIXID);
678                if(rs.wasNull())
679                    ctpa_nsfx_namesuffixid = null;
680                
681                String ctpa_companyname = rs.getString(CTPA_COMPANYNAME);
682                if(rs.wasNull())
683                    ctpa_companyname = null;
684                
685                String ctpa_attention = rs.getString(CTPA_ATTENTION);
686                if(rs.wasNull())
687                    ctpa_attention = null;
688                
689                String ctpa_address1 = rs.getString(CTPA_ADDRESS1);
690                if(rs.wasNull())
691                    ctpa_address1 = null;
692                
693                String ctpa_address2 = rs.getString(CTPA_ADDRESS2);
694                if(rs.wasNull())
695                    ctpa_address2 = null;
696                
697                String ctpa_address3 = rs.getString(CTPA_ADDRESS3);
698                if(rs.wasNull())
699                    ctpa_address3 = null;
700                
701                String ctpa_city = rs.getString(CTPA_CITY);
702                if(rs.wasNull())
703                    ctpa_city = null;
704                
705                Long ctpa_citygeocodeid = rs.getLong(CTPA_CITYGEOCODEID);
706                if(rs.wasNull())
707                    ctpa_citygeocodeid = null;
708                
709                Long ctpa_countygeocodeid = rs.getLong(CTPA_COUNTYGEOCODEID);
710                if(rs.wasNull())
711                    ctpa_countygeocodeid = null;
712                
713                String ctpa_state = rs.getString(CTPA_STATE);
714                if(rs.wasNull())
715                    ctpa_state = null;
716                
717                Long ctpa_stategeocodeid = rs.getLong(CTPA_STATEGEOCODEID);
718                if(rs.wasNull())
719                    ctpa_stategeocodeid = null;
720                
721                String ctpa_postalcode = rs.getString(CTPA_POSTALCODE);
722                if(rs.wasNull())
723                    ctpa_postalcode = null;
724                
725                Long ctpa_postalcodegeocodeid = rs.getLong(CTPA_POSTALCODEGEOCODEID);
726                if(rs.wasNull())
727                    ctpa_postalcodegeocodeid = null;
728                
729                Long ctpa_countrygeocodeid = rs.getLong(CTPA_COUNTRYGEOCODEID);
730                if(rs.wasNull())
731                    ctpa_countrygeocodeid = null;
732                
733                Boolean ctpa_iscommercial = rs.getInt(CTPA_ISCOMMERCIAL) == 1;
734                if(rs.wasNull())
735                    ctpa_iscommercial = null;
736                
737                Long ctpa_fromtime = rs.getLong(CTPA_FROMTIME);
738                if(rs.wasNull())
739                    ctpa_fromtime = null;
740                
741                Long ctpa_thrutime = rs.getLong(CTPA_THRUTIME);
742                if(rs.wasNull())
743                    ctpa_thrutime = null;
744                
745                ContactPostalAddressValue _value = new ContactPostalAddressValue(_pk, ctpa_cmch_contactmechanismid == null? null: new ContactMechanismPK(ctpa_cmch_contactmechanismid), ctpa_pert_personaltitleid == null? null: new PersonalTitlePK(ctpa_pert_personaltitleid), ctpa_firstname, ctpa_firstnamesdx, ctpa_middlename, ctpa_middlenamesdx, ctpa_lastname, ctpa_lastnamesdx, ctpa_nsfx_namesuffixid == null? null: new NameSuffixPK(ctpa_nsfx_namesuffixid), ctpa_companyname, ctpa_attention, ctpa_address1, ctpa_address2, ctpa_address3, ctpa_city, ctpa_citygeocodeid == null? null: new GeoCodePK(ctpa_citygeocodeid), ctpa_countygeocodeid == null? null: new GeoCodePK(ctpa_countygeocodeid), ctpa_state, ctpa_stategeocodeid == null? null: new GeoCodePK(ctpa_stategeocodeid), ctpa_postalcode, ctpa_postalcodegeocodeid == null? null: new GeoCodePK(ctpa_postalcodegeocodeid), ctpa_countrygeocodeid == null? null: new GeoCodePK(ctpa_countrygeocodeid), ctpa_iscommercial, ctpa_fromtime, ctpa_thrutime);
746                _entity = new ContactPostalAddress(_value, entityPermission);
747            }
748            
749            if(!foundInSessionCache) {
750                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
751                    session.putReadOnlyEntity(_pk, _entity);
752                    session.getValueCache().put(_entity.getContactPostalAddressValue());
753                } else {
754                    session.putReadWriteEntity(_pk, _entity);
755                }
756            }
757        } catch (SQLException se) {
758            throw new PersistenceDatabaseException(se);
759        }
760        
761        return _entity;
762    }
763    
764    public ContactPostalAddress create(ContactMechanism contactMechanism, PersonalTitle personalTitle, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffix nameSuffix, String companyName, String attention, String address1, String address2, String address3, String city, GeoCode cityGeoCode, GeoCode countyGeoCode, String state, GeoCode stateGeoCode, String postalCode, GeoCode postalCodeGeoCode, GeoCode countryGeoCode, Boolean isCommercial, Long fromTime, Long thruTime)
765            throws PersistenceDatabaseException, PersistenceNotNullException {
766        return create(contactMechanism == null ? null : contactMechanism.getPrimaryKey(), personalTitle == null ? null : personalTitle.getPrimaryKey(), firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffix == null ? null : nameSuffix.getPrimaryKey(), companyName, attention, address1, address2, address3, city, cityGeoCode == null ? null : cityGeoCode.getPrimaryKey(), countyGeoCode == null ? null : countyGeoCode.getPrimaryKey(), state, stateGeoCode == null ? null : stateGeoCode.getPrimaryKey(), postalCode, postalCodeGeoCode == null ? null : postalCodeGeoCode.getPrimaryKey(), countryGeoCode == null ? null : countryGeoCode.getPrimaryKey(), isCommercial, fromTime, thruTime);
767    }
768    
769    private void bindForCreate(PreparedStatement _ps, ContactPostalAddressValue _value)
770            throws SQLException {
771        _ps.setLong(1, _value.getEntityId());
772        
773        ContactMechanismPK ctpa_cmch_contactmechanismid = _value.getContactMechanismPK();
774        if(ctpa_cmch_contactmechanismid == null)
775            _ps.setNull(2, Types.BIGINT);
776        else
777            _ps.setLong(2, ctpa_cmch_contactmechanismid.getEntityId());
778            
779        PersonalTitlePK ctpa_pert_personaltitleid = _value.getPersonalTitlePK();
780        if(ctpa_pert_personaltitleid == null)
781            _ps.setNull(3, Types.BIGINT);
782        else
783            _ps.setLong(3, ctpa_pert_personaltitleid.getEntityId());
784            
785        String ctpa_firstname = _value.getFirstName();
786        if(ctpa_firstname == null)
787            _ps.setNull(4, Types.VARCHAR);
788        else
789            _ps.setString(4, ctpa_firstname);
790            
791        String ctpa_firstnamesdx = _value.getFirstNameSdx();
792        if(ctpa_firstnamesdx == null)
793            _ps.setNull(5, Types.VARCHAR);
794        else
795            _ps.setString(5, ctpa_firstnamesdx);
796            
797        String ctpa_middlename = _value.getMiddleName();
798        if(ctpa_middlename == null)
799            _ps.setNull(6, Types.VARCHAR);
800        else
801            _ps.setString(6, ctpa_middlename);
802            
803        String ctpa_middlenamesdx = _value.getMiddleNameSdx();
804        if(ctpa_middlenamesdx == null)
805            _ps.setNull(7, Types.VARCHAR);
806        else
807            _ps.setString(7, ctpa_middlenamesdx);
808            
809        String ctpa_lastname = _value.getLastName();
810        if(ctpa_lastname == null)
811            _ps.setNull(8, Types.VARCHAR);
812        else
813            _ps.setString(8, ctpa_lastname);
814            
815        String ctpa_lastnamesdx = _value.getLastNameSdx();
816        if(ctpa_lastnamesdx == null)
817            _ps.setNull(9, Types.VARCHAR);
818        else
819            _ps.setString(9, ctpa_lastnamesdx);
820            
821        NameSuffixPK ctpa_nsfx_namesuffixid = _value.getNameSuffixPK();
822        if(ctpa_nsfx_namesuffixid == null)
823            _ps.setNull(10, Types.BIGINT);
824        else
825            _ps.setLong(10, ctpa_nsfx_namesuffixid.getEntityId());
826            
827        String ctpa_companyname = _value.getCompanyName();
828        if(ctpa_companyname == null)
829            _ps.setNull(11, Types.VARCHAR);
830        else
831            _ps.setString(11, ctpa_companyname);
832            
833        String ctpa_attention = _value.getAttention();
834        if(ctpa_attention == null)
835            _ps.setNull(12, Types.VARCHAR);
836        else
837            _ps.setString(12, ctpa_attention);
838            
839        String ctpa_address1 = _value.getAddress1();
840        if(ctpa_address1 == null)
841            _ps.setNull(13, Types.VARCHAR);
842        else
843            _ps.setString(13, ctpa_address1);
844            
845        String ctpa_address2 = _value.getAddress2();
846        if(ctpa_address2 == null)
847            _ps.setNull(14, Types.VARCHAR);
848        else
849            _ps.setString(14, ctpa_address2);
850            
851        String ctpa_address3 = _value.getAddress3();
852        if(ctpa_address3 == null)
853            _ps.setNull(15, Types.VARCHAR);
854        else
855            _ps.setString(15, ctpa_address3);
856            
857        String ctpa_city = _value.getCity();
858        if(ctpa_city == null)
859            _ps.setNull(16, Types.VARCHAR);
860        else
861            _ps.setString(16, ctpa_city);
862            
863        GeoCodePK ctpa_citygeocodeid = _value.getCityGeoCodePK();
864        if(ctpa_citygeocodeid == null)
865            _ps.setNull(17, Types.BIGINT);
866        else
867            _ps.setLong(17, ctpa_citygeocodeid.getEntityId());
868            
869        GeoCodePK ctpa_countygeocodeid = _value.getCountyGeoCodePK();
870        if(ctpa_countygeocodeid == null)
871            _ps.setNull(18, Types.BIGINT);
872        else
873            _ps.setLong(18, ctpa_countygeocodeid.getEntityId());
874            
875        String ctpa_state = _value.getState();
876        if(ctpa_state == null)
877            _ps.setNull(19, Types.VARCHAR);
878        else
879            _ps.setString(19, ctpa_state);
880            
881        GeoCodePK ctpa_stategeocodeid = _value.getStateGeoCodePK();
882        if(ctpa_stategeocodeid == null)
883            _ps.setNull(20, Types.BIGINT);
884        else
885            _ps.setLong(20, ctpa_stategeocodeid.getEntityId());
886            
887        String ctpa_postalcode = _value.getPostalCode();
888        if(ctpa_postalcode == null)
889            _ps.setNull(21, Types.VARCHAR);
890        else
891            _ps.setString(21, ctpa_postalcode);
892            
893        GeoCodePK ctpa_postalcodegeocodeid = _value.getPostalCodeGeoCodePK();
894        if(ctpa_postalcodegeocodeid == null)
895            _ps.setNull(22, Types.BIGINT);
896        else
897            _ps.setLong(22, ctpa_postalcodegeocodeid.getEntityId());
898            
899        GeoCodePK ctpa_countrygeocodeid = _value.getCountryGeoCodePK();
900        if(ctpa_countrygeocodeid == null)
901            _ps.setNull(23, Types.BIGINT);
902        else
903            _ps.setLong(23, ctpa_countrygeocodeid.getEntityId());
904            
905        Boolean ctpa_iscommercial = _value.getIsCommercial();
906        if(ctpa_iscommercial == null)
907            _ps.setNull(24, Types.BIT);
908        else
909            _ps.setInt(24, ctpa_iscommercial? 1: 0);
910            
911        Long ctpa_fromtime = _value.getFromTime();
912        if(ctpa_fromtime == null)
913            _ps.setNull(25, Types.BIGINT);
914        else
915            _ps.setLong(25, ctpa_fromtime);
916            
917        Long ctpa_thrutime = _value.getThruTime();
918        if(ctpa_thrutime == null)
919            _ps.setNull(26, Types.BIGINT);
920        else
921            _ps.setLong(26, ctpa_thrutime);
922            
923    }
924    
925    public ContactPostalAddress create(ContactMechanismPK contactMechanismPK, PersonalTitlePK personalTitlePK, String firstName, String firstNameSdx, String middleName, String middleNameSdx, String lastName, String lastNameSdx, NameSuffixPK nameSuffixPK, String companyName, String attention, String address1, String address2, String address3, String city, GeoCodePK cityGeoCodePK, GeoCodePK countyGeoCodePK, String state, GeoCodePK stateGeoCodePK, String postalCode, GeoCodePK postalCodeGeoCodePK, GeoCodePK countryGeoCodePK, Boolean isCommercial, Long fromTime, Long thruTime)
926            throws PersistenceDatabaseException, PersistenceNotNullException {
927        ContactPostalAddressPK _pk = getNextPK();
928        ContactPostalAddressValue _value = new ContactPostalAddressValue(_pk, contactMechanismPK, personalTitlePK, firstName, firstNameSdx, middleName, middleNameSdx, lastName, lastNameSdx, nameSuffixPK, companyName, attention, address1, address2, address3, city, cityGeoCodePK, countyGeoCodePK, state, stateGeoCodePK, postalCode, postalCodeGeoCodePK, countryGeoCodePK, isCommercial, fromTime, thruTime);
929        
930        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
931        
932        try {
933            bindForCreate(_ps, _value);
934            
935            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
936                int _count = _ps.executeUpdate();
937                
938                if(_count != 1) {
939                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
940                }
941            } else {
942                 _ps.executeUpdate();
943            }
944            
945            session.getValueCache().put(_value);
946        } catch (SQLException se) {
947            throw new PersistenceDatabaseException(se);
948        }
949        
950        ContactPostalAddress _entity = new ContactPostalAddress(_value, EntityPermission.READ_ONLY);
951        session.putReadOnlyEntity(_pk, _entity);
952        
953        return _entity;
954    }
955    
956    public void create(Collection<ContactPostalAddressValue> _values)
957            throws PersistenceDatabaseException, PersistenceNotNullException {
958        int _size = _values.size();
959        
960        if(_size > 0) {
961            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
962            List<ContactPostalAddressValue> _cacheValues = new ArrayList<>(_size);
963            
964            try {
965                for(ContactPostalAddressValue _value : _values) {
966                    _value.setEntityId(entityIdGenerator.getNextEntityId());
967                    bindForCreate(_ps, _value);
968                    
969                    _ps.addBatch();
970                    
971                    _cacheValues.add(_value);
972                }
973                
974                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
975                    int[] _counts = _ps.executeBatch();
976                    
977                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
978                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
979                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
980                        }
981                    }
982                } else {
983                     _ps.executeBatch();
984                }
985                
986                _ps.clearBatch();
987            } catch (SQLException se) {
988                throw new PersistenceDatabaseException(se);
989            }
990            
991            _cacheValues.forEach((_cacheValue) -> {
992                ContactPostalAddress _cacheEntity = new ContactPostalAddress(_cacheValue, EntityPermission.READ_ONLY);
993                
994                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
995            });
996        }
997    }
998    
999    private boolean bindForStore(PreparedStatement _ps, ContactPostalAddressValue _value)
1000            throws SQLException {
1001        boolean _hasBeenModified = _value.hasBeenModified();
1002        
1003        if(_hasBeenModified) {
1004            ContactMechanismPK ctpa_cmch_contactmechanismid = _value.getContactMechanismPK();
1005            if(ctpa_cmch_contactmechanismid == null)
1006                _ps.setNull(1, Types.BIGINT);
1007            else
1008                _ps.setLong(1, ctpa_cmch_contactmechanismid.getEntityId());
1009            
1010            PersonalTitlePK ctpa_pert_personaltitleid = _value.getPersonalTitlePK();
1011            if(ctpa_pert_personaltitleid == null)
1012                _ps.setNull(2, Types.BIGINT);
1013            else
1014                _ps.setLong(2, ctpa_pert_personaltitleid.getEntityId());
1015            
1016            String ctpa_firstname = _value.getFirstName();
1017            if(ctpa_firstname == null)
1018                _ps.setNull(3, Types.VARCHAR);
1019            else
1020                _ps.setString(3, ctpa_firstname);
1021            
1022            String ctpa_firstnamesdx = _value.getFirstNameSdx();
1023            if(ctpa_firstnamesdx == null)
1024                _ps.setNull(4, Types.VARCHAR);
1025            else
1026                _ps.setString(4, ctpa_firstnamesdx);
1027            
1028            String ctpa_middlename = _value.getMiddleName();
1029            if(ctpa_middlename == null)
1030                _ps.setNull(5, Types.VARCHAR);
1031            else
1032                _ps.setString(5, ctpa_middlename);
1033            
1034            String ctpa_middlenamesdx = _value.getMiddleNameSdx();
1035            if(ctpa_middlenamesdx == null)
1036                _ps.setNull(6, Types.VARCHAR);
1037            else
1038                _ps.setString(6, ctpa_middlenamesdx);
1039            
1040            String ctpa_lastname = _value.getLastName();
1041            if(ctpa_lastname == null)
1042                _ps.setNull(7, Types.VARCHAR);
1043            else
1044                _ps.setString(7, ctpa_lastname);
1045            
1046            String ctpa_lastnamesdx = _value.getLastNameSdx();
1047            if(ctpa_lastnamesdx == null)
1048                _ps.setNull(8, Types.VARCHAR);
1049            else
1050                _ps.setString(8, ctpa_lastnamesdx);
1051            
1052            NameSuffixPK ctpa_nsfx_namesuffixid = _value.getNameSuffixPK();
1053            if(ctpa_nsfx_namesuffixid == null)
1054                _ps.setNull(9, Types.BIGINT);
1055            else
1056                _ps.setLong(9, ctpa_nsfx_namesuffixid.getEntityId());
1057            
1058            String ctpa_companyname = _value.getCompanyName();
1059            if(ctpa_companyname == null)
1060                _ps.setNull(10, Types.VARCHAR);
1061            else
1062                _ps.setString(10, ctpa_companyname);
1063            
1064            String ctpa_attention = _value.getAttention();
1065            if(ctpa_attention == null)
1066                _ps.setNull(11, Types.VARCHAR);
1067            else
1068                _ps.setString(11, ctpa_attention);
1069            
1070            String ctpa_address1 = _value.getAddress1();
1071            if(ctpa_address1 == null)
1072                _ps.setNull(12, Types.VARCHAR);
1073            else
1074                _ps.setString(12, ctpa_address1);
1075            
1076            String ctpa_address2 = _value.getAddress2();
1077            if(ctpa_address2 == null)
1078                _ps.setNull(13, Types.VARCHAR);
1079            else
1080                _ps.setString(13, ctpa_address2);
1081            
1082            String ctpa_address3 = _value.getAddress3();
1083            if(ctpa_address3 == null)
1084                _ps.setNull(14, Types.VARCHAR);
1085            else
1086                _ps.setString(14, ctpa_address3);
1087            
1088            String ctpa_city = _value.getCity();
1089            if(ctpa_city == null)
1090                _ps.setNull(15, Types.VARCHAR);
1091            else
1092                _ps.setString(15, ctpa_city);
1093            
1094            GeoCodePK ctpa_citygeocodeid = _value.getCityGeoCodePK();
1095            if(ctpa_citygeocodeid == null)
1096                _ps.setNull(16, Types.BIGINT);
1097            else
1098                _ps.setLong(16, ctpa_citygeocodeid.getEntityId());
1099            
1100            GeoCodePK ctpa_countygeocodeid = _value.getCountyGeoCodePK();
1101            if(ctpa_countygeocodeid == null)
1102                _ps.setNull(17, Types.BIGINT);
1103            else
1104                _ps.setLong(17, ctpa_countygeocodeid.getEntityId());
1105            
1106            String ctpa_state = _value.getState();
1107            if(ctpa_state == null)
1108                _ps.setNull(18, Types.VARCHAR);
1109            else
1110                _ps.setString(18, ctpa_state);
1111            
1112            GeoCodePK ctpa_stategeocodeid = _value.getStateGeoCodePK();
1113            if(ctpa_stategeocodeid == null)
1114                _ps.setNull(19, Types.BIGINT);
1115            else
1116                _ps.setLong(19, ctpa_stategeocodeid.getEntityId());
1117            
1118            String ctpa_postalcode = _value.getPostalCode();
1119            if(ctpa_postalcode == null)
1120                _ps.setNull(20, Types.VARCHAR);
1121            else
1122                _ps.setString(20, ctpa_postalcode);
1123            
1124            GeoCodePK ctpa_postalcodegeocodeid = _value.getPostalCodeGeoCodePK();
1125            if(ctpa_postalcodegeocodeid == null)
1126                _ps.setNull(21, Types.BIGINT);
1127            else
1128                _ps.setLong(21, ctpa_postalcodegeocodeid.getEntityId());
1129            
1130            GeoCodePK ctpa_countrygeocodeid = _value.getCountryGeoCodePK();
1131            if(ctpa_countrygeocodeid == null)
1132                _ps.setNull(22, Types.BIGINT);
1133            else
1134                _ps.setLong(22, ctpa_countrygeocodeid.getEntityId());
1135            
1136            Boolean ctpa_iscommercial = _value.getIsCommercial();
1137            if(ctpa_iscommercial == null)
1138                _ps.setNull(23, Types.BIT);
1139            else
1140                _ps.setInt(23, ctpa_iscommercial? 1: 0);
1141            
1142            Long ctpa_fromtime = _value.getFromTime();
1143            if(ctpa_fromtime == null)
1144                _ps.setNull(24, Types.BIGINT);
1145            else
1146                _ps.setLong(24, ctpa_fromtime);
1147            
1148            Long ctpa_thrutime = _value.getThruTime();
1149            if(ctpa_thrutime == null)
1150                _ps.setNull(25, Types.BIGINT);
1151            else
1152                _ps.setLong(25, ctpa_thrutime);
1153            
1154            _ps.setLong(26, _value.getPrimaryKey().getEntityId());
1155            
1156            _value.clearHasBeenModified();
1157        }
1158        
1159        return _hasBeenModified;
1160    }
1161    
1162    @Override
1163    public void store(ContactPostalAddress entity)
1164            throws PersistenceDatabaseException {
1165        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1166        
1167        try {
1168            ContactPostalAddressValue _value = entity.getContactPostalAddressValue();
1169            
1170            if(bindForStore(_ps, _value)) {
1171                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1172                    int _count = _ps.executeUpdate();
1173                    
1174                    if(_count != 1) {
1175                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1176                    }
1177                } else {
1178                     _ps.executeUpdate();
1179                }
1180                
1181                session.getValueCache().put(_value);
1182            }
1183        } catch (SQLException se) {
1184            throw new PersistenceDatabaseException(se);
1185        }
1186    }
1187    
1188    @Override
1189    public void store(Collection<ContactPostalAddress> entities)
1190            throws PersistenceDatabaseException {
1191        if(entities.size() > 0) {
1192            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1193            int _modifiedEntities = 0;
1194            
1195            try {
1196                for(ContactPostalAddress entity : entities) {
1197                    if(bindForStore(_ps, entity.getContactPostalAddressValue())) {
1198                        _ps.addBatch();
1199                        _modifiedEntities++;
1200                    }
1201                }
1202                
1203                if(_modifiedEntities != 0) {
1204                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1205                        int[] _counts = _ps.executeBatch();
1206                        
1207                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1208                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1209                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1210                            }
1211                        }
1212                    } else {
1213                         _ps.executeBatch();
1214                    }
1215                    
1216                    _ps.clearBatch();
1217                    
1218                    entities.forEach((entity) -> {
1219                        session.getValueCache().put(entity.getContactPostalAddressValue());
1220                    });
1221                }
1222            } catch (SQLException se) {
1223                throw new PersistenceDatabaseException(se);
1224            }
1225        }
1226    }
1227    
1228    @Override
1229    public void remove(ContactPostalAddress entity)
1230            throws PersistenceDatabaseException {
1231        remove(entity.getPrimaryKey());
1232    }
1233    
1234    @Override
1235    public void remove(ContactPostalAddressPK pk)
1236            throws PersistenceDatabaseException {
1237        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1238        long _entityId = pk.getEntityId();
1239        
1240        try {
1241            _ps.setLong(1, _entityId);
1242            
1243            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1244                int _count = _ps.executeUpdate();
1245                
1246                if(_count != 1) {
1247                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1248                }
1249            } else {
1250                 _ps.executeUpdate();
1251            }
1252            
1253            session.getValueCache().remove(pk);
1254        } catch (SQLException se) {
1255            throw new PersistenceDatabaseException(se);
1256        }
1257        
1258        session.removed(pk, false);
1259    }
1260    
1261    @Override
1262    public void remove(Collection<ContactPostalAddressPK> pks)
1263            throws PersistenceDatabaseException {
1264        if(pks.size() > 0) {
1265            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1266            int _modifiedEntities = 0;
1267            
1268            try {
1269                for(ContactPostalAddressPK pk : pks) {
1270                    long _entityId = pk.getEntityId();
1271                    
1272                    _ps.setLong(1, _entityId);
1273                    
1274                    _ps.addBatch();
1275                    _modifiedEntities++;
1276                }
1277                
1278                if(_modifiedEntities != 0) {
1279                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1280                        int[] _counts = _ps.executeBatch();
1281                        
1282                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1283                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1284                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1285                            }
1286                        }
1287                    } else {
1288                        _ps.executeBatch();
1289                    }
1290                    
1291                    _ps.clearBatch();
1292                    
1293                    pks.forEach((pk) -> {
1294                        session.getValueCache().remove(pk);
1295                    });
1296                }
1297            } catch (SQLException se) {
1298                throw new PersistenceDatabaseException(se);
1299            }
1300            
1301            pks.forEach((pk) -> {
1302                session.removed(pk, true);
1303            });
1304        }
1305    }
1306    
1307    @Override
1308    public boolean validPK(ContactPostalAddressPK pk)
1309            throws PersistenceDatabaseException {
1310        boolean valid = false;
1311        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1312        ResultSet _rs = null;
1313        
1314        try {
1315            _ps.setLong(1, pk.getEntityId());
1316            
1317            _rs = _ps.executeQuery();
1318            if(_rs.next()) {
1319                long _count = _rs.getLong(1);
1320                if(_rs.wasNull())
1321                    _count = 0;
1322                
1323                if(_count == 1)
1324                    valid = true;
1325            }
1326        } catch (SQLException se) {
1327            throw new PersistenceDatabaseException(se);
1328        } finally {
1329            if(_rs != null) {
1330                try {
1331                    _rs.close();
1332                } catch (SQLException se) {
1333                    // do nothing
1334                }
1335            }
1336        }
1337        
1338        return valid;
1339    }
1340    
1341}