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