Search in sources :

Example 6 with NJdbcException

use of com.alibaba.nacos.config.server.exception.NJdbcException in project nacos by alibaba.

the class DistributedDatabaseOperateImpl method queryMany.

@Override
public List<Map<String, Object>> queryMany(String sql, Object[] args) {
    try {
        LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "queryMany info : sql : {}, args : {}", sql, args);
        byte[] data = serializer.serialize(SelectRequest.builder().queryType(QueryType.QUERY_MANY_WITH_LIST_WITH_ARGS).sql(sql).args(args).build());
        final boolean blockRead = EmbeddedStorageContextUtils.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
        Response response = innerRead(ReadRequest.newBuilder().setGroup(group()).setData(ByteString.copyFrom(data)).build(), blockRead);
        if (response.getSuccess()) {
            return serializer.deserialize(response.getData().toByteArray(), List.class);
        }
        throw new NJdbcException(response.getErrMsg());
    } catch (Exception e) {
        LogUtil.FATAL_LOG.error("An exception occurred during the query operation : {}", e.toString());
        throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
    }
}
Also used : Response(com.alibaba.nacos.consistency.entity.Response) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) TimeoutException(java.util.concurrent.TimeoutException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConsistencyException(com.alibaba.nacos.consistency.exception.ConsistencyException) DataAccessException(org.springframework.dao.DataAccessException) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)

Example 7 with NJdbcException

use of com.alibaba.nacos.config.server.exception.NJdbcException in project nacos by alibaba.

the class DistributedDatabaseOperateImpl method queryMany.

@Override
public <R> List<R> queryMany(String sql, Object[] args, Class<R> rClass) {
    try {
        LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "queryMany info : sql : {}, args : {}", sql, args);
        byte[] data = serializer.serialize(SelectRequest.builder().queryType(QueryType.QUERY_MANY_NO_MAPPER_WITH_ARGS).sql(sql).args(args).className(rClass.getCanonicalName()).build());
        final boolean blockRead = EmbeddedStorageContextUtils.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
        Response response = innerRead(ReadRequest.newBuilder().setGroup(group()).setData(ByteString.copyFrom(data)).build(), blockRead);
        if (response.getSuccess()) {
            return serializer.deserialize(response.getData().toByteArray(), List.class);
        }
        throw new NJdbcException(response.getErrMsg());
    } catch (Exception e) {
        LogUtil.FATAL_LOG.error("An exception occurred during the query operation : {}", e.toString());
        throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
    }
}
Also used : Response(com.alibaba.nacos.consistency.entity.Response) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) TimeoutException(java.util.concurrent.TimeoutException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConsistencyException(com.alibaba.nacos.consistency.exception.ConsistencyException) DataAccessException(org.springframework.dao.DataAccessException) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)

Aggregations

NacosException (com.alibaba.nacos.api.exception.NacosException)7 NacosRuntimeException (com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)7 NJdbcException (com.alibaba.nacos.config.server.exception.NJdbcException)7 Response (com.alibaba.nacos.consistency.entity.Response)7 ConsistencyException (com.alibaba.nacos.consistency.exception.ConsistencyException)7 TimeoutException (java.util.concurrent.TimeoutException)7 DataAccessException (org.springframework.dao.DataAccessException)7 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)7 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)7 JustForTest (com.alibaba.nacos.common.JustForTest)1 RestResult (com.alibaba.nacos.common.model.RestResult)1 RestResultUtils (com.alibaba.nacos.common.model.RestResultUtils)1 Event (com.alibaba.nacos.common.notify.Event)1 NotifyCenter (com.alibaba.nacos.common.notify.NotifyCenter)1 Subscriber (com.alibaba.nacos.common.notify.listener.Subscriber)1 ExceptionUtil (com.alibaba.nacos.common.utils.ExceptionUtil)1 JacksonUtils (com.alibaba.nacos.common.utils.JacksonUtils)1 LoggerUtils (com.alibaba.nacos.common.utils.LoggerUtils)1 MD5Utils (com.alibaba.nacos.common.utils.MD5Utils)1 Preconditions (com.alibaba.nacos.common.utils.Preconditions)1