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