Coverage Summary for Class: NonRecursiveGrantDomainCreatePermissionSysPersister (com.acciente.oacc.sql.internal.persister)

Class Class, % Method, % Line, %
NonRecursiveGrantDomainCreatePermissionSysPersister 100% (1/ 1) 100% (2/ 2) 88.2% (15/ 17)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc.sql.internal.persister; 19  20 import com.acciente.oacc.DomainCreatePermission; 21 import com.acciente.oacc.Resource; 22 import com.acciente.oacc.sql.SQLProfile; 23 import com.acciente.oacc.sql.internal.persister.id.Id; 24 import com.acciente.oacc.sql.internal.persister.id.ResourceId; 25  26 import java.io.Serializable; 27 import java.sql.SQLException; 28 import java.util.HashSet; 29 import java.util.Set; 30  31 public class NonRecursiveGrantDomainCreatePermissionSysPersister extends CommonGrantDomainCreatePermissionSysPersister implements Serializable { 32  private static final long serialVersionUID = 1L; 33  34  public NonRecursiveGrantDomainCreatePermissionSysPersister(SQLProfile sqlProfile, 35  SQLStrings sqlStrings) { 36  super(sqlProfile, sqlStrings); 37  } 38  39  @Override 40  public Set<DomainCreatePermission> getDomainCreateSysPermissionsIncludeInherited(SQLConnection connection, 41  Resource accessorResource) { 42  SQLStatement statement = null; 43  44  try { 45  // first get all the resources from which the accessor inherits any permissions 46  final Set<Id<ResourceId>> accessorResourceIds 47  = NonRecursivePersisterHelper.getInheritedAccessorResourceIds(sqlStrings, connection, accessorResource); 48  49  // now accumulate the domain create permissions from each of the (inherited) accessors 50  Set<DomainCreatePermission> domainCreatePermissions = new HashSet<>(); 51  statement = connection.prepareStatement(sqlStrings.SQL_findInGrantDomainCreatePermissionSys_withoutInheritance_SysPermissionID_BY_AccessorID); 52  53  for (Id<ResourceId> accessorResourceId : accessorResourceIds) { 54  statement.setResourceId(1, accessorResourceId); 55  SQLResult resultSet = statement.executeQuery(); 56  57  while (resultSet.next()) { 58  domainCreatePermissions.add(getDomainCreateSysPermission(resultSet)); 59  } 60  resultSet.close(); 61  } 62  63  return domainCreatePermissions; 64  } 65  catch (SQLException e) { 66  throw new RuntimeException(e); 67  } 68  finally { 69  closeStatement(statement); 70  } 71  } 72 }