Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATACMNS-483 - Support for wrapper types as return types for reposito…
…ry methods. The repository method invocation mechanism now post-processes the result of the actual method invocation in case it's not type-compatible with the return type of the invoked method and invokes a conversion if applicable. This allows us to register custom converters for well-known wrapper types. We currently support Optional from both Google Guava and JDK 8. Implementation notice We use some JDK 8 type stubs from the Spring Data Build project to be able to compile using JDKs < 8. This is necessary as we need to remain compatible with Spring 3.2.x for the Dijkstra release train and our test executions still run into some issues with it a Java 8 runtime (mostly ASM related). These issues were reported in [0, 1] and we'll probably get off the hack for Dijkstra GA by upgrading to Spring 3.2.9. [0] https://jira.spring.io/browse/SPR-11719 [1] https://jira.spring.io/browse/SPR-11718
- Loading branch information
Showing
9 changed files
with
368 additions
and
22 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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/springframework/data/repository/util/NullableWrapper.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,58 @@ | ||
/* | ||
* Copyright 2014 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 | ||
* | ||
* http://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.util; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
|
||
/** | ||
* Simple value object to wrap a nullable delegate. Used to be able to write {@link Converter} implementations that | ||
* convert {@literal null} into an object of some sort. | ||
* | ||
* @author Oliver Gierke | ||
* @since 1.8 | ||
* @see QueryExecutionConverters | ||
*/ | ||
public class NullableWrapper { | ||
|
||
private final Object value; | ||
|
||
/** | ||
* Creates a new {@link NullableWrapper} for the given value. | ||
* | ||
* @param value can be {@literal null}. | ||
*/ | ||
public NullableWrapper(Object value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Returns the type of the contained value. WIll fall back to {@link Object} in case the value is {@literal null}. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
public Class<?> getValueType() { | ||
return value == null ? Object.class : value.getClass(); | ||
} | ||
|
||
/** | ||
* Returns the backing valie | ||
* | ||
* @return the value can be {@literal null}. | ||
*/ | ||
public Object getValue() { | ||
return value; | ||
} | ||
} |
Oops, something went wrong.