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