org.springframework.orm.ObjectRetrievalFailureException Java Examples

The following examples show how to use org.springframework.orm.ObjectRetrievalFailureException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleJdbcClinic.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Transactional(readOnly = true)
public Pet loadPet(int id) throws DataAccessException {
	JdbcPet pet;
	try {
		pet = this.simpleJdbcTemplate.queryForObject(
				"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=?",
				new JdbcPetRowMapper(),
				id);
	}
	catch (EmptyResultDataAccessException ex) {
		throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
	}
	Owner owner = loadOwner(pet.getOwnerId());
	owner.addPet(pet);
	pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
	loadVisits(pet);
	return pet;
}
 
Example #2
Source File: BusinessObjectDaoOjb.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * @see org.kuali.rice.krad.dao.BusinessObjectDao#findBySinglePrimaryKey(java.lang.Class, java.lang.Object)
 */
public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey) {
	if (primaryKey.getClass().getName().startsWith("java.lang.")
               || primaryKey.getClass().getName().startsWith("java.sql.")
               || primaryKey.getClass().getName().startsWith("java.math.")
               || primaryKey.getClass().getName().startsWith("java.util.")) {
		try {
			return (T) getPersistenceBrokerTemplate().getObjectById(clazz, primaryKey);
		} catch (  ObjectRetrievalFailureException ex  ) {
    		// it doesn't exist, just return null
			return null;
		}
	} else {
		Criteria criteria = buildCriteria(clazz, primaryKey);

        return (T) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(clazz, criteria));
	}
}
 
Example #3
Source File: JdbcPetRepositoryImpl.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #4
Source File: JdbcOwnerRepositoryImpl.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
 * for the corresponding owner, if not already loaded.
 */
@Override
public Owner findById(int id) throws DataAccessException {
    Owner owner;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        owner = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
                params,
                BeanPropertyRowMapper.newInstance(Owner.class)
        );
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Owner.class, id);
    }
    loadPetsAndVisits(owner);
    return owner;
}
 
Example #5
Source File: JdbcPetRepositoryImpl.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #6
Source File: JdbcOwnerRepositoryImpl.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
/**
 * Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
 * for the corresponding owner, if not already loaded.
 */
@Override
public Owner findById(int id) throws DataAccessException {
    Owner owner;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        owner = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
                params,
                BeanPropertyRowMapper.newInstance(Owner.class)
        );
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Owner.class, id);
    }
    loadPetsAndVisits(owner);
    return owner;
}
 
Example #7
Source File: SimpleJdbcClinic.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Loads the {@link Owner} with the supplied <code>id</code>; also loads
 * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
 * owner, if not already loaded.
 */
@Transactional(readOnly = true)
public Owner loadOwner(int id) throws DataAccessException {
	Owner owner;
	try {
		owner = this.simpleJdbcTemplate.queryForObject(
				"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id=?",
				ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
				id);
	}
	catch (EmptyResultDataAccessException ex) {
		throw new ObjectRetrievalFailureException(Owner.class, new Integer(id));
	}
	loadPetsAndVisits(owner);
	return owner;
}
 
Example #8
Source File: JdbcOwnerRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
/**
 * Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
 * for the corresponding owner, if not already loaded.
 */
@Override
public Owner findById(int id) throws DataAccessException {
    Owner owner;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        owner = this.namedParameterJdbcTemplate.queryForObject(
            "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
            params,
            BeanPropertyRowMapper.newInstance(Owner.class)
        );
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Owner.class, id);
    }
    loadPetsAndVisits(owner);
    return owner;
}
 
Example #9
Source File: JdbcPetRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
            params,
            new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #10
Source File: JdbcOwnerRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
/**
 * Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
 * for the corresponding owner, if not already loaded.
 */
@Override
public Owner findById(int id) throws DataAccessException {
    Owner owner;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        owner = this.namedParameterJdbcTemplate.queryForObject(
            "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
            params,
            BeanPropertyRowMapper.newInstance(Owner.class)
        );
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Owner.class, id);
    }
    loadPetsAndVisits(owner);
    return owner;
}
 
Example #11
Source File: DefaultExceptionHandler.java    From spring-rest-server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequestMapping(produces = {Versions.V1_0, Versions.V2_0})
@ExceptionHandler(ObjectRetrievalFailureException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public @ResponseBody Map<String, Object> handleValidationException(ObjectRetrievalFailureException ex) throws IOException {
    Map<String, Object>  map = Maps.newHashMap();
    map.put("error", "Entity Not Found");
    map.put("cause", ex.getMessage());
    return map;
}
 
Example #12
Source File: TicketService.java    From spring-rest-server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Ticket get(final long id) {
    Ticket ticket = ticketDao.findOne(id);
    if (ticket != null) {
        return ticket;
    }
    throw new ObjectRetrievalFailureException(Ticket.class, id);
}
 
Example #13
Source File: TicketService.java    From spring-rest-server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void deleteLocationScan(Ticket ticket, Long locationId) {

        for (Iterator<LocationScan> locationIterator = ticket.getLocationScans().iterator() ; locationIterator.hasNext(); ) {
            LocationScan location = locationIterator.next();
            if (locationId.equals(location.getId())) {
                locationIterator.remove();
                return;
            }
        }

        throw new ObjectRetrievalFailureException(Location.class, locationId);
    }
 
Example #14
Source File: HibernateDao.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public T get(PK id) {
    T entity = (T) getHibernateTemplate().get(this.entityClass, id);

    if (entity == null) {
        log.warn("'" + this.entityClass.getSimpleName() + "' object with id '" + id + "' not found...");
        throw new ObjectRetrievalFailureException(this.entityClass, id);
    }

    return entity;
}
 
Example #15
Source File: TicketService.java    From spring-rest-server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Location addLocationScan(Ticket ticket, Long locationId) {
    Location location = locationDao.findOne(locationId);
    if (location == null) {
        throw new ObjectRetrievalFailureException(Ticket.class, locationId);
    }

    LocationScan locationScan = new LocationScan();
    locationScan.setLocation(location);
    locationScan.setTimestamp(new Date());
    ticket.getLocationScans().add(locationScan);
    store(ticket);

    return location;
}
 
Example #16
Source File: PeopleFlowActionTypeServiceTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public PeopleFlowDefinition getPeopleFlow(@WebParam(name = "peopleFlowId") String peopleFlowId) throws RiceIllegalArgumentException {
    if (validPeopleFlowIds.contains(peopleFlowId)) {
        return PeopleFlowDefinition.Builder.create("myNamespace", "myPeopleFlowName").build();
    } else {
        // simulate what our PeopleFlowServiceImpl would do
        throw new ObjectRetrievalFailureException("", new RuntimeException());
    }
}
 
Example #17
Source File: OjbCollectionHelper.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * OJB RemovalAwareLists do not survive through the response/request lifecycle. This method is a work-around to forcibly remove
 * business objects that are found in Collections stored in the database but not in memory.
 * 
 * @param orig
 * @param id
 * @param template
 */
public void processCollections2(OjbCollectionAware template, PersistableBusinessObject orig, PersistableBusinessObject copy) {
    // if copy is null this is the first time we are saving the object, don't have to worry about updating collections
    if (copy == null) {
        return;
    }
    
    List<Collection<PersistableBusinessObject>> originalCollections = orig.buildListOfDeletionAwareLists();

    if (originalCollections != null && !originalCollections.isEmpty()) {
        /*
         * Prior to being saved, the version in the database will not yet reflect any deleted collections. So, a freshly
         * retrieved version will contain objects that need to be removed:
         */
        try {
            List<Collection<PersistableBusinessObject>> copyCollections = copy.buildListOfDeletionAwareLists();
            int size = originalCollections.size();

            if (copyCollections.size() != size) {
                throw new RuntimeException("size mismatch while attempting to process list of Collections to manage");
            }

            for (int i = 0; i < size; i++) {
                Collection<PersistableBusinessObject> origSource = originalCollections.get(i);
                Collection<PersistableBusinessObject> copySource = copyCollections.get(i);
                List<PersistableBusinessObject> list = findUnwantedElements(copySource, origSource);
                cleanse(template, origSource, list);
            }
        }
        catch (ObjectRetrievalFailureException orfe) {
            // object wasn't found, must be pre-save
        }
    }
}
 
Example #18
Source File: OjbCollectionHelper.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * OJB RemovalAwareLists do not survive through the response/request lifecycle. This method is a work-around to forcibly remove
 * business objects that are found in Collections stored in the database but not in memory.
 * 
 * @param orig
 * @param id
 * @param template
 */
public void processCollections(OjbCollectionAware template, PersistableBusinessObject orig, PersistableBusinessObject copy) {
    if (copy == null) {
        return;
    }
    
    List<Collection<PersistableBusinessObject>> originalCollections = orig.buildListOfDeletionAwareLists();

    if (originalCollections != null && !originalCollections.isEmpty()) {
        /*
         * Prior to being saved, the version in the database will not yet reflect any deleted collections. So, a freshly
         * retrieved version will contain objects that need to be removed:
         */
        try {
            List<Collection<PersistableBusinessObject>> copyCollections = copy.buildListOfDeletionAwareLists();
            int size = originalCollections.size();

            if (copyCollections.size() != size) {
                throw new RuntimeException("size mismatch while attempting to process list of Collections to manage");
            }

            for (int i = 0; i < size; i++) {
                Collection<PersistableBusinessObject> origSource = originalCollections.get(i);
                Collection<PersistableBusinessObject> copySource = copyCollections.get(i);
                List<PersistableBusinessObject> list = findUnwantedElements(copySource, origSource);
                cleanse(template, origSource, list);
            }
        }
        catch (ObjectRetrievalFailureException orfe) {
            // object wasn't found, must be pre-save
        }
    }
}
 
Example #19
Source File: EntityUtils.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 * @param entities the collection to search
 * @param entityClass the entity class to look up
 * @param entityId the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
		throws ObjectRetrievalFailureException {
	for (T entity : entities) {
		if (entity.getId() == entityId && entityClass.isInstance(entity)) {
			return entity;
		}
	}
	throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #20
Source File: PurApOjbCollectionHelper.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * OJB RemovalAwareLists do not survive through the response/request lifecycle. This method is a work-around to forcibly remove
 * business objects that are found in Collections stored in the database but not in memory.
 * 
 * @param orig
 * @param id
 * @param template
 */
public void processCollections2(OjbCollectionAware template, PersistableBusinessObject orig, PersistableBusinessObject copy) {
    // if copy is null this is the first time we are saving the object, don't have to worry about updating collections
    if (copy == null) {
        return;
    }

    List originalCollections = orig.buildListOfDeletionAwareLists();

    if (originalCollections != null && !originalCollections.isEmpty()) {
        /*
         * Prior to being saved, the version in the database will not yet reflect any deleted collections. So, a freshly
         * retrieved version will contain objects that need to be removed:
         */
        try {
            List copyCollections = copy.buildListOfDeletionAwareLists();
            int size = originalCollections.size();

            if (copyCollections.size() != size) {
                throw new RuntimeException("size mismatch while attempting to process list of Collections to manage");
            }

            for (int i = 0; i < size; i++) {
                Collection origSource = (Collection) originalCollections.get(i);
                Collection copySource = (Collection) copyCollections.get(i);
                List list = findUnwantedElements(copySource, origSource, null, 0);
                cleanse(template, origSource, list);

            }
        }
        catch (ObjectRetrievalFailureException orfe) {
            // object wasn't found, must be pre-save
        }
    }
}
 
Example #21
Source File: PurApOjbCollectionHelper.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method processes collections recursively up to the depth level specified
 * 
 * @param template
 * @param orig
 * @param copy
 */
private void processCollectionsRecurse(OjbCollectionAware template, PersistableBusinessObject orig, PersistableBusinessObject copy, int depth) {
    if (copy == null || depth < 1) {
        return;
    }

    List originalCollections = orig.buildListOfDeletionAwareLists();

    if (originalCollections != null && !originalCollections.isEmpty()) {
        /*
         * Prior to being saved, the version in the database will not yet reflect any deleted collections. So, a freshly
         * retrieved version will contain objects that need to be removed:
         */
        try {
            List copyCollections = copy.buildListOfDeletionAwareLists();
            int size = originalCollections.size();

            if (copyCollections.size() != size) {
                throw new RuntimeException("size mismatch while attempting to process list of Collections to manage");
            }

            for (int i = 0; i < size; i++) {
                Collection<PersistableBusinessObject> origSource = (Collection<PersistableBusinessObject>) originalCollections.get(i);
                Collection<PersistableBusinessObject> copySource = (Collection<PersistableBusinessObject>) copyCollections.get(i);
                List list = findUnwantedElements(copySource, origSource, template, depth - 1);
                cleanse(template, origSource, list);

            }
        }
        catch (ObjectRetrievalFailureException orfe) {
            // object wasn't found, must be pre-save
        }
    }
}
 
Example #22
Source File: EntityUtils.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
    throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #23
Source File: JdbcPetRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    Integer ownerId;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        ownerId = this.namedParameterJdbcTemplate.queryForObject("SELECT owner_id FROM pets WHERE id=:id", params, Integer.class);
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(ownerId);
    return EntityUtils.getById(owner.getPets(), Pet.class, id);
}
 
Example #24
Source File: EntityUtils.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
    throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #25
Source File: EntityUtils.java    From spring-init with Apache License 2.0 5 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
    throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #26
Source File: EntityUtils.java    From audit4j-demo with Apache License 2.0 3 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException
 *          if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
        throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #27
Source File: EntityUtils.java    From docker-workflow-plugin with MIT License 3 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException
 *          if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
        throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #28
Source File: EntityUtils.java    From activejpa with Apache License 2.0 3 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given collection.
 *
 * @param entities    the collection to search
 * @param entityClass the entity class to look up
 * @param entityId    the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException
 *          if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
        throws ObjectRetrievalFailureException {
    for (T entity : entities) {
        if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) {
            return entity;
        }
    }
    throw new ObjectRetrievalFailureException(entityClass, entityId);
}
 
Example #29
Source File: EntityUtils.java    From cacheonix-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Look up the entity of the given class with the given id in the given
 * collection.
 *
 * @param entities the collection to search
 * @param entityClass the entity class to look up
 * @param entityId the entity id to look up
 * @return the found entity
 * @throws ObjectRetrievalFailureException if the entity was not found
 */
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
		throws ObjectRetrievalFailureException {
	for (T entity : entities) {
		if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) {
			return entity;
		}
	}
	throw new ObjectRetrievalFailureException(entityClass, new Integer(entityId));
}