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