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