forked from hibernate/hibernate-reactive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hibernate#1905] Reactive find with lock in Quarkus with reactive hib…
…ernate
- Loading branch information
Showing
15 changed files
with
298 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveCallbackImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright: Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.reactive.engine.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
import org.hibernate.loader.ast.spi.AfterLoadAction; | ||
import org.hibernate.metamodel.mapping.EntityMappingType; | ||
import org.hibernate.reactive.logging.impl.Log; | ||
import org.hibernate.sql.exec.spi.Callback; | ||
|
||
import static java.lang.invoke.MethodHandles.lookup; | ||
import static org.hibernate.reactive.logging.impl.LoggerFactory.make; | ||
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture; | ||
|
||
/** | ||
* Reactive equivalent of {@link org.hibernate.sql.exec.internal.CallbackImpl} | ||
*/ | ||
public class ReactiveCallbackImpl implements Callback { | ||
private static final Log LOG = make( Log.class, lookup() ); | ||
|
||
private final List<ReactiveAfterLoadAction> afterLoadActions; | ||
|
||
public ReactiveCallbackImpl() { | ||
this.afterLoadActions = new ArrayList<>( 1 ); | ||
} | ||
|
||
@Override | ||
public void registerAfterLoadAction(AfterLoadAction afterLoadAction) { | ||
throw LOG.nonReactiveMethodCall( "registerReactiveAfterLoadAction(ReactiveCallbackImpl)" ); | ||
} | ||
|
||
public void registerReactiveAfterLoadAction(ReactiveAfterLoadAction afterLoadAction) { | ||
afterLoadActions.add( afterLoadAction ); | ||
} | ||
|
||
@Override | ||
public void invokeAfterLoadActions( | ||
Object entity, | ||
EntityMappingType entityMappingType, | ||
SharedSessionContractImplementor session) { | ||
throw LOG.nonReactiveMethodCall( "invokeAfterLoadActions(Object, EntityMappingType, SharedSessionContractImplementor)" ); | ||
} | ||
|
||
public CompletionStage<Void> invokeReactiveLoadActions( | ||
Object entity, | ||
EntityMappingType entityMappingType, | ||
SharedSessionContractImplementor session) { | ||
for ( int i = 0; i < afterLoadActions.size(); i++ ) { | ||
afterLoadActions.get( i ).reactiveAfterLoad( entity, entityMappingType, session ); | ||
} | ||
return voidFuture(); | ||
} | ||
|
||
@Override | ||
public boolean hasAfterLoadActions() { | ||
return !afterLoadActions.isEmpty(); | ||
} | ||
|
||
public interface ReactiveAfterLoadAction { | ||
/** | ||
* The action trigger - the {@code entity} is being loaded | ||
*/ | ||
CompletionStage<Void> reactiveAfterLoad(Object entity, EntityMappingType entityMappingType, SharedSessionContractImplementor session); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.