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