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