DATACMNS-152 - Improved API in mapping subsystem.

PersistentProperty now exposes isEntity(). Mapping context now allows accessing a PersistentEntity referred to from a PersistentProperty. JavaDoc cleanups in MappingContext interface.
This commit is contained in:
Oliver Gierke
2012-04-14 13:27:50 +02:00
parent 67c8c53f5e
commit 81718ae373
4 changed files with 48 additions and 20 deletions

View File

@@ -54,6 +54,14 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
Association<P> getAssociation();
/**
* Returns whether the type of the {@link PersistentProperty} is actually to be regarded as {@link PersistentEntity}
* in turn.
*
* @return
*/
boolean isEntity();
/**
* Returns whether the property is the ID property of the owning {@link PersistentEntity}.
*

View File

@@ -165,6 +165,24 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
return addPersistentEntity(type);
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#getPersistentEntity(org.springframework.data.mapping.PersistentProperty)
*/
public E getPersistentEntity(P persistentProperty) {
if (persistentProperty == null) {
return null;
}
try {
read.lock();
return persistentEntities.get(persistentProperty.getTypeInformation());
} finally {
read.unlock();
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#getPersistentPropertyPath(java.lang.Class, java.lang.String)
@@ -260,7 +278,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
// Inform listeners
if (null != applicationEventPublisher) {
applicationEventPublisher.publishEvent(new MappingContextEvent<E, P>(entity, typeInformation));
applicationEventPublisher.publishEvent(new MappingContextEvent<E, P>(entity));
}
return entity;

View File

@@ -1,4 +1,5 @@
/* Copyright 2004-2005 the original author or authors.
/*
* Copyright 2011-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.
@@ -17,32 +18,20 @@ package org.springframework.data.mapping.context;
import java.util.Collection;
import java.util.List;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.util.TypeInformation;
import org.springframework.validation.Validator;
/**
* <p>
* This interface defines the overall context including all known PersistentEntity instances and methods to obtain
* instances on demand
* </p>
* <p/>
* <p>
* This interface is used internally to establish associations between entities and also at runtime to obtain entities
* by name
* </p>
* <p/>
* <p>
* The generic type parameters T & R are used to specify the mapped form of a class (example Table) and property
* (example Column) respectively.
* </p>
* <p/>
* instances on demand. it is used internally to establish associations between entities and also at runtime to obtain
* entities by name.
*
* @author Graeme Rocher
* @author Jon Brisbin
* @author Oliver Gierke
* @author Jon Brisbin
* @author Graeme Rocher
*/
public interface MappingContext<E extends PersistentEntity<?, P>, P extends PersistentProperty<P>> {
@@ -69,6 +58,15 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
*/
E getPersistentEntity(TypeInformation<?> type);
/**
* Returns the {@link PersistentEntity} mapped by the given {@link PersistentProperty}.
*
* @param persistentProperty
* @return the {@link PersistentEntity} mapped by the given {@link PersistentProperty} or null if no
* {@link PersistentEntity} exists for it or the {@link PersistentProperty} does not refer to an entity.
*/
E getPersistentEntity(P persistentProperty);
/**
* Returns all {@link PersistentProperty}s for the given path expression based on the given {@link PropertyPath}.
*

View File

@@ -175,7 +175,11 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
return getType().isArray();
}
protected boolean isEntity() {
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentProperty#isEntity()
*/
public boolean isEntity() {
TypeInformation<?> actualType = information.getActualType();
boolean isComplexType = actualType == null ? false : !simpleTypeHolder.isSimpleType(actualType.getType());