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