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