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