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