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