001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * OfferItemFixedPriceFactory.java
021 */
022
023package com.echothree.model.data.offer.server.factory;
024
025import com.echothree.model.data.offer.common.pk.OfferItemPricePK;
026
027import com.echothree.model.data.offer.server.entity.OfferItemPrice;
028
029import com.echothree.model.data.offer.common.OfferItemFixedPriceConstants;
030import com.echothree.model.data.offer.common.pk.OfferItemFixedPricePK;
031import com.echothree.model.data.offer.server.value.OfferItemFixedPriceValue;
032import com.echothree.model.data.offer.server.entity.OfferItemFixedPrice;
033import com.echothree.util.common.exception.PersistenceDatabaseException;
034import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
035import com.echothree.util.common.exception.PersistenceNotNullException;
036import com.echothree.util.server.persistence.BaseFactory;
037import com.echothree.util.server.persistence.EntityIdGenerator;
038import com.echothree.util.server.persistence.EntityPermission;
039import com.echothree.util.server.persistence.PersistenceDebugFlags;
040import com.echothree.util.server.persistence.Session;
041import java.sql.PreparedStatement;
042import java.sql.ResultSet;
043import java.sql.SQLException;
044import java.sql.Types;
045import java.io.ByteArrayInputStream;
046import java.io.StringReader;
047import java.util.ArrayList;
048import java.util.Collection;
049import java.util.HashSet;
050import java.util.List;
051import java.util.Map;
052import java.util.Set;
053import javax.enterprise.context.ApplicationScoped;
054import javax.enterprise.inject.spi.CDI;
055import javax.inject.Inject;
056import org.slf4j.Logger;
057import org.slf4j.LoggerFactory;
058
059@ApplicationScoped
060public class OfferItemFixedPriceFactory
061        implements BaseFactory<OfferItemFixedPricePK, OfferItemFixedPrice> {
062    
063    @Inject
064    Session session;
065    
066    //private static final Logger log = LoggerFactory.getLogger(OfferItemFixedPriceFactory.class);
067    
068    final private static String SQL_SELECT_READ_ONLY = "SELECT ofritmfp_offeritemfixedpriceid, ofritmfp_ofritmp_offeritempriceid, ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime FROM offeritemfixedprices WHERE ofritmfp_offeritemfixedpriceid = ?";
069    final private static String SQL_SELECT_READ_WRITE = "SELECT ofritmfp_offeritemfixedpriceid, ofritmfp_ofritmp_offeritempriceid, ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime FROM offeritemfixedprices WHERE ofritmfp_offeritemfixedpriceid = ? FOR UPDATE";
070    final private static String SQL_INSERT = "INSERT INTO offeritemfixedprices (ofritmfp_offeritemfixedpriceid, ofritmfp_ofritmp_offeritempriceid, ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime) VALUES (?, ?, ?, ?, ?)";
071    final private static String SQL_UPDATE = "UPDATE offeritemfixedprices SET ofritmfp_ofritmp_offeritempriceid = ?, ofritmfp_unitprice = ?, ofritmfp_fromtime = ?, ofritmfp_thrutime = ? WHERE ofritmfp_offeritemfixedpriceid = ?";
072    final private static String SQL_DELETE = "DELETE FROM offeritemfixedprices WHERE ofritmfp_offeritemfixedpriceid = ?";
073    final private static String SQL_VALID = "SELECT COUNT(*) FROM offeritemfixedprices WHERE ofritmfp_offeritemfixedpriceid = ?";
074    
075    final private static String PK_COLUMN = "ofritmfp_offeritemfixedpriceid";
076    final private static String ALL_COLUMNS = "ofritmfp_offeritemfixedpriceid, ofritmfp_ofritmp_offeritempriceid, ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime";
077    final public static String TABLE_NAME = "offeritemfixedprices";
078    
079    final public static String OFRITMFP_OFFERITEMFIXEDPRICEID = "ofritmfp_offeritemfixedpriceid";
080    final public static String OFRITMFP_OFRITMP_OFFERITEMPRICEID = "ofritmfp_ofritmp_offeritempriceid";
081    final public static String OFRITMFP_UNITPRICE = "ofritmfp_unitprice";
082    final public static String OFRITMFP_FROMTIME = "ofritmfp_fromtime";
083    final public static String OFRITMFP_THRUTIME = "ofritmfp_thrutime";
084    
085    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(OfferItemFixedPriceConstants.COMPONENT_VENDOR_NAME, OfferItemFixedPriceConstants.ENTITY_TYPE_NAME);
086    
087    /** Creates a new instance of OfferItemFixedPriceFactory */
088    protected OfferItemFixedPriceFactory() {
089        super();
090    }
091    
092    public static OfferItemFixedPriceFactory getInstance() {
093        return CDI.current().select(OfferItemFixedPriceFactory.class).get();
094    }
095    
096    @Override
097    public String getPKColumn() {
098        return PK_COLUMN;
099    }
100    
101    @Override
102    public String getAllColumns() {
103        return ALL_COLUMNS;
104    }
105    
106    @Override
107    public String getTableName() {
108        return TABLE_NAME;
109    }
110    
111    @Override
112    public String getComponentVendorName() {
113        return OfferItemFixedPriceConstants.COMPONENT_VENDOR_NAME;
114    }
115    
116    @Override
117    public String getEntityTypeName() {
118        return OfferItemFixedPriceConstants.ENTITY_TYPE_NAME;
119    }
120    
121    public PreparedStatement prepareStatement(String query) {
122        return session.prepareStatement(OfferItemFixedPriceFactory.class, query);
123    }
124    
125    public OfferItemFixedPricePK getNextPK() {
126        return new OfferItemFixedPricePK(entityIdGenerator.getNextEntityId());
127    }
128    
129    public Set<OfferItemFixedPricePK> getPKsFromResultSetAsSet(ResultSet rs)
130            throws PersistenceDatabaseException {
131        Set<OfferItemFixedPricePK> _result = new HashSet<>();
132        
133        try {
134            while(rs.next()) {
135                _result.add(getPKFromResultSet(rs));
136            }
137        } catch (SQLException se) {
138            throw new PersistenceDatabaseException(se);
139        }
140        
141        return _result;
142    }
143    
144    public java.util.List<OfferItemFixedPricePK> getPKsFromResultSetAsList(ResultSet rs)
145            throws PersistenceDatabaseException {
146        java.util.List<OfferItemFixedPricePK> _result = new ArrayList<>();
147        
148        try {
149            while(rs.next()) {
150                _result.add(getPKFromResultSet(rs));
151            }
152        } catch (SQLException se) {
153            throw new PersistenceDatabaseException(se);
154        }
155        
156        return _result;
157    }
158    
159    public OfferItemFixedPricePK getPKFromResultSet(ResultSet rs)
160            throws PersistenceDatabaseException {
161        OfferItemFixedPricePK _result;
162        
163        try {
164            long ofritmfp_offeritemfixedpriceid = rs.getLong(OFRITMFP_OFFERITEMFIXEDPRICEID);
165            Long _entityId = rs.wasNull() ? null : ofritmfp_offeritemfixedpriceid;
166            
167            _result = new OfferItemFixedPricePK(_entityId);
168        } catch (SQLException se) {
169            throw new PersistenceDatabaseException(se);
170        }
171        
172        return _result;
173    }
174    
175    public java.util.List<OfferItemFixedPriceValue> getValuesFromPKs(Collection<OfferItemFixedPricePK> pks)
176            throws PersistenceDatabaseException {
177        java.util.List<OfferItemFixedPriceValue> _values = new ArrayList<>(pks.size());
178        
179        for(OfferItemFixedPricePK _pk: pks) {
180            _values.add(getValueFromPK(_pk));
181        }
182        
183        return _values;
184    }
185    
186    public OfferItemFixedPriceValue getValueFromPK(OfferItemFixedPricePK pk)
187            throws PersistenceDatabaseException {
188        OfferItemFixedPriceValue _value;
189        
190        // See if we already have the entity in the session cache
191        OfferItemFixedPrice _entity = (OfferItemFixedPrice)session.getEntity(pk);
192        if(_entity == null)
193            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getOfferItemFixedPriceValue();
194        else
195            _value = _entity.getOfferItemFixedPriceValue();
196        
197        return _value;
198    }
199    
200    public java.util.List<OfferItemFixedPriceValue> getValuesFromResultSet(ResultSet rs)
201            throws PersistenceDatabaseException {
202        java.util.List<OfferItemFixedPriceValue> _result = new ArrayList<>();
203        
204        try {
205            while(rs.next()) {
206                _result.add(getValueFromResultSet(rs));
207            }
208        } catch (SQLException se) {
209            throw new PersistenceDatabaseException(se);
210        }
211        
212        return _result;
213    }
214    
215    public OfferItemFixedPriceValue getValueFromResultSet(ResultSet rs)
216            throws PersistenceDatabaseException {
217        OfferItemFixedPriceValue _value;
218        
219        try {
220            Long ofritmfp_offeritemfixedpriceid = rs.getLong(OFRITMFP_OFFERITEMFIXEDPRICEID);
221            OfferItemFixedPricePK _pk = new OfferItemFixedPricePK(ofritmfp_offeritemfixedpriceid);
222            
223            // See if we already have the entity in the session cache
224            OfferItemFixedPrice _entity = (OfferItemFixedPrice)session.getEntity(_pk);
225            
226            if(_entity == null) {
227                Long ofritmfp_ofritmp_offeritempriceid = rs.getLong(OFRITMFP_OFRITMP_OFFERITEMPRICEID);
228                if(rs.wasNull())
229                    ofritmfp_ofritmp_offeritempriceid = null;
230                
231                Long ofritmfp_unitprice = rs.getLong(OFRITMFP_UNITPRICE);
232                if(rs.wasNull())
233                    ofritmfp_unitprice = null;
234                
235                Long ofritmfp_fromtime = rs.getLong(OFRITMFP_FROMTIME);
236                if(rs.wasNull())
237                    ofritmfp_fromtime = null;
238                
239                Long ofritmfp_thrutime = rs.getLong(OFRITMFP_THRUTIME);
240                if(rs.wasNull())
241                    ofritmfp_thrutime = null;
242                
243                _value = new OfferItemFixedPriceValue(_pk, new OfferItemPricePK(ofritmfp_ofritmp_offeritempriceid), ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime);
244            } else
245                _value = _entity.getOfferItemFixedPriceValue();
246        } catch (SQLException se) {
247            throw new PersistenceDatabaseException(se);
248        }
249        
250        return _value;
251    }
252    
253    public java.util.List<OfferItemFixedPrice> getEntitiesFromPKs(EntityPermission entityPermission, Collection<OfferItemFixedPricePK> pks)
254            throws PersistenceDatabaseException {
255        java.util.List<OfferItemFixedPrice> _entities = new ArrayList<>(pks.size());
256        
257        for(OfferItemFixedPricePK _pk: pks) {
258            _entities.add(getEntityFromPK(entityPermission, _pk));
259        }
260        
261        return _entities;
262    }
263    
264    public OfferItemFixedPrice getEntityFromValue(EntityPermission entityPermission, OfferItemFixedPriceValue value) {
265        return getEntityFromPK(entityPermission, value.getPrimaryKey());
266    }
267    
268    public OfferItemFixedPrice getEntityFromCache(OfferItemFixedPricePK pk) {
269        OfferItemFixedPriceValue _value = (OfferItemFixedPriceValue)session.getValueCache().get(pk);
270    
271        return _value == null ? null : new OfferItemFixedPrice(_value, EntityPermission.READ_ONLY);
272    }
273    
274    public OfferItemFixedPrice getEntityFromPK(EntityPermission entityPermission, OfferItemFixedPricePK pk)
275            throws PersistenceDatabaseException {
276        OfferItemFixedPrice _entity;
277        
278        // See if we already have the entity in the session cache
279        _entity = (OfferItemFixedPrice)session.getEntity(pk);
280        if(_entity != null) {
281            // If the requested permission is READ_WRITE, and the cached permission is
282            // READ_ONLY, then pretend that the cached object wasn't found, and create
283            // a new entity that is READ_WRITE.
284            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
285                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
286                    _entity = null;
287            }
288        }
289        
290        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
291            _entity = getEntityFromCache(pk);
292        }
293        
294        if(_entity == null) {
295            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
296            long _entityId = pk.getEntityId();
297            ResultSet _rs = null;
298            
299            try {
300                _ps.setLong(1, _entityId);
301                _rs = _ps.executeQuery();
302                if(_rs.next()) {
303                    _entity = getEntityFromResultSet(entityPermission, _rs);
304                }
305            } catch (SQLException se) {
306                throw new PersistenceDatabaseException(se);
307            } finally {
308                if(_rs != null) {
309                    try {
310                        _rs.close();
311                    } catch (SQLException se) {
312                        // do nothing
313                    }
314                }
315            }
316        }
317        
318        return _entity;
319    }
320    
321    public Set<OfferItemFixedPricePK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
322            throws PersistenceDatabaseException {
323        Set<OfferItemFixedPricePK> _pks;
324        ResultSet _rs = null;
325        
326        try {
327            if(params.length != 0) {
328                Session.setQueryParams(ps, params);
329            }
330            
331            _rs = ps.executeQuery();
332            _pks = getPKsFromResultSetAsSet(_rs);
333            _rs.close();
334        } catch (SQLException se) {
335            throw new PersistenceDatabaseException(se);
336        } finally {
337            if(_rs != null) {
338                try {
339                    _rs.close();
340                } catch (SQLException se) {
341                    // do nothing
342                }
343            }
344        }
345        
346        return _pks;
347    }
348    
349    public java.util.List<OfferItemFixedPricePK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
350            throws PersistenceDatabaseException {
351        java.util.List<OfferItemFixedPricePK> _pks;
352        ResultSet _rs = null;
353        
354        try {
355            if(params.length != 0) {
356                Session.setQueryParams(ps, params);
357            }
358            
359            _rs = ps.executeQuery();
360            _pks = getPKsFromResultSetAsList(_rs);
361            _rs.close();
362        } catch (SQLException se) {
363            throw new PersistenceDatabaseException(se);
364        } finally {
365            if(_rs != null) {
366                try {
367                    _rs.close();
368                } catch (SQLException se) {
369                    // do nothing
370                }
371            }
372        }
373        
374        return _pks;
375    }
376    
377    public OfferItemFixedPricePK getPKFromQuery(PreparedStatement ps, final Object... params)
378            throws PersistenceDatabaseException {
379        OfferItemFixedPricePK _pk = null;
380        ResultSet _rs = null;
381        
382        try {
383            if(params.length != 0) {
384                Session.setQueryParams(ps, params);
385            }
386            
387            _rs = ps.executeQuery();
388            if(_rs.next()) {
389                _pk = getPKFromResultSet(_rs);
390            }
391            _rs.close();
392        } catch (SQLException se) {
393            throw new PersistenceDatabaseException(se);
394        } finally {
395            if(_rs != null) {
396                try {
397                    _rs.close();
398                } catch (SQLException se) {
399                    // do nothing
400                }
401            }
402        }
403        
404        return _pk;
405    }
406    
407    public java.util.List<OfferItemFixedPrice> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
408            throws PersistenceDatabaseException {
409        PreparedStatement ps = session.prepareStatement(OfferItemFixedPriceFactory.class, queryMap.get(entityPermission));
410        
411        return getEntitiesFromQuery(entityPermission, ps, params);
412    }
413    
414    public java.util.List<OfferItemFixedPrice> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
415            throws PersistenceDatabaseException {
416        PreparedStatement ps = session.prepareStatement(OfferItemFixedPriceFactory.class, queryMap.get(entityPermission));
417        
418        return getEntitiesFromQuery(entityPermission, ps);
419    }
420    
421    public java.util.List<OfferItemFixedPrice> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
422            throws PersistenceDatabaseException {
423        java.util.List<OfferItemFixedPrice> _entities;
424        ResultSet _rs = null;
425        
426        try {
427            if(params.length != 0) {
428                Session.setQueryParams(ps, params);
429            }
430            
431            _rs = ps.executeQuery();
432            _entities = getEntitiesFromResultSet(entityPermission, _rs);
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 _entities;
447    }
448    
449    public OfferItemFixedPrice getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
450            throws PersistenceDatabaseException {
451        PreparedStatement ps = session.prepareStatement(OfferItemFixedPriceFactory.class, queryMap.get(entityPermission));
452        
453        return getEntityFromQuery(entityPermission, ps, params);
454    }
455    
456    public OfferItemFixedPrice getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
457            throws PersistenceDatabaseException {
458        PreparedStatement ps = session.prepareStatement(OfferItemFixedPriceFactory.class, queryMap.get(entityPermission));
459        
460        return getEntityFromQuery(entityPermission, ps);
461    }
462    
463    public OfferItemFixedPrice getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
464            throws PersistenceDatabaseException {
465        OfferItemFixedPrice _entity = null;
466        ResultSet _rs = null;
467        
468        try {
469            if(params.length != 0) {
470                Session.setQueryParams(ps, params);
471            }
472            
473            _rs = ps.executeQuery();
474            if(_rs.next()) {
475                _entity = getEntityFromResultSet(entityPermission, _rs);
476            }
477            _rs.close();
478        } catch (SQLException se) {
479            throw new PersistenceDatabaseException(se);
480        } finally {
481            if(_rs != null) {
482                try {
483                    _rs.close();
484                } catch (SQLException se) {
485                    // do nothing
486                }
487            }
488        }
489        
490        return _entity;
491    }
492    
493    public java.util.List<OfferItemFixedPrice> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
494            throws PersistenceDatabaseException {
495        java.util.List<OfferItemFixedPrice> _result = new ArrayList<>();
496        
497        try {
498            while(rs.next()) {
499                _result.add(getEntityFromResultSet(entityPermission, rs));
500            }
501        } catch (SQLException se) {
502            throw new PersistenceDatabaseException(se);
503        }
504        
505        return _result;
506    }
507    
508    public OfferItemFixedPrice getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
509            throws PersistenceDatabaseException {
510        OfferItemFixedPrice _entity;
511        
512        try {
513            Long ofritmfp_offeritemfixedpriceid = rs.getLong(OFRITMFP_OFFERITEMFIXEDPRICEID);
514            OfferItemFixedPricePK _pk = new OfferItemFixedPricePK(ofritmfp_offeritemfixedpriceid);
515            
516            // See if we already have the entity in the session cache
517            _entity = (OfferItemFixedPrice)session.getEntity(_pk);
518            if(_entity != null) {
519                // If the requested permission is READ_WRITE, and the cached permission is
520                // READ_ONLY, then pretend that the cached object wasn't found, and create
521                // a new entity that is READ_WRITE.
522                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
523                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
524                        _entity = null;
525                }
526            }
527            boolean foundInSessionCache = _entity != null;
528            
529            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
530                _entity = getEntityFromCache(_pk);
531            }
532            
533            if(_entity == null) {
534                Long ofritmfp_ofritmp_offeritempriceid = rs.getLong(OFRITMFP_OFRITMP_OFFERITEMPRICEID);
535                if(rs.wasNull())
536                    ofritmfp_ofritmp_offeritempriceid = null;
537                
538                Long ofritmfp_unitprice = rs.getLong(OFRITMFP_UNITPRICE);
539                if(rs.wasNull())
540                    ofritmfp_unitprice = null;
541                
542                Long ofritmfp_fromtime = rs.getLong(OFRITMFP_FROMTIME);
543                if(rs.wasNull())
544                    ofritmfp_fromtime = null;
545                
546                Long ofritmfp_thrutime = rs.getLong(OFRITMFP_THRUTIME);
547                if(rs.wasNull())
548                    ofritmfp_thrutime = null;
549                
550                OfferItemFixedPriceValue _value = new OfferItemFixedPriceValue(_pk, ofritmfp_ofritmp_offeritempriceid == null? null: new OfferItemPricePK(ofritmfp_ofritmp_offeritempriceid), ofritmfp_unitprice, ofritmfp_fromtime, ofritmfp_thrutime);
551                _entity = new OfferItemFixedPrice(_value, entityPermission);
552            }
553            
554            if(!foundInSessionCache) {
555                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
556                    session.putReadOnlyEntity(_pk, _entity);
557                    session.getValueCache().put(_entity.getOfferItemFixedPriceValue());
558                } else {
559                    session.putReadWriteEntity(_pk, _entity);
560                }
561            }
562        } catch (SQLException se) {
563            throw new PersistenceDatabaseException(se);
564        }
565        
566        return _entity;
567    }
568    
569    public OfferItemFixedPrice create(OfferItemPrice offerItemPrice, Long unitPrice, Long fromTime, Long thruTime)
570            throws PersistenceDatabaseException, PersistenceNotNullException {
571        return create(offerItemPrice == null ? null : offerItemPrice.getPrimaryKey(), unitPrice, fromTime, thruTime);
572    }
573    
574    private void bindForCreate(PreparedStatement _ps, OfferItemFixedPriceValue _value)
575            throws SQLException {
576        _ps.setLong(1, _value.getEntityId());
577        
578        OfferItemPricePK ofritmfp_ofritmp_offeritempriceid = _value.getOfferItemPricePK();
579        if(ofritmfp_ofritmp_offeritempriceid == null)
580            _ps.setNull(2, Types.BIGINT);
581        else
582            _ps.setLong(2, ofritmfp_ofritmp_offeritempriceid.getEntityId());
583            
584        Long ofritmfp_unitprice = _value.getUnitPrice();
585        if(ofritmfp_unitprice == null)
586            _ps.setNull(3, Types.BIGINT);
587        else
588            _ps.setLong(3, ofritmfp_unitprice);
589            
590        Long ofritmfp_fromtime = _value.getFromTime();
591        if(ofritmfp_fromtime == null)
592            _ps.setNull(4, Types.BIGINT);
593        else
594            _ps.setLong(4, ofritmfp_fromtime);
595            
596        Long ofritmfp_thrutime = _value.getThruTime();
597        if(ofritmfp_thrutime == null)
598            _ps.setNull(5, Types.BIGINT);
599        else
600            _ps.setLong(5, ofritmfp_thrutime);
601            
602    }
603    
604    public OfferItemFixedPrice create(OfferItemPricePK offerItemPricePK, Long unitPrice, Long fromTime, Long thruTime)
605            throws PersistenceDatabaseException, PersistenceNotNullException {
606        OfferItemFixedPricePK _pk = getNextPK();
607        OfferItemFixedPriceValue _value = new OfferItemFixedPriceValue(_pk, offerItemPricePK, unitPrice, fromTime, thruTime);
608        
609        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
610        
611        try {
612            bindForCreate(_ps, _value);
613            
614            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
615                int _count = _ps.executeUpdate();
616                
617                if(_count != 1) {
618                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
619                }
620            } else {
621                 _ps.executeUpdate();
622            }
623            
624            session.getValueCache().put(_value);
625        } catch (SQLException se) {
626            throw new PersistenceDatabaseException(se);
627        }
628        
629        OfferItemFixedPrice _entity = new OfferItemFixedPrice(_value, EntityPermission.READ_ONLY);
630        session.putReadOnlyEntity(_pk, _entity);
631        
632        return _entity;
633    }
634    
635    public void create(Collection<OfferItemFixedPriceValue> _values)
636            throws PersistenceDatabaseException, PersistenceNotNullException {
637        int _size = _values.size();
638        
639        if(_size > 0) {
640            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
641            List<OfferItemFixedPriceValue> _cacheValues = new ArrayList<>(_size);
642            
643            try {
644                for(OfferItemFixedPriceValue _value : _values) {
645                    _value.setEntityId(entityIdGenerator.getNextEntityId());
646                    bindForCreate(_ps, _value);
647                    
648                    _ps.addBatch();
649                    
650                    _cacheValues.add(_value);
651                }
652                
653                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
654                    int[] _counts = _ps.executeBatch();
655                    
656                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
657                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
658                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
659                        }
660                    }
661                } else {
662                     _ps.executeBatch();
663                }
664                
665                _ps.clearBatch();
666            } catch (SQLException se) {
667                throw new PersistenceDatabaseException(se);
668            }
669            
670            _cacheValues.forEach((_cacheValue) -> {
671                OfferItemFixedPrice _cacheEntity = new OfferItemFixedPrice(_cacheValue, EntityPermission.READ_ONLY);
672                
673                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
674            });
675        }
676    }
677    
678    private boolean bindForStore(PreparedStatement _ps, OfferItemFixedPriceValue _value)
679            throws SQLException {
680        boolean _hasBeenModified = _value.hasBeenModified();
681        
682        if(_hasBeenModified) {
683            OfferItemPricePK ofritmfp_ofritmp_offeritempriceid = _value.getOfferItemPricePK();
684            if(ofritmfp_ofritmp_offeritempriceid == null)
685                _ps.setNull(1, Types.BIGINT);
686            else
687                _ps.setLong(1, ofritmfp_ofritmp_offeritempriceid.getEntityId());
688            
689            Long ofritmfp_unitprice = _value.getUnitPrice();
690            if(ofritmfp_unitprice == null)
691                _ps.setNull(2, Types.BIGINT);
692            else
693                _ps.setLong(2, ofritmfp_unitprice);
694            
695            Long ofritmfp_fromtime = _value.getFromTime();
696            if(ofritmfp_fromtime == null)
697                _ps.setNull(3, Types.BIGINT);
698            else
699                _ps.setLong(3, ofritmfp_fromtime);
700            
701            Long ofritmfp_thrutime = _value.getThruTime();
702            if(ofritmfp_thrutime == null)
703                _ps.setNull(4, Types.BIGINT);
704            else
705                _ps.setLong(4, ofritmfp_thrutime);
706            
707            _ps.setLong(5, _value.getPrimaryKey().getEntityId());
708            
709            _value.clearHasBeenModified();
710        }
711        
712        return _hasBeenModified;
713    }
714    
715    @Override
716    public void store(OfferItemFixedPrice entity)
717            throws PersistenceDatabaseException {
718        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
719        
720        try {
721            OfferItemFixedPriceValue _value = entity.getOfferItemFixedPriceValue();
722            
723            if(bindForStore(_ps, _value)) {
724                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
725                    int _count = _ps.executeUpdate();
726                    
727                    if(_count != 1) {
728                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
729                    }
730                } else {
731                     _ps.executeUpdate();
732                }
733                
734                session.getValueCache().put(_value);
735            }
736        } catch (SQLException se) {
737            throw new PersistenceDatabaseException(se);
738        }
739    }
740    
741    @Override
742    public void store(Collection<OfferItemFixedPrice> entities)
743            throws PersistenceDatabaseException {
744        if(entities.size() > 0) {
745            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
746            int _modifiedEntities = 0;
747            
748            try {
749                for(OfferItemFixedPrice entity : entities) {
750                    if(bindForStore(_ps, entity.getOfferItemFixedPriceValue())) {
751                        _ps.addBatch();
752                        _modifiedEntities++;
753                    }
754                }
755                
756                if(_modifiedEntities != 0) {
757                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
758                        int[] _counts = _ps.executeBatch();
759                        
760                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
761                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
762                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
763                            }
764                        }
765                    } else {
766                         _ps.executeBatch();
767                    }
768                    
769                    _ps.clearBatch();
770                    
771                    entities.forEach((entity) -> {
772                        session.getValueCache().put(entity.getOfferItemFixedPriceValue());
773                    });
774                }
775            } catch (SQLException se) {
776                throw new PersistenceDatabaseException(se);
777            }
778        }
779    }
780    
781    @Override
782    public void remove(OfferItemFixedPrice entity)
783            throws PersistenceDatabaseException {
784        remove(entity.getPrimaryKey());
785    }
786    
787    @Override
788    public void remove(OfferItemFixedPricePK pk)
789            throws PersistenceDatabaseException {
790        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
791        long _entityId = pk.getEntityId();
792        
793        try {
794            _ps.setLong(1, _entityId);
795            
796            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
797                int _count = _ps.executeUpdate();
798                
799                if(_count != 1) {
800                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
801                }
802            } else {
803                 _ps.executeUpdate();
804            }
805            
806            session.getValueCache().remove(pk);
807        } catch (SQLException se) {
808            throw new PersistenceDatabaseException(se);
809        }
810        
811        session.removed(pk, false);
812    }
813    
814    @Override
815    public void remove(Collection<OfferItemFixedPricePK> pks)
816            throws PersistenceDatabaseException {
817        if(pks.size() > 0) {
818            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
819            int _modifiedEntities = 0;
820            
821            try {
822                for(OfferItemFixedPricePK pk : pks) {
823                    long _entityId = pk.getEntityId();
824                    
825                    _ps.setLong(1, _entityId);
826                    
827                    _ps.addBatch();
828                    _modifiedEntities++;
829                }
830                
831                if(_modifiedEntities != 0) {
832                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
833                        int[] _counts = _ps.executeBatch();
834                        
835                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
836                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
837                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
838                            }
839                        }
840                    } else {
841                        _ps.executeBatch();
842                    }
843                    
844                    _ps.clearBatch();
845                    
846                    pks.forEach((pk) -> {
847                        session.getValueCache().remove(pk);
848                    });
849                }
850            } catch (SQLException se) {
851                throw new PersistenceDatabaseException(se);
852            }
853            
854            pks.forEach((pk) -> {
855                session.removed(pk, true);
856            });
857        }
858    }
859    
860    @Override
861    public boolean validPK(OfferItemFixedPricePK pk)
862            throws PersistenceDatabaseException {
863        boolean valid = false;
864        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
865        ResultSet _rs = null;
866        
867        try {
868            _ps.setLong(1, pk.getEntityId());
869            
870            _rs = _ps.executeQuery();
871            if(_rs.next()) {
872                long _count = _rs.getLong(1);
873                if(_rs.wasNull())
874                    _count = 0;
875                
876                if(_count == 1)
877                    valid = true;
878            }
879        } catch (SQLException se) {
880            throw new PersistenceDatabaseException(se);
881        } finally {
882            if(_rs != null) {
883                try {
884                    _rs.close();
885                } catch (SQLException se) {
886                    // do nothing
887                }
888            }
889        }
890        
891        return valid;
892    }
893    
894}