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