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