-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATACMNS-172 - Improved handling of invalid PropertyPaths.
Introduced PropertyReferenceException to capture the invalid property and the base PropertyPath a property expression could be resolved into. Introduced getLeafProperty() to be able to access the leaf property of a property path being created.
- Loading branch information
Showing
3 changed files
with
219 additions
and
45 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
87 changes: 87 additions & 0 deletions
87
...mmons-core/src/main/java/org/springframework/data/mapping/PropertyReferenceException.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,87 @@ | ||
/* | ||
* Copyright 2012 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.mapping; | ||
|
||
import org.springframework.data.util.TypeInformation; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* Exception being thrown when creating {@link PropertyPath} instances. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
public class PropertyReferenceException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -5254424051438976570L; | ||
private static final String ERROR_TEMPLATE = "No property %s found for type %s"; | ||
|
||
private final String propertyName; | ||
private final TypeInformation<?> type; | ||
private final PropertyPath base; | ||
|
||
/** | ||
* Creates a new {@link PropertyReferenceException}. | ||
* | ||
* @param propertyName the name of the property not found on the given type. | ||
* @param type the type the property could not be found on. | ||
* @param base the base {@link PropertyPath}. | ||
*/ | ||
public PropertyReferenceException(String propertyName, TypeInformation<?> type, PropertyPath base) { | ||
|
||
Assert.hasText(propertyName); | ||
Assert.notNull(type); | ||
|
||
this.propertyName = propertyName; | ||
this.type = type; | ||
this.base = base; | ||
} | ||
|
||
/** | ||
* Returns the name of the property not found. | ||
* | ||
* @return will not be {@literal null} or empty. | ||
*/ | ||
public String getPropertyName() { | ||
return propertyName; | ||
} | ||
|
||
/** | ||
* Returns the type the property could not be found on. | ||
* | ||
* @return the type | ||
*/ | ||
public TypeInformation<?> getType() { | ||
return type; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see java.lang.Throwable#getMessage() | ||
*/ | ||
@Override | ||
public String getMessage() { | ||
return String.format(ERROR_TEMPLATE, propertyName, type.getType().getName()); | ||
} | ||
|
||
/** | ||
* Returns the {@link PropertyPath} which could be resolved so far. | ||
* | ||
* @return | ||
*/ | ||
public PropertyPath getBaseProperty() { | ||
return base; | ||
} | ||
} |
Oops, something went wrong.