-
Notifications
You must be signed in to change notification settings - Fork 63
Hibernate 6 movement with dropwizard 2 #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: hibernate6
Are you sure you want to change the base?
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,15 @@ | ||
| package io.appform.dropwizard.sharding.dao; | ||
|
|
||
| import io.dropwizard.util.Generics; | ||
| import org.hibernate.Criteria; | ||
| import jakarta.persistence.criteria.CriteriaQuery; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.hibernate.Hibernate; | ||
| import org.hibernate.HibernateException; | ||
| import org.hibernate.NonUniqueResultException; | ||
| import org.hibernate.Session; | ||
| import org.hibernate.SessionFactory; | ||
| import org.hibernate.query.Query; | ||
| import org.hibernate.query.internal.AbstractProducedQuery; | ||
|
|
||
| import javax.persistence.criteria.CriteriaQuery; | ||
| import java.io.Serializable; | ||
| import java.util.List; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
@@ -43,18 +42,6 @@ protected Session currentSession() { | |
| return sessionFactory.getCurrentSession(); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class was copied from dropwizard hibernate package into this repo. Let's check dropwizard-hibernate module for 5.x and see if anything else should be added/removed from here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No major changes apart from import changes + movement from Serilizable to Object for id lookup |
||
| /** | ||
| * Creates a new {@link Criteria} query for {@code <E>}. | ||
| * | ||
| * @return a new {@link Criteria} query | ||
| * @see Session#createCriteria(Class) | ||
| * @deprecated Use {@link AbstractDAO#criteriaQuery()} instead. | ||
| */ | ||
| @Deprecated | ||
| protected Criteria criteria() { | ||
| return currentSession().createCriteria(entityClass); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link CriteriaQuery} for {@code <E>}. | ||
| * | ||
|
|
@@ -116,25 +103,22 @@ public Class<E> getEntityClass() { | |
| * @throws HibernateException if there is more than one matching result | ||
| */ | ||
| protected E uniqueResult(CriteriaQuery<E> criteriaQuery) throws HibernateException { | ||
| return AbstractProducedQuery.uniqueElement( | ||
| return uniqueElement( | ||
| currentSession() | ||
| .createQuery(requireNonNull(criteriaQuery)) | ||
| .getResultList() | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Convenience method to return a single instance that matches the criteria, or null if the | ||
| * criteria returns no results. | ||
| * | ||
| * @param criteria the {@link Criteria} query to run | ||
| * @return the single result or {@code null} | ||
| * @throws HibernateException if there is more than one matching result | ||
| * @see Criteria#uniqueResult() | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| protected E uniqueResult(Criteria criteria) throws HibernateException { | ||
| return (E) requireNonNull(criteria).uniqueResult(); | ||
| private static <T> @Nullable T uniqueElement(List<T> list) throws NonUniqueResultException { | ||
| if (list.isEmpty()) { | ||
| return null; | ||
| } | ||
| final T head = list.get(0); | ||
| if (list.stream().anyMatch(element -> element != head)) { | ||
| throw new NonUniqueResultException(list.size()); | ||
| } | ||
| return head; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -150,18 +134,6 @@ protected E uniqueResult(Query<E> query) throws HibernateException { | |
| return requireNonNull(query).uniqueResult(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the results of a {@link Criteria} query. | ||
| * | ||
| * @param criteria the {@link Criteria} query to run | ||
| * @return the list of matched query results | ||
| * @see Criteria#list() | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| protected List<E> list(Criteria criteria) throws HibernateException { | ||
| return requireNonNull(criteria).list(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the results of a {@link CriteriaQuery} query. | ||
| * | ||
|
|
@@ -191,10 +163,10 @@ protected List<E> list(Query<E> query) throws HibernateException { | |
| * @param id an identifier | ||
| * @return a persistent instance or {@code null} | ||
| * @throws HibernateException | ||
| * @see Session#get(Class, Serializable) | ||
| * @see Session#get(Class, Object) | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| protected E get(Serializable id) { | ||
| protected E get(Object id) { | ||
| return (E) currentSession().get(entityClass, requireNonNull(id)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r0goyal please suggest on naming convention of release version..will update accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use this 2.1.12-HIBERNATE6-RC0