@Override public T getOne(ID id) { Assert.notNull(id, ID_MUST_NOT_BE_NULL); return em.getReference(getDomainClass(), id); }
/** * Creates a {@link TypedQuery} for the given {@link Specification} and {@link Sort}. * * @param spec can be {@literal null}. * @param sort must not be {@literal null}. * @return */ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) { return getQuery(spec, getDomainClass(), sort); }
/** * Creates a new count query for the given {@link Specification}. * * @param spec can be {@literal null}. * @return * @deprecated override {@link #getCountQuery(Specification, Class)} instead */ @Deprecated protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) { return getCountQuery(spec, getDomainClass()); }
/** * Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and * {@link Specification}. * * @param query must not be {@literal null}. * @param spec can be {@literal null}. * @param pageable must not be {@literal null}. * @return * @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead */ @Deprecated protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec) { return readPage(query, getDomainClass(), pageable, spec); }
@Override public Optional<T> findById(ID id) { Assert.notNull(id, ID_MUST_NOT_BE_NULL); Class<T> domainType = getDomainClass(); if (metadata == null) { return Optional.ofNullable(em.find(domainType, id)); } LockModeType type = metadata.getLockModeType(); Map<String, Object> hints = getQueryHints().withFetchGraphs(em).asMap(); return Optional.ofNullable(type == null ? em.find(domainType, id, hints) : em.find(domainType, id, type, hints)); }
@Override public long count(@Nullable Specification<T> spec) { return executeCountQuery(getCountQuery(spec, getDomainClass())); }
@Override public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable) { TypedQuery<T> query = getQuery(spec, pageable); return isUnpaged(pageable) ? new PageImpl<T>(query.getResultList()) : readPage(query, getDomainClass(), pageable, spec); }
/** * Creates a new {@link TypedQuery} from the given {@link Specification}. * * @param spec can be {@literal null}. * @param pageable must not be {@literal null}. * @return */ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) { Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted(); return getQuery(spec, getDomainClass(), sort); }
@Override public T getOne(ID id) { Assert.notNull(id, ID_MUST_NOT_BE_NULL); return em.getReference(getDomainClass(), id); }
/** * Creates a new count query for the given {@link Specification}. * * @param spec can be {@literal null}. * @return * @deprecated override {@link #getCountQuery(Specification, Class)} instead */ @Deprecated protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) { return getCountQuery(spec, getDomainClass()); }
/** * Creates a {@link TypedQuery} for the given {@link Specification} and {@link Sort}. * * @param spec can be {@literal null}. * @param sort must not be {@literal null}. * @return */ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) { return getQuery(spec, getDomainClass(), sort); }
/** * Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and * {@link Specification}. * * @param query must not be {@literal null}. * @param spec can be {@literal null}. * @param pageable must not be {@literal null}. * @return * @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead */ @Deprecated protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec) { return readPage(query, getDomainClass(), pageable, spec); }
public Optional<T> findById(ID id) { Assert.notNull(id, ID_MUST_NOT_BE_NULL); Class<T> domainType = getDomainClass(); if (metadata == null) { return Optional.ofNullable(em.find(domainType, id)); } LockModeType type = metadata.getLockModeType(); Map<String, Object> hints = getQueryHints().withFetchGraphs(em).asMap(); return Optional.ofNullable(type == null ? em.find(domainType, id, hints) : em.find(domainType, id, type, hints)); }
public long count(@Nullable Specification<T> spec) { return executeCountQuery(getCountQuery(spec, getDomainClass())); }
public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable) { TypedQuery<T> query = getQuery(spec, pageable); return isUnpaged(pageable) ? new PageImpl<T>(query.getResultList()) : readPage(query, getDomainClass(), pageable, spec); }
/** * Creates a new {@link TypedQuery} from the given {@link Specification}. * * @param spec can be {@literal null}. * @param pageable must not be {@literal null}. * @return */ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) { Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted(); return getQuery(spec, getDomainClass(), sort); }