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