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