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