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