remove two default impls that threw UnsupportedOperationException

added some links in Javadoc

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-21 21:37:59 +02:00
parent 0f35a7d14c
commit 1b00f690ce
3 changed files with 28 additions and 12 deletions

View File

@ -235,6 +235,9 @@ public interface SessionFactory extends EntityManagerFactory, Referenceable, Ser
/** /**
* Open a {@link Session} and use it to perform an action * Open a {@link Session} and use it to perform an action
* within the bounds of a transaction. * within the bounds of a transaction.
*
* @apiNote This method competes with the JPA-defined method
* {@link #runInTransaction}
*/ */
default void inTransaction(Consumer<Session> action) { default void inTransaction(Consumer<Session> action) {
inSession( session -> manageTransaction( session, session.beginTransaction(), action ) ); inSession( session -> manageTransaction( session, session.beginTransaction(), action ) );
@ -273,6 +276,9 @@ public interface SessionFactory extends EntityManagerFactory, Referenceable, Ser
/** /**
* Open a {@link Session} and use it to obtain a value * Open a {@link Session} and use it to obtain a value
* within the bounds of a transaction. * within the bounds of a transaction.
*
* @apiNote This method competes with the JPA-defined method
* {@link #callInTransaction}
*/ */
default <R> R fromTransaction(Function<Session,R> action) { default <R> R fromTransaction(Function<Session,R> action) {
return fromSession( session -> manageTransaction( session, session.beginTransaction(), action ) ); return fromSession( session -> manageTransaction( session, session.beginTransaction(), action ) );

View File

@ -22,9 +22,12 @@ import org.hibernate.query.criteria.HibernateCriteriaBuilder;
*/ */
public interface SharedSessionContract extends QueryProducer, AutoCloseable, Serializable { public interface SharedSessionContract extends QueryProducer, AutoCloseable, Serializable {
/** /**
* Obtain the tenant identifier associated with this session. * Obtain the tenant identifier associated with this session, as a string.
* *
* @return The tenant identifier associated with this session, or {@code null} * @return The tenant identifier associated with this session, or {@code null}
*
* @see org.hibernate.context.spi.CurrentTenantIdentifierResolver
* @see SessionBuilder#tenantIdentifier(Object)
*/ */
String getTenantIdentifier(); String getTenantIdentifier();
@ -33,6 +36,9 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* *
* @return The tenant identifier associated with this session, or {@code null} * @return The tenant identifier associated with this session, or {@code null}
* @since 6.4 * @since 6.4
*
* @see org.hibernate.context.spi.CurrentTenantIdentifierResolver
* @see SessionBuilder#tenantIdentifier(Object)
*/ */
Object getTenantIdentifierValue(); Object getTenantIdentifierValue();
@ -41,19 +47,20 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* *
* @throws HibernateException Indicates problems cleaning up. * @throws HibernateException Indicates problems cleaning up.
*/ */
@Override
void close() throws HibernateException; void close() throws HibernateException;
/** /**
* Check if the session is still open. * Check if the session is still open.
* *
* @return boolean * @return {@code true} if it is open
*/ */
boolean isOpen(); boolean isOpen();
/** /**
* Check if the session is currently connected. * Check if the session is currently connected.
* *
* @return boolean * @return {@code true} if it is connected
*/ */
boolean isConnected(); boolean isConnected();
@ -62,16 +69,18 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* If a new underlying transaction is required, begin the transaction. Otherwise, * If a new underlying transaction is required, begin the transaction. Otherwise,
* continue the new work in the context of the existing underlying transaction. * continue the new work in the context of the existing underlying transaction.
* *
* @return a {@link Transaction} instance * @return an instance of {@link Transaction} representing the new transaction
* *
* @see #getTransaction() * @see #getTransaction()
* @see Transaction#begin()
*/ */
Transaction beginTransaction(); Transaction beginTransaction();
/** /**
* Get the {@link Transaction} instance associated with this session. * Get the {@link Transaction} instance associated with this session.
* *
* @return a Transaction instance * @return an instance of {@link Transaction} representing the transaction
* associated with this session
* *
* @see jakarta.persistence.EntityManager#getTransaction() * @see jakarta.persistence.EntityManager#getTransaction()
*/ */
@ -228,10 +237,11 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* @param work The work to be performed. * @param work The work to be performed.
* *
* @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException} * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException}
*
* @apiNote This method competes with the JPA-defined method
* {@link jakarta.persistence.EntityManager#runWithConnection}
*/ */
default void doWork(Work work) throws HibernateException { void doWork(Work work) throws HibernateException;
throw new UnsupportedOperationException();
}
/** /**
* Perform work using the {@link java.sql.Connection} underlying by this session, * Perform work using the {@link java.sql.Connection} underlying by this session,
@ -243,10 +253,11 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* @return the result of calling {@link ReturningWork#execute}. * @return the result of calling {@link ReturningWork#execute}.
* *
* @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException} * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException}
*
* @apiNote This method competes with the JPA-defined method
* {@link jakarta.persistence.EntityManager#callWithConnection}
*/ */
default <T> T doReturningWork(ReturningWork<T> work) throws HibernateException { <T> T doReturningWork(ReturningWork<T> work);
throw new UnsupportedOperationException();
}
/** /**
* Create a new mutable {@link EntityGraph} with only a root node. * Create a new mutable {@link EntityGraph} with only a root node.

View File

@ -24,7 +24,6 @@ import org.hibernate.generator.Generator;
import org.hibernate.generator.OnExecutionGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.values.GeneratedValues; import org.hibernate.generator.values.GeneratedValues;
import org.hibernate.generator.values.GeneratedValuesMutationDelegate; import org.hibernate.generator.values.GeneratedValuesMutationDelegate;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMappingsList; import org.hibernate.metamodel.mapping.AttributeMappingsList;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;