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