com.brinvex.util.persistence.api.EntityDaoSupport Maven / Gradle / Ivy
/*
* Copyright © 2023 Brinvex ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.brinvex.util.persistence.api;
import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.From;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.metamodel.SingularAttribute;
import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAccessor;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
public interface EntityDaoSupport {
ENTITY getById(EntityManager em, Class entityType, ID id);
ENTITY getByIdForUpdate(
EntityManager em,
Class entityType,
ID id,
Duration lockTimeout
);
ENTITY getByIdForUpdateSkipLocked(
EntityManager em,
Class entityType,
ID id
);
ENTITY getByIdAndCheckVersion(
EntityManager em,
Class entityType,
ID id,
short optLockVersion,
Function optLockVersionGetter
);
List findByIds(
EntityManager em,
Class entityType,
Collection ids,
SingularAttribute super ENTITY, ID> idAttribute
);
DTO findByIdAsDTO(
EntityManager em,
Class entityType,
ID id,
SingularAttribute super ENTITY, ID> idAttribute,
Class dtoType,
List> constructorParameters
);
ENTITY getReference(
EntityManager em, Class entityType, ID id
);
void persist(EntityManager em, ENTITY entity);
void detach(EntityManager em, ENTITY entity);
void flush(EntityManager em);
void clear(EntityManager em);
void flushAndClear(EntityManager em);
void remove(EntityManager em, ENTITY entity);
int bulkDeleteByIds(
EntityManager em,
Class entityType,
SingularAttribute super ENTITY, ID> idAttribute,
Collection ids
);
Join fetchJoin(From, F> from, SingularAttribute super F, T> attribute);
List getResults(EntityManager em, CriteriaQuery query);
List getResults(EntityManager em, CriteriaQuery query, Integer offset, Integer limit);
List getResults(EntityManager em, CriteriaQuery query, QueryCacheMode queryCacheMode);
List getResults(
EntityManager em,
CriteriaQuery query,
Integer offset,
Integer limit,
QueryCacheMode queryCacheMode
);
CriteriaQuery applySelections(
CriteriaBuilder cb,
CriteriaQuery q,
Class resultType,
Collection> selections
);
long count(
EntityManager em,
CriteriaQuery query,
QueryCacheMode queryCacheMode,
SingularAttribute super ENTITY, ID> idAttribute
);
R getUniqueResult(EntityManager em, CriteriaQuery q);
R getUniqueResult(EntityManager em, CriteriaQuery q, QueryCacheMode queryCacheMode);
R getFirstResult(EntityManager em, CriteriaQuery q);
R getFirstResult(EntityManager em, CriteriaQuery q, Integer offset);
R getFirstResult(EntityManager em, CriteriaQuery q, QueryCacheMode queryCacheMode);
R getFirstResultForUpdate(
EntityManager em,
CriteriaQuery q,
Duration lockTimeout
);
R getFirstResultForUpdateSkipLocked(EntityManager em, CriteriaQuery q);
Predicate asPredicate(
CriteriaBuilder cb,
Expression attribute,
NumberFilter numberFilter
);
Predicate inCollection(
CriteriaBuilder cb,
Expression attribute,
Collection filterItems
);
Predicate betweenLeftInclRightExcl(
CriteriaBuilder cb,
Path leftAttribute, Path rightAttribute, LocalDate testDate
);
Predicate betweenLeftInclRightExcl(
CriteriaBuilder cb,
Path leftAttribute, Path rightAttribute, LocalDateTime testDate
);
Expression sum(
CriteriaBuilder cb,
Expression expression1,
Expression expression2,
Expression expression3
);
Expression least(CriteriaBuilder cb, Integer literal1, Expression expression2);
Expression greatest(CriteriaBuilder cb, Integer literal1, Expression expression2);
Expression day(CriteriaBuilder cb, Expression extends TemporalAccessor> datetimeExpression);
Expression month(CriteriaBuilder cb, Expression extends TemporalAccessor> datetimeExpression);
Expression year(CriteriaBuilder cb, Expression extends TemporalAccessor> datetimeExpression);
Expression epochSeconds(
CriteriaBuilder cb,
Expression extends TemporalAccessor> datetimeExpression
);
Expression dayDiff(
CriteriaBuilder cb,
Expression extends TemporalAccessor> leftDatetimeExpression,
Expression extends TemporalAccessor> rightDatetimeExpression
);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy