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