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