Skip to content

Create QueryProducer interface for Stage and Mutiny #2130

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

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

DavideD
Copy link
Member

@DavideD DavideD commented Feb 19, 2025

A first draft of the shared session contract. I've basically collected the methods we already have in both sessions.

See Mutiny.SharedSessionContract (or Stage.SharedSessionContract).
Personally, I like knowing which methods are not specific to a session.

@DavideD DavideD requested review from FroMage and gavinking February 19, 2025 17:20
@gavinking
Copy link
Member

SharedSessionContract is not a good name, so before anything else, an acceptable name needs to be found.

@gavinking
Copy link
Member

Also, please don't move fetch() up. It has different semantics between the two kinds of session.

@gavinking
Copy link
Member

Also not sure it's a good idea to move batchFetchSize onto StatelessSession. That was left off deliberately.

@DavideD
Copy link
Member Author

DavideD commented Feb 20, 2025

OK, I'm going to revert back the fetch and getBatchFetchSize().

@DavideD DavideD force-pushed the 2104-common-shared-contract branch from d1d85a2 to 2e42d90 Compare February 20, 2025 09:52
@DavideD
Copy link
Member Author

DavideD commented Feb 20, 2025

OK, I'm going to revert back the fetch and getBatchFetchSize().

Done

@DavideD
Copy link
Member Author

DavideD commented Feb 20, 2025

By the way, why do we have .persist(Object) and .persist(Object...). Isn't the second one enough?

*
* @throws IllegalArgumentException if the given instance is not managed
* @see org.hibernate.Hibernate#unproxy(Object)

Check notice

Code scanning / CodeQL

Confusing overloading of methods Note

Method Session.refresh(..) could be confused with overloaded method
refresh
, since dispatch depends on static types.
@gavinking
Copy link
Member

By the way, why do we have .persist(Object) and .persist(Object...). Isn't the second one enough?

Just avoids an array instantiation in the overwhelmingly more common case that you're only passing one entity. That's unlikely to be a huge overhead, but the overload doesn't cause any problems that I'm aware of.

@DavideD DavideD changed the title Share session contract Shared session contract Feb 20, 2025
@DavideD
Copy link
Member Author

DavideD commented Apr 23, 2025

Should I close this PR or are we going to merge it if the shared contract has a different name?

@gavinking
Copy link
Member

I think if it were called QueryProducer, and had only query-related operations, then I would like it a whole lot more.

@DavideD DavideD force-pushed the 2104-common-shared-contract branch from 2e42d90 to c9057e6 Compare April 30, 2025 13:00
@DavideD
Copy link
Member Author

DavideD commented Apr 30, 2025

I've renamed the interface QueryReproducer, and I've included the following method:

<R> SelectionQuery<R> createSelectionQuery(String queryString, Class<R> resultType);
<R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference);
MutationQuery createMutationQuery(String queryString);
MutationQuery createMutationQuery(CriteriaUpdate<?> updateQuery);
MutationQuery createMutationQuery(CriteriaDelete<?> deleteQuery);
MutationQuery createMutationQuery(JpaCriteriaInsert<?> insert);
<R> Query<R> createQuery(String queryString);
<R> SelectionQuery<R> createQuery(String queryString, Class<R> resultType);
<R> SelectionQuery<R> createQuery(CriteriaQuery<R> criteriaQuery);
<R> MutationQuery createQuery(CriteriaUpdate<R> criteriaUpdate);
<R> MutationQuery createQuery(CriteriaDelete<R> criteriaDelete);
<R> Query<R> createNamedQuery(String queryName);
<R> SelectionQuery<R> createNamedQuery(String queryName, Class<R> resultType);
<R> Query<R> createNativeQuery(String queryString);
<R> Query<R> createNativeQuery(String queryString, AffectedEntities affectedEntities);
<R> SelectionQuery<R> createNativeQuery(String queryString, Class<R> resultType);
<R> SelectionQuery<R> createNativeQuery(String queryString, Class<R> resultType, AffectedEntities affectedEntities);
<R> SelectionQuery<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping);
<R> SelectionQuery<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping, AffectedEntities affectedEntities);
CriteriaBuilder getCriteriaBuilder();

<T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName);
<T> EntityGraph<T> createEntityGraph(Class<T> rootType);
<T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName);

Object getIdentifier(Object entity);
<T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName);
<T> Uni<T> unproxy(T association);

@gavinking
Copy link
Member

Object getIdentifier(Object entity);

Let's not pull this one up, it's nothing to do with queries, and in ORM it's not pulled up because it has different semantics between Session and StatelessSession.

<T> Uni<T> unproxy(T association);

Why pull up unproxy() but not fetch()?

Copy link
Contributor

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@DavideD DavideD force-pushed the 2104-common-shared-contract branch 2 times, most recently from 81e50ef to 65098e6 Compare April 30, 2025 15:27
@DavideD DavideD force-pushed the 2104-common-shared-contract branch from 65098e6 to e43220e Compare April 30, 2025 15:37
@DavideD
Copy link
Member Author

DavideD commented Apr 30, 2025

Why pull up unproxy() but not fetch()?

I removed them from QueryProducer and left them where they are now

@DavideD DavideD added this to the 3.0.0.CR1 milestone Apr 30, 2025
@DavideD DavideD marked this pull request as ready for review April 30, 2025 15:59
@DavideD
Copy link
Member Author

DavideD commented Apr 30, 2025

@gavinking I think we can merge it now, but can you give it another look and let me know if there's more to change, please?

@DavideD
Copy link
Member Author

DavideD commented Apr 30, 2025

If anything, this should be at least a good starting point

@gavinking
Copy link
Member

Fine, I mean the diff is utterly unreadable, so it's pretty hard to give much feedback.

@DavideD DavideD merged commit 41506a4 into hibernate:main Apr 30, 2025
18 checks passed
@DavideD
Copy link
Member Author

DavideD commented Apr 30, 2025

Merged, thanks!

@DavideD DavideD changed the title Shared session contract Create QueryProducer interface for Stage and Mutiny Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants