001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * PaymentMethodCreditCardFactory.java
021 */
022
023package com.echothree.model.data.payment.server.factory;
024
025import com.echothree.model.data.payment.common.pk.PaymentMethodPK;
026
027import com.echothree.model.data.payment.server.entity.PaymentMethod;
028
029import com.echothree.model.data.payment.common.PaymentMethodCreditCardConstants;
030import com.echothree.model.data.payment.common.pk.PaymentMethodCreditCardPK;
031import com.echothree.model.data.payment.server.value.PaymentMethodCreditCardValue;
032import com.echothree.model.data.payment.server.entity.PaymentMethodCreditCard;
033import com.echothree.util.common.exception.PersistenceDatabaseException;
034import com.echothree.util.common.exception.PersistenceDatabaseUpdateException;
035import com.echothree.util.common.exception.PersistenceNotNullException;
036import com.echothree.util.server.persistence.BaseFactory;
037import com.echothree.util.server.persistence.EntityIdGenerator;
038import com.echothree.util.server.persistence.EntityPermission;
039import com.echothree.util.server.persistence.PersistenceDebugFlags;
040import com.echothree.util.server.persistence.Session;
041import java.sql.PreparedStatement;
042import java.sql.ResultSet;
043import java.sql.SQLException;
044import java.sql.Types;
045import java.io.ByteArrayInputStream;
046import java.io.StringReader;
047import java.util.ArrayList;
048import java.util.Collection;
049import java.util.HashSet;
050import java.util.List;
051import java.util.Map;
052import java.util.Set;
053import javax.enterprise.context.ApplicationScoped;
054import javax.enterprise.inject.spi.CDI;
055import javax.inject.Inject;
056import org.jooq.ResultQuery;
057import org.slf4j.Logger;
058import org.slf4j.LoggerFactory;
059
060@ApplicationScoped
061public class PaymentMethodCreditCardFactory
062        implements BaseFactory<PaymentMethodCreditCardPK, PaymentMethodCreditCard> {
063    
064    @Inject
065    Session session;
066    
067    //private static final Logger log = LoggerFactory.getLogger(PaymentMethodCreditCardFactory.class);
068    
069    final private static String SQL_SELECT_READ_ONLY = "SELECT pmcc_paymentmethodcreditcardid, pmcc_pm_paymentmethodid, pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime FROM paymentmethodcreditcards WHERE pmcc_paymentmethodcreditcardid = ?";
070    final private static String SQL_SELECT_READ_WRITE = "SELECT pmcc_paymentmethodcreditcardid, pmcc_pm_paymentmethodid, pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime FROM paymentmethodcreditcards WHERE pmcc_paymentmethodcreditcardid = ? FOR UPDATE";
071    final private static String SQL_INSERT = "INSERT INTO paymentmethodcreditcards (pmcc_paymentmethodcreditcardid, pmcc_pm_paymentmethodid, pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
072    final private static String SQL_UPDATE = "UPDATE paymentmethodcreditcards SET pmcc_pm_paymentmethodid = ?, pmcc_requestnameoncard = ?, pmcc_requirenameoncard = ?, pmcc_checkcardnumber = ?, pmcc_requestexpirationdate = ?, pmcc_requireexpirationdate = ?, pmcc_checkexpirationdate = ?, pmcc_requestsecuritycode = ?, pmcc_requiresecuritycode = ?, pmcc_cardnumbervalidationpattern = ?, pmcc_securitycodevalidationpattern = ?, pmcc_retaincreditcard = ?, pmcc_retainsecuritycode = ?, pmcc_requestbilling = ?, pmcc_requirebilling = ?, pmcc_requestissuer = ?, pmcc_requireissuer = ?, pmcc_fromtime = ?, pmcc_thrutime = ? WHERE pmcc_paymentmethodcreditcardid = ?";
073    final private static String SQL_DELETE = "DELETE FROM paymentmethodcreditcards WHERE pmcc_paymentmethodcreditcardid = ?";
074    final private static String SQL_VALID = "SELECT COUNT(*) FROM paymentmethodcreditcards WHERE pmcc_paymentmethodcreditcardid = ?";
075    
076    final private static String PK_COLUMN = "pmcc_paymentmethodcreditcardid";
077    final private static String ALL_COLUMNS = "pmcc_paymentmethodcreditcardid, pmcc_pm_paymentmethodid, pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime";
078    final public static String TABLE_NAME = "paymentmethodcreditcards";
079    
080    final public static String PMCC_PAYMENTMETHODCREDITCARDID = "pmcc_paymentmethodcreditcardid";
081    final public static String PMCC_PM_PAYMENTMETHODID = "pmcc_pm_paymentmethodid";
082    final public static String PMCC_REQUESTNAMEONCARD = "pmcc_requestnameoncard";
083    final public static String PMCC_REQUIRENAMEONCARD = "pmcc_requirenameoncard";
084    final public static String PMCC_CHECKCARDNUMBER = "pmcc_checkcardnumber";
085    final public static String PMCC_REQUESTEXPIRATIONDATE = "pmcc_requestexpirationdate";
086    final public static String PMCC_REQUIREEXPIRATIONDATE = "pmcc_requireexpirationdate";
087    final public static String PMCC_CHECKEXPIRATIONDATE = "pmcc_checkexpirationdate";
088    final public static String PMCC_REQUESTSECURITYCODE = "pmcc_requestsecuritycode";
089    final public static String PMCC_REQUIRESECURITYCODE = "pmcc_requiresecuritycode";
090    final public static String PMCC_CARDNUMBERVALIDATIONPATTERN = "pmcc_cardnumbervalidationpattern";
091    final public static String PMCC_SECURITYCODEVALIDATIONPATTERN = "pmcc_securitycodevalidationpattern";
092    final public static String PMCC_RETAINCREDITCARD = "pmcc_retaincreditcard";
093    final public static String PMCC_RETAINSECURITYCODE = "pmcc_retainsecuritycode";
094    final public static String PMCC_REQUESTBILLING = "pmcc_requestbilling";
095    final public static String PMCC_REQUIREBILLING = "pmcc_requirebilling";
096    final public static String PMCC_REQUESTISSUER = "pmcc_requestissuer";
097    final public static String PMCC_REQUIREISSUER = "pmcc_requireissuer";
098    final public static String PMCC_FROMTIME = "pmcc_fromtime";
099    final public static String PMCC_THRUTIME = "pmcc_thrutime";
100    
101    final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(PaymentMethodCreditCardConstants.COMPONENT_VENDOR_NAME, PaymentMethodCreditCardConstants.ENTITY_TYPE_NAME);
102    
103    /** Creates a new instance of PaymentMethodCreditCardFactory */
104    protected PaymentMethodCreditCardFactory() {
105        super();
106    }
107    
108    public static PaymentMethodCreditCardFactory getInstance() {
109        return CDI.current().select(PaymentMethodCreditCardFactory.class).get();
110    }
111    
112    @Override
113    public String getPKColumn() {
114        return PK_COLUMN;
115    }
116    
117    @Override
118    public String getAllColumns() {
119        return ALL_COLUMNS;
120    }
121    
122    @Override
123    public String getTableName() {
124        return TABLE_NAME;
125    }
126    
127    @Override
128    public String getComponentVendorName() {
129        return PaymentMethodCreditCardConstants.COMPONENT_VENDOR_NAME;
130    }
131    
132    @Override
133    public String getEntityTypeName() {
134        return PaymentMethodCreditCardConstants.ENTITY_TYPE_NAME;
135    }
136    
137    public PreparedStatement prepareStatement(String query) {
138        return session.prepareStatement(PaymentMethodCreditCardFactory.class, query);
139    }
140    
141    public PaymentMethodCreditCardPK getNextPK() {
142        return new PaymentMethodCreditCardPK(entityIdGenerator.getNextEntityId());
143    }
144    
145    public Set<PaymentMethodCreditCardPK> getPKsFromResultSetAsSet(ResultSet rs)
146            throws PersistenceDatabaseException {
147        Set<PaymentMethodCreditCardPK> _result = new HashSet<>();
148        
149        try {
150            while(rs.next()) {
151                _result.add(getPKFromResultSet(rs));
152            }
153        } catch (SQLException se) {
154            throw new PersistenceDatabaseException(se);
155        }
156        
157        return _result;
158    }
159    
160    public java.util.List<PaymentMethodCreditCardPK> getPKsFromResultSetAsList(ResultSet rs)
161            throws PersistenceDatabaseException {
162        java.util.List<PaymentMethodCreditCardPK> _result = new ArrayList<>();
163        
164        try {
165            while(rs.next()) {
166                _result.add(getPKFromResultSet(rs));
167            }
168        } catch (SQLException se) {
169            throw new PersistenceDatabaseException(se);
170        }
171        
172        return _result;
173    }
174    
175    public PaymentMethodCreditCardPK getPKFromResultSet(ResultSet rs)
176            throws PersistenceDatabaseException {
177        PaymentMethodCreditCardPK _result;
178        
179        try {
180            long pmcc_paymentmethodcreditcardid = rs.getLong(PMCC_PAYMENTMETHODCREDITCARDID);
181            Long _entityId = rs.wasNull() ? null : pmcc_paymentmethodcreditcardid;
182            
183            _result = new PaymentMethodCreditCardPK(_entityId);
184        } catch (SQLException se) {
185            throw new PersistenceDatabaseException(se);
186        }
187        
188        return _result;
189    }
190    
191    public java.util.List<PaymentMethodCreditCardValue> getValuesFromPKs(Collection<PaymentMethodCreditCardPK> pks)
192            throws PersistenceDatabaseException {
193        java.util.List<PaymentMethodCreditCardValue> _values = new ArrayList<>(pks.size());
194        
195        for(PaymentMethodCreditCardPK _pk: pks) {
196            _values.add(getValueFromPK(_pk));
197        }
198        
199        return _values;
200    }
201    
202    public PaymentMethodCreditCardValue getValueFromPK(PaymentMethodCreditCardPK pk)
203            throws PersistenceDatabaseException {
204        PaymentMethodCreditCardValue _value;
205        
206        // See if we already have the entity in the session cache
207        PaymentMethodCreditCard _entity = (PaymentMethodCreditCard)session.getEntity(pk);
208        if(_entity == null)
209            _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getPaymentMethodCreditCardValue();
210        else
211            _value = _entity.getPaymentMethodCreditCardValue();
212        
213        return _value;
214    }
215    
216    public java.util.List<PaymentMethodCreditCardValue> getValuesFromResultSet(ResultSet rs)
217            throws PersistenceDatabaseException {
218        java.util.List<PaymentMethodCreditCardValue> _result = new ArrayList<>();
219        
220        try {
221            while(rs.next()) {
222                _result.add(getValueFromResultSet(rs));
223            }
224        } catch (SQLException se) {
225            throw new PersistenceDatabaseException(se);
226        }
227        
228        return _result;
229    }
230    
231    public PaymentMethodCreditCardValue getValueFromResultSet(ResultSet rs)
232            throws PersistenceDatabaseException {
233        PaymentMethodCreditCardValue _value;
234        
235        try {
236            Long pmcc_paymentmethodcreditcardid = rs.getLong(PMCC_PAYMENTMETHODCREDITCARDID);
237            PaymentMethodCreditCardPK _pk = new PaymentMethodCreditCardPK(pmcc_paymentmethodcreditcardid);
238            
239            // See if we already have the entity in the session cache
240            PaymentMethodCreditCard _entity = (PaymentMethodCreditCard)session.getEntity(_pk);
241            
242            if(_entity == null) {
243                Long pmcc_pm_paymentmethodid = rs.getLong(PMCC_PM_PAYMENTMETHODID);
244                if(rs.wasNull())
245                    pmcc_pm_paymentmethodid = null;
246                
247                Boolean pmcc_requestnameoncard = rs.getInt(PMCC_REQUESTNAMEONCARD) == 1;
248                if(rs.wasNull())
249                    pmcc_requestnameoncard = null;
250                
251                Boolean pmcc_requirenameoncard = rs.getInt(PMCC_REQUIRENAMEONCARD) == 1;
252                if(rs.wasNull())
253                    pmcc_requirenameoncard = null;
254                
255                Boolean pmcc_checkcardnumber = rs.getInt(PMCC_CHECKCARDNUMBER) == 1;
256                if(rs.wasNull())
257                    pmcc_checkcardnumber = null;
258                
259                Boolean pmcc_requestexpirationdate = rs.getInt(PMCC_REQUESTEXPIRATIONDATE) == 1;
260                if(rs.wasNull())
261                    pmcc_requestexpirationdate = null;
262                
263                Boolean pmcc_requireexpirationdate = rs.getInt(PMCC_REQUIREEXPIRATIONDATE) == 1;
264                if(rs.wasNull())
265                    pmcc_requireexpirationdate = null;
266                
267                Boolean pmcc_checkexpirationdate = rs.getInt(PMCC_CHECKEXPIRATIONDATE) == 1;
268                if(rs.wasNull())
269                    pmcc_checkexpirationdate = null;
270                
271                Boolean pmcc_requestsecuritycode = rs.getInt(PMCC_REQUESTSECURITYCODE) == 1;
272                if(rs.wasNull())
273                    pmcc_requestsecuritycode = null;
274                
275                Boolean pmcc_requiresecuritycode = rs.getInt(PMCC_REQUIRESECURITYCODE) == 1;
276                if(rs.wasNull())
277                    pmcc_requiresecuritycode = null;
278                
279                String pmcc_cardnumbervalidationpattern = rs.getString(PMCC_CARDNUMBERVALIDATIONPATTERN);
280                if(rs.wasNull())
281                    pmcc_cardnumbervalidationpattern = null;
282                
283                String pmcc_securitycodevalidationpattern = rs.getString(PMCC_SECURITYCODEVALIDATIONPATTERN);
284                if(rs.wasNull())
285                    pmcc_securitycodevalidationpattern = null;
286                
287                Boolean pmcc_retaincreditcard = rs.getInt(PMCC_RETAINCREDITCARD) == 1;
288                if(rs.wasNull())
289                    pmcc_retaincreditcard = null;
290                
291                Boolean pmcc_retainsecuritycode = rs.getInt(PMCC_RETAINSECURITYCODE) == 1;
292                if(rs.wasNull())
293                    pmcc_retainsecuritycode = null;
294                
295                Boolean pmcc_requestbilling = rs.getInt(PMCC_REQUESTBILLING) == 1;
296                if(rs.wasNull())
297                    pmcc_requestbilling = null;
298                
299                Boolean pmcc_requirebilling = rs.getInt(PMCC_REQUIREBILLING) == 1;
300                if(rs.wasNull())
301                    pmcc_requirebilling = null;
302                
303                Boolean pmcc_requestissuer = rs.getInt(PMCC_REQUESTISSUER) == 1;
304                if(rs.wasNull())
305                    pmcc_requestissuer = null;
306                
307                Boolean pmcc_requireissuer = rs.getInt(PMCC_REQUIREISSUER) == 1;
308                if(rs.wasNull())
309                    pmcc_requireissuer = null;
310                
311                Long pmcc_fromtime = rs.getLong(PMCC_FROMTIME);
312                if(rs.wasNull())
313                    pmcc_fromtime = null;
314                
315                Long pmcc_thrutime = rs.getLong(PMCC_THRUTIME);
316                if(rs.wasNull())
317                    pmcc_thrutime = null;
318                
319                _value = new PaymentMethodCreditCardValue(_pk, new PaymentMethodPK(pmcc_pm_paymentmethodid), pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime);
320            } else
321                _value = _entity.getPaymentMethodCreditCardValue();
322        } catch (SQLException se) {
323            throw new PersistenceDatabaseException(se);
324        }
325        
326        return _value;
327    }
328    
329    public java.util.List<PaymentMethodCreditCard> getEntitiesFromPKs(EntityPermission entityPermission, Collection<PaymentMethodCreditCardPK> pks)
330            throws PersistenceDatabaseException {
331        java.util.List<PaymentMethodCreditCard> _entities = new ArrayList<>(pks.size());
332        
333        for(PaymentMethodCreditCardPK _pk: pks) {
334            _entities.add(getEntityFromPK(entityPermission, _pk));
335        }
336        
337        return _entities;
338    }
339    
340    public PaymentMethodCreditCard getEntityFromValue(EntityPermission entityPermission, PaymentMethodCreditCardValue value) {
341        return getEntityFromPK(entityPermission, value.getPrimaryKey());
342    }
343    
344    public PaymentMethodCreditCard getEntityFromCache(PaymentMethodCreditCardPK pk) {
345        PaymentMethodCreditCardValue _value = (PaymentMethodCreditCardValue)session.getValueCache().get(pk);
346    
347        return _value == null ? null : new PaymentMethodCreditCard(_value, EntityPermission.READ_ONLY);
348    }
349    
350    public PaymentMethodCreditCard getEntityFromPK(EntityPermission entityPermission, PaymentMethodCreditCardPK pk)
351            throws PersistenceDatabaseException {
352        PaymentMethodCreditCard _entity;
353        
354        // See if we already have the entity in the session cache
355        _entity = (PaymentMethodCreditCard)session.getEntity(pk);
356        if(_entity != null) {
357            // If the requested permission is READ_WRITE, and the cached permission is
358            // READ_ONLY, then pretend that the cached object wasn't found, and create
359            // a new entity that is READ_WRITE.
360            if(entityPermission.equals(EntityPermission.READ_WRITE)) {
361                if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
362                    _entity = null;
363            }
364        }
365        
366        if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
367            _entity = getEntityFromCache(pk);
368        }
369        
370        if(_entity == null) {
371            PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE);
372            long _entityId = pk.getEntityId();
373            ResultSet _rs = null;
374            
375            try {
376                _ps.setLong(1, _entityId);
377                _rs = _ps.executeQuery();
378                if(_rs.next()) {
379                    _entity = getEntityFromResultSet(entityPermission, _rs);
380                }
381            } catch (SQLException se) {
382                throw new PersistenceDatabaseException(se);
383            } finally {
384                if(_rs != null) {
385                    try {
386                        _rs.close();
387                    } catch (SQLException se) {
388                        // do nothing
389                    }
390                }
391            }
392        }
393        
394        return _entity;
395    }
396    
397    public Set<PaymentMethodCreditCardPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params)
398            throws PersistenceDatabaseException {
399        Set<PaymentMethodCreditCardPK> _pks;
400        ResultSet _rs = null;
401        
402        try {
403            if(params.length != 0) {
404                Session.setQueryParams(ps, params);
405            }
406            
407            _rs = ps.executeQuery();
408            _pks = getPKsFromResultSetAsSet(_rs);
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 _pks;
423    }
424    
425    public java.util.List<PaymentMethodCreditCardPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params)
426            throws PersistenceDatabaseException {
427        java.util.List<PaymentMethodCreditCardPK> _pks;
428        ResultSet _rs = null;
429        
430        try {
431            if(params.length != 0) {
432                Session.setQueryParams(ps, params);
433            }
434            
435            _rs = ps.executeQuery();
436            _pks = getPKsFromResultSetAsList(_rs);
437            _rs.close();
438        } catch (SQLException se) {
439            throw new PersistenceDatabaseException(se);
440        } finally {
441            if(_rs != null) {
442                try {
443                    _rs.close();
444                } catch (SQLException se) {
445                    // do nothing
446                }
447            }
448        }
449        
450        return _pks;
451    }
452    
453    public PaymentMethodCreditCardPK getPKFromQuery(PreparedStatement ps, final Object... params)
454            throws PersistenceDatabaseException {
455        PaymentMethodCreditCardPK _pk = null;
456        ResultSet _rs = null;
457        
458        try {
459            if(params.length != 0) {
460                Session.setQueryParams(ps, params);
461            }
462            
463            _rs = ps.executeQuery();
464            if(_rs.next()) {
465                _pk = getPKFromResultSet(_rs);
466            }
467            _rs.close();
468        } catch (SQLException se) {
469            throw new PersistenceDatabaseException(se);
470        } finally {
471            if(_rs != null) {
472                try {
473                    _rs.close();
474                } catch (SQLException se) {
475                    // do nothing
476                }
477            }
478        }
479        
480        return _pk;
481    }
482    
483    public java.util.List<PaymentMethodCreditCard> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
484            throws PersistenceDatabaseException {
485        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, queryMap.get(entityPermission));
486        
487        return getEntitiesFromQuery(entityPermission, ps, params);
488    }
489    
490    public java.util.List<PaymentMethodCreditCard> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
491            throws PersistenceDatabaseException {
492        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, queryMap.get(entityPermission));
493        
494        return getEntitiesFromQuery(entityPermission, ps);
495    }
496    
497    public java.util.List<PaymentMethodCreditCard> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
498            throws PersistenceDatabaseException {
499        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, query.getSQL());
500        
501        return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray());
502    }
503    
504    public java.util.List<PaymentMethodCreditCard> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
505            throws PersistenceDatabaseException {
506        java.util.List<PaymentMethodCreditCard> _entities;
507        ResultSet _rs = null;
508        
509        try {
510            if(params.length != 0) {
511                Session.setQueryParams(ps, params);
512            }
513            
514            _rs = ps.executeQuery();
515            _entities = getEntitiesFromResultSet(entityPermission, _rs);
516            _rs.close();
517        } catch (SQLException se) {
518            throw new PersistenceDatabaseException(se);
519        } finally {
520            if(_rs != null) {
521                try {
522                    _rs.close();
523                } catch (SQLException se) {
524                    // do nothing
525                }
526            }
527        }
528        
529        return _entities;
530    }
531    
532    public PaymentMethodCreditCard getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params)
533            throws PersistenceDatabaseException {
534        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, queryMap.get(entityPermission));
535        
536        return getEntityFromQuery(entityPermission, ps, params);
537    }
538    
539    public PaymentMethodCreditCard getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap)
540            throws PersistenceDatabaseException {
541        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, queryMap.get(entityPermission));
542        
543        return getEntityFromQuery(entityPermission, ps);
544    }
545    
546    public PaymentMethodCreditCard getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query)
547            throws PersistenceDatabaseException {
548        PreparedStatement ps = session.prepareStatement(PaymentMethodCreditCardFactory.class, query.getSQL());
549        
550        return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray());
551    }
552    
553    public PaymentMethodCreditCard getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params)
554            throws PersistenceDatabaseException {
555        PaymentMethodCreditCard _entity = null;
556        ResultSet _rs = null;
557        
558        try {
559            if(params.length != 0) {
560                Session.setQueryParams(ps, params);
561            }
562            
563            _rs = ps.executeQuery();
564            if(_rs.next()) {
565                _entity = getEntityFromResultSet(entityPermission, _rs);
566            }
567            _rs.close();
568        } catch (SQLException se) {
569            throw new PersistenceDatabaseException(se);
570        } finally {
571            if(_rs != null) {
572                try {
573                    _rs.close();
574                } catch (SQLException se) {
575                    // do nothing
576                }
577            }
578        }
579        
580        return _entity;
581    }
582    
583    public java.util.List<PaymentMethodCreditCard> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs)
584            throws PersistenceDatabaseException {
585        java.util.List<PaymentMethodCreditCard> _result = new ArrayList<>();
586        
587        try {
588            while(rs.next()) {
589                _result.add(getEntityFromResultSet(entityPermission, rs));
590            }
591        } catch (SQLException se) {
592            throw new PersistenceDatabaseException(se);
593        }
594        
595        return _result;
596    }
597    
598    public PaymentMethodCreditCard getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs)
599            throws PersistenceDatabaseException {
600        PaymentMethodCreditCard _entity;
601        
602        try {
603            Long pmcc_paymentmethodcreditcardid = rs.getLong(PMCC_PAYMENTMETHODCREDITCARDID);
604            PaymentMethodCreditCardPK _pk = new PaymentMethodCreditCardPK(pmcc_paymentmethodcreditcardid);
605            
606            // See if we already have the entity in the session cache
607            _entity = (PaymentMethodCreditCard)session.getEntity(_pk);
608            if(_entity != null) {
609                // If the requested permission is READ_WRITE, and the cached permission is
610                // READ_ONLY, then pretend that the cached object wasn't found, and create
611                // a new entity that is READ_WRITE.
612                if(entityPermission.equals(EntityPermission.READ_WRITE)) {
613                    if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY))
614                        _entity = null;
615                }
616            }
617            boolean foundInSessionCache = _entity != null;
618            
619            if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) {
620                _entity = getEntityFromCache(_pk);
621            }
622            
623            if(_entity == null) {
624                Long pmcc_pm_paymentmethodid = rs.getLong(PMCC_PM_PAYMENTMETHODID);
625                if(rs.wasNull())
626                    pmcc_pm_paymentmethodid = null;
627                
628                Boolean pmcc_requestnameoncard = rs.getInt(PMCC_REQUESTNAMEONCARD) == 1;
629                if(rs.wasNull())
630                    pmcc_requestnameoncard = null;
631                
632                Boolean pmcc_requirenameoncard = rs.getInt(PMCC_REQUIRENAMEONCARD) == 1;
633                if(rs.wasNull())
634                    pmcc_requirenameoncard = null;
635                
636                Boolean pmcc_checkcardnumber = rs.getInt(PMCC_CHECKCARDNUMBER) == 1;
637                if(rs.wasNull())
638                    pmcc_checkcardnumber = null;
639                
640                Boolean pmcc_requestexpirationdate = rs.getInt(PMCC_REQUESTEXPIRATIONDATE) == 1;
641                if(rs.wasNull())
642                    pmcc_requestexpirationdate = null;
643                
644                Boolean pmcc_requireexpirationdate = rs.getInt(PMCC_REQUIREEXPIRATIONDATE) == 1;
645                if(rs.wasNull())
646                    pmcc_requireexpirationdate = null;
647                
648                Boolean pmcc_checkexpirationdate = rs.getInt(PMCC_CHECKEXPIRATIONDATE) == 1;
649                if(rs.wasNull())
650                    pmcc_checkexpirationdate = null;
651                
652                Boolean pmcc_requestsecuritycode = rs.getInt(PMCC_REQUESTSECURITYCODE) == 1;
653                if(rs.wasNull())
654                    pmcc_requestsecuritycode = null;
655                
656                Boolean pmcc_requiresecuritycode = rs.getInt(PMCC_REQUIRESECURITYCODE) == 1;
657                if(rs.wasNull())
658                    pmcc_requiresecuritycode = null;
659                
660                String pmcc_cardnumbervalidationpattern = rs.getString(PMCC_CARDNUMBERVALIDATIONPATTERN);
661                if(rs.wasNull())
662                    pmcc_cardnumbervalidationpattern = null;
663                
664                String pmcc_securitycodevalidationpattern = rs.getString(PMCC_SECURITYCODEVALIDATIONPATTERN);
665                if(rs.wasNull())
666                    pmcc_securitycodevalidationpattern = null;
667                
668                Boolean pmcc_retaincreditcard = rs.getInt(PMCC_RETAINCREDITCARD) == 1;
669                if(rs.wasNull())
670                    pmcc_retaincreditcard = null;
671                
672                Boolean pmcc_retainsecuritycode = rs.getInt(PMCC_RETAINSECURITYCODE) == 1;
673                if(rs.wasNull())
674                    pmcc_retainsecuritycode = null;
675                
676                Boolean pmcc_requestbilling = rs.getInt(PMCC_REQUESTBILLING) == 1;
677                if(rs.wasNull())
678                    pmcc_requestbilling = null;
679                
680                Boolean pmcc_requirebilling = rs.getInt(PMCC_REQUIREBILLING) == 1;
681                if(rs.wasNull())
682                    pmcc_requirebilling = null;
683                
684                Boolean pmcc_requestissuer = rs.getInt(PMCC_REQUESTISSUER) == 1;
685                if(rs.wasNull())
686                    pmcc_requestissuer = null;
687                
688                Boolean pmcc_requireissuer = rs.getInt(PMCC_REQUIREISSUER) == 1;
689                if(rs.wasNull())
690                    pmcc_requireissuer = null;
691                
692                Long pmcc_fromtime = rs.getLong(PMCC_FROMTIME);
693                if(rs.wasNull())
694                    pmcc_fromtime = null;
695                
696                Long pmcc_thrutime = rs.getLong(PMCC_THRUTIME);
697                if(rs.wasNull())
698                    pmcc_thrutime = null;
699                
700                PaymentMethodCreditCardValue _value = new PaymentMethodCreditCardValue(_pk, pmcc_pm_paymentmethodid == null? null: new PaymentMethodPK(pmcc_pm_paymentmethodid), pmcc_requestnameoncard, pmcc_requirenameoncard, pmcc_checkcardnumber, pmcc_requestexpirationdate, pmcc_requireexpirationdate, pmcc_checkexpirationdate, pmcc_requestsecuritycode, pmcc_requiresecuritycode, pmcc_cardnumbervalidationpattern, pmcc_securitycodevalidationpattern, pmcc_retaincreditcard, pmcc_retainsecuritycode, pmcc_requestbilling, pmcc_requirebilling, pmcc_requestissuer, pmcc_requireissuer, pmcc_fromtime, pmcc_thrutime);
701                _entity = new PaymentMethodCreditCard(_value, entityPermission);
702            }
703            
704            if(!foundInSessionCache) {
705                if(entityPermission.equals(EntityPermission.READ_ONLY)) {
706                    session.putReadOnlyEntity(_pk, _entity);
707                    session.getValueCache().put(_entity.getPaymentMethodCreditCardValue());
708                } else {
709                    session.putReadWriteEntity(_pk, _entity);
710                }
711            }
712        } catch (SQLException se) {
713            throw new PersistenceDatabaseException(se);
714        }
715        
716        return _entity;
717    }
718    
719    public PaymentMethodCreditCard create(PaymentMethod paymentMethod, Boolean requestNameOnCard, Boolean requireNameOnCard, Boolean checkCardNumber, Boolean requestExpirationDate, Boolean requireExpirationDate, Boolean checkExpirationDate, Boolean requestSecurityCode, Boolean requireSecurityCode, String cardNumberValidationPattern, String securityCodeValidationPattern, Boolean retainCreditCard, Boolean retainSecurityCode, Boolean requestBilling, Boolean requireBilling, Boolean requestIssuer, Boolean requireIssuer, Long fromTime, Long thruTime)
720            throws PersistenceDatabaseException, PersistenceNotNullException {
721        return create(paymentMethod == null ? null : paymentMethod.getPrimaryKey(), requestNameOnCard, requireNameOnCard, checkCardNumber, requestExpirationDate, requireExpirationDate, checkExpirationDate, requestSecurityCode, requireSecurityCode, cardNumberValidationPattern, securityCodeValidationPattern, retainCreditCard, retainSecurityCode, requestBilling, requireBilling, requestIssuer, requireIssuer, fromTime, thruTime);
722    }
723    
724    private void bindForCreate(PreparedStatement _ps, PaymentMethodCreditCardValue _value)
725            throws SQLException {
726        _ps.setLong(1, _value.getEntityId());
727        
728        PaymentMethodPK pmcc_pm_paymentmethodid = _value.getPaymentMethodPK();
729        if(pmcc_pm_paymentmethodid == null)
730            _ps.setNull(2, Types.BIGINT);
731        else
732            _ps.setLong(2, pmcc_pm_paymentmethodid.getEntityId());
733            
734        Boolean pmcc_requestnameoncard = _value.getRequestNameOnCard();
735        if(pmcc_requestnameoncard == null)
736            _ps.setNull(3, Types.BIT);
737        else
738            _ps.setInt(3, pmcc_requestnameoncard? 1: 0);
739            
740        Boolean pmcc_requirenameoncard = _value.getRequireNameOnCard();
741        if(pmcc_requirenameoncard == null)
742            _ps.setNull(4, Types.BIT);
743        else
744            _ps.setInt(4, pmcc_requirenameoncard? 1: 0);
745            
746        Boolean pmcc_checkcardnumber = _value.getCheckCardNumber();
747        if(pmcc_checkcardnumber == null)
748            _ps.setNull(5, Types.BIT);
749        else
750            _ps.setInt(5, pmcc_checkcardnumber? 1: 0);
751            
752        Boolean pmcc_requestexpirationdate = _value.getRequestExpirationDate();
753        if(pmcc_requestexpirationdate == null)
754            _ps.setNull(6, Types.BIT);
755        else
756            _ps.setInt(6, pmcc_requestexpirationdate? 1: 0);
757            
758        Boolean pmcc_requireexpirationdate = _value.getRequireExpirationDate();
759        if(pmcc_requireexpirationdate == null)
760            _ps.setNull(7, Types.BIT);
761        else
762            _ps.setInt(7, pmcc_requireexpirationdate? 1: 0);
763            
764        Boolean pmcc_checkexpirationdate = _value.getCheckExpirationDate();
765        if(pmcc_checkexpirationdate == null)
766            _ps.setNull(8, Types.BIT);
767        else
768            _ps.setInt(8, pmcc_checkexpirationdate? 1: 0);
769            
770        Boolean pmcc_requestsecuritycode = _value.getRequestSecurityCode();
771        if(pmcc_requestsecuritycode == null)
772            _ps.setNull(9, Types.BIT);
773        else
774            _ps.setInt(9, pmcc_requestsecuritycode? 1: 0);
775            
776        Boolean pmcc_requiresecuritycode = _value.getRequireSecurityCode();
777        if(pmcc_requiresecuritycode == null)
778            _ps.setNull(10, Types.BIT);
779        else
780            _ps.setInt(10, pmcc_requiresecuritycode? 1: 0);
781            
782        String pmcc_cardnumbervalidationpattern = _value.getCardNumberValidationPattern();
783        if(pmcc_cardnumbervalidationpattern == null)
784            _ps.setNull(11, Types.VARCHAR);
785        else
786            _ps.setString(11, pmcc_cardnumbervalidationpattern);
787            
788        String pmcc_securitycodevalidationpattern = _value.getSecurityCodeValidationPattern();
789        if(pmcc_securitycodevalidationpattern == null)
790            _ps.setNull(12, Types.VARCHAR);
791        else
792            _ps.setString(12, pmcc_securitycodevalidationpattern);
793            
794        Boolean pmcc_retaincreditcard = _value.getRetainCreditCard();
795        if(pmcc_retaincreditcard == null)
796            _ps.setNull(13, Types.BIT);
797        else
798            _ps.setInt(13, pmcc_retaincreditcard? 1: 0);
799            
800        Boolean pmcc_retainsecuritycode = _value.getRetainSecurityCode();
801        if(pmcc_retainsecuritycode == null)
802            _ps.setNull(14, Types.BIT);
803        else
804            _ps.setInt(14, pmcc_retainsecuritycode? 1: 0);
805            
806        Boolean pmcc_requestbilling = _value.getRequestBilling();
807        if(pmcc_requestbilling == null)
808            _ps.setNull(15, Types.BIT);
809        else
810            _ps.setInt(15, pmcc_requestbilling? 1: 0);
811            
812        Boolean pmcc_requirebilling = _value.getRequireBilling();
813        if(pmcc_requirebilling == null)
814            _ps.setNull(16, Types.BIT);
815        else
816            _ps.setInt(16, pmcc_requirebilling? 1: 0);
817            
818        Boolean pmcc_requestissuer = _value.getRequestIssuer();
819        if(pmcc_requestissuer == null)
820            _ps.setNull(17, Types.BIT);
821        else
822            _ps.setInt(17, pmcc_requestissuer? 1: 0);
823            
824        Boolean pmcc_requireissuer = _value.getRequireIssuer();
825        if(pmcc_requireissuer == null)
826            _ps.setNull(18, Types.BIT);
827        else
828            _ps.setInt(18, pmcc_requireissuer? 1: 0);
829            
830        Long pmcc_fromtime = _value.getFromTime();
831        if(pmcc_fromtime == null)
832            _ps.setNull(19, Types.BIGINT);
833        else
834            _ps.setLong(19, pmcc_fromtime);
835            
836        Long pmcc_thrutime = _value.getThruTime();
837        if(pmcc_thrutime == null)
838            _ps.setNull(20, Types.BIGINT);
839        else
840            _ps.setLong(20, pmcc_thrutime);
841            
842    }
843    
844    public PaymentMethodCreditCard create(PaymentMethodPK paymentMethodPK, Boolean requestNameOnCard, Boolean requireNameOnCard, Boolean checkCardNumber, Boolean requestExpirationDate, Boolean requireExpirationDate, Boolean checkExpirationDate, Boolean requestSecurityCode, Boolean requireSecurityCode, String cardNumberValidationPattern, String securityCodeValidationPattern, Boolean retainCreditCard, Boolean retainSecurityCode, Boolean requestBilling, Boolean requireBilling, Boolean requestIssuer, Boolean requireIssuer, Long fromTime, Long thruTime)
845            throws PersistenceDatabaseException, PersistenceNotNullException {
846        PaymentMethodCreditCardPK _pk = getNextPK();
847        PaymentMethodCreditCardValue _value = new PaymentMethodCreditCardValue(_pk, paymentMethodPK, requestNameOnCard, requireNameOnCard, checkCardNumber, requestExpirationDate, requireExpirationDate, checkExpirationDate, requestSecurityCode, requireSecurityCode, cardNumberValidationPattern, securityCodeValidationPattern, retainCreditCard, retainSecurityCode, requestBilling, requireBilling, requestIssuer, requireIssuer, fromTime, thruTime);
848        
849        PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
850        
851        try {
852            bindForCreate(_ps, _value);
853            
854            if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
855                int _count = _ps.executeUpdate();
856                
857                if(_count != 1) {
858                    throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count);
859                }
860            } else {
861                 _ps.executeUpdate();
862            }
863            
864            session.getValueCache().put(_value);
865        } catch (SQLException se) {
866            throw new PersistenceDatabaseException(se);
867        }
868        
869        PaymentMethodCreditCard _entity = new PaymentMethodCreditCard(_value, EntityPermission.READ_ONLY);
870        session.putReadOnlyEntity(_pk, _entity);
871        
872        return _entity;
873    }
874    
875    public void create(Collection<PaymentMethodCreditCardValue> _values)
876            throws PersistenceDatabaseException, PersistenceNotNullException {
877        int _size = _values.size();
878        
879        if(_size > 0) {
880            PreparedStatement _ps = session.prepareStatement(SQL_INSERT);
881            List<PaymentMethodCreditCardValue> _cacheValues = new ArrayList<>(_size);
882            
883            try {
884                for(PaymentMethodCreditCardValue _value : _values) {
885                    _value.setEntityId(entityIdGenerator.getNextEntityId());
886                    bindForCreate(_ps, _value);
887                    
888                    _ps.addBatch();
889                    
890                    _cacheValues.add(_value);
891                }
892                
893                if(PersistenceDebugFlags.CheckEntityInsertRowCount) {
894                    int[] _counts = _ps.executeBatch();
895                    
896                    for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) {
897                        if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
898                            throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
899                        }
900                    }
901                } else {
902                     _ps.executeBatch();
903                }
904                
905                _ps.clearBatch();
906            } catch (SQLException se) {
907                throw new PersistenceDatabaseException(se);
908            }
909            
910            _cacheValues.forEach((_cacheValue) -> {
911                PaymentMethodCreditCard _cacheEntity = new PaymentMethodCreditCard(_cacheValue, EntityPermission.READ_ONLY);
912                
913                session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity);
914            });
915        }
916    }
917    
918    private boolean bindForStore(PreparedStatement _ps, PaymentMethodCreditCardValue _value)
919            throws SQLException {
920        boolean _hasBeenModified = _value.hasBeenModified();
921        
922        if(_hasBeenModified) {
923            PaymentMethodPK pmcc_pm_paymentmethodid = _value.getPaymentMethodPK();
924            if(pmcc_pm_paymentmethodid == null)
925                _ps.setNull(1, Types.BIGINT);
926            else
927                _ps.setLong(1, pmcc_pm_paymentmethodid.getEntityId());
928            
929            Boolean pmcc_requestnameoncard = _value.getRequestNameOnCard();
930            if(pmcc_requestnameoncard == null)
931                _ps.setNull(2, Types.BIT);
932            else
933                _ps.setInt(2, pmcc_requestnameoncard? 1: 0);
934            
935            Boolean pmcc_requirenameoncard = _value.getRequireNameOnCard();
936            if(pmcc_requirenameoncard == null)
937                _ps.setNull(3, Types.BIT);
938            else
939                _ps.setInt(3, pmcc_requirenameoncard? 1: 0);
940            
941            Boolean pmcc_checkcardnumber = _value.getCheckCardNumber();
942            if(pmcc_checkcardnumber == null)
943                _ps.setNull(4, Types.BIT);
944            else
945                _ps.setInt(4, pmcc_checkcardnumber? 1: 0);
946            
947            Boolean pmcc_requestexpirationdate = _value.getRequestExpirationDate();
948            if(pmcc_requestexpirationdate == null)
949                _ps.setNull(5, Types.BIT);
950            else
951                _ps.setInt(5, pmcc_requestexpirationdate? 1: 0);
952            
953            Boolean pmcc_requireexpirationdate = _value.getRequireExpirationDate();
954            if(pmcc_requireexpirationdate == null)
955                _ps.setNull(6, Types.BIT);
956            else
957                _ps.setInt(6, pmcc_requireexpirationdate? 1: 0);
958            
959            Boolean pmcc_checkexpirationdate = _value.getCheckExpirationDate();
960            if(pmcc_checkexpirationdate == null)
961                _ps.setNull(7, Types.BIT);
962            else
963                _ps.setInt(7, pmcc_checkexpirationdate? 1: 0);
964            
965            Boolean pmcc_requestsecuritycode = _value.getRequestSecurityCode();
966            if(pmcc_requestsecuritycode == null)
967                _ps.setNull(8, Types.BIT);
968            else
969                _ps.setInt(8, pmcc_requestsecuritycode? 1: 0);
970            
971            Boolean pmcc_requiresecuritycode = _value.getRequireSecurityCode();
972            if(pmcc_requiresecuritycode == null)
973                _ps.setNull(9, Types.BIT);
974            else
975                _ps.setInt(9, pmcc_requiresecuritycode? 1: 0);
976            
977            String pmcc_cardnumbervalidationpattern = _value.getCardNumberValidationPattern();
978            if(pmcc_cardnumbervalidationpattern == null)
979                _ps.setNull(10, Types.VARCHAR);
980            else
981                _ps.setString(10, pmcc_cardnumbervalidationpattern);
982            
983            String pmcc_securitycodevalidationpattern = _value.getSecurityCodeValidationPattern();
984            if(pmcc_securitycodevalidationpattern == null)
985                _ps.setNull(11, Types.VARCHAR);
986            else
987                _ps.setString(11, pmcc_securitycodevalidationpattern);
988            
989            Boolean pmcc_retaincreditcard = _value.getRetainCreditCard();
990            if(pmcc_retaincreditcard == null)
991                _ps.setNull(12, Types.BIT);
992            else
993                _ps.setInt(12, pmcc_retaincreditcard? 1: 0);
994            
995            Boolean pmcc_retainsecuritycode = _value.getRetainSecurityCode();
996            if(pmcc_retainsecuritycode == null)
997                _ps.setNull(13, Types.BIT);
998            else
999                _ps.setInt(13, pmcc_retainsecuritycode? 1: 0);
1000            
1001            Boolean pmcc_requestbilling = _value.getRequestBilling();
1002            if(pmcc_requestbilling == null)
1003                _ps.setNull(14, Types.BIT);
1004            else
1005                _ps.setInt(14, pmcc_requestbilling? 1: 0);
1006            
1007            Boolean pmcc_requirebilling = _value.getRequireBilling();
1008            if(pmcc_requirebilling == null)
1009                _ps.setNull(15, Types.BIT);
1010            else
1011                _ps.setInt(15, pmcc_requirebilling? 1: 0);
1012            
1013            Boolean pmcc_requestissuer = _value.getRequestIssuer();
1014            if(pmcc_requestissuer == null)
1015                _ps.setNull(16, Types.BIT);
1016            else
1017                _ps.setInt(16, pmcc_requestissuer? 1: 0);
1018            
1019            Boolean pmcc_requireissuer = _value.getRequireIssuer();
1020            if(pmcc_requireissuer == null)
1021                _ps.setNull(17, Types.BIT);
1022            else
1023                _ps.setInt(17, pmcc_requireissuer? 1: 0);
1024            
1025            Long pmcc_fromtime = _value.getFromTime();
1026            if(pmcc_fromtime == null)
1027                _ps.setNull(18, Types.BIGINT);
1028            else
1029                _ps.setLong(18, pmcc_fromtime);
1030            
1031            Long pmcc_thrutime = _value.getThruTime();
1032            if(pmcc_thrutime == null)
1033                _ps.setNull(19, Types.BIGINT);
1034            else
1035                _ps.setLong(19, pmcc_thrutime);
1036            
1037            _ps.setLong(20, _value.getPrimaryKey().getEntityId());
1038            
1039            _value.clearHasBeenModified();
1040        }
1041        
1042        return _hasBeenModified;
1043    }
1044    
1045    @Override
1046    public void store(PaymentMethodCreditCard entity)
1047            throws PersistenceDatabaseException {
1048        PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1049        
1050        try {
1051            PaymentMethodCreditCardValue _value = entity.getPaymentMethodCreditCardValue();
1052            
1053            if(bindForStore(_ps, _value)) {
1054                if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1055                    int _count = _ps.executeUpdate();
1056                    
1057                    if(_count != 1) {
1058                        throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count);
1059                    }
1060                } else {
1061                     _ps.executeUpdate();
1062                }
1063                
1064                session.getValueCache().put(_value);
1065            }
1066        } catch (SQLException se) {
1067            throw new PersistenceDatabaseException(se);
1068        }
1069    }
1070    
1071    @Override
1072    public void store(Collection<PaymentMethodCreditCard> entities)
1073            throws PersistenceDatabaseException {
1074        if(entities.size() > 0) {
1075            PreparedStatement _ps = session.prepareStatement(SQL_UPDATE);
1076            int _modifiedEntities = 0;
1077            
1078            try {
1079                for(PaymentMethodCreditCard entity : entities) {
1080                    if(bindForStore(_ps, entity.getPaymentMethodCreditCardValue())) {
1081                        _ps.addBatch();
1082                        _modifiedEntities++;
1083                    }
1084                }
1085                
1086                if(_modifiedEntities != 0) {
1087                    if(PersistenceDebugFlags.CheckEntityUpdateRowCount) {
1088                        int[] _counts = _ps.executeBatch();
1089                        
1090                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1091                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1092                                throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1093                            }
1094                        }
1095                    } else {
1096                         _ps.executeBatch();
1097                    }
1098                    
1099                    _ps.clearBatch();
1100                    
1101                    entities.forEach((entity) -> {
1102                        session.getValueCache().put(entity.getPaymentMethodCreditCardValue());
1103                    });
1104                }
1105            } catch (SQLException se) {
1106                throw new PersistenceDatabaseException(se);
1107            }
1108        }
1109    }
1110    
1111    @Override
1112    public void remove(PaymentMethodCreditCard entity)
1113            throws PersistenceDatabaseException {
1114        remove(entity.getPrimaryKey());
1115    }
1116    
1117    @Override
1118    public void remove(PaymentMethodCreditCardPK pk)
1119            throws PersistenceDatabaseException {
1120        PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1121        long _entityId = pk.getEntityId();
1122        
1123        try {
1124            _ps.setLong(1, _entityId);
1125            
1126            if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1127                int _count = _ps.executeUpdate();
1128                
1129                if(_count != 1) {
1130                    throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count);
1131                }
1132            } else {
1133                 _ps.executeUpdate();
1134            }
1135            
1136            session.getValueCache().remove(pk);
1137        } catch (SQLException se) {
1138            throw new PersistenceDatabaseException(se);
1139        }
1140        
1141        session.removed(pk, false);
1142    }
1143    
1144    @Override
1145    public void remove(Collection<PaymentMethodCreditCardPK> pks)
1146            throws PersistenceDatabaseException {
1147        if(pks.size() > 0) {
1148            PreparedStatement _ps = session.prepareStatement(SQL_DELETE);
1149            int _modifiedEntities = 0;
1150            
1151            try {
1152                for(PaymentMethodCreditCardPK pk : pks) {
1153                    long _entityId = pk.getEntityId();
1154                    
1155                    _ps.setLong(1, _entityId);
1156                    
1157                    _ps.addBatch();
1158                    _modifiedEntities++;
1159                }
1160                
1161                if(_modifiedEntities != 0) {
1162                    if(PersistenceDebugFlags.CheckEntityDeleteRowCount) {
1163                        int[] _counts = _ps.executeBatch();
1164                        
1165                        for(int _countOffset = 0 ; _countOffset < _modifiedEntities  ; _countOffset++) {
1166                            if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) {
1167                                throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]);
1168                            }
1169                        }
1170                    } else {
1171                        _ps.executeBatch();
1172                    }
1173                    
1174                    _ps.clearBatch();
1175                    
1176                    pks.forEach((pk) -> {
1177                        session.getValueCache().remove(pk);
1178                    });
1179                }
1180            } catch (SQLException se) {
1181                throw new PersistenceDatabaseException(se);
1182            }
1183            
1184            pks.forEach((pk) -> {
1185                session.removed(pk, true);
1186            });
1187        }
1188    }
1189    
1190    @Override
1191    public boolean validPK(PaymentMethodCreditCardPK pk)
1192            throws PersistenceDatabaseException {
1193        boolean valid = false;
1194        PreparedStatement _ps = session.prepareStatement(SQL_VALID);
1195        ResultSet _rs = null;
1196        
1197        try {
1198            _ps.setLong(1, pk.getEntityId());
1199            
1200            _rs = _ps.executeQuery();
1201            if(_rs.next()) {
1202                long _count = _rs.getLong(1);
1203                if(_rs.wasNull())
1204                    _count = 0;
1205                
1206                if(_count == 1)
1207                    valid = true;
1208            }
1209        } catch (SQLException se) {
1210            throw new PersistenceDatabaseException(se);
1211        } finally {
1212            if(_rs != null) {
1213                try {
1214                    _rs.close();
1215                } catch (SQLException se) {
1216                    // do nothing
1217                }
1218            }
1219        }
1220        
1221        return valid;
1222    }
1223    
1224}