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