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