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