DefaultBaseDao.java 文件源码

java
阅读 45 收藏 0 点赞 0 评论 0

项目:minijax 作者:
/**
 * Converts a JPA rollback exception into a conflict exception.
 *
 * @param ex The database rollback exception.
 * @return A structured key/value conflict exception.
 */
private static ConflictException convertRollbackToConflict(final PersistenceException ex) {
    final List<Pattern> patterns = Arrays.asList(
            Pattern.compile("Duplicate entry '(?<value>[^']+)' for key '(?<key>[^']+)'"),
            Pattern.compile("CONSTRAINT_INDEX_[a-zA-Z0-9_]+ ON PUBLIC\\.[a-zA-Z]+\\((?<key>[a-zA-Z]+)\\) VALUES \\('(?<value>[^']+)'"));

    for (final Pattern pattern : patterns) {
        final Matcher matcher = pattern.matcher(ex.getMessage());
        if (matcher.find()) {
            final String key = matcher.group("key").toLowerCase();
            final String value = matcher.group("value");
            return new ConflictException(key, value);
        }
    }

    LOG.warn("Unrecognized RollbackException: {}", ex.getMessage(), ex);
    throw ex;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号