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

Class Class, % Method, % Line, %
NonRecursiveResourcePersister 100% (1/ 1) 100% (2/ 2) 85.7% (18/ 21)


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.sql.SQLProfile; 21 import com.acciente.oacc.sql.internal.persister.id.DomainId; 22 import com.acciente.oacc.sql.internal.persister.id.Id; 23  24 import java.io.Serializable; 25 import java.sql.SQLException; 26 import java.util.Set; 27  28 public class NonRecursiveResourcePersister extends CommonResourcePersister implements Serializable { 29  private static final long serialVersionUID = 1L; 30  31  public NonRecursiveResourcePersister(SQLProfile sqlProfile, 32  SQLStrings sqlStrings) { 33  super(sqlProfile, sqlStrings); 34  } 35  36  @Override 37  public boolean isDomainEmpty(SQLConnection connection, Id<DomainId> domainId) { 38  SQLStatement statement = null; 39  40  try { 41  boolean isEmpty = true; 42  SQLResult resultSet; 43  44  final Set<Id<DomainId>> descendantDomainIds 45  = NonRecursivePersisterHelper.getDescendantDomainIdsOrderedByAscendingLevel(sqlStrings, 46  connection, 47  domainId); 48  49  statement = connection.prepareStatement(sqlStrings.SQL_findInResource_withoutInheritance_COUNTResourceID_BY_DomainID); 50  for (Id<DomainId> descendantDomainId : descendantDomainIds) { 51  statement.setResourceDomainId(1, descendantDomainId); 52  resultSet = statement.executeQuery(); 53  54  if (!resultSet.next()) { 55  throw new IllegalArgumentException("Could not read resource count for domain: " + domainId); 56  } 57  58  final int count = resultSet.getInteger("COUNTResourceID"); 59  resultSet.close(); 60  61  if (count > 0) { 62  isEmpty = false; 63  break; 64  } 65  } 66  67  return isEmpty; 68  } 69  catch (SQLException e) { 70  throw new RuntimeException(e); 71  } 72  finally { 73  closeStatement(statement); 74  } 75  } 76 }