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 * GeoCodeCountryFactory.java
021 */
022
023package com.echothree.model.data.geo.server.factory;
024
025import com.echothree.model.data.geo.common.pk.GeoCodePK;
026import com.echothree.model.data.contact.common.pk.PostalAddressFormatPK;
027
028import com.echothree.model.data.geo.server.entity.GeoCode;
029import com.echothree.model.data.contact.server.entity.PostalAddressFormat;
030
031import com.echothree.model.data.geo.common.GeoCodeCountryConstants;
032import com.echothree.model.data.geo.common.pk.GeoCodeCountryPK;
033import com.echothree.model.data.geo.server.value.GeoCodeCountryValue;
034import com.echothree.model.data.geo.server.entity.GeoCodeCountry;
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 java.sql.PreparedStatement;
044import java.sql.ResultSet;
045import java.sql.SQLException;
046import java.sql.Types;
047import java.io.ByteArrayInputStream;
048import java.io.StringReader;
049import java.util.ArrayList;
050import java.util.Collection;
051import java.util.HashSet;
052import java.util.List;
053import java.util.Map;
054import java.util.Set;
055import javax.enterprise.context.ApplicationScoped;
056import javax.enterprise.inject.spi.CDI;
057import javax.inject.Inject;
058import org.slf4j.Logger;
059import org.slf4j.LoggerFactory;
060
061@ApplicationScoped
062public class GeoCodeCountryFactory
063        implements BaseFactory<GeoCodeCountryPK, GeoCodeCountry> {
064    
065    @Inject
066    Session session;
067    
068    //private static final Logger log = LoggerFactory.getLogger(GeoCodeCountryFactory.class);
069    
070    final private static String SQL_SELECT_READ_ONLY = "SELECT geoc_geocodecountryid, geoc_geo_geocodeid, geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, geoc_pstafmt_postaladdressformatid, geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime FROM geocodecountries WHERE geoc_geocodecountryid = ?";
071    final private static String SQL_SELECT_READ_WRITE = "SELECT geoc_geocodecountryid, geoc_geo_geocodeid, geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, geoc_pstafmt_postaladdressformatid, geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime FROM geocodecountries WHERE geoc_geocodecountryid = ? FOR UPDATE";
072    final private static String SQL_INSERT = "INSERT INTO geocodecountries (geoc_geocodecountryid, geoc_geo_geocodeid, geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, geoc_pstafmt_postaladdressformatid, geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
073    final private static String SQL_UPDATE = "UPDATE geocodecountries SET geoc_geo_geocodeid = ?, geoc_telephonecode = ?, geoc_areacodepattern = ?, geoc_areacoderequired = ?, geoc_areacodeexample = ?, geoc_telephonenumberpattern = ?, geoc_telephonenumberexample = ?, geoc_pstafmt_postaladdressformatid = ?, geoc_cityrequired = ?, geoc_citygeocoderequired = ?, geoc_staterequired = ?, geoc_stategeocoderequired = ?, geoc_postalcodepattern = ?, geoc_postalcoderequired = ?, geoc_postalcodegeocoderequired = ?, geoc_postalcodelength = ?, geoc_postalcodegeocodelength = ?, geoc_postalcodeexample = ?, geoc_fromtime = ?, geoc_thrutime = ? WHERE geoc_geocodecountryid = ?";
074    final private static String SQL_DELETE = "DELETE FROM geocodecountries WHERE geoc_geocodecountryid = ?";
075    final private static String SQL_VALID = "SELECT COUNT(*) FROM geocodecountries WHERE geoc_geocodecountryid = ?";
076    
077    final private static String PK_COLUMN = "geoc_geocodecountryid";
078    final private static String ALL_COLUMNS = "geoc_geocodecountryid, geoc_geo_geocodeid, geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, geoc_pstafmt_postaladdressformatid, geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime";
079    final public static String TABLE_NAME = "geocodecountries";
080    
081    final public static String GEOC_GEOCODECOUNTRYID = "geoc_geocodecountryid";
082    final public static String GEOC_GEO_GEOCODEID = "geoc_geo_geocodeid";
083    final public static String GEOC_TELEPHONECODE = "geoc_telephonecode";
084    final public static String GEOC_AREACODEPATTERN = "geoc_areacodepattern";
085    final public static String GEOC_AREACODEREQUIRED = "geoc_areacoderequired";
086    final public static String GEOC_AREACODEEXAMPLE = "geoc_areacodeexample";
087    final public static String GEOC_TELEPHONENUMBERPATTERN = "geoc_telephonenumberpattern";
088    final public static String GEOC_TELEPHONENUMBEREXAMPLE = "geoc_telephonenumberexample";
089    final public static String GEOC_PSTAFMT_POSTALADDRESSFORMATID = "geoc_pstafmt_postaladdressformatid";
090    final public static String GEOC_CITYREQUIRED = "geoc_cityrequired";
091    final public static String GEOC_CITYGEOCODEREQUIRED = "geoc_citygeocoderequired";
092    final public static String GEOC_STATEREQUIRED = "geoc_staterequired";
093    final public static String GEOC_STATEGEOCODEREQUIRED = "geoc_stategeocoderequired";
094    final public static String GEOC_POSTALCODEPATTERN = "geoc_postalcodepattern";
095    final public static String GEOC_POSTALCODEREQUIRED = "geoc_postalcoderequired";
096    final public static String GEOC_POSTALCODEGEOCODEREQUIRED = "geoc_postalcodegeocoderequired";
097    final public static String GEOC_POSTALCODELENGTH = "geoc_postalcodelength";
098    final public static String GEOC_POSTALCODEGEOCODELENGTH = "geoc_postalcodegeocodelength";
099    final public static String GEOC_POSTALCODEEXAMPLE = "geoc_postalcodeexample";
100    final public static String GEOC_FROMTIME = "geoc_fromtime";
101    final public static String GEOC_THRUTIME = "geoc_thrutime";
102    
103    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(GeoCodeCountryConstants.COMPONENT_VENDOR_NAME, GeoCodeCountryConstants.ENTITY_TYPE_NAME);
104    
105    /** Creates a new instance of GeoCodeCountryFactory */
106    protected GeoCodeCountryFactory() {
107        super();
108    }
109    
110    public static GeoCodeCountryFactory getInstance() {
111        return CDI.current().select(GeoCodeCountryFactory.class).get();
112    }
113    
114    @Override
115    public String getPKColumn() {
116        return PK_COLUMN;
117    }
118    
119    @Override
120    public String getAllColumns() {
121        return ALL_COLUMNS;
122    }
123    
124    @Override
125    public String getTableName() {
126        return TABLE_NAME;
127    }
128    
129    @Override
130    public String getComponentVendorName() {
131        return GeoCodeCountryConstants.COMPONENT_VENDOR_NAME;
132    }
133    
134    @Override
135    public String getEntityTypeName() {
136        return GeoCodeCountryConstants.ENTITY_TYPE_NAME;
137    }
138    
139    public PreparedStatement prepareStatement(String query) {
140        return session.prepareStatement(GeoCodeCountryFactory.class, query);
141    }
142    
143    public GeoCodeCountryPK getNextPK() {
144        return new GeoCodeCountryPK(entityIdGenerator.getNextEntityId());
145    }
146    
147    public Set<GeoCodeCountryPK> getPKsFromResultSetAsSet(ResultSet rs)
148            throws PersistenceDatabaseException {
149        Set<GeoCodeCountryPK> _result = new HashSet<>();
150        
151        try {
152            while(rs.next()) {
153                _result.add(getPKFromResultSet(rs));
154            }
155        } catch (SQLException se) {
156            throw new PersistenceDatabaseException(se);
157        }
158        
159        return _result;
160    }
161    
162    public java.util.List<GeoCodeCountryPK> getPKsFromResultSetAsList(ResultSet rs)
163            throws PersistenceDatabaseException {
164        java.util.List<GeoCodeCountryPK> _result = new ArrayList<>();
165        
166        try {
167            while(rs.next()) {
168                _result.add(getPKFromResultSet(rs));
169            }
170        } catch (SQLException se) {
171            throw new PersistenceDatabaseException(se);
172        }
173        
174        return _result;
175    }
176    
177    public GeoCodeCountryPK getPKFromResultSet(ResultSet rs)
178            throws PersistenceDatabaseException {
179        GeoCodeCountryPK _result;
180        
181        try {
182            long geoc_geocodecountryid = rs.getLong(GEOC_GEOCODECOUNTRYID);
183            Long _entityId = rs.wasNull() ? null : geoc_geocodecountryid;
184            
185            _result = new GeoCodeCountryPK(_entityId);
186        } catch (SQLException se) {
187            throw new PersistenceDatabaseException(se);
188        }
189        
190        return _result;
191    }
192    
193    public java.util.List<GeoCodeCountryValue> getValuesFromPKs(Collection<GeoCodeCountryPK> pks)
194            throws PersistenceDatabaseException {
195        java.util.List<GeoCodeCountryValue> _values = new ArrayList<>(pks.size());
196        
197        for(GeoCodeCountryPK _pk: pks) {
198            _values.add(getValueFromPK(_pk));
199        }
200        
201        return _values;
202    }
203    
204    public GeoCodeCountryValue getValueFromPK(GeoCodeCountryPK pk)
205            throws PersistenceDatabaseException {
206        GeoCodeCountryValue _value;
207        
208        // See if we already have the entity in the session cache
209        GeoCodeCountry _entity = (GeoCodeCountry)session.getEntity(pk);
210        if(_entity == null)
211            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getGeoCodeCountryValue();
212        else
213            _value = _entity.getGeoCodeCountryValue();
214        
215        return _value;
216    }
217    
218    public java.util.List<GeoCodeCountryValue> getValuesFromResultSet(ResultSet rs)
219            throws PersistenceDatabaseException {
220        java.util.List<GeoCodeCountryValue> _result = new ArrayList<>();
221        
222        try {
223            while(rs.next()) {
224                _result.add(getValueFromResultSet(rs));
225            }
226        } catch (SQLException se) {
227            throw new PersistenceDatabaseException(se);
228        }
229        
230        return _result;
231    }
232    
233    public GeoCodeCountryValue getValueFromResultSet(ResultSet rs)
234            throws PersistenceDatabaseException {
235        GeoCodeCountryValue _value;
236        
237        try {
238            Long geoc_geocodecountryid = rs.getLong(GEOC_GEOCODECOUNTRYID);
239            GeoCodeCountryPK _pk = new GeoCodeCountryPK(geoc_geocodecountryid);
240            
241            // See if we already have the entity in the session cache
242            GeoCodeCountry _entity = (GeoCodeCountry)session.getEntity(_pk);
243            
244            if(_entity == null) {
245                Long geoc_geo_geocodeid = rs.getLong(GEOC_GEO_GEOCODEID);
246                if(rs.wasNull())
247                    geoc_geo_geocodeid = null;
248                
249                String geoc_telephonecode = rs.getString(GEOC_TELEPHONECODE);
250                if(rs.wasNull())
251                    geoc_telephonecode = null;
252                
253                String geoc_areacodepattern = rs.getString(GEOC_AREACODEPATTERN);
254                if(rs.wasNull())
255                    geoc_areacodepattern = null;
256                
257                Boolean geoc_areacoderequired = rs.getInt(GEOC_AREACODEREQUIRED) == 1;
258                if(rs.wasNull())
259                    geoc_areacoderequired = null;
260                
261                String geoc_areacodeexample = rs.getString(GEOC_AREACODEEXAMPLE);
262                if(rs.wasNull())
263                    geoc_areacodeexample = null;
264                
265                String geoc_telephonenumberpattern = rs.getString(GEOC_TELEPHONENUMBERPATTERN);
266                if(rs.wasNull())
267                    geoc_telephonenumberpattern = null;
268                
269                String geoc_telephonenumberexample = rs.getString(GEOC_TELEPHONENUMBEREXAMPLE);
270                if(rs.wasNull())
271                    geoc_telephonenumberexample = null;
272                
273                Long geoc_pstafmt_postaladdressformatid = rs.getLong(GEOC_PSTAFMT_POSTALADDRESSFORMATID);
274                if(rs.wasNull())
275                    geoc_pstafmt_postaladdressformatid = null;
276                
277                Boolean geoc_cityrequired = rs.getInt(GEOC_CITYREQUIRED) == 1;
278                if(rs.wasNull())
279                    geoc_cityrequired = null;
280                
281                Boolean geoc_citygeocoderequired = rs.getInt(GEOC_CITYGEOCODEREQUIRED) == 1;
282                if(rs.wasNull())
283                    geoc_citygeocoderequired = null;
284                
285                Boolean geoc_staterequired = rs.getInt(GEOC_STATEREQUIRED) == 1;
286                if(rs.wasNull())
287                    geoc_staterequired = null;
288                
289                Boolean geoc_stategeocoderequired = rs.getInt(GEOC_STATEGEOCODEREQUIRED) == 1;
290                if(rs.wasNull())
291                    geoc_stategeocoderequired = null;
292                
293                String geoc_postalcodepattern = rs.getString(GEOC_POSTALCODEPATTERN);
294                if(rs.wasNull())
295                    geoc_postalcodepattern = null;
296                
297                Boolean geoc_postalcoderequired = rs.getInt(GEOC_POSTALCODEREQUIRED) == 1;
298                if(rs.wasNull())
299                    geoc_postalcoderequired = null;
300                
301                Boolean geoc_postalcodegeocoderequired = rs.getInt(GEOC_POSTALCODEGEOCODEREQUIRED) == 1;
302                if(rs.wasNull())
303                    geoc_postalcodegeocoderequired = null;
304                
305                Integer geoc_postalcodelength = rs.getInt(GEOC_POSTALCODELENGTH);
306                if(rs.wasNull())
307                    geoc_postalcodelength = null;
308                
309                Integer geoc_postalcodegeocodelength = rs.getInt(GEOC_POSTALCODEGEOCODELENGTH);
310                if(rs.wasNull())
311                    geoc_postalcodegeocodelength = null;
312                
313                String geoc_postalcodeexample = rs.getString(GEOC_POSTALCODEEXAMPLE);
314                if(rs.wasNull())
315                    geoc_postalcodeexample = null;
316                
317                Long geoc_fromtime = rs.getLong(GEOC_FROMTIME);
318                if(rs.wasNull())
319                    geoc_fromtime = null;
320                
321                Long geoc_thrutime = rs.getLong(GEOC_THRUTIME);
322                if(rs.wasNull())
323                    geoc_thrutime = null;
324                
325                _value = new GeoCodeCountryValue(_pk, new GeoCodePK(geoc_geo_geocodeid), geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, new PostalAddressFormatPK(geoc_pstafmt_postaladdressformatid), geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime);
326            } else
327                _value = _entity.getGeoCodeCountryValue();
328        } catch (SQLException se) {
329            throw new PersistenceDatabaseException(se);
330        }
331        
332        return _value;
333    }
334    
335    public java.util.List<GeoCodeCountry> getEntitiesFromPKs(EntityPermission entityPermission, Collection<GeoCodeCountryPK> pks)
336            throws PersistenceDatabaseException {
337        java.util.List<GeoCodeCountry> _entities = new ArrayList<>(pks.size());
338        
339        for(GeoCodeCountryPK _pk: pks) {
340            _entities.add(getEntityFromPK(entityPermission, _pk));
341        }
342        
343        return _entities;
344    }
345    
346    public GeoCodeCountry getEntityFromValue(EntityPermission entityPermission, GeoCodeCountryValue value) {
347        return getEntityFromPK(entityPermission, value.getPrimaryKey());
348    }
349    
350    public GeoCodeCountry getEntityFromCache(GeoCodeCountryPK pk) {
351        GeoCodeCountryValue _value = (GeoCodeCountryValue)session.getValueCache().get(pk);
352    
353        return _value == null ? null : new GeoCodeCountry(_value, EntityPermission.READ_ONLY);
354    }
355    
356    public GeoCodeCountry getEntityFromPK(EntityPermission entityPermission, GeoCodeCountryPK pk)
357            throws PersistenceDatabaseException {
358        GeoCodeCountry _entity;
359        
360        // See if we already have the entity in the session cache
361        _entity = (GeoCodeCountry)session.getEntity(pk);
362        if(_entity != null) {
363            // If the requested permission is READ_WRITE, and the cached permission is
364            // READ_ONLY, then pretend that the cached object wasn't found, and create
365            // a new entity that is READ_WRITE.
366            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
367                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
368                    _entity = null;
369            }
370        }
371        
372        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
373            _entity = getEntityFromCache(pk);
374        }
375        
376        if(_entity == null) {
377            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
378            long _entityId = pk.getEntityId();
379            ResultSet _rs = null;
380            
381            try {
382                _ps.setLong(1, _entityId);
383                _rs = _ps.executeQuery();
384                if(_rs.next()) {
385                    _entity = getEntityFromResultSet(entityPermission, _rs);
386                }
387            } catch (SQLException se) {
388                throw new PersistenceDatabaseException(se);
389            } finally {
390                if(_rs != null) {
391                    try {
392                        _rs.close();
393                    } catch (SQLException se) {
394                        // do nothing
395                    }
396                }
397            }
398        }
399        
400        return _entity;
401    }
402    
403    public Set<GeoCodeCountryPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
404            throws PersistenceDatabaseException {
405        Set<GeoCodeCountryPK> _pks;
406        ResultSet _rs = null;
407        
408        try {
409            if(params.length != 0) {
410                Session.setQueryParams(ps, params);
411            }
412            
413            _rs = ps.executeQuery();
414            _pks = getPKsFromResultSetAsSet(_rs);
415            _rs.close();
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        return _pks;
429    }
430    
431    public java.util.List<GeoCodeCountryPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
432            throws PersistenceDatabaseException {
433        java.util.List<GeoCodeCountryPK> _pks;
434        ResultSet _rs = null;
435        
436        try {
437            if(params.length != 0) {
438                Session.setQueryParams(ps, params);
439            }
440            
441            _rs = ps.executeQuery();
442            _pks = getPKsFromResultSetAsList(_rs);
443            _rs.close();
444        } catch (SQLException se) {
445            throw new PersistenceDatabaseException(se);
446        } finally {
447            if(_rs != null) {
448                try {
449                    _rs.close();
450                } catch (SQLException se) {
451                    // do nothing
452                }
453            }
454        }
455        
456        return _pks;
457    }
458    
459    public GeoCodeCountryPK getPKFromQuery(PreparedStatement ps, final Object... params)
460            throws PersistenceDatabaseException {
461        GeoCodeCountryPK _pk = null;
462        ResultSet _rs = null;
463        
464        try {
465            if(params.length != 0) {
466                Session.setQueryParams(ps, params);
467            }
468            
469            _rs = ps.executeQuery();
470            if(_rs.next()) {
471                _pk = getPKFromResultSet(_rs);
472            }
473            _rs.close();
474        } catch (SQLException se) {
475            throw new PersistenceDatabaseException(se);
476        } finally {
477            if(_rs != null) {
478                try {
479                    _rs.close();
480                } catch (SQLException se) {
481                    // do nothing
482                }
483            }
484        }
485        
486        return _pk;
487    }
488    
489    public java.util.List<GeoCodeCountry> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
490            throws PersistenceDatabaseException {
491        PreparedStatement ps = session.prepareStatement(GeoCodeCountryFactory.class, queryMap.get(entityPermission));
492        
493        return getEntitiesFromQuery(entityPermission, ps, params);
494    }
495    
496    public java.util.List<GeoCodeCountry> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
497            throws PersistenceDatabaseException {
498        PreparedStatement ps = session.prepareStatement(GeoCodeCountryFactory.class, queryMap.get(entityPermission));
499        
500        return getEntitiesFromQuery(entityPermission, ps);
501    }
502    
503    public java.util.List<GeoCodeCountry> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
504            throws PersistenceDatabaseException {
505        java.util.List<GeoCodeCountry> _entities;
506        ResultSet _rs = null;
507        
508        try {
509            if(params.length != 0) {
510                Session.setQueryParams(ps, params);
511            }
512            
513            _rs = ps.executeQuery();
514            _entities = getEntitiesFromResultSet(entityPermission, _rs);
515            _rs.close();
516        } catch (SQLException se) {
517            throw new PersistenceDatabaseException(se);
518        } finally {
519            if(_rs != null) {
520                try {
521                    _rs.close();
522                } catch (SQLException se) {
523                    // do nothing
524                }
525            }
526        }
527        
528        return _entities;
529    }
530    
531    public GeoCodeCountry getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
532            throws PersistenceDatabaseException {
533        PreparedStatement ps = session.prepareStatement(GeoCodeCountryFactory.class, queryMap.get(entityPermission));
534        
535        return getEntityFromQuery(entityPermission, ps, params);
536    }
537    
538    public GeoCodeCountry getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
539            throws PersistenceDatabaseException {
540        PreparedStatement ps = session.prepareStatement(GeoCodeCountryFactory.class, queryMap.get(entityPermission));
541        
542        return getEntityFromQuery(entityPermission, ps);
543    }
544    
545    public GeoCodeCountry getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
546            throws PersistenceDatabaseException {
547        GeoCodeCountry _entity = null;
548        ResultSet _rs = null;
549        
550        try {
551            if(params.length != 0) {
552                Session.setQueryParams(ps, params);
553            }
554            
555            _rs = ps.executeQuery();
556            if(_rs.next()) {
557                _entity = getEntityFromResultSet(entityPermission, _rs);
558            }
559            _rs.close();
560        } catch (SQLException se) {
561            throw new PersistenceDatabaseException(se);
562        } finally {
563            if(_rs != null) {
564                try {
565                    _rs.close();
566                } catch (SQLException se) {
567                    // do nothing
568                }
569            }
570        }
571        
572        return _entity;
573    }
574    
575    public java.util.List<GeoCodeCountry> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
576            throws PersistenceDatabaseException {
577        java.util.List<GeoCodeCountry> _result = new ArrayList<>();
578        
579        try {
580            while(rs.next()) {
581                _result.add(getEntityFromResultSet(entityPermission, rs));
582            }
583        } catch (SQLException se) {
584            throw new PersistenceDatabaseException(se);
585        }
586        
587        return _result;
588    }
589    
590    public GeoCodeCountry getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
591            throws PersistenceDatabaseException {
592        GeoCodeCountry _entity;
593        
594        try {
595            Long geoc_geocodecountryid = rs.getLong(GEOC_GEOCODECOUNTRYID);
596            GeoCodeCountryPK _pk = new GeoCodeCountryPK(geoc_geocodecountryid);
597            
598            // See if we already have the entity in the session cache
599            _entity = (GeoCodeCountry)session.getEntity(_pk);
600            if(_entity != null) {
601                // If the requested permission is READ_WRITE, and the cached permission is
602                // READ_ONLY, then pretend that the cached object wasn't found, and create
603                // a new entity that is READ_WRITE.
604                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
605                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
606                        _entity = null;
607                }
608            }
609            boolean foundInSessionCache = _entity != null;
610            
611            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
612                _entity = getEntityFromCache(_pk);
613            }
614            
615            if(_entity == null) {
616                Long geoc_geo_geocodeid = rs.getLong(GEOC_GEO_GEOCODEID);
617                if(rs.wasNull())
618                    geoc_geo_geocodeid = null;
619                
620                String geoc_telephonecode = rs.getString(GEOC_TELEPHONECODE);
621                if(rs.wasNull())
622                    geoc_telephonecode = null;
623                
624                String geoc_areacodepattern = rs.getString(GEOC_AREACODEPATTERN);
625                if(rs.wasNull())
626                    geoc_areacodepattern = null;
627                
628                Boolean geoc_areacoderequired = rs.getInt(GEOC_AREACODEREQUIRED) == 1;
629                if(rs.wasNull())
630                    geoc_areacoderequired = null;
631                
632                String geoc_areacodeexample = rs.getString(GEOC_AREACODEEXAMPLE);
633                if(rs.wasNull())
634                    geoc_areacodeexample = null;
635                
636                String geoc_telephonenumberpattern = rs.getString(GEOC_TELEPHONENUMBERPATTERN);
637                if(rs.wasNull())
638                    geoc_telephonenumberpattern = null;
639                
640                String geoc_telephonenumberexample = rs.getString(GEOC_TELEPHONENUMBEREXAMPLE);
641                if(rs.wasNull())
642                    geoc_telephonenumberexample = null;
643                
644                Long geoc_pstafmt_postaladdressformatid = rs.getLong(GEOC_PSTAFMT_POSTALADDRESSFORMATID);
645                if(rs.wasNull())
646                    geoc_pstafmt_postaladdressformatid = null;
647                
648                Boolean geoc_cityrequired = rs.getInt(GEOC_CITYREQUIRED) == 1;
649                if(rs.wasNull())
650                    geoc_cityrequired = null;
651                
652                Boolean geoc_citygeocoderequired = rs.getInt(GEOC_CITYGEOCODEREQUIRED) == 1;
653                if(rs.wasNull())
654                    geoc_citygeocoderequired = null;
655                
656                Boolean geoc_staterequired = rs.getInt(GEOC_STATEREQUIRED) == 1;
657                if(rs.wasNull())
658                    geoc_staterequired = null;
659                
660                Boolean geoc_stategeocoderequired = rs.getInt(GEOC_STATEGEOCODEREQUIRED) == 1;
661                if(rs.wasNull())
662                    geoc_stategeocoderequired = null;
663                
664                String geoc_postalcodepattern = rs.getString(GEOC_POSTALCODEPATTERN);
665                if(rs.wasNull())
666                    geoc_postalcodepattern = null;
667                
668                Boolean geoc_postalcoderequired = rs.getInt(GEOC_POSTALCODEREQUIRED) == 1;
669                if(rs.wasNull())
670                    geoc_postalcoderequired = null;
671                
672                Boolean geoc_postalcodegeocoderequired = rs.getInt(GEOC_POSTALCODEGEOCODEREQUIRED) == 1;
673                if(rs.wasNull())
674                    geoc_postalcodegeocoderequired = null;
675                
676                Integer geoc_postalcodelength = rs.getInt(GEOC_POSTALCODELENGTH);
677                if(rs.wasNull())
678                    geoc_postalcodelength = null;
679                
680                Integer geoc_postalcodegeocodelength = rs.getInt(GEOC_POSTALCODEGEOCODELENGTH);
681                if(rs.wasNull())
682                    geoc_postalcodegeocodelength = null;
683                
684                String geoc_postalcodeexample = rs.getString(GEOC_POSTALCODEEXAMPLE);
685                if(rs.wasNull())
686                    geoc_postalcodeexample = null;
687                
688                Long geoc_fromtime = rs.getLong(GEOC_FROMTIME);
689                if(rs.wasNull())
690                    geoc_fromtime = null;
691                
692                Long geoc_thrutime = rs.getLong(GEOC_THRUTIME);
693                if(rs.wasNull())
694                    geoc_thrutime = null;
695                
696                GeoCodeCountryValue _value = new GeoCodeCountryValue(_pk, geoc_geo_geocodeid == null? null: new GeoCodePK(geoc_geo_geocodeid), geoc_telephonecode, geoc_areacodepattern, geoc_areacoderequired, geoc_areacodeexample, geoc_telephonenumberpattern, geoc_telephonenumberexample, geoc_pstafmt_postaladdressformatid == null? null: new PostalAddressFormatPK(geoc_pstafmt_postaladdressformatid), geoc_cityrequired, geoc_citygeocoderequired, geoc_staterequired, geoc_stategeocoderequired, geoc_postalcodepattern, geoc_postalcoderequired, geoc_postalcodegeocoderequired, geoc_postalcodelength, geoc_postalcodegeocodelength, geoc_postalcodeexample, geoc_fromtime, geoc_thrutime);
697                _entity = new GeoCodeCountry(_value, entityPermission);
698            }
699            
700            if(!foundInSessionCache) {
701                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
702                    session.putReadOnlyEntity(_pk, _entity);
703                    session.getValueCache().put(_entity.getGeoCodeCountryValue());
704                } else {
705                    session.putReadWriteEntity(_pk, _entity);
706                }
707            }
708        } catch (SQLException se) {
709            throw new PersistenceDatabaseException(se);
710        }
711        
712        return _entity;
713    }
714    
715    public GeoCodeCountry create(GeoCode geoCode, String telephoneCode, String areaCodePattern, Boolean areaCodeRequired, String areaCodeExample, String telephoneNumberPattern, String telephoneNumberExample, PostalAddressFormat postalAddressFormat, Boolean cityRequired, Boolean cityGeoCodeRequired, Boolean stateRequired, Boolean stateGeoCodeRequired, String postalCodePattern, Boolean postalCodeRequired, Boolean postalCodeGeoCodeRequired, Integer postalCodeLength, Integer postalCodeGeoCodeLength, String postalCodeExample, Long fromTime, Long thruTime)
716            throws PersistenceDatabaseException, PersistenceNotNullException {
717        return create(geoCode == null ? null : geoCode.getPrimaryKey(), telephoneCode, areaCodePattern, areaCodeRequired, areaCodeExample, telephoneNumberPattern, telephoneNumberExample, postalAddressFormat == null ? null : postalAddressFormat.getPrimaryKey(), cityRequired, cityGeoCodeRequired, stateRequired, stateGeoCodeRequired, postalCodePattern, postalCodeRequired, postalCodeGeoCodeRequired, postalCodeLength, postalCodeGeoCodeLength, postalCodeExample, fromTime, thruTime);
718    }
719    
720    private void bindForCreate(PreparedStatement _ps, GeoCodeCountryValue _value)
721            throws SQLException {
722        _ps.setLong(1, _value.getEntityId());
723        
724        GeoCodePK geoc_geo_geocodeid = _value.getGeoCodePK();
725        if(geoc_geo_geocodeid == null)
726            _ps.setNull(2, Types.BIGINT);
727        else
728            _ps.setLong(2, geoc_geo_geocodeid.getEntityId());
729            
730        String geoc_telephonecode = _value.getTelephoneCode();
731        if(geoc_telephonecode == null)
732            _ps.setNull(3, Types.VARCHAR);
733        else
734            _ps.setString(3, geoc_telephonecode);
735            
736        String geoc_areacodepattern = _value.getAreaCodePattern();
737        if(geoc_areacodepattern == null)
738            _ps.setNull(4, Types.VARCHAR);
739        else
740            _ps.setString(4, geoc_areacodepattern);
741            
742        Boolean geoc_areacoderequired = _value.getAreaCodeRequired();
743        if(geoc_areacoderequired == null)
744            _ps.setNull(5, Types.BIT);
745        else
746            _ps.setInt(5, geoc_areacoderequired? 1: 0);
747            
748        String geoc_areacodeexample = _value.getAreaCodeExample();
749        if(geoc_areacodeexample == null)
750            _ps.setNull(6, Types.VARCHAR);
751        else
752            _ps.setString(6, geoc_areacodeexample);
753            
754        String geoc_telephonenumberpattern = _value.getTelephoneNumberPattern();
755        if(geoc_telephonenumberpattern == null)
756            _ps.setNull(7, Types.VARCHAR);
757        else
758            _ps.setString(7, geoc_telephonenumberpattern);
759            
760        String geoc_telephonenumberexample = _value.getTelephoneNumberExample();
761        if(geoc_telephonenumberexample == null)
762            _ps.setNull(8, Types.VARCHAR);
763        else
764            _ps.setString(8, geoc_telephonenumberexample);
765            
766        PostalAddressFormatPK geoc_pstafmt_postaladdressformatid = _value.getPostalAddressFormatPK();
767        if(geoc_pstafmt_postaladdressformatid == null)
768            _ps.setNull(9, Types.BIGINT);
769        else
770            _ps.setLong(9, geoc_pstafmt_postaladdressformatid.getEntityId());
771            
772        Boolean geoc_cityrequired = _value.getCityRequired();
773        if(geoc_cityrequired == null)
774            _ps.setNull(10, Types.BIT);
775        else
776            _ps.setInt(10, geoc_cityrequired? 1: 0);
777            
778        Boolean geoc_citygeocoderequired = _value.getCityGeoCodeRequired();
779        if(geoc_citygeocoderequired == null)
780            _ps.setNull(11, Types.BIT);
781        else
782            _ps.setInt(11, geoc_citygeocoderequired? 1: 0);
783            
784        Boolean geoc_staterequired = _value.getStateRequired();
785        if(geoc_staterequired == null)
786            _ps.setNull(12, Types.BIT);
787        else
788            _ps.setInt(12, geoc_staterequired? 1: 0);
789            
790        Boolean geoc_stategeocoderequired = _value.getStateGeoCodeRequired();
791        if(geoc_stategeocoderequired == null)
792            _ps.setNull(13, Types.BIT);
793        else
794            _ps.setInt(13, geoc_stategeocoderequired? 1: 0);
795            
796        String geoc_postalcodepattern = _value.getPostalCodePattern();
797        if(geoc_postalcodepattern == null)
798            _ps.setNull(14, Types.VARCHAR);
799        else
800            _ps.setString(14, geoc_postalcodepattern);
801            
802        Boolean geoc_postalcoderequired = _value.getPostalCodeRequired();
803        if(geoc_postalcoderequired == null)
804            _ps.setNull(15, Types.BIT);
805        else
806            _ps.setInt(15, geoc_postalcoderequired? 1: 0);
807            
808        Boolean geoc_postalcodegeocoderequired = _value.getPostalCodeGeoCodeRequired();
809        if(geoc_postalcodegeocoderequired == null)
810            _ps.setNull(16, Types.BIT);
811        else
812            _ps.setInt(16, geoc_postalcodegeocoderequired? 1: 0);
813            
814        Integer geoc_postalcodelength = _value.getPostalCodeLength();
815        if(geoc_postalcodelength == null)
816            _ps.setNull(17, Types.INTEGER);
817        else
818            _ps.setInt(17, geoc_postalcodelength);
819            
820        Integer geoc_postalcodegeocodelength = _value.getPostalCodeGeoCodeLength();
821        if(geoc_postalcodegeocodelength == null)
822            _ps.setNull(18, Types.INTEGER);
823        else
824            _ps.setInt(18, geoc_postalcodegeocodelength);
825            
826        String geoc_postalcodeexample = _value.getPostalCodeExample();
827        if(geoc_postalcodeexample == null)
828            _ps.setNull(19, Types.VARCHAR);
829        else
830            _ps.setString(19, geoc_postalcodeexample);
831            
832        Long geoc_fromtime = _value.getFromTime();
833        if(geoc_fromtime == null)
834            _ps.setNull(20, Types.BIGINT);
835        else
836            _ps.setLong(20, geoc_fromtime);
837            
838        Long geoc_thrutime = _value.getThruTime();
839        if(geoc_thrutime == null)
840            _ps.setNull(21, Types.BIGINT);
841        else
842            _ps.setLong(21, geoc_thrutime);
843            
844    }
845    
846    public GeoCodeCountry create(GeoCodePK geoCodePK, String telephoneCode, String areaCodePattern, Boolean areaCodeRequired, String areaCodeExample, String telephoneNumberPattern, String telephoneNumberExample, PostalAddressFormatPK postalAddressFormatPK, Boolean cityRequired, Boolean cityGeoCodeRequired, Boolean stateRequired, Boolean stateGeoCodeRequired, String postalCodePattern, Boolean postalCodeRequired, Boolean postalCodeGeoCodeRequired, Integer postalCodeLength, Integer postalCodeGeoCodeLength, String postalCodeExample, Long fromTime, Long thruTime)
847            throws PersistenceDatabaseException, PersistenceNotNullException {
848        GeoCodeCountryPK _pk = getNextPK();
849        GeoCodeCountryValue _value = new GeoCodeCountryValue(_pk, geoCodePK, telephoneCode, areaCodePattern, areaCodeRequired, areaCodeExample, telephoneNumberPattern, telephoneNumberExample, postalAddressFormatPK, cityRequired, cityGeoCodeRequired, stateRequired, stateGeoCodeRequired, postalCodePattern, postalCodeRequired, postalCodeGeoCodeRequired, postalCodeLength, postalCodeGeoCodeLength, postalCodeExample, fromTime, thruTime);
850        
851        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
852        
853        try {
854            bindForCreate(_ps, _value);
855            
856            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
857                int _count = _ps.executeUpdate();
858                
859                if(_count != 1) {
860                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
861                }
862            } else {
863                 _ps.executeUpdate();
864            }
865            
866            session.getValueCache().put(_value);
867        } catch (SQLException se) {
868            throw new PersistenceDatabaseException(se);
869        }
870        
871        GeoCodeCountry _entity = new GeoCodeCountry(_value, EntityPermission.READ_ONLY);
872        session.putReadOnlyEntity(_pk, _entity);
873        
874        return _entity;
875    }
876    
877    public void create(Collection<GeoCodeCountryValue> _values)
878            throws PersistenceDatabaseException, PersistenceNotNullException {
879        int _size = _values.size();
880        
881        if(_size > 0) {
882            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
883            List<GeoCodeCountryValue> _cacheValues = new ArrayList<>(_size);
884            
885            try {
886                for(GeoCodeCountryValue _value : _values) {
887                    _value.setEntityId(entityIdGenerator.getNextEntityId());
888                    bindForCreate(_ps, _value);
889                    
890                    _ps.addBatch();
891                    
892                    _cacheValues.add(_value);
893                }
894                
895                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
896                    int[] _counts = _ps.executeBatch();
897                    
898                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
899                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
900                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
901                        }
902                    }
903                } else {
904                     _ps.executeBatch();
905                }
906                
907                _ps.clearBatch();
908            } catch (SQLException se) {
909                throw new PersistenceDatabaseException(se);
910            }
911            
912            _cacheValues.forEach((_cacheValue) -> {
913                GeoCodeCountry _cacheEntity = new GeoCodeCountry(_cacheValue, EntityPermission.READ_ONLY);
914                
915                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
916            });
917        }
918    }
919    
920    private boolean bindForStore(PreparedStatement _ps, GeoCodeCountryValue _value)
921            throws SQLException {
922        boolean _hasBeenModified = _value.hasBeenModified();
923        
924        if(_hasBeenModified) {
925            GeoCodePK geoc_geo_geocodeid = _value.getGeoCodePK();
926            if(geoc_geo_geocodeid == null)
927                _ps.setNull(1, Types.BIGINT);
928            else
929                _ps.setLong(1, geoc_geo_geocodeid.getEntityId());
930            
931            String geoc_telephonecode = _value.getTelephoneCode();
932            if(geoc_telephonecode == null)
933                _ps.setNull(2, Types.VARCHAR);
934            else
935                _ps.setString(2, geoc_telephonecode);
936            
937            String geoc_areacodepattern = _value.getAreaCodePattern();
938            if(geoc_areacodepattern == null)
939                _ps.setNull(3, Types.VARCHAR);
940            else
941                _ps.setString(3, geoc_areacodepattern);
942            
943            Boolean geoc_areacoderequired = _value.getAreaCodeRequired();
944            if(geoc_areacoderequired == null)
945                _ps.setNull(4, Types.BIT);
946            else
947                _ps.setInt(4, geoc_areacoderequired? 1: 0);
948            
949            String geoc_areacodeexample = _value.getAreaCodeExample();
950            if(geoc_areacodeexample == null)
951                _ps.setNull(5, Types.VARCHAR);
952            else
953                _ps.setString(5, geoc_areacodeexample);
954            
955            String geoc_telephonenumberpattern = _value.getTelephoneNumberPattern();
956            if(geoc_telephonenumberpattern == null)
957                _ps.setNull(6, Types.VARCHAR);
958            else
959                _ps.setString(6, geoc_telephonenumberpattern);
960            
961            String geoc_telephonenumberexample = _value.getTelephoneNumberExample();
962            if(geoc_telephonenumberexample == null)
963                _ps.setNull(7, Types.VARCHAR);
964            else
965                _ps.setString(7, geoc_telephonenumberexample);
966            
967            PostalAddressFormatPK geoc_pstafmt_postaladdressformatid = _value.getPostalAddressFormatPK();
968            if(geoc_pstafmt_postaladdressformatid == null)
969                _ps.setNull(8, Types.BIGINT);
970            else
971                _ps.setLong(8, geoc_pstafmt_postaladdressformatid.getEntityId());
972            
973            Boolean geoc_cityrequired = _value.getCityRequired();
974            if(geoc_cityrequired == null)
975                _ps.setNull(9, Types.BIT);
976            else
977                _ps.setInt(9, geoc_cityrequired? 1: 0);
978            
979            Boolean geoc_citygeocoderequired = _value.getCityGeoCodeRequired();
980            if(geoc_citygeocoderequired == null)
981                _ps.setNull(10, Types.BIT);
982            else
983                _ps.setInt(10, geoc_citygeocoderequired? 1: 0);
984            
985            Boolean geoc_staterequired = _value.getStateRequired();
986            if(geoc_staterequired == null)
987                _ps.setNull(11, Types.BIT);
988            else
989                _ps.setInt(11, geoc_staterequired? 1: 0);
990            
991            Boolean geoc_stategeocoderequired = _value.getStateGeoCodeRequired();
992            if(geoc_stategeocoderequired == null)
993                _ps.setNull(12, Types.BIT);
994            else
995                _ps.setInt(12, geoc_stategeocoderequired? 1: 0);
996            
997            String geoc_postalcodepattern = _value.getPostalCodePattern();
998            if(geoc_postalcodepattern == null)
999                _ps.setNull(13, Types.VARCHAR);
1000            else
1001                _ps.setString(13, geoc_postalcodepattern);
1002            
1003            Boolean geoc_postalcoderequired = _value.getPostalCodeRequired();
1004            if(geoc_postalcoderequired == null)
1005                _ps.setNull(14, Types.BIT);
1006            else
1007                _ps.setInt(14, geoc_postalcoderequired? 1: 0);
1008            
1009            Boolean geoc_postalcodegeocoderequired = _value.getPostalCodeGeoCodeRequired();
1010            if(geoc_postalcodegeocoderequired == null)
1011                _ps.setNull(15, Types.BIT);
1012            else
1013                _ps.setInt(15, geoc_postalcodegeocoderequired? 1: 0);
1014            
1015            Integer geoc_postalcodelength = _value.getPostalCodeLength();
1016            if(geoc_postalcodelength == null)
1017                _ps.setNull(16, Types.INTEGER);
1018            else
1019                _ps.setInt(16, geoc_postalcodelength);
1020            
1021            Integer geoc_postalcodegeocodelength = _value.getPostalCodeGeoCodeLength();
1022            if(geoc_postalcodegeocodelength == null)
1023                _ps.setNull(17, Types.INTEGER);
1024            else
1025                _ps.setInt(17, geoc_postalcodegeocodelength);
1026            
1027            String geoc_postalcodeexample = _value.getPostalCodeExample();
1028            if(geoc_postalcodeexample == null)
1029                _ps.setNull(18, Types.VARCHAR);
1030            else
1031                _ps.setString(18, geoc_postalcodeexample);
1032            
1033            Long geoc_fromtime = _value.getFromTime();
1034            if(geoc_fromtime == null)
1035                _ps.setNull(19, Types.BIGINT);
1036            else
1037                _ps.setLong(19, geoc_fromtime);
1038            
1039            Long geoc_thrutime = _value.getThruTime();
1040            if(geoc_thrutime == null)
1041                _ps.setNull(20, Types.BIGINT);
1042            else
1043                _ps.setLong(20, geoc_thrutime);
1044            
1045            _ps.setLong(21, _value.getPrimaryKey().getEntityId());
1046            
1047            _value.clearHasBeenModified();
1048        }
1049        
1050        return _hasBeenModified;
1051    }
1052    
1053    @Override
1054    public void store(GeoCodeCountry entity)
1055            throws PersistenceDatabaseException {
1056        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1057        
1058        try {
1059            GeoCodeCountryValue _value = entity.getGeoCodeCountryValue();
1060            
1061            if(bindForStore(_ps, _value)) {
1062                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1063                    int _count = _ps.executeUpdate();
1064                    
1065                    if(_count != 1) {
1066                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1067                    }
1068                } else {
1069                     _ps.executeUpdate();
1070                }
1071                
1072                session.getValueCache().put(_value);
1073            }
1074        } catch (SQLException se) {
1075            throw new PersistenceDatabaseException(se);
1076        }
1077    }
1078    
1079    @Override
1080    public void store(Collection<GeoCodeCountry> entities)
1081            throws PersistenceDatabaseException {
1082        if(entities.size() > 0) {
1083            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1084            int _modifiedEntities = 0;
1085            
1086            try {
1087                for(GeoCodeCountry entity : entities) {
1088                    if(bindForStore(_ps, entity.getGeoCodeCountryValue())) {
1089                        _ps.addBatch();
1090                        _modifiedEntities++;
1091                    }
1092                }
1093                
1094                if(_modifiedEntities != 0) {
1095                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1096                        int[] _counts = _ps.executeBatch();
1097                        
1098                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1099                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1100                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1101                            }
1102                        }
1103                    } else {
1104                         _ps.executeBatch();
1105                    }
1106                    
1107                    _ps.clearBatch();
1108                    
1109                    entities.forEach((entity) -> {
1110                        session.getValueCache().put(entity.getGeoCodeCountryValue());
1111                    });
1112                }
1113            } catch (SQLException se) {
1114                throw new PersistenceDatabaseException(se);
1115            }
1116        }
1117    }
1118    
1119    @Override
1120    public void remove(GeoCodeCountry entity)
1121            throws PersistenceDatabaseException {
1122        remove(entity.getPrimaryKey());
1123    }
1124    
1125    @Override
1126    public void remove(GeoCodeCountryPK pk)
1127            throws PersistenceDatabaseException {
1128        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1129        long _entityId = pk.getEntityId();
1130        
1131        try {
1132            _ps.setLong(1, _entityId);
1133            
1134            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1135                int _count = _ps.executeUpdate();
1136                
1137                if(_count != 1) {
1138                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1139                }
1140            } else {
1141                 _ps.executeUpdate();
1142            }
1143            
1144            session.getValueCache().remove(pk);
1145        } catch (SQLException se) {
1146            throw new PersistenceDatabaseException(se);
1147        }
1148        
1149        session.removed(pk, false);
1150    }
1151    
1152    @Override
1153    public void remove(Collection<GeoCodeCountryPK> pks)
1154            throws PersistenceDatabaseException {
1155        if(pks.size() > 0) {
1156            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1157            int _modifiedEntities = 0;
1158            
1159            try {
1160                for(GeoCodeCountryPK pk : pks) {
1161                    long _entityId = pk.getEntityId();
1162                    
1163                    _ps.setLong(1, _entityId);
1164                    
1165                    _ps.addBatch();
1166                    _modifiedEntities++;
1167                }
1168                
1169                if(_modifiedEntities != 0) {
1170                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1171                        int[] _counts = _ps.executeBatch();
1172                        
1173                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1174                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1175                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1176                            }
1177                        }
1178                    } else {
1179                        _ps.executeBatch();
1180                    }
1181                    
1182                    _ps.clearBatch();
1183                    
1184                    pks.forEach((pk) -> {
1185                        session.getValueCache().remove(pk);
1186                    });
1187                }
1188            } catch (SQLException se) {
1189                throw new PersistenceDatabaseException(se);
1190            }
1191            
1192            pks.forEach((pk) -> {
1193                session.removed(pk, true);
1194            });
1195        }
1196    }
1197    
1198    @Override
1199    public boolean validPK(GeoCodeCountryPK pk)
1200            throws PersistenceDatabaseException {
1201        boolean valid = false;
1202        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1203        ResultSet _rs = null;
1204        
1205        try {
1206            _ps.setLong(1, pk.getEntityId());
1207            
1208            _rs = _ps.executeQuery();
1209            if(_rs.next()) {
1210                long _count = _rs.getLong(1);
1211                if(_rs.wasNull())
1212                    _count = 0;
1213                
1214                if(_count == 1)
1215                    valid = true;
1216            }
1217        } catch (SQLException se) {
1218            throw new PersistenceDatabaseException(se);
1219        } finally {
1220            if(_rs != null) {
1221                try {
1222                    _rs.close();
1223                } catch (SQLException se) {
1224                    // do nothing
1225                }
1226            }
1227        }
1228        
1229        return valid;
1230    }
1231    
1232}