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