Java Code Examples for org.springframework.dao.InvalidDataAccessResourceUsageException

The following examples show how to use org.springframework.dao.InvalidDataAccessResourceUsageException. These examples are extracted from open source projects. 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 Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 2
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 3
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 4
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 5
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 6
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 7
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example 8
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {

	if (ex instanceof DataAccessException) {
		return (DataAccessException) ex;
	} else if (ex instanceof DiscoveryException) {
		return translateImpl((Neo4jException) ex, TransientDataAccessResourceException::new);
	} else if (ex instanceof DatabaseException) {
		return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new);
	} else if (ex instanceof ServiceUnavailableException) {
		return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new);
	} else if (ex instanceof SessionExpiredException) {
		return translateImpl((Neo4jException) ex, RecoverableDataAccessException::new);
	} else if (ex instanceof ProtocolException) {
		return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new);
	} else if (ex instanceof TransientException) {
		return translateImpl((Neo4jException) ex, TransientDataAccessResourceException::new);
	} else if (ex instanceof ValueException) {
		return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new);
	} else if (ex instanceof AuthenticationException) {
		return translateImpl((Neo4jException) ex, PermissionDeniedDataAccessException::new);
	} else if (ex instanceof ResultConsumedException) {
		return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new);
	} else if (ex instanceof FatalDiscoveryException) {
		return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new);
	} else if (ex instanceof TransactionNestingException) {
		return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new);
	} else if (ex instanceof ClientException) {
		return translateImpl((Neo4jException) ex, InvalidDataAccessResourceUsageException::new);
	}

	log.warn(() -> String.format("Don't know how to translate exception of type %s", ex.getClass()));
	return null;
}
 
Example 9
@Test
void shouldKeepErrorCodeIntact() {

	Neo4jPersistenceExceptionTranslator translator = new Neo4jPersistenceExceptionTranslator();
	DataAccessException dataAccessException = translator
		.translateExceptionIfPossible(
			new ClientException("Neo.ClientError.Statement.EntityNotFound", "Something went wrong."));
	assertThat(dataAccessException).isNotNull().isInstanceOf(InvalidDataAccessResourceUsageException.class);
	assertThat(dataAccessException.getMessage())
		.isEqualTo("Something went wrong.; Error code 'Neo.ClientError.Statement.EntityNotFound'");
}
 
Example 10
Source Project: dubbox   Source File: SolrJsonResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setResponse(NamedList<Object> response) {

	super.setResponse(response);
	try {
		root = new ObjectMapper().readTree((String) getResponse().get("json"));
	} catch (Exception e) {
		throw new InvalidDataAccessResourceUsageException("Unable to parse json from response.", e);
	}
}
 
Example 11
Source Project: dubbox   Source File: MappingJacksonResponseParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NamedList<Object> processResponse(InputStream body, String encoding) {

	NamedList<Object> result = new NamedList<Object>();
	try {
		result.add("json", StreamUtils.copyToString(body, Charset.forName(encoding)));
	} catch (IOException e) {
		throw new InvalidDataAccessResourceUsageException("Unable to read json from stream.", e);
	}
	return result;
}
 
Example 12
@Test
public void shouldNotStopSchemaExportOnError() throws Exception {
	
	initializeMappingContext(Person.class);
	
	when(crateOperations.execute(isA(CrateAction.class))).thenThrow(new NoSuchTableException("table does not exist", null)).
															 thenThrow(new InvalidDataAccessResourceUsageException("Error!!"));
	
	CratePersistentEntitySchemaManager manager = new CratePersistentEntitySchemaManager(crateOperations, CREATE);
	manager.setIgnoreFailures(true);
	manager.afterPropertiesSet();
	
	verify(crateOperations, times(2)).execute(any(CrateAction.class));
}
 
Example 13
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 14
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 15
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 16
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 17
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 18
Source Project: redisson   Source File: RedissonConnectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
Example 19
@Test(expected = InvalidDataAccessResourceUsageException.class)
public void whenRetrievingDataUserNoSelectRights_thenInvalidResourceUsageException() {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(restDataSource);
    jdbcTemplate.execute("revoke select from tutorialuser");

    try {
        fooService.findAll();
    } finally {
        jdbcTemplate.execute("grant select to tutorialuser");
    }
}
 
Example 20
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	
	if(ex instanceof NoNodeAvailableException) {
		return new DataAccessResourceFailureException(ex.getMessage(), ex);
	}
	
	if(ex instanceof SQLActionException) {
		
		int errorCode = ((SQLActionException)ex).errorCode();
		
		switch (errorCode) {
		case DUPLICATE_PRIMARY_KEY:
			return new DuplicateKeyException(ex.getMessage(), ex);
		case VERSION_CONFLICT:
			return new OptimisticLockingFailureException(ex.getMessage(), ex);
		case FIELD_VALIDATION_FAILED:
			return new DataIntegrityViolationException(ex.getMessage(), ex);
		case DUPLICATE_TABLE_NAME:
			return new DuplicateTableException(ex.getMessage(), ex);
		case UNKNOWN_TABLE:
			return new NoSuchTableException(ex.getMessage(), ex);
		case INVALID_SQL_STATEMENT_OR_SYNTAX:
		case INVALID_TABLE_NAME:
		case UNKNOWN_ANALYZER:
		case UNKNOWN_COLUMN:
		case UNKNOWN_TYPE:
		case UNKNOWN_SCHEMA:
		case UNKNOWN_PARTITION:
		case COLUMN_ALIAS_AMBIGUOUS:
		case FEATURE_NOT_SUPPORTED_YET:
		case INVALID_ANALYZER_DEFINITION:
		case ALTER_TABLE_ALIAS_NOT_SUPPORTED:
		case TABLE_ALIAS_CONTAINS_TABLES_WITH_DIFFERENT_SCHEMA:
			return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
		case UNHANDLED_SERVER_ERROR:
		case TASKS_EXECUTION_FAILED:
		case SHARDS_NOT_AVAILABLE:
		case QUERY_FAILED_ON_SHARDS:
			return new DataAccessResourceFailureException(ex.getMessage(), ex);
		default:
			return new UncategorizedCrateException(ex.getMessage(), ex);
		}
	}
	
	return null;
}
 
Example 21
@Test(expected=DataAccessException.class)
public void shouldNotAlterTableOnError() throws Exception {
	
	initializeMappingContext(Person.class);
	
	List<ColumnMetadata> columns = asList(createColumnMetadata("['name']", STRING),
										  createColumnMetadata("['age']", INTEGER));
	
	TableMetadata metadata = new TableMetadata("person", columns, DEFAULT_PARAMS);
	
	when(crateOperations.execute(isA(ColumnMetadataAction.class),
								 isA(ColumnMetadataAction.class))).thenReturn(columns);
	
	when(crateOperations.execute(isA(TableMetadataAction.class),
			 					 isA(TableMetadataAction.class))).thenReturn(metadata);
	
	when(crateOperations.execute(isA(CrateAction.class))).thenThrow(new InvalidDataAccessResourceUsageException("Error!!"));
	
	CratePersistentEntitySchemaManager manager = new CratePersistentEntitySchemaManager(crateOperations, UPDATE);
	manager.afterPropertiesSet();
}