-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
RepositoryMethodContext
to repository.core
package.
RepositoryMethodContext are now made available for dependency injection via RepositoryConfigurationExtensionSupport.registerBeansForRoot(…). Moved RMC into repository.core package (previously repository.core.support) and only expose factory methods on DefaultRepositoryMethodContext. DRMC also exposes a injection proxy lookup method that creates a proxy equipped with a TargetSource delegating to DRMC.getInstance() (previously ….getContext()). An additional, static DRMC.forMethod(…) allows the creation of a default instance for testing purposes. Rename getRepository() to getMetadata() on RMC. Fixes GH-3175.
- Loading branch information
Showing
8 changed files
with
207 additions
and
108 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
56 changes: 56 additions & 0 deletions
56
src/main/java/org/springframework/data/repository/core/RepositoryMethodContext.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,56 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.repository.core; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Interface containing methods and value objects to obtain information about the current repository method invocation. | ||
* <p> | ||
* The {@link #currentMethod()} method is usable if the repository factory is configured to expose the current | ||
* repository method metadata (not the default). It returns the invoked repository method. Target objects or advice can | ||
* use this to make advised calls. | ||
* <p> | ||
* Spring Data's framework does not expose method metadata by default, as there is a performance cost in doing so. | ||
* <p> | ||
* The functionality in this class might be used by a target object that needed access to resources on the invocation. | ||
* However, this approach should not be used when there is a reasonable alternative, as it makes application code | ||
* dependent on usage in particular. | ||
* | ||
* @author Christoph Strobl | ||
* @author Mark Paluch | ||
* @author Oliver Drotbohm | ||
* @since 3.4.0 | ||
*/ | ||
public interface RepositoryMethodContext { | ||
|
||
/** | ||
* Returns the metadata for the repository. | ||
* | ||
* @return the repository metadata, will never be {@literal null}. | ||
*/ | ||
RepositoryMetadata getMetadata(); | ||
|
||
/** | ||
* Returns the current method that is being invoked. | ||
* <p> | ||
* The method object represents the method as being invoked on the repository interface. It doesn't match the backing | ||
* repository implementation in case the method invocation is delegated to an implementation method. | ||
* | ||
* @return the current method, will never be {@literal null}.. | ||
*/ | ||
Method getMethod(); | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...main/java/org/springframework/data/repository/core/support/DynamicLookupTargetSource.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,79 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.repository.core.support; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.springframework.aop.TargetSource; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* A {@link TargetSource}, that will re-obtain an instance using the configured supplier. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 3.4.0 | ||
*/ | ||
class DynamicLookupTargetSource<T> implements TargetSource { | ||
|
||
private final Class<T> type; | ||
private final Supplier<? extends T> supplier; | ||
|
||
/** | ||
* Creates a new {@link DynamicLookupTargetSource} for the given type and {@link Supplier}. | ||
* | ||
* @param type must not be {@literal null}. | ||
* @param supplier must not be {@literal null}. | ||
*/ | ||
public DynamicLookupTargetSource(Class<T> type, Supplier<? extends T> supplier) { | ||
|
||
Assert.notNull(type, "Type must not be null!"); | ||
Assert.notNull(supplier, "Supplier must not be null!"); | ||
|
||
this.type = type; | ||
this.supplier = supplier; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.aop.TargetSource#isStatic() | ||
*/ | ||
@Override | ||
public boolean isStatic() { | ||
return false; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.aop.TargetSource#getTarget() | ||
*/ | ||
@Override | ||
@Nullable | ||
public Object getTarget() throws Exception { | ||
return supplier.get(); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.aop.TargetSource#getTargetClass() | ||
*/ | ||
@Override | ||
@NonNull | ||
public Class<?> getTargetClass() { | ||
return type; | ||
} | ||
} |
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
94 changes: 0 additions & 94 deletions
94
src/main/java/org/springframework/data/repository/core/support/RepositoryMethodContext.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.