List of usage examples for org.springframework.dao InvalidDataAccessResourceUsageException InvalidDataAccessResourceUsageException
public InvalidDataAccessResourceUsageException(String msg, Throwable cause)
From source file:com.frank.search.solr.core.schema.SolrJsonResponse.java
@Override public void setResponse(NamedList<Object> response) { super.setResponse(response); try {//from ww w . ja v a 2 s . co m root = new ObjectMapper().readTree((String) getResponse().get("json")); } catch (Exception e) { throw new InvalidDataAccessResourceUsageException("Unable to parse json from response.", e); } }
From source file:com.frank.search.solr.core.schema.MappingJacksonResponseParser.java
@Override public NamedList<Object> processResponse(InputStream body, String encoding) { NamedList<Object> result = new NamedList<Object>(); try {/*from w w w . j a va2 s.com*/ result.add("json", StreamUtils.copyToString(body, Charset.forName(encoding))); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Unable to read json from stream.", e); } return result; }
From source file:com._4dconcept.springframework.data.marklogic.core.MarklogicExceptionTranslator.java
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { // Check for well-known MarklogicException subclasses. String exception = ClassUtils.getShortName(ClassUtils.getUserClass(ex.getClass())); if (RESOURCE_FAILURE_EXCEPTIONS.contains(exception)) { return new DataAccessResourceFailureException(ex.getMessage(), ex); }//w w w . java 2 s . c om if (RESOURCE_USAGE_EXCEPTIONS.contains(exception)) { return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex); } if (DATA_INTEGRETY_EXCEPTIONS.contains(exception)) { return new DataIntegrityViolationException(ex.getMessage(), ex); } return null; }
From source file:com.frank.search.solr.core.schema.SolrSchemaWriter.java
private void writeFieldDefinitions(Collection<SchemaDefinition.FieldDefinition> definitions, String collectionName) {/* w w w . java 2s. c o m*/ if (!CollectionUtils.isEmpty(definitions)) { try { SolrSchemaRequest.create().fields(definitions).build() .process(factory.getSolrClient(collectionName)); } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to write schema field definitions.", e); } } }
From source file:com.frank.search.solr.core.schema.SolrSchemaWriter.java
SchemaDefinition loadExistingSchema(String collectionName) { try {// ww w .j a va 2 s. c o m SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrClient(collectionName)); if (response != null && response.getNode("schema") != null) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.AUTO_DETECT_CREATORS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class); } return null; } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e); } catch (SolrException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
/** * Translates low level database exceptions to application level exceptions * * @param e the low level amazon client exception * @param action crud action name/*from w w w .ja v a 2 s.co m*/ * @param conditionalSupplier creates condition failed exception (context dependent) * @return a translation of the AWS/DynamoDB exception */ DataAccessException convertDynamoDBException(AmazonClientException e, String action, Supplier<? extends DataAccessException> conditionalSupplier) { final String format = "unable to %s entity due to %s."; if (e instanceof ConditionalCheckFailedException) { return conditionalSupplier.get(); } else if (e instanceof ProvisionedThroughputExceededException) { return new QueryTimeoutException(String.format(Locale.ENGLISH, format, action, "throttling"), e); } else if (e instanceof ResourceNotFoundException) { return new NonTransientDataAccessResourceException( String.format(Locale.ENGLISH, format, action, "table does not exist"), e); } else if (e instanceof AmazonServiceException) { AmazonServiceException ase = (AmazonServiceException) e; if (VALIDATION_EXCEPTION.equals(((AmazonServiceException) e).getErrorCode())) { return new InvalidDataAccessResourceUsageException( String.format(Locale.ENGLISH, format, action, "client error"), e); } else { return new DynamoDbServiceException( String.format(Locale.ENGLISH, format, action, "DynamoDB service error"), ase); } } else { return new InvalidDataAccessResourceUsageException( String.format(Locale.ENGLISH, format, action, "client error"), e); } }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
protected DataAccessException processUpdateItemException(K key, AmazonClientException e) { final String format = "unable to update entity due to %s."; if (e instanceof ConditionalCheckFailedException) { if (null == findOne(key)) { return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e); }//from w ww.j ava 2s . c om return new OptimisticLockingFailureException(UPDATE_FAILED_NOT_FOUND_OR_BAD_VERSION, e); } else if (e instanceof ProvisionedThroughputExceededException) { throw new QueryTimeoutException(String.format(Locale.ENGLISH, format, "throttling"), e); } else if (e instanceof AmazonServiceException) { AmazonServiceException ase = (AmazonServiceException) e; if (VALIDATION_EXCEPTION.equals(ase.getErrorCode())) { if (EXPRESSION_REFERS_TO_NON_EXTANT_ATTRIBUTE.equals(ase.getErrorMessage()) && null == findOne(key)) { // if no locking and we get a specific message, then it also means the item does not exist return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e); } return new InvalidDataAccessResourceUsageException( String.format(Locale.ENGLISH, format, "client error"), e); } else { return new DynamoDbServiceException(String.format(Locale.ENGLISH, format, "DynamoDB service error"), ase); } } else { return new InvalidDataAccessResourceUsageException( String.format(Locale.ENGLISH, format, "client error"), e); } }
From source file:org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService.java
private Object[] getFieldsForUpdate(ClientDetails clientDetails) { String json = null;/* w w w .ja v a 2 s . c o m*/ try { json = JsonUtils.writeValueAsString(clientDetails.getAdditionalInformation()); } catch (Exception e) { logger.warn("Could not serialize additional information: " + clientDetails, e); throw new InvalidDataAccessResourceUsageException( "Could not serialize additional information:" + clientDetails.getClientId(), e); } return new Object[] { clientDetails.getResourceIds() != null ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds()) : null, clientDetails.getScope() != null ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope()) : null, clientDetails.getAuthorizedGrantTypes() != null ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes()) : null, clientDetails.getRegisteredRedirectUri() != null ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri()) : null, clientDetails.getAuthorities() != null ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities()) : null, clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json, getAutoApproveScopes(clientDetails), new Timestamp(System.currentTimeMillis()), clientDetails.getClientId(), IdentityZoneHolder.get().getId() }; }
From source file:org.openspaces.events.AbstractEventListenerContainer.java
/** * Initialize this container. If this container is not configured with "activeWhenPrimary" flag * set to <code>true</code> will call {@link #doStart()} (if it is set to <code>true</code>, * lifecycle of the container will be controlled by the current space mode). {@link * #doInitialize()} will be called for additional initialization after the possible {@link * #doStart()} call.// w w w .j ava 2 s . com * * @see #onApplicationEvent(org.springframework.context.ApplicationEvent) */ public void initialize() throws DataAccessException { initializeTransactionManager(); initializeTemplate(); initializeExceptionHandler(); synchronized (this.lifecycleMonitor) { this.active = true; this.lifecycleMonitor.notifyAll(); } doInitialize(); if (!activeWhenPrimary) { doStart(); } if (registerSpaceModeListener) { SpaceMode currentMode = SpaceMode.PRIMARY; if (!SpaceUtils.isRemoteProtocol(gigaSpace.getSpace())) { primaryBackupListener = new PrimaryBackupListener(); try { IJSpace clusterMemberSpace = SpaceUtils.getClusterMemberSpace(gigaSpace.getSpace()); ISpaceModeListener remoteListener = (ISpaceModeListener) clusterMemberSpace.getDirectProxy() .getStubHandler().exportObject(primaryBackupListener); currentMode = ((IInternalRemoteJSpaceAdmin) clusterMemberSpace.getAdmin()) .addSpaceModeListener(remoteListener); } catch (RemoteException e) { throw new InvalidDataAccessResourceUsageException( "Failed to register space mode listener with space [" + gigaSpace.getSpace() + "]", e); } } SpaceInitializationIndicator.setInitializer(); try { onApplicationEvent(new BeforeSpaceModeChangeEvent(gigaSpace.getSpace(), currentMode)); onApplicationEvent(new AfterSpaceModeChangeEvent(gigaSpace.getSpace(), currentMode)); } finally { SpaceInitializationIndicator.unsetInitializer(); } } }
From source file:org.openspaces.events.AbstractSpaceListeningContainer.java
/** * Initialize this container. If this container is not configured with "activeWhenPrimary" flag * set to <code>true</code> will call {@link #doStart()} (if it is set to <code>true</code>, * lifecycle of the container will be controlled by the current space mode). * {@link #doInitialize()} will be called for additional initialization after the possible * {@link #doStart()} call./*from w w w .j a v a 2 s. com*/ * * @see #onApplicationEvent(org.springframework.context.ApplicationEvent) */ public void initialize() throws DataAccessException { synchronized (this.lifecycleMonitor) { this.active = true; this.lifecycleMonitor.notifyAll(); } doInitialize(); if (!activeWhenPrimary) { doStart(); } if (registerSpaceModeListener) { SpaceMode currentMode = SpaceMode.PRIMARY; if (!SpaceUtils.isRemoteProtocol(gigaSpace.getSpace())) { primaryBackupListener = new PrimaryBackupListener(); try { IJSpace clusterMemberSpace = SpaceUtils.getClusterMemberSpace(gigaSpace.getSpace()); ISpaceModeListener remoteListener = (ISpaceModeListener) clusterMemberSpace.getDirectProxy() .getStubHandler().exportObject(primaryBackupListener); currentMode = ((IInternalRemoteJSpaceAdmin) clusterMemberSpace.getAdmin()) .addSpaceModeListener(remoteListener); } catch (RemoteException e) { throw new InvalidDataAccessResourceUsageException( "Failed to register space mode listener with space [" + gigaSpace.getSpace() + "]", e); } } SpaceInitializationIndicator.setInitializer(); try { onApplicationEvent(new BeforeSpaceModeChangeEvent(gigaSpace.getSpace(), currentMode)); onApplicationEvent(new AfterSpaceModeChangeEvent(gigaSpace.getSpace(), currentMode)); } finally { SpaceInitializationIndicator.unsetInitializer(); } } }