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