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