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