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