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