List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException
public DataRetrievalFailureException(String msg)
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractGenericEntityDAO.java
public final T getByTechId(final TechId techId) throws DataAccessException { assert techId != null : "Technical identifier unspecified."; final Object entity = getHibernateTemplate().get(getEntityClass(), techId.getId()); T result = null;//from w ww.ja v a 2 s . co m if (entity == null) { throw new DataRetrievalFailureException(getEntityDescription() + " with ID " + techId.getId() + " does not exist. Maybe someone has just deleted it."); } else { result = getEntity(getHibernateTemplate().get(getEntityClass(), techId.getId())); } if (operationLog.isDebugEnabled()) { operationLog.debug( String.format("%s(%s): '%s'.", MethodUtils.getCurrentMethod().getName(), techId, result)); } return result; }
From source file:fr.keemto.core.fetching.IncrementalFetchingTaskTest.java
@Test(expected = FetchingException.class) public void whenEventRepositoryFailsShouldThrowException() throws Exception { when(eventRepository.getMostRecentEvent(any(Account.class))).thenReturn(mostRecentEvent); doThrow(new DataRetrievalFailureException("")).when(eventRepository).persist(anyList()); task.run();//from w w w .j a v a2 s . com }
From source file:com.jpeterson.littles3.dao.je.JeBucketDao.java
/** * This method retrieves the <code>Bucket</code> representation of a * bucket from the underlying JE database via the bucket's name. * /*w w w. ja v a2s . c o m*/ * @param bucket * The bucket name. * @throws DataRetrievalFailureException * Could not find the <code>Bucket</code> for the provided * <code>bucket</code> name. * @throws DataAccessResourceFailureException * General failure retrieving the bucket from the JE database. * @throws DataAccessException * General failure retrieving the bucket. */ public Bucket loadBucket(String bucket) throws DataAccessException { DatabaseEntry theKey; DatabaseEntry theData; // Environment myDbEnvironment = null; Database database = null; try { theKey = new DatabaseEntry(bucket.getBytes("UTF-8")); theData = new DatabaseEntry(); database = jeCentral.getDatabase(JeCentral.BUCKET_DB_NAME); if (database.get(null, theKey, theData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { return (Bucket) bucketBinding.entryToObject(theData); } else { throw new DataRetrievalFailureException("Could not find Bucket: " + bucket); } } catch (DatabaseException e) { throw new DataAccessResourceFailureException("Unable to load a database record", e); } catch (UnsupportedEncodingException e) { // should not happen e.printStackTrace(); throw new DataAccessResourceFailureException("Unexpected encoding error", e); } }
From source file:com.github.jguaneri.notifications.repository.impl.NotificationRepositoryHibernateImpl.java
@SuppressWarnings("unchecked") @Override/* w ww.j a v a 2 s .c o m*/ public List<Notification> query(final NotificationSpecification notificationSpecification) { if (notificationSpecification instanceof HibernateSpecification) { return this.sessionFactory.getCurrentSession().createCriteria(Notification.class) .add(((HibernateSpecification) notificationSpecification).toCriteria()).list(); } else { throw new DataRetrievalFailureException( "Invalid NotificationSpecification. Instance must implement HibernateSpecification"); } }
From source file:de.theit.hudson.crowd.CrowdUserDetailsService.java
/** * {@inheritDoc}/*from w w w . ja v a 2s . c o m*/ * * @see org.acegisecurity.userdetails.UserDetailsService#loadUserByUsername(java.lang.String) */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { // check whether there's at least one active group the user is a member // of if (!this.configuration.isGroupMember(username)) { throw new DataRetrievalFailureException(userNotValid(username, this.configuration.allowedGroupNames)); } User user; try { // load the user object from the remote Crowd server if (LOG.isLoggable(Level.FINE)) { LOG.fine("Loading user object from the remote Crowd server..."); } user = this.configuration.crowdClient.getUser(username); } catch (UserNotFoundException ex) { if (LOG.isLoggable(Level.INFO)) { LOG.info(userNotFound(username)); } throw new UsernameNotFoundException(userNotFound(username), ex); } catch (ApplicationPermissionException ex) { LOG.warning(applicationPermission()); throw new DataRetrievalFailureException(applicationPermission(), ex); } catch (InvalidAuthenticationException ex) { LOG.warning(invalidAuthentication()); throw new DataRetrievalFailureException(invalidAuthentication(), ex); } catch (OperationFailedException ex) { LOG.log(Level.SEVERE, operationFailed(), ex); throw new DataRetrievalFailureException(operationFailed(), ex); } // create the list of granted authorities List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); // add the "authenticated" authority to the list of granted // authorities... authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY); // ..and all authorities retrieved from the Crowd server authorities.addAll(this.configuration.getAuthoritiesForUser(username)); return new CrowdUser(user, authorities); }
From source file:com.gzj.tulip.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime) { Number result;/*from w ww. ja va2 s .c o m*/ DataAccess dataAccess = dataAccessFactory.getDataAccess(// runtime.getMetaData(), runtime.getAttributes()); if (returnGeneratedKeys.shouldReturnGerneratedKeys(runtime)) { ArrayList<Map<String, Object>> keys = new ArrayList<Map<String, Object>>(1); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else { result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (returnType == Number.class) { return result; } else if (returnType == String.class || returnType == CharSequence.class) { return String.valueOf(result); } else { throw new DataRetrievalFailureException( "The generated key is not of a supported numeric type: " + returnType.getName()); } }
From source file:com.sinosoft.one.data.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime, Class<?> returnType) { // DAOIdentity?1/20 if (returnType == Identity.class) { if (new Random().nextInt(20) == 1) { new IllegalArgumentException( "message by zhiliang.wang: change the deprecated Identity to @ReturnGeneratedKeys please: " + runtime.getMetaData()).printStackTrace(); }/* w ww .j a va2s . c om*/ } Number result; DataAccess dataAccess = new DataAccessImpl(em); if (returnGeneratedKeys) { //ArrayList<Number> keys = new ArrayList<Number>(1); List<Map<String, Object>> keys = new ArrayList<Map<String, Object>>(); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else { result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (returnType == Identity.class) { return new Identity((Number) result); } else if (Number.class.isAssignableFrom(returnType)) { return result; } else { throw new DataRetrievalFailureException("The generated key is not of a supported numeric type. " + "Unable to cast [" + result.getClass().getName() + "] to [" + Number.class.getName() + "]"); } }
From source file:com.jpeterson.littles3.dao.je.JeS3ObjectDao.java
/** * This method retrieves the <code>S3Object</code> representation of an * object from the underlying JE database via the object's bucket and key. * //from w ww . ja v a 2 s. c o m * @param bucket * The bucket identifying the object. * @param key * The key identifying the object. * @return The <code>S3Object</code> identified by the provided * <code>bucket</code> + <code>key</code>. * @throws DataRetrievalFailureException * Could not find the <code>S3Object</code> for the provided * <code>bucket</code> and <code>key</code>. * @throws DataAccessResourceFailureException * General failure retrieving the GUID from the JE database. * @throws DataAccessException * General failure retrieving the GUID. */ public S3Object loadS3Object(String bucket, String key) throws DataAccessException { DatabaseEntry theKey; DatabaseEntry theData; // Environment myDbEnvironment = null; Database database = null; try { S3Object s3ObjectBucketKey = new S3ObjectBucketKey(); s3ObjectBucketKey.setBucket(bucket); s3ObjectBucketKey.setKey(key); theKey = new DatabaseEntry(); s3ObjectBucketKeyBinding.objectToEntry(s3ObjectBucketKey, theKey); theData = new DatabaseEntry(); // TODO: generalize this /* * EnvironmentConfig envConfig = new EnvironmentConfig(); * envConfig.setAllowCreate(true); myDbEnvironment = new * Environment(new File( "C:/temp/StorageEngine/db"), envConfig); * * DatabaseConfig dbConfig = new DatabaseConfig(); * dbConfig.setAllowCreate(true); database = * myDbEnvironment.openDatabase(null, "sampleDatabase", dbConfig); */ database = jeCentral.getDatabase(JeCentral.OBJECT_DB_NAME); if (database.get(null, theKey, theData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { return (S3Object) fileS3ObjectBinding.entryToObject(theData); } else { throw new DataRetrievalFailureException("Could not find S3Object"); } } catch (DatabaseException e) { throw new DataAccessResourceFailureException("Unable to load a database record", e); } finally { /* * if (database != null) { try { database.close(); } catch * (DatabaseException e) { // do nothing } } database = null; * * if (myDbEnvironment != null) { try { myDbEnvironment.close(); } * catch (DatabaseException e) { // do nothing } } myDbEnvironment = * null; */ } }
From source file:com.github.peholmst.springsecuritydemo.services.impl.CategoryServiceImpl.java
@Override @Transactional/*from ww w. j av a 2 s .com*/ public Category updateCategory(Category category) { assert category != null : "category must not be null"; if (logger.isDebugEnabled()) { logger.debug("Updating category [" + category + "]"); } if (!containsCategory(category)) { if (logger.isDebugEnabled()) { logger.debug("Cannot update category [" + category + "] as it could not be found"); } throw new DataRetrievalFailureException("Could not find category to update"); } else { Category merged = getEntityManager().merge(category); getEntityManager().flush(); return merged; } }
From source file:com.github.peholmst.springsecuritydemo.services.stubs.CategoryServiceStub.java
@Override public Category updateCategory(Category category) { if (category.getId() == null || !categories.containsKey(category.getId())) { throw new DataRetrievalFailureException("Category could not be found"); }/* ww w . jav a 2 s. co m*/ // Check that parent property points to a valid category if (category.getParent() != null && !categories.containsKey(category.getParent().getId())) { throw new IllegalArgumentException("Invalid parent property"); } Category parent = category.getParent(); if (parent == null) { parent = NULL_CATEGORY; } // Remove reference to old parent if the parent property has changed Category oldParent = categoryToParentMap.get(category.getId()); if (oldParent != null && !oldParent.equals(parent)) { categories.get(oldParent.getId()).children.remove(category); categoryToParentMap.remove(category.getId()); } // Update the parent index if the parent property has changed if (!parent.equals(oldParent)) { categories.get(parent.getId()).children.add(category); categoryToParentMap.put(category.getId(), parent); } return category; }