|
6 | 6 | package org.hibernate.reactive.persister.entity.mutation;
|
7 | 7 |
|
8 | 8 | import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
|
| 9 | + |
9 | 10 | import java.util.concurrent.CompletionStage;
|
| 11 | + |
10 | 12 | import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
11 | 13 | import org.hibernate.generator.BeforeExecutionGenerator;
|
12 | 14 | import org.hibernate.generator.EventType;
|
|
22 | 24 |
|
23 | 25 | final class GeneratorValueUtil {
|
24 | 26 |
|
25 |
| - private GeneratorValueUtil() { |
26 |
| - } |
27 |
| - |
28 |
| - |
29 |
| - static CompletionStage<?> generateValue( |
30 |
| - SharedSessionContractImplementor session, Object entity, Object currentValue, |
31 |
| - BeforeExecutionGenerator generator, EventType eventType) { |
32 |
| - if (generator instanceof StageGenerator) { |
33 |
| - final Stage.Session stageSession = new StageSessionImpl( (ReactiveSession) session ); |
34 |
| - return ((StageGenerator) generator).generate(stageSession, entity, currentValue, eventType); |
35 |
| - } |
36 |
| - |
37 |
| - if (generator instanceof MutinyGenerator) { |
38 |
| - MutinySessionFactoryImpl mutinyFactory = new MutinySessionFactoryImpl( (SessionFactoryImpl) session.getFactory() ); |
39 |
| - Mutiny.Session mutinySession = new MutinySessionImpl( (ReactiveSession) session, mutinyFactory ); |
40 |
| - return ((MutinyGenerator) generator).generate(mutinySession, entity, currentValue, eventType).subscribeAsCompletionStage(); |
41 |
| - } |
42 |
| - |
43 |
| - |
44 |
| - // We should throw an exception, but I don't want to break things for people using @CreationTimestamp or similar |
45 |
| - // annotations. We need an alternative for Hibernate Reactive. |
46 |
| - return completedFuture( generator.generate( session, entity, currentValue, eventType) ); |
47 |
| - } |
| 27 | + private GeneratorValueUtil() { |
| 28 | + } |
| 29 | + |
| 30 | + static CompletionStage<?> generateValue( |
| 31 | + SharedSessionContractImplementor session, Object entity, Object currentValue, |
| 32 | + BeforeExecutionGenerator generator, EventType eventType) { |
| 33 | + if ( generator instanceof StageGenerator ) { |
| 34 | + final Stage.Session stageSession = new StageSessionImpl( (ReactiveSession) session ); |
| 35 | + return ( (StageGenerator) generator ).generate( stageSession, entity, currentValue, eventType ); |
| 36 | + } |
| 37 | + |
| 38 | + if ( generator instanceof MutinyGenerator ) { |
| 39 | + MutinySessionFactoryImpl mutinyFactory = new MutinySessionFactoryImpl( (SessionFactoryImpl) session.getFactory() ); |
| 40 | + Mutiny.Session mutinySession = new MutinySessionImpl( (ReactiveSession) session, mutinyFactory ); |
| 41 | + return ( (MutinyGenerator) generator ).generate( mutinySession, entity, currentValue, eventType ) |
| 42 | + .subscribeAsCompletionStage(); |
| 43 | + } |
| 44 | + |
| 45 | + // We should throw an exception, but I don't want to break things for people using @CreationTimestamp or similar |
| 46 | + // annotations. We need an alternative for Hibernate Reactive. |
| 47 | + return completedFuture( generator.generate( session, entity, currentValue, eventType ) ); |
| 48 | + } |
48 | 49 | }
|
0 commit comments