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