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
288 additions
and
26 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
70 changes: 70 additions & 0 deletions
70
...-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,70 @@ | ||
/* 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.loader.ast.spi.ReactiveAfterLoadAction; | ||
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.loop; | ||
|
||
/** | ||
* 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)" ); | ||
} | ||
|
||
/** | ||
* Reactive version of {@link org.hibernate.sql.exec.internal.CallbackImpl#invokeAfterLoadActions(Object, EntityMappingType, SharedSessionContractImplementor)} | ||
*/ | ||
public CompletionStage<Void> invokeReactiveLoadActions( | ||
Object entity, | ||
EntityMappingType entityMappingType, | ||
SharedSessionContractImplementor session) { | ||
return loop( | ||
afterLoadActions, afterLoadAction -> | ||
afterLoadAction.reactiveAfterLoad( entity, entityMappingType, session ) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean hasAfterLoadActions() { | ||
return !afterLoadActions.isEmpty(); | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
...ive-core/src/main/java/org/hibernate/reactive/loader/ast/spi/ReactiveAfterLoadAction.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,26 @@ | ||
/* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright: Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.reactive.loader.ast.spi; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
import org.hibernate.metamodel.mapping.EntityMappingType; | ||
|
||
/** | ||
* Reactive version of {@link org.hibernate.loader.ast.spi.AfterLoadAction} | ||
*/ | ||
public interface ReactiveAfterLoadAction { | ||
/** | ||
* @see org.hibernate.loader.ast.spi.AfterLoadAction#afterLoad(Object, EntityMappingType, SharedSessionContractImplementor) | ||
* | ||
* 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
Oops, something went wrong.