use of org.springframework.jdbc.UncategorizedSQLException in project doma-spring-boot by domaframework.
the class DomaPersistenceExceptionTranslator method translateExceptionIfPossible.
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (!(ex instanceof JdbcException)) {
// Fallback to other translators if not JdbcException
return null;
}
if (ex instanceof OptimisticLockException) {
return new OptimisticLockingFailureException(ex.getMessage(), ex);
} else if (ex instanceof UniqueConstraintException) {
return new DuplicateKeyException(ex.getMessage(), ex);
} else if (ex instanceof NonUniqueResultException || ex instanceof NonSingleColumnException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
} else if (ex instanceof NoResultException) {
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
} else if (ex instanceof UnknownColumnException || ex instanceof ResultMappingException) {
return new TypeMismatchDataAccessException(ex.getMessage(), ex);
}
if (ex.getCause() instanceof SQLException) {
SQLException e = (SQLException) ex.getCause();
String sql = null;
if (ex instanceof SqlExecutionException) {
sql = ((SqlExecutionException) ex).getRawSql();
}
DataAccessException dae = translator.translate(ex.getMessage(), sql, e);
return (dae != null ? dae : new UncategorizedSQLException(ex.getMessage(), sql, e));
}
return new UncategorizedDataAccessException(ex.getMessage(), ex) {
};
}
use of org.springframework.jdbc.UncategorizedSQLException in project com.revolsys.open by revolsys.
the class JdbcConnection method getException.
public DataAccessException getException(final String task, final String sql, final SQLException e) {
SQLExceptionTranslator exceptionTransaltor;
if (this.dataSource == null) {
exceptionTransaltor = new SQLStateSQLExceptionTranslator();
} else {
exceptionTransaltor = new SQLErrorCodeSQLExceptionTranslator(this.dataSource);
}
final DataAccessException translatedException = exceptionTransaltor.translate(task, sql, e);
if (translatedException == null) {
return new UncategorizedSQLException(task, sql, e);
} else {
return translatedException;
}
}
use of org.springframework.jdbc.UncategorizedSQLException in project thinglinks by mqttsnet.
the class TdEngineController method addColumnForSuperTable.
@PostMapping("/addColumnInStb")
public R addColumnForSuperTable(@RequestBody SuperTableDto superTableDto) {
String superTableName = superTableDto.getSuperTableName();
if (StringUtils.isBlank(superTableName)) {
return R.fail("invalid operation: superTableName can not be empty");
}
Fields fields = superTableDto.getFields();
if (fields == null) {
return R.fail("invalid operation: fields can not be empty");
}
try {
FieldsVo fieldsVo = FieldsVo.fieldsTranscoding(fields);
this.tdEngineService.addColumnForSuperTable(superTableName, fieldsVo);
log.info("successful operation: add column for superTable '" + superTableName + "' success");
return R.ok();
} catch (UncategorizedSQLException e) {
String message = e.getCause().getMessage();
try {
message = message.substring(message.lastIndexOf("invalid operation"));
} catch (Exception ex) {
}
log.error(message);
return R.fail(message);
} catch (SQLException e) {
log.error(e.getMessage());
return R.fail(e.getMessage());
}
}
use of org.springframework.jdbc.UncategorizedSQLException in project thinglinks by mqttsnet.
the class TdEngineController method createSuperTable.
/**
* @param superTableDto 创建超级表需要的入参的实体类
* @return R
* @MethodDescription 创建超级表
* @author thinglinks
* @Date 2021/12/27 16:26
*/
@PostMapping("/createSTb")
public R createSuperTable(@Validated @RequestBody SuperTableDto superTableDto) {
// 从入参对象获取列字段(超级表结构)对象集合
List<Fields> schemaFields = superTableDto.getSchemaFields();
// 从入参对象获取标签字段对象集合
List<Fields> tagsFields = superTableDto.getTagsFields();
// 从入参获取数据库名称
String databaseName = superTableDto.getDatabaseName();
// 从入参获取超级表名称
String superTableName = superTableDto.getSuperTableName();
// 获取列字段对象集合的第一个对象的字段数据类型
DataTypeEnum dataType = schemaFields.get(0).getDataType();
// 如果该数据类型不是时间戳,打印和返回报错信息
if (dataType == null || !"timestamp".equals(dataType.getDataType())) {
log.error("invalid operation: first column must be timestamp");
return R.fail("invalid operation: the first column must be timestamp");
}
try {
// 将列字段对象集合和标签字段对象集合转码为字段Vo类对象集合
List<FieldsVo> schemaFieldsVoList = FieldsVo.fieldsTranscoding(schemaFields);
List<FieldsVo> tagsFieldsVoList = FieldsVo.fieldsTranscoding(tagsFields);
// 创建超级表
this.tdEngineService.createSuperTable(schemaFieldsVoList, tagsFieldsVoList, databaseName, superTableName);
log.info("successful operation: created superTable '" + superTableName + "' success");
return R.ok();
} catch (UncategorizedSQLException e) {
String message = e.getCause().getMessage();
try {
message = message.substring(message.lastIndexOf("invalid operation"));
} catch (Exception ex) {
}
log.error(message);
return R.fail(message);
} catch (SQLException e) {
log.error(e.getMessage());
return R.fail(e.getMessage());
}
}
use of org.springframework.jdbc.UncategorizedSQLException in project solarnetwork-central by SolarNetwork.
the class MyBatisExceptionTranslator method translateExceptionIfPossible.
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
if (e != null && e.getCause() instanceof DataAccessException) {
// could be something like CannotGetJdbcConnectionException, so use that directly
return (DataAccessException) e.getCause();
}
DataAccessException result = super.translateExceptionIfPossible(e);
if (result instanceof UncategorizedSQLException || result == null) {
SQLException sqlEx = null;
Throwable t = e;
while (t != null && sqlEx == null) {
if (t instanceof SQLException) {
sqlEx = (SQLException) t;
} else if (t instanceof UncategorizedSQLException) {
sqlEx = ((UncategorizedSQLException) t).getSQLException();
}
t = t.getCause();
}
if (sqlEx != null) {
final String sqlState = sqlEx.getSQLState();
final String sqlMessage = sqlEx.getMessage();
if (sqlStateConfigurations == null) {
loadExceptionProperties();
}
final List<SqlStateErrorConfig> configs = (sqlStateConfigurations != null ? sqlStateConfigurations.get(sqlState) : null);
if (configs != null) {
for (SqlStateErrorConfig config : configs) {
if (config.messagePattern.matcher(sqlMessage).find()) {
result = config.type.toException(sqlEx, result);
}
}
}
}
}
return result;
}
Aggregations