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