List of usage examples for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException
public ObjectRetrievalFailureException(String persistentClassName, Object identifier)
From source file:me.bulat.jivr.webmin.utils.EntityUtils.java
/** * 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//from w w w . ja v a 2 s . com * @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); }
From source file:com.branded.holdings.qpc.util.EntityUtils.java
/** * 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/* www. ja v a 2s . c o m*/ * @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); }
From source file:com.jklas.sample.petclinic.util.EntityUtils.java
/** * Look up the entity of the given class with the given id * in the given collection.//from w w w.ja v a 2s. co m * @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 Entity getById(Collection entities, Class entityClass, int entityId) throws ObjectRetrievalFailureException { for (Iterator it = entities.iterator(); it.hasNext();) { Entity entity = (Entity) it.next(); if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) { return entity; } } throw new ObjectRetrievalFailureException(entityClass, new Integer(entityId)); }
From source file:com.rosy.investigate.dao.hibernate.BusinessLicenseDaoHibernate.java
/** * @see com.rosy.investigate.dao.BusinessLicenseDao#getBusinessLicense(String id) */// w w w .ja v a 2 s. c o m public BusinessLicense getBusinessLicense(final String id) { BusinessLicense businessLicense = (BusinessLicense) getHibernateTemplate().get(BusinessLicense.class, id); if (businessLicense == null) { log.warn("uh oh, businessLicense with id '" + id + "' not found..."); throw new ObjectRetrievalFailureException(BusinessLicense.class, id); } return businessLicense; }
From source file:com.gisgraphy.dao.hibernate.UniversalDaoHibernate.java
/** * {@inheritDoc}//from w w w . ja v a2s . c om */ public Object get(Class<?> clazz, Serializable id) { Object o = getHibernateTemplate().get(clazz, id); if (o == null) { throw new ObjectRetrievalFailureException(clazz, id); } return o; }
From source file:net.eusashead.hateoas.springhalbuilder.controller.OrderController.java
@Transactional @RequestMapping(method = { RequestMethod.GET, RequestMethod.HEAD }) public ResponseEntity<Representation> get(@PathVariable("id") Integer id, HalResponseBuilder builder) { Order order = orderRepository.findOne(id); if (order == null) { throw new ObjectRetrievalFailureException(Order.class, id); }//from ww w . ja va2 s . co m return builder.convert(order, new OrderRepresentationWriter()).etag(order.getVersion()) .lastModified(order.getUpdated()).build(); }
From source file:org.openhie.openempi.service.impl.UniversalManagerTest.java
@Test public void testDelete() { final Exception ex = new ObjectRetrievalFailureException(User.class, "foo"); context.checking(new Expectations() { {// www.j a v a 2s. c om one(dao).remove(User.class, "foo"); one(dao).get(User.class, "foo"); will(throwException(ex)); } }); manager.remove(User.class, "foo"); new AssertThrows(ObjectRetrievalFailureException.class) { public void test() { manager.get(User.class, "foo"); } }.runTest(); }
From source file:podd.server.authn.impl.PoddUserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException, DataAccessException { try {/*from w ww .j av a 2 s .c o m*/ User user = userDao.loadByUserName(s.toLowerCase()); if (null == user) { throw new UsernameNotFoundException("Cannot find user " + s + " in the system."); } else { boolean accountActive = user.getStatus().equals(ACTIVE); final GrantedAuthority[] grantedAuthorities = getUserAuthorities( user.getRepositoryRole().getName()); return new org.springframework.security.userdetails.User(s, user.getPasswordHash(), accountActive, true, true, accountActive, grantedAuthorities); } } catch (podd.dataaccess.exception.DataAccessException e) { throw new ObjectRetrievalFailureException("Error loading user by name: " + s, e); } }
From source file:com.rambird.miles.repository.jdbc.JdbcUserRepositoryImpl.java
/** * 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. *///from w ww . ja va 2s . c o m @Override public User authUser(String userName, String password) throws DataAccessException { User user; try { Map<String, Object> params = new HashMap<String, Object>(); params.put("userName", userName); params.put("password", password); user = this.namedParameterJdbcTemplate.queryForObject( "SELECT user_name, full_name, home FROM myoath WHERE user_name= :userName", params, ParameterizedBeanPropertyRowMapper.newInstance(User.class)); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(User.class, userName); } return user; }
From source file:org.opennms.ng.dao.support.NodeSnmpResourceType.java
/** * <p>getResourceDirectory</p> * * @param nodeId a int.//from w ww. j a va2s. c o m * @param verify a boolean. * @return a {@link java.io.File} object. */ public File getResourceDirectory(int nodeId, boolean verify) { File snmp = new File(m_resourceDao.getRrdDirectory(verify), DefaultResourceDao.SNMP_DIRECTORY); File node = new File(snmp, Integer.toString(nodeId)); if (verify && !node.isDirectory()) { throw new ObjectRetrievalFailureException(File.class, "No node directory exists for node " + nodeId + ": " + node); } return node; }