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