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