Example usage for javax.persistence EntityNotFoundException EntityNotFoundException

List of usage examples for javax.persistence EntityNotFoundException EntityNotFoundException

Introduction

In this page you can find the example usage for javax.persistence EntityNotFoundException EntityNotFoundException.

Prototype

public EntityNotFoundException(String message) 

Source Link

Document

Constructs a new EntityNotFoundException exception with the specified detail message.

Usage

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

@Nullable
public ConfigurationDefinition getResourceConfigurationDefinitionWithTemplatesForResourceType(Subject subject,
        int resourceTypeId) {
    Query query = entityManager/*  www.j  a v a 2s .  c  om*/
            .createNamedQuery(ConfigurationDefinition.QUERY_FIND_RESOURCE_BY_RESOURCE_TYPE_ID);
    query.setParameter("resourceTypeId", resourceTypeId);
    ConfigurationDefinition configurationDefinition = null;
    try {
        configurationDefinition = (ConfigurationDefinition) query.getSingleResult();
    } catch (NoResultException e) {
        ResourceType resourceType = entityManager.find(ResourceType.class, resourceTypeId);
        if (resourceType == null) {
            throw new EntityNotFoundException("A resource type with id " + resourceTypeId + " does not exist.");
        }
    }

    // Eager Load the templates
    if ((configurationDefinition != null) && (configurationDefinition.getTemplates() != null)) {
        configurationDefinition.getTemplates().size();
    }

    return configurationDefinition;
}

From source file:org.rhq.enterprise.server.configuration.ConfigurationManagerBean.java

@Nullable
public ConfigurationDefinition getPluginConfigurationDefinitionForResourceType(Subject subject,
        int resourceTypeId) {
    Query query = entityManager.createNamedQuery(ConfigurationDefinition.QUERY_FIND_PLUGIN_BY_RESOURCE_TYPE_ID);
    query.setParameter("resourceTypeId", resourceTypeId);
    ConfigurationDefinition configurationDefinition = null;
    try {/*from   w w  w . ja  v  a 2s  . c  om*/
        configurationDefinition = (ConfigurationDefinition) query.getSingleResult();
    } catch (NoResultException e) {
        ResourceType resourceType = entityManager.find(ResourceType.class, resourceTypeId);
        if (resourceType == null) {
            throw new EntityNotFoundException("A resource type with id " + resourceTypeId + " does not exist.");
        }
    }

    // Eager Load the templates
    if ((configurationDefinition != null) && (configurationDefinition.getTemplates() != null)) {
        configurationDefinition.getTemplates().size();
    }

    return configurationDefinition;
}

From source file:org.zanata.action.VersionHome.java

public void validateProjectSlug() {
    if (projectDAO.getBySlug(getProjectSlug()) == null) {
        throw new EntityNotFoundException("no entity with slug " + getProjectSlug());
    }//  ww w  .  j  av  a 2s  . co  m
}