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