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