GenericDaoBase.java 文件源码

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

项目:cosmic 作者:
protected T findById(final ID id, final boolean removed, final Boolean lock) {
    final StringBuilder sql = new StringBuilder(_selectByIdSql);
    if (!removed && _removed != null) {
        sql.append(" AND ").append(_removed.first());
    }
    if (lock != null) {
        sql.append(lock ? FOR_UPDATE_CLAUSE : SHARE_MODE_CLAUSE);
    }
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        pstmt = txn.prepareAutoCloseStatement(sql.toString());

        if (_idField.getAnnotation(EmbeddedId.class) == null) {
            prepareAttribute(1, pstmt, _idAttributes.get(_table)[0], id);
        }

        final ResultSet rs = pstmt.executeQuery();
        return rs.next() ? toEntityBean(rs, true) : null;
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + pstmt, e);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号