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