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