Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1069545] Clean the subcategory class as well the persisting layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Negrea committed Apr 22, 2014
1 parent f49e400 commit 3cf7f85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import org.rhq.core.clientapi.descriptor.plugin.SubCategoryDescriptor;
import org.rhq.core.domain.resource.ResourceSubCategory;
import org.rhq.core.domain.resource.ResourceType;
Expand Down Expand Up @@ -58,7 +60,6 @@ public static ResourceSubCategory getSubCategory(SubCategoryDescriptor descripto
}

subCat.setDescription(descriptor.getDescription());
//resourceType.addSubCategory(subCat);

List<SubCategoryDescriptor> childDescriptors = descriptor.getSubcategory();
if (childDescriptors != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
Expand All @@ -38,8 +35,6 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
Expand All @@ -55,12 +50,9 @@
@Entity
@SequenceGenerator(allocationSize = org.rhq.core.domain.util.Constants.ALLOCATION_SIZE, name = "RHQ_RESOURCE_SUBCAT_ID_SEQ", sequenceName = "RHQ_RESOURCE_SUBCAT_ID_SEQ")
@Table(name = "RHQ_RESOURCE_SUBCAT")
@NamedQueries( { @NamedQuery(name = ResourceSubCategory.QUERY_FIND_BY_NAME_AND_PLUGIN, query = "SELECT rsc FROM ResourceSubCategory AS rsc WHERE rsc.name = :name AND rsc.resourceType.plugin = :plugin") })
public class ResourceSubCategory implements Comparable<ResourceSubCategory>, Serializable {
private static final long serialVersionUID = 1L;

public static final String QUERY_FIND_BY_NAME_AND_PLUGIN = "ResourceSubCategory.findByNameAndPlugin";

@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "RHQ_RESOURCE_SUBCAT_ID_SEQ")
@Id
Expand Down Expand Up @@ -90,14 +82,6 @@ public class ResourceSubCategory implements Comparable<ResourceSubCategory>, Ser
@ManyToOne
private ResourceSubCategory parentSubCategory;

/**
* A subcategory is associated with the type of resource it was defined in This is nullable since child
* subcategories don't want to be directly associated with a resourceType, rather they can obtain their type through
* their parent
*/
@JoinColumn(name = "RESOURCE_TYPE_ID", updatable = false)
@ManyToOne
private ResourceType resourceType;

/* no-arg constructor required by EJB spec */
public ResourceSubCategory() {
Expand All @@ -114,50 +98,21 @@ public ResourceSubCategory(String name) {
this.mtime = this.ctime = System.currentTimeMillis();
}

/**
* Returns the resource types that belong to this subcategory; the Set of types is sorted by name.
*
* @return the resource types that belong to this subcategory; the Set of types is sorted by name
*/
@NotNull
/*@NotNull
@Deprecated
public Set<ResourceType> findTaggedResourceTypes() {
ResourceType parentResourceType = findParentResourceType();
Set<ResourceType> taggedResourceTypes = new TreeSet<ResourceType>();
findTaggedResourceTypes(parentResourceType, taggedResourceTypes);
return taggedResourceTypes;
}

private void findTaggedResourceTypes(ResourceType parentResourceType, Collection<ResourceType> taggedResourceTypes) {
Set<ResourceType> childResourceTypes = parentResourceType.getChildResourceTypes();
for (ResourceType childResourceType : childResourceTypes) {
if (this.equals(childResourceType.getSubCategory())) {
taggedResourceTypes.add(childResourceType);
}
// check children if their parents are tagged
findTaggedResourceTypes(childResourceType, taggedResourceTypes);
}
return new HashSet<ResourceType>();
}
@NotNull
@Deprecated
public ResourceType findParentResourceType() {
ResourceSubCategory subCategory = this;
while (subCategory != null && subCategory.getResourceType() == null)
subCategory = subCategory.getParentSubCategory();
if (subCategory == null)
throw new IllegalStateException(this + " has no parent resource type.");
return subCategory.getResourceType();
return null;
}
@Deprecated
public boolean isCreatable() {
for (ResourceType taggedResourceType : findTaggedResourceTypes()) {
// if any resourceType is creatable then this subCategory is
if (taggedResourceType.isCreatable()) {
return true;
}
}

return false;
}
}*/

public int getId() {
return this.id;
Expand Down Expand Up @@ -261,14 +216,6 @@ public ResourceSubCategory getParentSubCategory() {
return parentSubCategory;
}

public ResourceType getResourceType() {
return resourceType;
}

public void setResourceType(ResourceType resourceType) {
this.resourceType = resourceType;
}

public int compareTo(ResourceSubCategory that) {
return this.name.compareTo(that.getName());
}
Expand All @@ -287,19 +234,14 @@ public boolean equals(Object o) {

if (!name.equals(that.getName())) {
return false;
//if (plugin != null ? !plugin.equals(that.plugin) : that.plugin != null) return false;
}

return true;
}

@Override
public int hashCode() {
int result;
result = name.hashCode();

//result = 31 * result + (plugin != null ? plugin.hashCode() : 0);
return result;
return this.getName().hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void updateTypes(Set<ResourceType> resourceTypes) throws Exception {
}
}

// NO TRANSACTION SHOULD BE ACTIVE ON ENTRY
// NO TRANSACTION SHOULD BE ACTIVE ON ENTRY
// Start with no transaction so we can control the transactional boundaries. Obsolete type removal removes
// resources of the obsolete type. We need to avoid an umbrella transaction for the type removal because large
// inventories of obsolete resources will generate very large transactions. Potentially resulting in timeouts
Expand Down Expand Up @@ -294,7 +294,7 @@ private void removeResourceType(Subject subject, ResourceType existingType) {
c.addFilterResourceTypeId(existingType.getId());
c.addFilterInventoryStatus(null);
List<Resource> resources = resourceManager.findResourcesByCriteria(subject, c);
//Chunk through the results in 200(default) page element batches to avoid excessive
//Chunk through the results in 200(default) page element batches to avoid excessive
//memory usage for large deployments. No need to use CriteriaQuery here as this loop is more efficient at catching stragglers
while ((resources != null) && (!resources.isEmpty())) {
Iterator<Resource> resIter = resources.iterator();
Expand Down Expand Up @@ -885,7 +885,7 @@ private void updateSubCategory(ResourceSubCategory existingSubCat, ResourceSubCa
log.info("Metadata update: Adding new child SubCategory [" + newChildSubCategory.getName()
+ "] to SubCategory [" + existingSubCat.getName() + "]...");
existingSubCat.addChildSubCategory(newChildSubCategory);
entityManager.persist(newChildSubCategory);
entityManager.merge(newChildSubCategory);
}
return;
}
Expand Down Expand Up @@ -918,7 +918,7 @@ private void updateSubCategory(ResourceSubCategory existingSubCat, ResourceSubCa
log.info("Metadata update: Adding new child SubCategory [" + newChildSubCategory.getName()
+ "] to SubCategory [" + existingSubCat.getName() + "]...");
existingSubCat.addChildSubCategory(newChildSubCategory);
entityManager.persist(newChildSubCategory);
entityManager.merge(newChildSubCategory);
}
}

Expand Down

0 comments on commit 3cf7f85

Please sign in to comment.