Skip to content

Commit

Permalink
two fixes to Session API
Browse files Browse the repository at this point in the history
1. add Session.getFactory() and StatelessSession.getFactory()
2. fix the signature of mergeAll()
  • Loading branch information
gavinking committed Jul 11, 2023
1 parent 924c829 commit de384b2
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ default <T> Uni<T> find(Class<T> entityClass, Object id, LockModeType lockModeTy
*
* @see #merge(Object)
*/
<T> Uni<Void> mergeAll(T... entities);
Uni<Void> mergeAll(Object... entities);

/**
* Re-read the state of the given instance from the underlying database.
Expand Down Expand Up @@ -1352,6 +1352,11 @@ default Session setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {
* @return false if {@link #close()} has been called
*/
boolean isOpen();

/**
* The {@link SessionFactory} which created this session.
*/
SessionFactory getFactory();
}

/**
Expand Down Expand Up @@ -1755,6 +1760,11 @@ default Uni<Void> refresh(Object entity, LockModeType lockModeType) {
* connection.
*/
Uni<Void> close();

/**
* The {@link SessionFactory} which created this session.
*/
SessionFactory getFactory();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ public <T> Uni<T> merge(T entity) {
}

@Override
@SafeVarargs
public final <T> Uni<Void> mergeAll(T... entity) {
public final Uni<Void> mergeAll(Object... entity) {
return uni( () -> applyToAll( delegate::reactiveMerge, entity ) );
}

Expand Down Expand Up @@ -523,6 +522,11 @@ public boolean isOpen() {
return delegate.isOpen();
}

@Override
public Mutiny.SessionFactory getFactory() {
return factory;
}

@Override
public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName) {
return delegate.getResultSetMapping( resultType, mappingName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public boolean isOpen() {
return delegate.isOpen();
}

@Override
public MutinySessionFactoryImpl getFactory() {
return factory;
}

@Override
public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName) {
return delegate.getResultSetMapping( resultType, mappingName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ default <T> CompletionStage<T> find(Class<T> entityClass, Object id, LockModeTyp
*
* @see #merge(Object)
*/
<T> CompletionStage<Void> merge(T... entities);
CompletionStage<Void> merge(Object... entities);

/**
* Re-read the state of the given instance from the underlying database.
Expand Down Expand Up @@ -1390,6 +1390,11 @@ default Session setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {
* @return false if {@link #close()} has been called
*/
boolean isOpen();

/**
* The {@link SessionFactory} which created this session.
*/
SessionFactory getFactory();
}

/**
Expand Down Expand Up @@ -1802,6 +1807,11 @@ default CompletionStage<Void> refresh(Object entity, LockModeType lockModeType)
* connection.
*/
CompletionStage<Void> close();

/**
* The {@link SessionFactory} which created this session.
*/
SessionFactory getFactory();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public <T> CompletionStage<T> merge(T entity) {
return delegate.reactiveMerge( entity );
}

@Override @SafeVarargs
public final <T> CompletionStage<Void> merge(T... entity) {
@Override
public final CompletionStage<Void> merge(Object... entity) {
return applyToAll( delegate::reactiveMerge, entity );
}

Expand Down Expand Up @@ -460,6 +460,11 @@ public boolean isOpen() {
return delegate.isOpen();
}

@Override
public Stage.SessionFactory getFactory() {
return delegate.getFactory().unwrap( Stage.SessionFactory.class );
}

@Override
public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName) {
return delegate.getResultSetMapping( resultType, mappingName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public boolean isOpen() {
return delegate.isOpen();
}

@Override
public Stage.SessionFactory getFactory() {
return delegate.getFactory().unwrap( Stage.SessionFactory.class );
}

private Transaction<?> currentTransaction;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ public void reactiveClose(VertxTestContext context) {
);
}

@Test void testFactory(VertxTestContext context) {
test( context, getMutinySessionFactory().withSession( session -> {
session.getFactory().getCache().evictAll();
session.getFactory().getMetamodel().entity(GuineaPig.class);
session.getFactory().getCriteriaBuilder().createQuery(GuineaPig.class);
session.getFactory().getStatistics().isStatisticsEnabled();
return Uni.createFrom().voidItem();
} ) );
}

@Test
public void testMetamodel() {
EntityType<GuineaPig> pig = getSessionFactory().getMetamodel().entity(GuineaPig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.reactive.common.AffectedEntities;
import org.hibernate.reactive.stage.Stage;

import org.hibernate.reactive.util.impl.CompletionStages;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -770,6 +771,16 @@ public void testMetamodel() {
assertEquals( "GuineaPig", pig.getName() );
}

@Test void testFactory(VertxTestContext context) {
test( context, getSessionFactory().withSession( session -> {
session.getFactory().getCache().evictAll();
session.getFactory().getMetamodel().entity(GuineaPig.class);
session.getFactory().getCriteriaBuilder().createQuery(GuineaPig.class);
session.getFactory().getStatistics().isStatisticsEnabled();
return CompletionStages.voidFuture();
} ) );
}

@Test
public void testTransactionPropagation(VertxTestContext context) {
test( context, getSessionFactory().withTransaction(
Expand Down

0 comments on commit de384b2

Please sign in to comment.