DATACMNS-401 - Some cleanups regarding generics and deprecations.

Suppress deprecation warnings for GenericTypeResolver for now. Added Simple(Property|Association)Handler to ease working with untyped PersistentProperty instances without having to fall back to raw types. Polished Sonargraph architecture description.
This commit is contained in:
Oliver Gierke
2013-11-13 22:27:58 +00:00
parent fed61720b0
commit c0fc0f905a
9 changed files with 109 additions and 6 deletions

View File

@@ -140,10 +140,14 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> {
*/
void doWithProperties(PropertyHandler<P> handler);
void doWithProperties(SimplePropertyHandler handler);
/**
* Applies the given {@link AssociationHandler} to all {@link Association} contained in this {@link PersistentEntity}.
*
* @param handler must not be {@literal null}.
*/
void doWithAssociations(AssociationHandler<P> handler);
void doWithAssociations(SimpleAssociationHandler handler);
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2013 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;
/**
* Association handler to work with the untyped {@link PersistentProperty} based {@link Association}.
*
* @author Oliver Gierke
* @see PropertyHandler
*/
public interface SimpleAssociationHandler {
/**
* Handle the given {@link Association}.
*
* @param association will never be {@literal null}.
*/
void doWithAssociation(Association<? extends PersistentProperty<?>> association);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2013 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;
/**
* A property handler to work with untyped {@link PersistentProperty} instances.
*
* @author Oliver Gierke
*/
public interface SimplePropertyHandler {
/**
* Handle the given {@link PersistentProperty}.
*
* @param property will never be {@literal null}.
*/
void doWithPersistentProperty(PersistentProperty<?> property);
}

View File

@@ -30,6 +30,8 @@ import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -251,7 +253,9 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
* @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler)
*/
public void doWithProperties(PropertyHandler<P> handler) {
Assert.notNull(handler);
for (P property : properties) {
if (!property.isTransient() && !property.isAssociation()) {
handler.doWithPersistentProperty(property);
@@ -259,17 +263,48 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler.Simple)
*/
@Override
public void doWithProperties(SimplePropertyHandler handler) {
Assert.notNull(handler);
for (PersistentProperty<?> property : properties) {
if (!property.isTransient() && !property.isAssociation()) {
handler.doWithPersistentProperty(property);
}
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#doWithAssociations(org.springframework.data.mapping.AssociationHandler)
*/
public void doWithAssociations(AssociationHandler<P> handler) {
Assert.notNull(handler);
for (Association<P> association : associations) {
handler.doWithAssociation(association);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#doWithAssociations(org.springframework.data.mapping.SimpleAssociationHandler)
*/
public void doWithAssociations(SimpleAssociationHandler handler) {
Assert.notNull(handler);
for (Association<? extends PersistentProperty<?>> association : associations) {
handler.doWithAssociation(association);
}
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.MutablePersistentEntity#verify()
*/