org.hibernate.ObjectNotFoundException#org.springframework.dao.InvalidDataAccessResourceUsageException源码实例Demo

下面列出了org.hibernate.ObjectNotFoundException#org.springframework.dao.InvalidDataAccessResourceUsageException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码2 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码3 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码4 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码5 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码6 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
源代码7 项目: redisson   文件: RedissonConnectionFactory.java
@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");
}
 
@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;
}
 
@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'");
}
 
源代码10 项目: dubbox   文件: SolrJsonResponse.java
@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);
	}
}
 
源代码11 项目: dubbox   文件: MappingJacksonResponseParser.java
@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;
}
 
@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));
}
 
源代码13 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
源代码14 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
源代码15 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
源代码16 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
源代码17 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
源代码18 项目: redisson   文件: RedissonConnectionFactory.java
@Override
public RedisClusterConnection getClusterConnection() {
    if (!redisson.getConfig().isClusterConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Cluster mode");
    }
    return new RedissonClusterConnection(redisson);
}
 
@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");
    }
}
 
@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;
}
 
@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();
}