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